Disallow meta type on super.

This commit is contained in:
chriseth 2020-12-01 10:24:50 +01:00
parent a6158e65c2
commit 52c49aebe8
8 changed files with 11 additions and 30 deletions

View File

@ -17,6 +17,7 @@ Breaking Changes:
* Type System: Explicit conversions from literals to integer type is as strict as implicit conversions.
* Type System: Explicit conversions from literals to enums are only allowed if the value fits in the enum.
* Type System: Declarations with the name ``this``, ``super`` and ``_`` are disallowed, with the exception of public functions and events.
* Type System: Disallow ``type(super)``.
* Command Line Interface: JSON fields `abi`, `devdoc`, `userdoc` and `storage-layout` are now sub-objects rather than strings.
Language Features:

View File

@ -226,16 +226,13 @@ TypePointers TypeChecker::typeCheckMetaTypeFunctionAndRetrieveReturnType(Functio
{
vector<ASTPointer<Expression const>> arguments = _functionCall.arguments();
if (arguments.size() != 1)
{
m_errorReporter.typeError(
m_errorReporter.fatalTypeError(
8885_error,
_functionCall.location(),
"This function takes one argument, but " +
toString(arguments.size()) +
" were provided."
);
return {};
}
TypePointer firstArgType = type(*arguments.front());
bool wrongType = false;
@ -243,26 +240,22 @@ TypePointers TypeChecker::typeCheckMetaTypeFunctionAndRetrieveReturnType(Functio
{
TypeType const* typeTypePtr = dynamic_cast<TypeType const*>(firstArgType);
Type::Category typeCategory = typeTypePtr->actualType()->category();
if (
typeCategory != Type::Category::Contract &&
typeCategory != Type::Category::Integer
)
if (auto const* contractType = dynamic_cast<ContractType const*>(typeTypePtr->actualType()))
wrongType = contractType->isSuper();
else if (typeCategory != Type::Category::Integer)
wrongType = true;
}
else
wrongType = true;
if (wrongType)
{
m_errorReporter.typeError(
m_errorReporter.fatalTypeError(
4259_error,
arguments.front()->location(),
"Invalid type for argument in the function call. "
"A contract type or an integer type is required, but " +
type(*arguments.front())->toString(true) + " provided."
);
return {};
}
return {TypeProvider::meta(dynamic_cast<TypeType const&>(*firstArgType).actualType())};
}
@ -2886,6 +2879,7 @@ bool TypeChecker::visit(MemberAccess const& _memberAccess)
{
annotation.isPure = true;
ContractType const& accessedContractType = dynamic_cast<ContractType const&>(*magicType->typeArgument());
solAssert(!accessedContractType.isSuper(), "");
if (
memberName == "runtimeCode" &&
!accessedContractType.immutableVariables().empty()
@ -2895,13 +2889,7 @@ bool TypeChecker::visit(MemberAccess const& _memberAccess)
_memberAccess.location(),
"\"runtimeCode\" is not available for contracts containing immutable variables."
);
if (accessedContractType.isSuper())
m_errorReporter.typeError(
3625_error,
_memberAccess.location(),
"\"creationCode\" and \"runtimeCode\" are not available for the \"super\" contract."
);
else if (m_currentContract)
if (m_currentContract)
{
// TODO in the same way as with ``new``,
// this is not properly detecting creation-cycles if they go through

View File

@ -21,13 +21,9 @@ contract Test is C {
function i() public pure returns (string memory) {
return type(I).name;
}
function j() public pure returns (string memory) {
return type(super).name;
}
}
// ----
// c() -> 0x20, 1, "C"
// a() -> 0x20, 1, "A"
// i() -> 0x20, 1, "I"
// j() -> 0x20, 1, "C"

View File

@ -10,5 +10,4 @@ contract SuperTest is Other {
}
}
// ----
// TypeError 3625: (172-196): "creationCode" and "runtimeCode" are not available for the "super" contract.
// TypeError 3625: (272-295): "creationCode" and "runtimeCode" are not available for the "super" contract.
// TypeError 4259: (177-182): Invalid type for argument in the function call. A contract type or an integer type is required, but type(contract super SuperTest) provided.

View File

@ -14,4 +14,4 @@ abstract contract Test is ERC165 {
}
}
// ----
// TypeError 9582: (587-610): Member "interfaceID" not found or not visible after argument-dependent lookup in type(contract super Test).
// TypeError 4259: (592-597): Invalid type for argument in the function call. A contract type or an integer type is required, but type(contract super Test) provided.

View File

@ -49,6 +49,5 @@ contract D is B, C {
return true;
}
}
// ----
// f() -> true
// TypeError 4259: (440-445): Invalid type for argument in the function call. A contract type or an integer type is required, but type(contract super B) provided.

View File

@ -5,4 +5,3 @@ contract Test {
}
// ----
// TypeError 4259: (65-75): Invalid type for argument in the function call. A contract type or an integer type is required, but type(contract Test) provided.
// TypeError 4259: (60-76): Invalid type for argument in the function call. A contract type or an integer type is required, but tuple() provided.

View File

@ -15,4 +15,3 @@ contract C {
// TypeError 5347: (72-76): Try can only be used with external function calls and contract creation calls.
// TypeError 2536: (119-128): Try can only be used with external function calls and contract creation calls.
// TypeError 4259: (176-183): Invalid type for argument in the function call. A contract type or an integer type is required, but type(address) provided.
// TypeError 2536: (171-184): Try can only be used with external function calls and contract creation calls.