From 34da6c88111a0245e5ffb9bfbd192310488980d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20=C5=9Aliwak?= Date: Thu, 20 Apr 2023 13:39:08 +0200 Subject: [PATCH] Remove the inaccurate Type::categoryName() and change the error message for invalid calls to one independent of the category --- libsolidity/analysis/TypeChecker.cpp | 6 +--- libsolidity/ast/Types.cpp | 29 ------------------- libsolidity/ast/Types.h | 2 -- libsolutil/StringUtils.h | 9 ------ .../functionCalls/enum_value_not_callable.sol | 2 +- .../functionCalls/int_not_callable.sol | 2 +- .../functionCalls/magic_not_callable.sol | 2 +- .../functionCalls/mapping_not_callable.sol | 2 +- .../functionCalls/modifier_not_callable.sol | 2 +- .../functionCalls/module_not_callable.sol | 2 +- .../functionCalls/this_not_callable.sol | 2 +- .../462_callable_crash.sol | 2 +- .../492_do_not_crash_on_not_lvalue.sol | 2 +- ...ariable_function_conflict_former_crash.sol | 2 +- .../tupleAssignments/double_storage_crash.sol | 2 +- .../syntaxTests/types/function_call_fail.sol | 2 +- 16 files changed, 13 insertions(+), 57 deletions(-) diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp index f0d4ecda3..e7721fd9e 100644 --- a/libsolidity/analysis/TypeChecker.cpp +++ b/libsolidity/analysis/TypeChecker.cpp @@ -2847,11 +2847,7 @@ bool TypeChecker::visit(FunctionCall const& _functionCall) } default: - m_errorReporter.fatalTypeError( - 5704_error, - _functionCall.location(), - capitalized(Type::categoryName(expressionType->category())) + " is not callable." - ); + m_errorReporter.fatalTypeError(5704_error, _functionCall.location(), "This expression is not callable."); // Unreachable, because fatalTypeError throws. We don't set kind, but that's okay because the switch below // is never reached. And, even if it was, SetOnce would trigger an assertion violation and not UB. funcCallAnno.isPure = argumentsArePure; diff --git a/libsolidity/ast/Types.cpp b/libsolidity/ast/Types.cpp index a8134fa3b..1218baee3 100644 --- a/libsolidity/ast/Types.cpp +++ b/libsolidity/ast/Types.cpp @@ -294,35 +294,6 @@ Type const* Type::commonType(Type const* _a, Type const* _b) return nullptr; } -char const* Type::categoryName(Type::Category _category) -{ - switch (_category) - { - case Category::Address: return "address"; - case Category::Integer: return "integer"; - case Category::RationalNumber: return "rational number literal"; - case Category::StringLiteral: return "string literal"; - case Category::Bool: return "boolean"; - case Category::FixedPoint: return "fixed-point number"; - case Category::Array: return "array"; - case Category::ArraySlice: return "array slice"; - case Category::FixedBytes: return "fixed-size byte array"; - case Category::Contract: return "contract"; - case Category::Struct: return "struct"; - case Category::Function: return "function"; - case Category::Enum: return "enum"; - case Category::UserDefinedValueType: return "user-defined value type"; - case Category::Tuple: return "tuple"; - case Category::Mapping: return "mapping"; - case Category::TypeType: return "type of a type"; - case Category::Modifier: return "modifier"; - case Category::Magic: return "magic variable"; - case Category::Module: return "module"; - case Category::InaccessibleDynamic: return "inaccessible dynamic value"; - } - util::unreachable(); -} - MemberList const& Type::members(ASTNode const* _currentScope) const { if (!m_members[_currentScope]) diff --git a/libsolidity/ast/Types.h b/libsolidity/ast/Types.h index 9c6389a29..fa1a299a9 100644 --- a/libsolidity/ast/Types.h +++ b/libsolidity/ast/Types.h @@ -201,8 +201,6 @@ public: static Type const* commonType(Type const* _a, Type const* _b); virtual Category category() const = 0; - static char const* categoryName(Type::Category _category); - /// @returns a valid solidity identifier such that two types should compare equal if and /// only if they have the same identifier. /// The identifier should start with "t_". diff --git a/libsolutil/StringUtils.h b/libsolutil/StringUtils.h index b01dba63b..0d5bc7839 100644 --- a/libsolutil/StringUtils.h +++ b/libsolutil/StringUtils.h @@ -160,15 +160,6 @@ inline std::string toLower(std::string _s) return _s; } -/// Returns a copy of the string with the first character converted to its uppercase equivalent. -/// Uses the classic "C" locale semantics. -inline std::string capitalized(std::string _s) -{ - if (_s.size() > 0) - _s[0] = toUpper(_s[0]); - return _s; -} - /// Checks whether _c is a decimal digit character. It uses the classic "C" locale semantics. /// @param _c character to be checked /// @return true if _c is a decimal digit character, false otherwise diff --git a/test/libsolidity/syntaxTests/functionCalls/enum_value_not_callable.sol b/test/libsolidity/syntaxTests/functionCalls/enum_value_not_callable.sol index 0735f446f..f2d7cd1b2 100644 --- a/test/libsolidity/syntaxTests/functionCalls/enum_value_not_callable.sol +++ b/test/libsolidity/syntaxTests/functionCalls/enum_value_not_callable.sol @@ -4,4 +4,4 @@ contract C { uint a = E.B(1000); } // ---- -// TypeError 5704: (46-55): Enum is not callable. +// TypeError 5704: (46-55): This expression is not callable. diff --git a/test/libsolidity/syntaxTests/functionCalls/int_not_callable.sol b/test/libsolidity/syntaxTests/functionCalls/int_not_callable.sol index 5481ff1a3..e1ddbc7db 100644 --- a/test/libsolidity/syntaxTests/functionCalls/int_not_callable.sol +++ b/test/libsolidity/syntaxTests/functionCalls/int_not_callable.sol @@ -5,4 +5,4 @@ contract C } } // ---- -// TypeError 5704: (53-60): Rational number literal is not callable. +// TypeError 5704: (53-60): This expression is not callable. diff --git a/test/libsolidity/syntaxTests/functionCalls/magic_not_callable.sol b/test/libsolidity/syntaxTests/functionCalls/magic_not_callable.sol index b74685d4b..c93f0bb88 100644 --- a/test/libsolidity/syntaxTests/functionCalls/magic_not_callable.sol +++ b/test/libsolidity/syntaxTests/functionCalls/magic_not_callable.sol @@ -2,4 +2,4 @@ contract C { uint a = msg(1000); } // ---- -// TypeError 5704: (26-35): Magic variable is not callable. +// TypeError 5704: (26-35): This expression is not callable. diff --git a/test/libsolidity/syntaxTests/functionCalls/mapping_not_callable.sol b/test/libsolidity/syntaxTests/functionCalls/mapping_not_callable.sol index d06712999..e5258b62b 100644 --- a/test/libsolidity/syntaxTests/functionCalls/mapping_not_callable.sol +++ b/test/libsolidity/syntaxTests/functionCalls/mapping_not_callable.sol @@ -3,4 +3,4 @@ contract C { uint a = m(1000); } // ---- -// TypeError 5704: (56-63): Mapping is not callable. +// TypeError 5704: (56-63): This expression is not callable. diff --git a/test/libsolidity/syntaxTests/functionCalls/modifier_not_callable.sol b/test/libsolidity/syntaxTests/functionCalls/modifier_not_callable.sol index 31ef66fe1..0f41072ec 100644 --- a/test/libsolidity/syntaxTests/functionCalls/modifier_not_callable.sol +++ b/test/libsolidity/syntaxTests/functionCalls/modifier_not_callable.sol @@ -4,4 +4,4 @@ contract C { modifier m(uint) { _; } } // ---- -// TypeError 5704: (26-33): Modifier is not callable. +// TypeError 5704: (26-33): This expression is not callable. diff --git a/test/libsolidity/syntaxTests/functionCalls/module_not_callable.sol b/test/libsolidity/syntaxTests/functionCalls/module_not_callable.sol index 63debdab7..1415810ae 100644 --- a/test/libsolidity/syntaxTests/functionCalls/module_not_callable.sol +++ b/test/libsolidity/syntaxTests/functionCalls/module_not_callable.sol @@ -6,4 +6,4 @@ contract C { uint a = A(1000); } // ---- -// TypeError 5704: (B.sol:48-55): Module is not callable. +// TypeError 5704: (B.sol:48-55): This expression is not callable. diff --git a/test/libsolidity/syntaxTests/functionCalls/this_not_callable.sol b/test/libsolidity/syntaxTests/functionCalls/this_not_callable.sol index 35c04d473..8de5683bc 100644 --- a/test/libsolidity/syntaxTests/functionCalls/this_not_callable.sol +++ b/test/libsolidity/syntaxTests/functionCalls/this_not_callable.sol @@ -6,4 +6,4 @@ contract C { } } // ---- -// TypeError 5704: (72-78): Contract is not callable. +// TypeError 5704: (72-78): This expression is not callable. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/462_callable_crash.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/462_callable_crash.sol index 6c5539e3b..1f9e7a1a0 100644 --- a/test/libsolidity/syntaxTests/nameAndTypeResolution/462_callable_crash.sol +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/462_callable_crash.sol @@ -6,4 +6,4 @@ contract C { } } // ---- -// TypeError 5704: (90-108): Rational number literal is not callable. +// TypeError 5704: (90-108): This expression is not callable. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/492_do_not_crash_on_not_lvalue.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/492_do_not_crash_on_not_lvalue.sol index 595785e93..d46920d1d 100644 --- a/test/libsolidity/syntaxTests/nameAndTypeResolution/492_do_not_crash_on_not_lvalue.sol +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/492_do_not_crash_on_not_lvalue.sol @@ -6,4 +6,4 @@ contract C { } } // ---- -// TypeError 5704: (153-157): Mapping is not callable. +// TypeError 5704: (153-157): This expression is not callable. diff --git a/test/libsolidity/syntaxTests/scoping/state_variable_function_conflict_former_crash.sol b/test/libsolidity/syntaxTests/scoping/state_variable_function_conflict_former_crash.sol index eeef3e7ea..f44ca63fd 100644 --- a/test/libsolidity/syntaxTests/scoping/state_variable_function_conflict_former_crash.sol +++ b/test/libsolidity/syntaxTests/scoping/state_variable_function_conflict_former_crash.sol @@ -11,4 +11,4 @@ contract SomeContract { } // ---- // DeclarationError 2333: (106-145): Identifier already declared. -// TypeError 5704: (185-195): Integer is not callable. +// TypeError 5704: (185-195): This expression is not callable. diff --git a/test/libsolidity/syntaxTests/tupleAssignments/double_storage_crash.sol b/test/libsolidity/syntaxTests/tupleAssignments/double_storage_crash.sol index 701af022b..b4bbb7367 100644 --- a/test/libsolidity/syntaxTests/tupleAssignments/double_storage_crash.sol +++ b/test/libsolidity/syntaxTests/tupleAssignments/double_storage_crash.sol @@ -7,4 +7,4 @@ contract CrashContract { } } // ---- -// TypeError 5704: (170-177): Rational number literal is not callable. +// TypeError 5704: (170-177): This expression is not callable. diff --git a/test/libsolidity/syntaxTests/types/function_call_fail.sol b/test/libsolidity/syntaxTests/types/function_call_fail.sol index 042b78f01..67631bc2b 100644 --- a/test/libsolidity/syntaxTests/types/function_call_fail.sol +++ b/test/libsolidity/syntaxTests/types/function_call_fail.sol @@ -4,4 +4,4 @@ contract C { } } // ---- -// TypeError 5704: (59-63): Rational number literal is not callable. +// TypeError 5704: (59-63): This expression is not callable.