Dynamic type as mapping key returns error instead of assertion fail

This commit is contained in:
Leonardo Alt 2018-07-31 11:44:39 +02:00
parent cc6fa6d61f
commit 583e7156ba
8 changed files with 50 additions and 1 deletions

View File

@ -110,6 +110,7 @@ Bugfixes:
* Type Checker: Fix freeze for negative fixed-point literals very close to ``0``, such as ``-1e-100``.
* Type Checker: Report error when using structs in events without experimental ABIEncoderV2. This used to crash or log the wrong values.
* Type Checker: Report error when using indexed structs in events with experimental ABIEncoderV2. This used to log wrong values.
* Type Checker: Dynamic types as key for public mappings return error instead of assertion fail.
* Type System: Allow arbitrary exponents for literals with a mantissa of zero.
### 0.4.24 (2018-05-16)

View File

@ -819,7 +819,9 @@ bool TypeChecker::visit(VariableDeclaration const& _variable)
)
m_errorReporter.typeError(_variable.location(), "Internal or recursive type is not allowed for public state variables.");
if (varType->category() == Type::Category::Array)
switch (varType->category())
{
case Type::Category::Array:
if (auto arrayType = dynamic_cast<ArrayType const*>(varType.get()))
if (
((arrayType->location() == DataLocation::Memory) ||
@ -827,6 +829,18 @@ bool TypeChecker::visit(VariableDeclaration const& _variable)
!arrayType->validForCalldata()
)
m_errorReporter.typeError(_variable.location(), "Array is too large to be encoded.");
break;
case Type::Category::Mapping:
if (auto mappingType = dynamic_cast<MappingType const*>(varType.get()))
if (
mappingType->keyType()->isDynamicallySized() &&
_variable.visibility() == Declaration::Visibility::Public
)
m_errorReporter.typeError(_variable.location(), "Dynamically-sized keys for public mappings are not supported.");
break;
default:
break;
}
return false;
}

View File

@ -0,0 +1,5 @@
contract c {
mapping(uint[] => uint) data;
}
// ----
// ParserError: (26-27): Expected '=>' but got '['

View File

@ -0,0 +1,8 @@
contract c {
struct S {
uint x;
}
mapping(S => uint) data;
}
// ----
// ParserError: (47-48): Expected elementary type name for mapping key type

View File

@ -0,0 +1,8 @@
contract c {
struct S {
string s;
}
mapping(S => uint) data;
}
// ----
// ParserError: (49-50): Expected elementary type name for mapping key type

View File

@ -0,0 +1,5 @@
contract c {
mapping(string[] => uint) data;
}
// ----
// ParserError: (28-29): Expected '=>' but got '['

View File

@ -0,0 +1,3 @@
contract c {
mapping(string => uint) data;
}

View File

@ -0,0 +1,5 @@
contract c {
mapping(string => uint) public data;
}
// ----
// TypeError: (14-49): Dynamically-sized keys for public mappings are not supported.