aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity
diff options
context:
space:
mode:
authorAlex Beregszaszi <alex@rtfs.hu>2017-08-12 07:45:37 +0800
committerAlex Beregszaszi <alex@rtfs.hu>2017-08-22 06:02:18 +0800
commitb25f0c52ac01857a82dda20ec2b646c7ae90cd7d (patch)
tree4148fa30c5386136ab7dc476ff61bba26a2bcc2c /libsolidity
parent2c2ae74217521aae93b9c7b058ce8687046c648c (diff)
downloaddexon-solidity-b25f0c52ac01857a82dda20ec2b646c7ae90cd7d.tar.gz
dexon-solidity-b25f0c52ac01857a82dda20ec2b646c7ae90cd7d.tar.zst
dexon-solidity-b25f0c52ac01857a82dda20ec2b646c7ae90cd7d.zip
Reject the creation of interface with the new statement
Diffstat (limited to 'libsolidity')
-rw-r--r--libsolidity/analysis/TypeChecker.cpp6
-rw-r--r--libsolidity/ast/Types.cpp3
2 files changed, 9 insertions, 0 deletions
diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp
index 32d078fd..f70b75d3 100644
--- a/libsolidity/analysis/TypeChecker.cpp
+++ b/libsolidity/analysis/TypeChecker.cpp
@@ -429,6 +429,10 @@ void TypeChecker::endVisit(InheritanceSpecifier const& _inheritance)
if (base->isLibrary())
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();
TypePointers parameterTypes = ContractType(*base).newExpressionType()->parameterTypes();
if (!arguments.empty() && parameterTypes.size() != arguments.size())
@@ -1554,6 +1558,8 @@ void TypeChecker::endVisit(NewExpression const& _newExpression)
if (!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())
m_errorReporter.typeError(
_newExpression.location(),
diff --git a/libsolidity/ast/Types.cpp b/libsolidity/ast/Types.cpp
index e6664895..adf41229 100644
--- a/libsolidity/ast/Types.cpp
+++ b/libsolidity/ast/Types.cpp
@@ -2140,6 +2140,8 @@ FunctionTypePointer FunctionType::newExpressionType(ContractDefinition const& _c
strings parameterNames;
StateMutability stateMutability = StateMutability::NonPayable;
+ solAssert(_contract.contractKind() != ContractDefinition::ContractKind::Interface, "");
+
if (constructor)
{
for (ASTPointer<VariableDeclaration> const& var: constructor->parameters())
@@ -2150,6 +2152,7 @@ FunctionTypePointer FunctionType::newExpressionType(ContractDefinition const& _c
if (constructor->isPayable())
stateMutability = StateMutability::Payable;
}
+
return make_shared<FunctionType>(
parameters,
TypePointers{make_shared<ContractType>(_contract)},