Change type of super to TypeType

This commit is contained in:
hrkrshnn
2020-11-10 15:38:21 +01:00
parent da92fe548e
commit 9eafa1fa1a
6 changed files with 190 additions and 151 deletions
+1 -1
View File
@@ -140,7 +140,7 @@ MagicVariableDeclaration const* GlobalContext::currentSuper() const
{
Type const* type = TypeProvider::emptyTuple();
if (m_currentContract)
type = TypeProvider::contract(*m_currentContract, true);
type = TypeProvider::typeType(TypeProvider::contract(*m_currentContract, true));
m_superPointer[m_currentContract] =
make_shared<MagicVariableDeclaration>(magicVariableToID("super"), "super", type);
}
+12 -4
View File
@@ -2760,9 +2760,12 @@ bool TypeChecker::visit(MemberAccess const& _memberAccess)
);
if (!funType->bound())
if (auto contractType = dynamic_cast<ContractType const*>(exprType))
if (contractType->isSuper())
if (auto typeType = dynamic_cast<TypeType const*>(exprType))
{
auto contractType = dynamic_cast<ContractType const*>(typeType->actualType());
if (contractType && contractType->isSuper())
requiredLookup = VirtualLookup::Super;
}
}
annotation.requiredLookup = requiredLookup;
@@ -2837,8 +2840,13 @@ bool TypeChecker::visit(MemberAccess const& _memberAccess)
_memberAccess.location(),
"\"runtimeCode\" is not available for contracts containing immutable variables."
);
if (m_currentContract)
if (accessedContractType.isSuper())
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``,
// this is not properly detecting creation-cycles if they go through
+2 -3
View File
@@ -194,8 +194,8 @@ void ViewPureChecker::endVisit(Identifier const& _identifier)
switch (magicVar->type()->category())
{
case Type::Category::Contract:
solAssert(_identifier.name() == "this" || _identifier.name() == "super", "");
if (!dynamic_cast<ContractType const&>(*magicVar->type()).isSuper())
solAssert(_identifier.name() == "this", "");
if (dynamic_cast<ContractType const*>(magicVar->type()))
// reads the address
mutability = StateMutability::View;
break;
@@ -440,4 +440,3 @@ void ViewPureChecker::endVisit(ModifierInvocation const& _modifier)
else
solAssert(dynamic_cast<ContractDefinition const*>(_modifier.name().annotation().referencedDeclaration), "");
}