aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity
diff options
context:
space:
mode:
authorAlex Beregszaszi <alex@rtfs.hu>2017-08-22 19:11:37 +0800
committerGitHub <noreply@github.com>2017-08-22 19:11:37 +0800
commit97169e58ae44e763323f2554f124eaf1ff3db508 (patch)
tree96512e3347e61427fabb7d6d8a4c67658dda1d59 /libsolidity
parentf874fc28d1cb657b6d4e04fa9d93bd8d061f30c4 (diff)
parent7b0046a9aafffec4e42be7e30c283e07ca1841b9 (diff)
downloaddexon-solidity-97169e58ae44e763323f2554f124eaf1ff3db508.tar.gz
dexon-solidity-97169e58ae44e763323f2554f124eaf1ff3db508.tar.zst
dexon-solidity-97169e58ae44e763323f2554f124eaf1ff3db508.zip
Merge pull request #2734 from ethereum/reject-create-interface
Reject the creation of interface with the new statement
Diffstat (limited to 'libsolidity')
-rw-r--r--libsolidity/analysis/TypeChecker.cpp8
-rw-r--r--libsolidity/ast/Types.cpp3
2 files changed, 10 insertions, 1 deletions
diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp
index 32d078fd..99f3c64c 100644
--- a/libsolidity/analysis/TypeChecker.cpp
+++ b/libsolidity/analysis/TypeChecker.cpp
@@ -430,7 +430,11 @@ void TypeChecker::endVisit(InheritanceSpecifier const& _inheritance)
m_errorReporter.typeError(_inheritance.location(), "Libraries cannot be inherited from.");
auto const& arguments = _inheritance.arguments();
- TypePointers parameterTypes = ContractType(*base).newExpressionType()->parameterTypes();
+ TypePointers parameterTypes;
+ if (base->contractKind() != ContractDefinition::ContractKind::Interface)
+ // Interfaces do not have constructors, so there are zero parameters.
+ parameterTypes = ContractType(*base).newExpressionType()->parameterTypes();
+
if (!arguments.empty() && parameterTypes.size() != arguments.size())
{
m_errorReporter.typeError(
@@ -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)},