aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity/analysis/TypeChecker.cpp
diff options
context:
space:
mode:
authorchriseth <c@ethdev.com>2015-11-17 07:06:57 +0800
committerchriseth <c@ethdev.com>2015-11-26 20:10:12 +0800
commit30b325fdc148d5014f04fd238362e3a1df10310f (patch)
treecd8df0c1f6e5462f2349a07d8f5f7d1fd156b4cc /libsolidity/analysis/TypeChecker.cpp
parentcd94aa978a77ace1296f9978bfae6d8735b5c91d (diff)
downloaddexon-solidity-30b325fdc148d5014f04fd238362e3a1df10310f.tar
dexon-solidity-30b325fdc148d5014f04fd238362e3a1df10310f.tar.gz
dexon-solidity-30b325fdc148d5014f04fd238362e3a1df10310f.tar.bz2
dexon-solidity-30b325fdc148d5014f04fd238362e3a1df10310f.tar.lz
dexon-solidity-30b325fdc148d5014f04fd238362e3a1df10310f.tar.xz
dexon-solidity-30b325fdc148d5014f04fd238362e3a1df10310f.tar.zst
dexon-solidity-30b325fdc148d5014f04fd238362e3a1df10310f.zip
Allow "new expressions" also for general type names.
Breaking change: If you want to send value with a contract creation, you have to use parentheses now: `(new ContractName).value(2 ether)(arg1, arg2)`
Diffstat (limited to 'libsolidity/analysis/TypeChecker.cpp')
-rw-r--r--libsolidity/analysis/TypeChecker.cpp67
1 files changed, 41 insertions, 26 deletions
diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp
index 0990a9e4..13c2235a 100644
--- a/libsolidity/analysis/TypeChecker.cpp
+++ b/libsolidity/analysis/TypeChecker.cpp
@@ -1045,34 +1045,43 @@ bool TypeChecker::visit(FunctionCall const& _functionCall)
void TypeChecker::endVisit(NewExpression const& _newExpression)
{
- auto contract = dynamic_cast<ContractDefinition const*>(&dereference(_newExpression.contractName()));
-
- if (!contract)
- fatalTypeError(_newExpression.location(), "Identifier is not a contract.");
- if (!contract->annotation().isFullyImplemented)
- typeError(_newExpression.location(), "Trying to create an instance of an abstract contract.");
-
- auto scopeContract = _newExpression.contractName().annotation().contractScope;
- scopeContract->annotation().contractDependencies.insert(contract);
- solAssert(
- !contract->annotation().linearizedBaseContracts.empty(),
- "Linearized base contracts not yet available."
- );
- if (contractDependenciesAreCyclic(*scopeContract))
- typeError(
- _newExpression.location(),
- "Circular reference for contract creation (cannot create instance of derived or same contract)."
+ if (auto contractName = dynamic_cast<UserDefinedTypeName const*>(&_newExpression.typeName()))
+ {
+ auto contract = dynamic_cast<ContractDefinition const*>(&dereference(*contractName));
+
+ if (!contract)
+ fatalTypeError(_newExpression.location(), "Identifier is not a contract.");
+ if (!contract->annotation().isFullyImplemented)
+ typeError(_newExpression.location(), "Trying to create an instance of an abstract contract.");
+
+ auto scopeContract = contractName->annotation().contractScope;
+ scopeContract->annotation().contractDependencies.insert(contract);
+ solAssert(
+ !contract->annotation().linearizedBaseContracts.empty(),
+ "Linearized base contracts not yet available."
);
+ if (contractDependenciesAreCyclic(*scopeContract))
+ typeError(
+ _newExpression.location(),
+ "Circular reference for contract creation (cannot create instance of derived or same contract)."
+ );
- auto contractType = make_shared<ContractType>(*contract);
- TypePointers const& parameterTypes = contractType->constructorType()->parameterTypes();
- _newExpression.annotation().type = make_shared<FunctionType>(
- parameterTypes,
- TypePointers{contractType},
- strings(),
- strings(),
- FunctionType::Location::Creation
- );
+ auto contractType = make_shared<ContractType>(*contract);
+ TypePointers const& parameterTypes = contractType->constructorType()->parameterTypes();
+ _newExpression.annotation().type = make_shared<FunctionType>(
+ parameterTypes,
+ TypePointers{contractType},
+ strings(),
+ strings(),
+ FunctionType::Location::Creation
+ );
+ }
+ else if (auto arrayTypeName = dynamic_cast<ArrayTypeName const*>(&_newExpression.typeName()))
+ {
+ solAssert(false, "Not yet implemented.");
+ }
+ else
+ fatalTypeError(_newExpression.location(), "Contract or array type expected.");
}
bool TypeChecker::visit(MemberAccess const& _memberAccess)
@@ -1288,6 +1297,12 @@ Declaration const& TypeChecker::dereference(Identifier const& _identifier)
return *_identifier.annotation().referencedDeclaration;
}
+Declaration const& TypeChecker::dereference(UserDefinedTypeName const& _typeName)
+{
+ solAssert(!!_typeName.annotation().referencedDeclaration, "Declaration not stored.");
+ return *_typeName.annotation().referencedDeclaration;
+}
+
void TypeChecker::expectType(Expression const& _expression, Type const& _expectedType)
{
_expression.accept(*this);