From 175580fe90135b4449db057b8079756a6319e912 Mon Sep 17 00:00:00 2001 From: Marenz Date: Thu, 17 Feb 2022 16:52:36 +0100 Subject: [PATCH] Make error message less confusing --- libsolidity/analysis/ViewPureChecker.cpp | 5 ++--- .../syntaxTests/freeFunctions/free_mutability.sol | 2 +- .../libsolidity/syntaxTests/multiSource/one_source.sol | 2 +- .../viewPureChecker/access_to_base_member_function.sol | 2 +- .../viewPureChecker/access_to_base_member_struct.sol | 4 ++-- .../viewPureChecker/access_to_base_members.sol | 2 +- .../array/access_to_array_push_view.sol | 2 +- .../viewPureChecker/builtin_functions_view_fail.sol | 10 +++++----- .../viewPureChecker/call_internal_functions_fail.sol | 2 +- .../syntaxTests/viewPureChecker/creation_view_fail.sol | 2 +- .../viewPureChecker/function_types_fail.sol | 4 ++-- .../viewPureChecker/gas_with_call_nonpayable.sol | 4 ++-- .../viewPureChecker/local_storage_variables_fail.sol | 2 +- .../syntaxTests/viewPureChecker/modifiers_fail.sol | 2 +- .../viewPureChecker/value_with_call_nonpayable.sol | 4 ++-- .../syntaxTests/viewPureChecker/write_storage_fail.sol | 2 +- 16 files changed, 25 insertions(+), 26 deletions(-) diff --git a/libsolidity/analysis/ViewPureChecker.cpp b/libsolidity/analysis/ViewPureChecker.cpp index 252210a12..3179a8eb7 100644 --- a/libsolidity/analysis/ViewPureChecker.cpp +++ b/libsolidity/analysis/ViewPureChecker.cpp @@ -256,10 +256,9 @@ void ViewPureChecker::reportMutability( m_errorReporter.typeError( 8961_error, _location, - "Function declared as " + + "Function cannot be declared as " + stateMutabilityToString(m_currentFunction->stateMutability()) + - ", but this expression (potentially) modifies the state and thus " - "requires non-payable (the default) or payable." + " because this expression (potentially) modifies the state." ); m_errors = true; } diff --git a/test/libsolidity/syntaxTests/freeFunctions/free_mutability.sol b/test/libsolidity/syntaxTests/freeFunctions/free_mutability.sol index dafa91ccb..9279ff1eb 100644 --- a/test/libsolidity/syntaxTests/freeFunctions/free_mutability.sol +++ b/test/libsolidity/syntaxTests/freeFunctions/free_mutability.sol @@ -5,4 +5,4 @@ function f() { function g(uint[] storage x) pure { x[0] = 1; } // ---- // Warning 2018: (0-39): Function state mutability can be restricted to pure -// TypeError 8961: (76-80): Function declared as pure, but this expression (potentially) modifies the state and thus requires non-payable (the default) or payable. +// TypeError 8961: (76-80): Function cannot be declared as pure because this expression (potentially) modifies the state. diff --git a/test/libsolidity/syntaxTests/multiSource/one_source.sol b/test/libsolidity/syntaxTests/multiSource/one_source.sol index 11ee49720..9c1d92eb5 100644 --- a/test/libsolidity/syntaxTests/multiSource/one_source.sol +++ b/test/libsolidity/syntaxTests/multiSource/one_source.sol @@ -4,4 +4,4 @@ contract A { function f() public pure { x = 42; } } // ---- -// TypeError 8961: (SourceName:53-54): Function declared as pure, but this expression (potentially) modifies the state and thus requires non-payable (the default) or payable. +// TypeError 8961: (SourceName:53-54): Function cannot be declared as pure because this expression (potentially) modifies the state. diff --git a/test/libsolidity/syntaxTests/viewPureChecker/access_to_base_member_function.sol b/test/libsolidity/syntaxTests/viewPureChecker/access_to_base_member_function.sol index 1b5a7ae50..0f434c743 100644 --- a/test/libsolidity/syntaxTests/viewPureChecker/access_to_base_member_function.sol +++ b/test/libsolidity/syntaxTests/viewPureChecker/access_to_base_member_function.sol @@ -8,4 +8,4 @@ contract B is A { } } // ---- -// TypeError 8961: (100-105): Function declared as view, but this expression (potentially) modifies the state and thus requires non-payable (the default) or payable. +// TypeError 8961: (100-105): Function cannot be declared as view because this expression (potentially) modifies the state. diff --git a/test/libsolidity/syntaxTests/viewPureChecker/access_to_base_member_struct.sol b/test/libsolidity/syntaxTests/viewPureChecker/access_to_base_member_struct.sol index 612fbb745..13d0ed913 100644 --- a/test/libsolidity/syntaxTests/viewPureChecker/access_to_base_member_struct.sol +++ b/test/libsolidity/syntaxTests/viewPureChecker/access_to_base_member_struct.sol @@ -15,7 +15,7 @@ contract B is A { } } // ---- -// TypeError 8961: (107-110): Function declared as view, but this expression (potentially) modifies the state and thus requires non-payable (the default) or payable. -// TypeError 8961: (166-171): Function declared as view, but this expression (potentially) modifies the state and thus requires non-payable (the default) or payable. +// TypeError 8961: (107-110): Function cannot be declared as view because this expression (potentially) modifies the state. +// TypeError 8961: (166-171): Function cannot be declared as view because this expression (potentially) modifies the state. // TypeError 2527: (244-247): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view". // TypeError 2527: (244-249): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view". diff --git a/test/libsolidity/syntaxTests/viewPureChecker/access_to_base_members.sol b/test/libsolidity/syntaxTests/viewPureChecker/access_to_base_members.sol index e9dccaecd..1203d2c67 100644 --- a/test/libsolidity/syntaxTests/viewPureChecker/access_to_base_members.sol +++ b/test/libsolidity/syntaxTests/viewPureChecker/access_to_base_members.sol @@ -12,4 +12,4 @@ contract B is A { } // ---- // TypeError 2527: (107-110): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view". -// TypeError 8961: (157-160): Function declared as view, but this expression (potentially) modifies the state and thus requires non-payable (the default) or payable. +// TypeError 8961: (157-160): Function cannot be declared as view because this expression (potentially) modifies the state. diff --git a/test/libsolidity/syntaxTests/viewPureChecker/array/access_to_array_push_view.sol b/test/libsolidity/syntaxTests/viewPureChecker/array/access_to_array_push_view.sol index 3b7c19f5e..27ba16eaf 100644 --- a/test/libsolidity/syntaxTests/viewPureChecker/array/access_to_array_push_view.sol +++ b/test/libsolidity/syntaxTests/viewPureChecker/array/access_to_array_push_view.sol @@ -5,4 +5,4 @@ contract A { } } // ---- -// TypeError 8961: (88-96): Function declared as view, but this expression (potentially) modifies the state and thus requires non-payable (the default) or payable. +// TypeError 8961: (88-96): Function cannot be declared as view because this expression (potentially) modifies the state. diff --git a/test/libsolidity/syntaxTests/viewPureChecker/builtin_functions_view_fail.sol b/test/libsolidity/syntaxTests/viewPureChecker/builtin_functions_view_fail.sol index 000f5b009..76a05d8be 100644 --- a/test/libsolidity/syntaxTests/viewPureChecker/builtin_functions_view_fail.sol +++ b/test/libsolidity/syntaxTests/viewPureChecker/builtin_functions_view_fail.sol @@ -20,8 +20,8 @@ contract C { } } // ---- -// TypeError 8961: (52-77): Function declared as view, but this expression (potentially) modifies the state and thus requires non-payable (the default) or payable. -// TypeError 8961: (132-153): Function declared as view, but this expression (potentially) modifies the state and thus requires non-payable (the default) or payable. -// TypeError 8961: (201-228): Function declared as view, but this expression (potentially) modifies the state and thus requires non-payable (the default) or payable. -// TypeError 8961: (293-323): Function declared as view, but this expression (potentially) modifies the state and thus requires non-payable (the default) or payable. -// TypeError 8961: (414-436): Function declared as view, but this expression (potentially) modifies the state and thus requires non-payable (the default) or payable. +// TypeError 8961: (52-77): Function cannot be declared as view because this expression (potentially) modifies the state. +// TypeError 8961: (132-153): Function cannot be declared as view because this expression (potentially) modifies the state. +// TypeError 8961: (201-228): Function cannot be declared as view because this expression (potentially) modifies the state. +// TypeError 8961: (293-323): Function cannot be declared as view because this expression (potentially) modifies the state. +// TypeError 8961: (414-436): Function cannot be declared as view because this expression (potentially) modifies the state. diff --git a/test/libsolidity/syntaxTests/viewPureChecker/call_internal_functions_fail.sol b/test/libsolidity/syntaxTests/viewPureChecker/call_internal_functions_fail.sol index a47de539e..38762a34a 100644 --- a/test/libsolidity/syntaxTests/viewPureChecker/call_internal_functions_fail.sol +++ b/test/libsolidity/syntaxTests/viewPureChecker/call_internal_functions_fail.sol @@ -7,4 +7,4 @@ contract C { } // ---- // TypeError 2527: (56-59): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view". -// TypeError 8961: (130-133): Function declared as view, but this expression (potentially) modifies the state and thus requires non-payable (the default) or payable. +// TypeError 8961: (130-133): Function cannot be declared as view because this expression (potentially) modifies the state. diff --git a/test/libsolidity/syntaxTests/viewPureChecker/creation_view_fail.sol b/test/libsolidity/syntaxTests/viewPureChecker/creation_view_fail.sol index 643ba8b26..c934c9093 100644 --- a/test/libsolidity/syntaxTests/viewPureChecker/creation_view_fail.sol +++ b/test/libsolidity/syntaxTests/viewPureChecker/creation_view_fail.sol @@ -3,4 +3,4 @@ contract C { function f() public view { new D(); } } // ---- -// TypeError 8961: (58-65): Function declared as view, but this expression (potentially) modifies the state and thus requires non-payable (the default) or payable. +// TypeError 8961: (58-65): Function cannot be declared as view because this expression (potentially) modifies the state. diff --git a/test/libsolidity/syntaxTests/viewPureChecker/function_types_fail.sol b/test/libsolidity/syntaxTests/viewPureChecker/function_types_fail.sol index 47027331f..f0ad5efcc 100644 --- a/test/libsolidity/syntaxTests/viewPureChecker/function_types_fail.sol +++ b/test/libsolidity/syntaxTests/viewPureChecker/function_types_fail.sol @@ -13,6 +13,6 @@ contract C { } } // ---- -// TypeError 8961: (92-103): Function declared as pure, but this expression (potentially) modifies the state and thus requires non-payable (the default) or payable. +// TypeError 8961: (92-103): Function cannot be declared as pure because this expression (potentially) modifies the state. // TypeError 2527: (193-202): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view". -// TypeError 8961: (289-300): Function declared as view, but this expression (potentially) modifies the state and thus requires non-payable (the default) or payable. +// TypeError 8961: (289-300): Function cannot be declared as view because this expression (potentially) modifies the state. diff --git a/test/libsolidity/syntaxTests/viewPureChecker/gas_with_call_nonpayable.sol b/test/libsolidity/syntaxTests/viewPureChecker/gas_with_call_nonpayable.sol index be8a5aeb8..65030cb30 100644 --- a/test/libsolidity/syntaxTests/viewPureChecker/gas_with_call_nonpayable.sol +++ b/test/libsolidity/syntaxTests/viewPureChecker/gas_with_call_nonpayable.sol @@ -8,5 +8,5 @@ contract C { } } // ---- -// TypeError 8961: (90-109): Function declared as view, but this expression (potentially) modifies the state and thus requires non-payable (the default) or payable. -// TypeError 8961: (180-197): Function declared as view, but this expression (potentially) modifies the state and thus requires non-payable (the default) or payable. +// TypeError 8961: (90-109): Function cannot be declared as view because this expression (potentially) modifies the state. +// TypeError 8961: (180-197): Function cannot be declared as view because this expression (potentially) modifies the state. diff --git a/test/libsolidity/syntaxTests/viewPureChecker/local_storage_variables_fail.sol b/test/libsolidity/syntaxTests/viewPureChecker/local_storage_variables_fail.sol index 774dd44e5..3b9054c41 100644 --- a/test/libsolidity/syntaxTests/viewPureChecker/local_storage_variables_fail.sol +++ b/test/libsolidity/syntaxTests/viewPureChecker/local_storage_variables_fail.sol @@ -12,4 +12,4 @@ contract C { } // ---- // TypeError 2527: (100-101): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view". -// TypeError 8961: (184-187): Function declared as view, but this expression (potentially) modifies the state and thus requires non-payable (the default) or payable. +// TypeError 8961: (184-187): Function cannot be declared as view because this expression (potentially) modifies the state. diff --git a/test/libsolidity/syntaxTests/viewPureChecker/modifiers_fail.sol b/test/libsolidity/syntaxTests/viewPureChecker/modifiers_fail.sol index 3c592844a..ad24e1827 100644 --- a/test/libsolidity/syntaxTests/viewPureChecker/modifiers_fail.sol +++ b/test/libsolidity/syntaxTests/viewPureChecker/modifiers_fail.sol @@ -9,4 +9,4 @@ contract C is D { } // ---- // TypeError 2527: (154-162): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view". -// TypeError 8961: (195-209): Function declared as view, but this expression (potentially) modifies the state and thus requires non-payable (the default) or payable. +// TypeError 8961: (195-209): Function cannot be declared as view because this expression (potentially) modifies the state. diff --git a/test/libsolidity/syntaxTests/viewPureChecker/value_with_call_nonpayable.sol b/test/libsolidity/syntaxTests/viewPureChecker/value_with_call_nonpayable.sol index af95cbe49..cfb41d320 100644 --- a/test/libsolidity/syntaxTests/viewPureChecker/value_with_call_nonpayable.sol +++ b/test/libsolidity/syntaxTests/viewPureChecker/value_with_call_nonpayable.sol @@ -8,5 +8,5 @@ contract C { } } // ---- -// TypeError 8961: (90-111): Function declared as view, but this expression (potentially) modifies the state and thus requires non-payable (the default) or payable. -// TypeError 8961: (182-201): Function declared as view, but this expression (potentially) modifies the state and thus requires non-payable (the default) or payable. +// TypeError 8961: (90-111): Function cannot be declared as view because this expression (potentially) modifies the state. +// TypeError 8961: (182-201): Function cannot be declared as view because this expression (potentially) modifies the state. diff --git a/test/libsolidity/syntaxTests/viewPureChecker/write_storage_fail.sol b/test/libsolidity/syntaxTests/viewPureChecker/write_storage_fail.sol index d6828aac6..c3875f411 100644 --- a/test/libsolidity/syntaxTests/viewPureChecker/write_storage_fail.sol +++ b/test/libsolidity/syntaxTests/viewPureChecker/write_storage_fail.sol @@ -3,4 +3,4 @@ contract C { function f() view public { x = 2; } } // ---- -// TypeError 8961: (56-57): Function declared as view, but this expression (potentially) modifies the state and thus requires non-payable (the default) or payable. +// TypeError 8961: (56-57): Function cannot be declared as view because this expression (potentially) modifies the state.