mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Packed Encoding: Disallow types in v2 that aren't allowed in v1
This commit is contained in:
committed by
chriseth
parent
227addfcef
commit
fe2429de9f
@@ -48,9 +48,9 @@ using namespace dev::solidity;
|
||||
namespace
|
||||
{
|
||||
|
||||
bool typeSupportedByOldABIEncoder(Type const& _type)
|
||||
bool typeSupportedByOldABIEncoder(Type const& _type, bool _isLibraryCall)
|
||||
{
|
||||
if (_type.dataStoredIn(DataLocation::Storage))
|
||||
if (_isLibraryCall && _type.dataStoredIn(DataLocation::Storage))
|
||||
return true;
|
||||
if (_type.category() == Type::Category::Struct)
|
||||
return false;
|
||||
@@ -58,7 +58,7 @@ bool typeSupportedByOldABIEncoder(Type const& _type)
|
||||
{
|
||||
auto const& arrayType = dynamic_cast<ArrayType const&>(_type);
|
||||
auto base = arrayType.baseType();
|
||||
if (!typeSupportedByOldABIEncoder(*base) || (base->category() == Type::Category::Array && base->isDynamicallySized()))
|
||||
if (!typeSupportedByOldABIEncoder(*base, _isLibraryCall) || (base->category() == Type::Category::Array && base->isDynamicallySized()))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -355,7 +355,7 @@ bool TypeChecker::visit(FunctionDefinition const& _function)
|
||||
if (
|
||||
_function.isPublic() &&
|
||||
!_function.sourceUnit().annotation().experimentalFeatures.count(ExperimentalFeature::ABIEncoderV2) &&
|
||||
!typeSupportedByOldABIEncoder(*type(var))
|
||||
!typeSupportedByOldABIEncoder(*type(var), isLibraryFunction)
|
||||
)
|
||||
m_errorReporter.typeError(
|
||||
var.location(),
|
||||
@@ -475,7 +475,7 @@ bool TypeChecker::visit(VariableDeclaration const& _variable)
|
||||
{
|
||||
vector<string> unsupportedTypes;
|
||||
for (auto const& param: getter.parameterTypes() + getter.returnParameterTypes())
|
||||
if (!typeSupportedByOldABIEncoder(*param))
|
||||
if (!typeSupportedByOldABIEncoder(*param, false /* isLibrary */))
|
||||
unsupportedTypes.emplace_back(param->toString());
|
||||
if (!unsupportedTypes.empty())
|
||||
m_errorReporter.typeError(_variable.location(),
|
||||
@@ -585,7 +585,7 @@ bool TypeChecker::visit(EventDefinition const& _eventDef)
|
||||
m_errorReporter.typeError(var->location(), "Internal or recursive type is not allowed as event parameter type.");
|
||||
if (
|
||||
!_eventDef.sourceUnit().annotation().experimentalFeatures.count(ExperimentalFeature::ABIEncoderV2) &&
|
||||
!typeSupportedByOldABIEncoder(*type(*var))
|
||||
!typeSupportedByOldABIEncoder(*type(*var), false /* isLibrary */)
|
||||
)
|
||||
m_errorReporter.typeError(
|
||||
var->location(),
|
||||
@@ -1550,6 +1550,15 @@ void TypeChecker::typeCheckABIEncodeFunctions(
|
||||
}
|
||||
}
|
||||
|
||||
if (isPacked && !typeSupportedByOldABIEncoder(*argType, false /* isLibrary */))
|
||||
{
|
||||
m_errorReporter.typeError(
|
||||
arguments[i]->location(),
|
||||
"Type not supported in packed mode."
|
||||
);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!argType->fullEncodingType(false, abiEncoderV2, !_functionType->padArguments()))
|
||||
m_errorReporter.typeError(
|
||||
arguments[i]->location(),
|
||||
|
||||
Reference in New Issue
Block a user