diff options
author | chriseth <chris@ethereum.org> | 2017-07-14 17:42:04 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-07-14 17:42:04 +0800 |
commit | b61f744dd9c5e954f53deb781c7e408da55dcda1 (patch) | |
tree | 8415b6d1950847ccd87f343f959de7d79faca80a | |
parent | 7c97546f44dae5b3996678d69f25b9da1a4eb2ab (diff) | |
parent | aec3eabdda3ba36ed33746fae9ed9eba02286fd4 (diff) | |
download | dexon-solidity-b61f744dd9c5e954f53deb781c7e408da55dcda1.tar dexon-solidity-b61f744dd9c5e954f53deb781c7e408da55dcda1.tar.gz dexon-solidity-b61f744dd9c5e954f53deb781c7e408da55dcda1.tar.bz2 dexon-solidity-b61f744dd9c5e954f53deb781c7e408da55dcda1.tar.lz dexon-solidity-b61f744dd9c5e954f53deb781c7e408da55dcda1.tar.xz dexon-solidity-b61f744dd9c5e954f53deb781c7e408da55dcda1.tar.zst dexon-solidity-b61f744dd9c5e954f53deb781c7e408da55dcda1.zip |
Merge pull request #2565 from ethereum/literal-string-error
Include types in explicit conversion error message
-rw-r--r-- | Changelog.md | 1 | ||||
-rw-r--r-- | libsolidity/analysis/TypeChecker.cpp | 9 | ||||
-rw-r--r-- | test/libsolidity/SolidityNameAndTypeResolution.cpp | 37 |
3 files changed, 46 insertions, 1 deletions
diff --git a/Changelog.md b/Changelog.md index 62b52942..e64a8fea 100644 --- a/Changelog.md +++ b/Changelog.md @@ -4,6 +4,7 @@ Features: * Inline Assembly: Show useful error message if trying to access calldata variables. * Inline Assembly: Support variable declaration without initial value (defaults to 0). * Type Checker: Disallow value transfers to contracts without a payable fallback function. + * Type Checker: Include types in explicit conversion error message. * Type Checker: Raise proper error for arrays too large for ABI encoding. Bugfixes: diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp index 29db7441..23f01752 100644 --- a/libsolidity/analysis/TypeChecker.cpp +++ b/libsolidity/analysis/TypeChecker.cpp @@ -1364,7 +1364,14 @@ bool TypeChecker::visit(FunctionCall const& _functionCall) // (data location cannot yet be specified for type conversions) resultType = ReferenceType::copyForLocationIfReference(argRefType->location(), resultType); if (!argType->isExplicitlyConvertibleTo(*resultType)) - m_errorReporter.typeError(_functionCall.location(), "Explicit type conversion not allowed."); + m_errorReporter.typeError( + _functionCall.location(), + "Explicit type conversion not allowed from \"" + + argType->toString() + + "\" to \"" + + resultType->toString() + + "\"." + ); } _functionCall.annotation().type = resultType; _functionCall.annotation().isPure = isPure; diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp index 36b48cfd..cb39101e 100644 --- a/test/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp @@ -6322,6 +6322,43 @@ BOOST_AUTO_TEST_CASE(too_large_arrays_for_calldata) CHECK_ERROR(text, TypeError, "Array is too large to be encoded as calldata."); } +BOOST_AUTO_TEST_CASE(explicit_literal_to_storage_string) +{ + char const* text = R"( + contract C { + function f() { + string memory x = "abc"; + x; + } + } + )"; + CHECK_SUCCESS_NO_WARNINGS(text); + text = R"( + contract C { + function f() { + string storage x = "abc"; + } + } + )"; + CHECK_ERROR(text, TypeError, "Type literal_string \"abc\" is not implicitly convertible to expected type string storage pointer."); + text = R"( + contract C { + function f() { + string x = "abc"; + } + } + )"; + CHECK_ERROR(text, TypeError, "Type literal_string \"abc\" is not implicitly convertible to expected type string storage pointer."); + text = R"( + contract C { + function f() { + string("abc"); + } + } + )"; + CHECK_ERROR(text, TypeError, "Explicit type conversion not allowed from \"literal_string \"abc\"\" to \"string storage pointer\""); +} + BOOST_AUTO_TEST_SUITE_END() } |