aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity/analysis
diff options
context:
space:
mode:
authorFederico Bond <federicobond@gmail.com>2017-07-09 09:42:42 +0800
committerFederico Bond <federicobond@gmail.com>2017-07-13 10:57:53 +0800
commitf20b150f3830d7a014258d92a26aba6a2bbdc8cb (patch)
tree1da74ae9b2a8c7b34f9be6ede23dc8980ec116a3 /libsolidity/analysis
parent757c500bda9a32cccc86e1ab24da31a99c0e6eac (diff)
downloaddexon-solidity-f20b150f3830d7a014258d92a26aba6a2bbdc8cb.tar.gz
dexon-solidity-f20b150f3830d7a014258d92a26aba6a2bbdc8cb.tar.zst
dexon-solidity-f20b150f3830d7a014258d92a26aba6a2bbdc8cb.zip
Add type error when attempting value transfer to a non-payable contract
Diffstat (limited to 'libsolidity/analysis')
-rw-r--r--libsolidity/analysis/TypeChecker.cpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp
index 90043b43..4e5a11ed 100644
--- a/libsolidity/analysis/TypeChecker.cpp
+++ b/libsolidity/analysis/TypeChecker.cpp
@@ -1631,6 +1631,25 @@ bool TypeChecker::visit(MemberAccess const& _memberAccess)
annotation.isLValue = annotation.referencedDeclaration->isLValue();
}
+ if (exprType->category() == Type::Category::Contract)
+ {
+ if (auto callType = dynamic_cast<FunctionType const*>(type(_memberAccess).get()))
+ {
+ auto kind = callType->kind();
+ auto contractType = dynamic_cast<ContractType const*>(exprType.get());
+ solAssert(!!contractType, "Should be contract type.");
+
+ if (
+ (kind == FunctionType::Kind::Send || kind == FunctionType::Kind::Transfer) &&
+ !contractType->isPayable()
+ )
+ m_errorReporter.typeError(
+ _memberAccess.location(),
+ "Value transfer to a contract without a payable fallback function."
+ );
+ }
+ }
+
// TODO some members might be pure, but for example `address(0x123).balance` is not pure
// although every subexpression is, so leaving this limited for now.
if (auto tt = dynamic_cast<TypeType const*>(exprType.get()))