mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Disallow constructor in interfaces
This commit is contained in:
parent
2c4bce2d62
commit
d5102c1db7
@ -931,6 +931,7 @@ Interfaces
|
|||||||
Interfaces are similar to abstract contracts, but they cannot have any functions implemented. There are further restrictions:
|
Interfaces are similar to abstract contracts, but they cannot have any functions implemented. There are further restrictions:
|
||||||
|
|
||||||
#. Cannot inherit other contracts or interfaces.
|
#. Cannot inherit other contracts or interfaces.
|
||||||
|
#. Cannot define constructor.
|
||||||
#. Cannot define variables.
|
#. Cannot define variables.
|
||||||
#. Cannot define structs.
|
#. Cannot define structs.
|
||||||
#. Cannot define enums.
|
#. Cannot define enums.
|
||||||
|
@ -463,6 +463,9 @@ bool TypeChecker::visit(FunctionDefinition const& _function)
|
|||||||
typeError(_function.location(), "Functions in interfaces cannot have an implementation.");
|
typeError(_function.location(), "Functions in interfaces cannot have an implementation.");
|
||||||
_function.body().accept(*this);
|
_function.body().accept(*this);
|
||||||
}
|
}
|
||||||
|
if (_function.isConstructor())
|
||||||
|
if (m_scope->contractKind() == ContractDefinition::ContractKind::Interface)
|
||||||
|
typeError(_function.location(), "Constructor cannot be defined in interfaces.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5343,7 +5343,7 @@ BOOST_AUTO_TEST_CASE(interface_constructor)
|
|||||||
function I();
|
function I();
|
||||||
}
|
}
|
||||||
)";
|
)";
|
||||||
success(text);
|
CHECK_ERROR(text, TypeError, "Constructor cannot be defined in interfaces");
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(interface_functions)
|
BOOST_AUTO_TEST_CASE(interface_functions)
|
||||||
|
Loading…
Reference in New Issue
Block a user