From 0afe025f193bbe1cd43db2579f5da96b11960beb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20=C5=9Aliwak?= Date: Fri, 2 Jun 2023 12:40:19 +0200 Subject: [PATCH] Minor tweaks to immutable tests for better diffs --- .../immutable/ctor_initialization_indirect_reading.sol | 2 +- .../immutable/function_initialization_reading.sol | 2 +- .../syntaxTests/immutable/function_pointer_reading.sol | 4 ++-- .../immutable/indirect_reading_during_statevar_init.sol | 4 ++-- .../immutable/inheritance_virtual_functions.sol | 6 +++--- .../immutable/init_in_constructor_modifier_param.sol | 7 +++++++ .../immutable/init_in_inheritance_specifier_param.sol | 2 +- .../syntaxTests/immutable/init_in_modifier_param.sol | 7 ------- .../immutable/multiple_inheritance_virtual_functions.sol | 6 +++--- .../multiple_inheritance_virtual_functions_with_super.sol | 6 +++--- .../syntaxTests/immutable/read_in_function_before_init.sol | 4 ++-- .../immutable/reading_after_initialization_function.sol | 4 ++-- .../syntaxTests/immutable/try_catch_initialized.sol | 1 - 13 files changed, 27 insertions(+), 28 deletions(-) create mode 100644 test/libsolidity/syntaxTests/immutable/init_in_constructor_modifier_param.sol delete mode 100644 test/libsolidity/syntaxTests/immutable/init_in_modifier_param.sol diff --git a/test/libsolidity/syntaxTests/immutable/ctor_initialization_indirect_reading.sol b/test/libsolidity/syntaxTests/immutable/ctor_initialization_indirect_reading.sol index 0ee583b56..1bd0f6b91 100644 --- a/test/libsolidity/syntaxTests/immutable/ctor_initialization_indirect_reading.sol +++ b/test/libsolidity/syntaxTests/immutable/ctor_initialization_indirect_reading.sol @@ -4,7 +4,7 @@ contract C { x = f(); } - function f() public pure returns (uint) { return 3 + x; } + function f() public view returns (uint) { return 3 + x; } } // ---- // TypeError 7733: (136-137): Immutable variables cannot be read before they are initialized. diff --git a/test/libsolidity/syntaxTests/immutable/function_initialization_reading.sol b/test/libsolidity/syntaxTests/immutable/function_initialization_reading.sol index 7933f8e7f..068688584 100644 --- a/test/libsolidity/syntaxTests/immutable/function_initialization_reading.sol +++ b/test/libsolidity/syntaxTests/immutable/function_initialization_reading.sol @@ -1,7 +1,7 @@ contract C { uint immutable x = f(); - function f() public pure returns (uint) { return 3 + x; } + function f() public view returns (uint) { return 3 + x; } } // ---- // TypeError 7733: (99-100): Immutable variables cannot be read before they are initialized. diff --git a/test/libsolidity/syntaxTests/immutable/function_pointer_reading.sol b/test/libsolidity/syntaxTests/immutable/function_pointer_reading.sol index e94fd155c..5c026300c 100644 --- a/test/libsolidity/syntaxTests/immutable/function_pointer_reading.sol +++ b/test/libsolidity/syntaxTests/immutable/function_pointer_reading.sol @@ -7,7 +7,7 @@ abstract contract B { } contract C is B(C.f) { - function f() internal returns(uint) { return x + 2; } + function f() internal view returns(uint) { return x + 2; } } // ---- -// TypeError 7733: (200-201): Immutable variables cannot be read before they are initialized. +// TypeError 7733: (205-206): Immutable variables cannot be read before they are initialized. diff --git a/test/libsolidity/syntaxTests/immutable/indirect_reading_during_statevar_init.sol b/test/libsolidity/syntaxTests/immutable/indirect_reading_during_statevar_init.sol index eaa2186f1..ff7927277 100644 --- a/test/libsolidity/syntaxTests/immutable/indirect_reading_during_statevar_init.sol +++ b/test/libsolidity/syntaxTests/immutable/indirect_reading_during_statevar_init.sol @@ -2,7 +2,7 @@ contract C { uint immutable x = 0; uint y = f(); - function f() internal returns(uint) { return x; } + function f() internal pure returns(uint) { return x; } } // ---- -// TypeError 7733: (107-108): Immutable variables cannot be read before they are initialized. +// TypeError 7733: (112-113): Immutable variables cannot be read before they are initialized. diff --git a/test/libsolidity/syntaxTests/immutable/inheritance_virtual_functions.sol b/test/libsolidity/syntaxTests/immutable/inheritance_virtual_functions.sol index dc11b8a61..f33ce4cc4 100644 --- a/test/libsolidity/syntaxTests/immutable/inheritance_virtual_functions.sol +++ b/test/libsolidity/syntaxTests/immutable/inheritance_virtual_functions.sol @@ -5,15 +5,15 @@ contract B { x = xInit(); } - function xInit() internal virtual returns(uint) { + function xInit() internal view virtual returns(uint) { return 3; } } contract C is B { - function xInit() internal override returns(uint) { + function xInit() internal view override returns(uint) { return x; } } // ---- -// TypeError 7733: (253-254): Immutable variables cannot be read before they are initialized. +// TypeError 7733: (263-264): Immutable variables cannot be read before they are initialized. diff --git a/test/libsolidity/syntaxTests/immutable/init_in_constructor_modifier_param.sol b/test/libsolidity/syntaxTests/immutable/init_in_constructor_modifier_param.sol new file mode 100644 index 000000000..d23416942 --- /dev/null +++ b/test/libsolidity/syntaxTests/immutable/init_in_constructor_modifier_param.sol @@ -0,0 +1,7 @@ +contract D { + uint immutable t; + modifier m(uint) { _; } + constructor() m(t = 2) {} +} +// ---- +// TypeError 1581: (83-84): Cannot write to immutable here: Immutable variables can only be initialized inline or assigned directly in the constructor. diff --git a/test/libsolidity/syntaxTests/immutable/init_in_inheritance_specifier_param.sol b/test/libsolidity/syntaxTests/immutable/init_in_inheritance_specifier_param.sol index 63662e1b7..cc56202e7 100644 --- a/test/libsolidity/syntaxTests/immutable/init_in_inheritance_specifier_param.sol +++ b/test/libsolidity/syntaxTests/immutable/init_in_inheritance_specifier_param.sol @@ -1,6 +1,6 @@ contract C { constructor(uint) {} } contract D is C(D.t = 2) { - uint immutable t; + uint immutable t; } // ---- // TypeError 1581: (52-55): Cannot write to immutable here: Immutable variables can only be initialized inline or assigned directly in the constructor. diff --git a/test/libsolidity/syntaxTests/immutable/init_in_modifier_param.sol b/test/libsolidity/syntaxTests/immutable/init_in_modifier_param.sol deleted file mode 100644 index 3e354b4e9..000000000 --- a/test/libsolidity/syntaxTests/immutable/init_in_modifier_param.sol +++ /dev/null @@ -1,7 +0,0 @@ -contract D { - uint immutable t; - modifier m(uint) { _; } - constructor() m(t=2) {} -} -// ---- -// TypeError 1581: (77-78): Cannot write to immutable here: Immutable variables can only be initialized inline or assigned directly in the constructor. diff --git a/test/libsolidity/syntaxTests/immutable/multiple_inheritance_virtual_functions.sol b/test/libsolidity/syntaxTests/immutable/multiple_inheritance_virtual_functions.sol index 33749c8cd..401b068cb 100644 --- a/test/libsolidity/syntaxTests/immutable/multiple_inheritance_virtual_functions.sol +++ b/test/libsolidity/syntaxTests/immutable/multiple_inheritance_virtual_functions.sol @@ -13,7 +13,7 @@ contract B { return f(); } - function f() internal virtual returns(uint) { return 3; } + function f() internal view virtual returns(uint) { return 3; } } contract C is A, B { @@ -21,9 +21,9 @@ contract C is A, B { return B.xInit(); } - function f() internal override(A, B) returns(uint) { + function f() internal view override(A, B) returns(uint) { return x; } } // ---- -// TypeError 7733: (489-490): Immutable variables cannot be read before they are initialized. +// TypeError 7733: (499-500): Immutable variables cannot be read before they are initialized. diff --git a/test/libsolidity/syntaxTests/immutable/multiple_inheritance_virtual_functions_with_super.sol b/test/libsolidity/syntaxTests/immutable/multiple_inheritance_virtual_functions_with_super.sol index 11da864db..bf5a1f85b 100644 --- a/test/libsolidity/syntaxTests/immutable/multiple_inheritance_virtual_functions_with_super.sol +++ b/test/libsolidity/syntaxTests/immutable/multiple_inheritance_virtual_functions_with_super.sol @@ -13,7 +13,7 @@ contract B { return f(); } - function f() internal virtual returns(uint) { return 3; } + function f() internal view virtual returns(uint) { return 3; } } contract C is A, B { @@ -21,9 +21,9 @@ contract C is A, B { return super.xInit(); } - function f() internal override(A, B) returns(uint) { + function f() internal view override(A, B) returns(uint) { return x; } } // ---- -// TypeError 7733: (493-494): Immutable variables cannot be read before they are initialized. +// TypeError 7733: (503-504): Immutable variables cannot be read before they are initialized. diff --git a/test/libsolidity/syntaxTests/immutable/read_in_function_before_init.sol b/test/libsolidity/syntaxTests/immutable/read_in_function_before_init.sol index 3ca0df270..6e934ff9d 100644 --- a/test/libsolidity/syntaxTests/immutable/read_in_function_before_init.sol +++ b/test/libsolidity/syntaxTests/immutable/read_in_function_before_init.sol @@ -2,11 +2,11 @@ abstract contract A { uint public t; constructor() { t = f(); } - function f() virtual view internal returns (uint); + function f() virtual pure internal returns (uint); } contract B is A { uint immutable x = 2; - function f() override view internal returns (uint) { return x; } + function f() override pure internal returns (uint) { return x; } } // ---- // TypeError 7733: (223-224): Immutable variables cannot be read before they are initialized. diff --git a/test/libsolidity/syntaxTests/immutable/reading_after_initialization_function.sol b/test/libsolidity/syntaxTests/immutable/reading_after_initialization_function.sol index 70d4ac4c8..32ac0cceb 100644 --- a/test/libsolidity/syntaxTests/immutable/reading_after_initialization_function.sol +++ b/test/libsolidity/syntaxTests/immutable/reading_after_initialization_function.sol @@ -1,5 +1,5 @@ contract C { - uint immutable x ; + uint immutable x; constructor() { @@ -13,4 +13,4 @@ contract C { } } // ---- -// TypeError 7733: (145-146): Immutable variables cannot be read before they are initialized. +// TypeError 7733: (141-142): Immutable variables cannot be read before they are initialized. diff --git a/test/libsolidity/syntaxTests/immutable/try_catch_initialized.sol b/test/libsolidity/syntaxTests/immutable/try_catch_initialized.sol index 2d901a020..9cd18a2b6 100644 --- a/test/libsolidity/syntaxTests/immutable/try_catch_initialized.sol +++ b/test/libsolidity/syntaxTests/immutable/try_catch_initialized.sol @@ -31,7 +31,6 @@ contract B revert(); } } - // ==== // EVMVersion: >=byzantium // ----