Merge pull request #10451 from ethereum/noTypeSuper

No type super
This commit is contained in:
chriseth 2020-12-02 15:56:41 +01:00 committed by GitHub
commit d50676ecb0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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 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: 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: 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. * Command Line Interface: JSON fields `abi`, `devdoc`, `userdoc` and `storage-layout` are now sub-objects rather than strings.
Language Features: Language Features:

View File

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

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; 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: (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 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 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 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.