Disallows index access on contracts and libraries.

This commit is contained in:
Erik Kundt 2019-02-21 16:38:02 +01:00 committed by Alex Beregszaszi
parent 97d3b88f65
commit 2d0daae796
4 changed files with 17 additions and 0 deletions

View File

@ -19,6 +19,7 @@ Bugfixes:
* Inline Assembly: Proper error message for missing variables.
* Optimizer: Fix internal error related to unused tag removal across assemblies. This never generated any invalid code.
* SMTChecker: Fixed crash when used with fixed-sized arrays.
* TypeChecker: Fix internal error and disallow index access on contracts and libraries.
* Yul: Properly detect name clashes with functions before their declaration.
* Yul: Take builtin functions into account in the compilability checker.

View File

@ -2208,6 +2208,8 @@ bool TypeChecker::visit(IndexAccess const& _access)
case Type::Category::TypeType:
{
TypeType const& typeType = dynamic_cast<TypeType const&>(*baseType);
if (dynamic_cast<ContractType const*>(typeType.actualType().get()))
m_errorReporter.typeError(_access.location(), "Index access for contracts or libraries is not possible.");
if (!index)
resultType = make_shared<TypeType>(make_shared<ArrayType>(DataLocation::Memory, typeType.actualType()));
else

View File

@ -0,0 +1,7 @@
contract C {
function f() view public {
C[0];
}
}
// ----
// TypeError: (52-56): Index access for contracts or libraries is not possible.

View File

@ -0,0 +1,7 @@
library C {
function f() view public {
C[0];
}
}
// ----
// TypeError: (51-55): Index access for contracts or libraries is not possible.