mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Reject the creation of interface with the new statement
This commit is contained in:
parent
2c2ae74217
commit
b25f0c52ac
@ -15,6 +15,7 @@ Bugfixes:
|
|||||||
* Parser: Limit maximum recursion depth.
|
* Parser: Limit maximum recursion depth.
|
||||||
* Type Checker: Crash fix related to ``using``.
|
* Type Checker: Crash fix related to ``using``.
|
||||||
* Type Checker: Disallow constructors in libraries.
|
* Type Checker: Disallow constructors in libraries.
|
||||||
|
* Type Checker: Reject the creation of interface contracts using the ``new`` statement.
|
||||||
|
|
||||||
### 0.4.15 (2017-08-08)
|
### 0.4.15 (2017-08-08)
|
||||||
|
|
||||||
|
@ -429,6 +429,10 @@ void TypeChecker::endVisit(InheritanceSpecifier const& _inheritance)
|
|||||||
if (base->isLibrary())
|
if (base->isLibrary())
|
||||||
m_errorReporter.typeError(_inheritance.location(), "Libraries cannot be inherited from.");
|
m_errorReporter.typeError(_inheritance.location(), "Libraries cannot be inherited from.");
|
||||||
|
|
||||||
|
// Interface can have no constructors - no need to validate
|
||||||
|
if (base->contractKind() == ContractDefinition::ContractKind::Interface)
|
||||||
|
return;
|
||||||
|
|
||||||
auto const& arguments = _inheritance.arguments();
|
auto const& arguments = _inheritance.arguments();
|
||||||
TypePointers parameterTypes = ContractType(*base).newExpressionType()->parameterTypes();
|
TypePointers parameterTypes = ContractType(*base).newExpressionType()->parameterTypes();
|
||||||
if (!arguments.empty() && parameterTypes.size() != arguments.size())
|
if (!arguments.empty() && parameterTypes.size() != arguments.size())
|
||||||
@ -1554,6 +1558,8 @@ void TypeChecker::endVisit(NewExpression const& _newExpression)
|
|||||||
|
|
||||||
if (!contract)
|
if (!contract)
|
||||||
m_errorReporter.fatalTypeError(_newExpression.location(), "Identifier is not a contract.");
|
m_errorReporter.fatalTypeError(_newExpression.location(), "Identifier is not a contract.");
|
||||||
|
if (contract->contractKind() == ContractDefinition::ContractKind::Interface)
|
||||||
|
m_errorReporter.fatalTypeError(_newExpression.location(), "Cannot instantiate an interface.");
|
||||||
if (!contract->annotation().unimplementedFunctions.empty())
|
if (!contract->annotation().unimplementedFunctions.empty())
|
||||||
m_errorReporter.typeError(
|
m_errorReporter.typeError(
|
||||||
_newExpression.location(),
|
_newExpression.location(),
|
||||||
|
@ -2140,6 +2140,8 @@ FunctionTypePointer FunctionType::newExpressionType(ContractDefinition const& _c
|
|||||||
strings parameterNames;
|
strings parameterNames;
|
||||||
StateMutability stateMutability = StateMutability::NonPayable;
|
StateMutability stateMutability = StateMutability::NonPayable;
|
||||||
|
|
||||||
|
solAssert(_contract.contractKind() != ContractDefinition::ContractKind::Interface, "");
|
||||||
|
|
||||||
if (constructor)
|
if (constructor)
|
||||||
{
|
{
|
||||||
for (ASTPointer<VariableDeclaration> const& var: constructor->parameters())
|
for (ASTPointer<VariableDeclaration> const& var: constructor->parameters())
|
||||||
@ -2150,6 +2152,7 @@ FunctionTypePointer FunctionType::newExpressionType(ContractDefinition const& _c
|
|||||||
if (constructor->isPayable())
|
if (constructor->isPayable())
|
||||||
stateMutability = StateMutability::Payable;
|
stateMutability = StateMutability::Payable;
|
||||||
}
|
}
|
||||||
|
|
||||||
return make_shared<FunctionType>(
|
return make_shared<FunctionType>(
|
||||||
parameters,
|
parameters,
|
||||||
TypePointers{make_shared<ContractType>(_contract)},
|
TypePointers{make_shared<ContractType>(_contract)},
|
||||||
|
@ -6709,6 +6709,32 @@ BOOST_AUTO_TEST_CASE(experimental_pragma)
|
|||||||
// CHECK_ERROR_ALLOW_MULTI(text, SyntaxError, "Duplicate experimental feature name.");
|
// CHECK_ERROR_ALLOW_MULTI(text, SyntaxError, "Duplicate experimental feature name.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(reject_interface_creation)
|
||||||
|
{
|
||||||
|
char const* text = R"(
|
||||||
|
interface I {}
|
||||||
|
contract C {
|
||||||
|
function f() {
|
||||||
|
new I();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)";
|
||||||
|
CHECK_ERROR(text, TypeError, "Cannot instantiate an interface.");
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(accept_library_creation)
|
||||||
|
{
|
||||||
|
char const* text = R"(
|
||||||
|
library L {}
|
||||||
|
contract C {
|
||||||
|
function f() {
|
||||||
|
new L();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)";
|
||||||
|
CHECK_SUCCESS(text);
|
||||||
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_SUITE_END()
|
BOOST_AUTO_TEST_SUITE_END()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user