From ef25454a048bee9049c6076421d08732aeacb8bb Mon Sep 17 00:00:00 2001 From: Martin Diz Date: Thu, 4 Oct 2018 12:31:52 -0300 Subject: Improved error message for lookup in function types. --- Changelog.md | 1 + libsolidity/analysis/TypeChecker.cpp | 21 +++++++++++++++++++-- ...ember_member_getter_call_without_parentheses.sol | 19 +++++++++++++++++++ .../576_member_getter_call_without_parentheses.sol | 17 +++++++++++++++++ ...er_call_without_parentheses_missing_function.sol | 15 +++++++++++++++ ...ivate_member_getter_call_without_parentheses.sol | 17 +++++++++++++++++ ...er_call_without_parentheses_private_function.sol | 17 +++++++++++++++++ 7 files changed, 105 insertions(+), 2 deletions(-) create mode 100644 test/libsolidity/syntaxTests/nameAndTypeResolution/575_member_member_getter_call_without_parentheses.sol create mode 100644 test/libsolidity/syntaxTests/nameAndTypeResolution/576_member_getter_call_without_parentheses.sol create mode 100644 test/libsolidity/syntaxTests/nameAndTypeResolution/577_member_getter_call_without_parentheses_missing_function.sol create mode 100644 test/libsolidity/syntaxTests/nameAndTypeResolution/578_private_member_getter_call_without_parentheses.sol create mode 100644 test/libsolidity/syntaxTests/nameAndTypeResolution/579_member_getter_call_without_parentheses_private_function.sol diff --git a/Changelog.md b/Changelog.md index 2d6f518c..465a9daa 100644 --- a/Changelog.md +++ b/Changelog.md @@ -99,6 +99,7 @@ Compiler Features: * Tests: Determine transaction status during IPC calls. * Code Generator: Allocate and free local variables according to their scope. * Removed ``pragma experimental "v0.5.0";``. + * Syntax Checker: Improved error message for lookup in function types. Bugfixes: * Build System: Support versions of CVC4 linked against CLN instead of GMP. In case of compilation issues due to the experimental SMT solver support, the solvers can be disabled when configuring the project with CMake using ``-DUSE_CVC4=OFF`` or ``-DUSE_Z3=OFF``. diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp index 39ea494d..5ffdda57 100644 --- a/libsolidity/analysis/TypeChecker.cpp +++ b/libsolidity/analysis/TypeChecker.cpp @@ -2141,8 +2141,25 @@ bool TypeChecker::visit(MemberAccess const& _memberAccess) ); } string errorMsg = "Member \"" + memberName + "\" not found or not visible " - "after argument-dependent lookup in " + exprType->toString() + - (memberName == "value" ? " - did you forget the \"payable\" modifier?" : "."); + "after argument-dependent lookup in " + exprType->toString() + "."; + if (memberName == "value") + { + errorMsg.pop_back(); + errorMsg += " - did you forget the \"payable\" modifier?"; + } + else if (exprType->category() == Type::Category::Function) + { + if (auto const& funType = dynamic_pointer_cast(exprType)) + { + auto const& t = funType->returnParameterTypes(); + if (t.size() == 1) + if ( + t.front()->category() == Type::Category::Contract || + t.front()->category() == Type::Category::Struct + ) + errorMsg += " Did you intend to call the function?"; + } + } if (exprType->category() == Type::Category::Contract) for (auto const& addressMember: AddressType::addressPayable().nativeMembers(nullptr)) if (addressMember.name == memberName) diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/575_member_member_getter_call_without_parentheses.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/575_member_member_getter_call_without_parentheses.sol new file mode 100644 index 00000000..61f43103 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/575_member_member_getter_call_without_parentheses.sol @@ -0,0 +1,19 @@ +contract A{ + function f() public pure{ + + } +} +contract B{ + A public a; +} +contract C{ + B public b; +} +contract D{ + C c; + function f() public view{ + c.b.a.f(); + } +} +// ---- +// TypeError: (170-175): Member "a" not found or not visible after argument-dependent lookup in function () view external returns (contract B). Did you intend to call the function? diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/576_member_getter_call_without_parentheses.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/576_member_getter_call_without_parentheses.sol new file mode 100644 index 00000000..bdc5fdc7 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/576_member_getter_call_without_parentheses.sol @@ -0,0 +1,17 @@ +contract A{ + function f() public pure{ + + } +} +contract B{ + A public a; +} +contract C{ + B b; + function f() public view{ + b.a.f(); + } +} + +// ---- +// TypeError: (140-145): Member "f" not found or not visible after argument-dependent lookup in function () view external returns (contract A). Did you intend to call the function? diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/577_member_getter_call_without_parentheses_missing_function.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/577_member_getter_call_without_parentheses_missing_function.sol new file mode 100644 index 00000000..d204d926 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/577_member_getter_call_without_parentheses_missing_function.sol @@ -0,0 +1,15 @@ +contract A{ + +} +contract B{ + A public a; +} +contract C{ + B b; + function f() public view{ + b.a.f(); + } +} + +// ---- +// TypeError: (104-109): Member "f" not found or not visible after argument-dependent lookup in function () view external returns (contract A). Did you intend to call the function? diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/578_private_member_getter_call_without_parentheses.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/578_private_member_getter_call_without_parentheses.sol new file mode 100644 index 00000000..e71da372 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/578_private_member_getter_call_without_parentheses.sol @@ -0,0 +1,17 @@ +contract A{ + function f() public pure{ + + } +} +contract B{ + A private a; +} +contract C{ + B b; + function f() public view{ + b.a.f(); + } +} + +// ---- +// TypeError: (141-144): Member "a" not found or not visible after argument-dependent lookup in contract B. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/579_member_getter_call_without_parentheses_private_function.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/579_member_getter_call_without_parentheses_private_function.sol new file mode 100644 index 00000000..18932238 --- /dev/null +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/579_member_getter_call_without_parentheses_private_function.sol @@ -0,0 +1,17 @@ +contract A{ + function f() private pure{ + + } +} +contract B{ + A public a; +} +contract C{ + B b; + function f() public view{ + b.a.f(); + } +} + +// ---- +// TypeError: (141-146): Member "f" not found or not visible after argument-dependent lookup in function () view external returns (contract A). Did you intend to call the function? -- cgit