diff --git a/Changelog.md b/Changelog.md index e24cb2462..9ecf2ce55 100644 --- a/Changelog.md +++ b/Changelog.md @@ -9,6 +9,8 @@ Compiler Features: Bugfixes: * Code Generator: Fix a crash when using ``@use-src`` and compiling from Yul to ewasm. * SMTChecker: Fix internal error when an unsafe target is solved more than once and the counterexample messages are different. + * Fix internal error when a function has a calldata struct argument with an internal type inside. + ### 0.8.10 (2021-11-09) diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp index 05fdc489b..5cc208d69 100644 --- a/libsolidity/analysis/TypeChecker.cpp +++ b/libsolidity/analysis/TypeChecker.cpp @@ -387,7 +387,7 @@ bool TypeChecker::visit(FunctionDefinition const& _function) _var.referenceLocation() == VariableDeclaration::Location::Storage && !m_currentContract->abstract() ) - m_errorReporter.typeError( + m_errorReporter.fatalTypeError( 3644_error, _var.location(), "This parameter has a type that can only be used internally. " @@ -403,7 +403,7 @@ bool TypeChecker::visit(FunctionDefinition const& _function) solAssert(!message.empty(), "Expected detailed error message!"); if (_function.isConstructor()) message += " You can make the contract abstract to avoid this problem."; - m_errorReporter.typeError(4103_error, _var.location(), message); + m_errorReporter.fatalTypeError(4103_error, _var.location(), message); } else if ( !useABICoderV2() && diff --git a/test/libsolidity/syntaxTests/abiEncoder/external_functions_taking_internal_types_nested_struct_with_mapping.sol b/test/libsolidity/syntaxTests/abiEncoder/external_functions_taking_internal_types_nested_struct_with_mapping.sol index 78660bdae..9c82812e9 100644 --- a/test/libsolidity/syntaxTests/abiEncoder/external_functions_taking_internal_types_nested_struct_with_mapping.sol +++ b/test/libsolidity/syntaxTests/abiEncoder/external_functions_taking_internal_types_nested_struct_with_mapping.sol @@ -7,4 +7,3 @@ contract C { } // ---- // TypeError 4103: (132-140): Types containing (nested) mappings can only be parameters or return variables of internal or library functions. -// TypeError 4061: (132-140): Type struct C.S is only valid in storage because it contains a (nested) mapping. diff --git a/test/libsolidity/syntaxTests/abiEncoder/external_functions_taking_internal_types_struct_with_mapping.sol b/test/libsolidity/syntaxTests/abiEncoder/external_functions_taking_internal_types_struct_with_mapping.sol index 297f809fd..144962c2a 100644 --- a/test/libsolidity/syntaxTests/abiEncoder/external_functions_taking_internal_types_struct_with_mapping.sol +++ b/test/libsolidity/syntaxTests/abiEncoder/external_functions_taking_internal_types_struct_with_mapping.sol @@ -6,4 +6,3 @@ contract C { } // ---- // TypeError 4103: (105-113): Types containing (nested) mappings can only be parameters or return variables of internal or library functions. -// TypeError 4061: (105-113): Type struct C.S is only valid in storage because it contains a (nested) mapping. diff --git a/test/libsolidity/syntaxTests/array/function_mapping.sol b/test/libsolidity/syntaxTests/array/function_mapping.sol index 531ef6c7b..3f64c081c 100644 --- a/test/libsolidity/syntaxTests/array/function_mapping.sol +++ b/test/libsolidity/syntaxTests/array/function_mapping.sol @@ -5,4 +5,3 @@ contract Test { } // ---- // TypeError 4103: (66-98): Types containing (nested) mappings can only be parameters or return variables of internal or library functions. -// TypeError 4061: (66-98): Type mapping(uint256 => uint256)[] is only valid in storage because it contains a (nested) mapping. diff --git a/test/libsolidity/syntaxTests/constructor/constructor_mapping_memory.sol b/test/libsolidity/syntaxTests/constructor/constructor_mapping_memory.sol index 266a440d6..b9e0ed801 100644 --- a/test/libsolidity/syntaxTests/constructor/constructor_mapping_memory.sol +++ b/test/libsolidity/syntaxTests/constructor/constructor_mapping_memory.sol @@ -3,4 +3,3 @@ contract A { } // ---- // TypeError 4103: (29-59): Types containing (nested) mappings can only be parameters or return variables of internal or library functions. You can make the contract abstract to avoid this problem. -// TypeError 4061: (29-59): Type mapping(uint256 => uint256) is only valid in storage because it contains a (nested) mapping. diff --git a/test/libsolidity/syntaxTests/functionCalls/calldata_struct_argument_with_internal_data_type_inside.sol b/test/libsolidity/syntaxTests/functionCalls/calldata_struct_argument_with_internal_data_type_inside.sol new file mode 100644 index 000000000..729dba778 --- /dev/null +++ b/test/libsolidity/syntaxTests/functionCalls/calldata_struct_argument_with_internal_data_type_inside.sol @@ -0,0 +1,8 @@ +contract C { + struct S { + function() a; + } + function f(S calldata) public {} +} +// ---- +// TypeError 4103: (56-66): Internal type is not allowed for public or external functions. \ No newline at end of file diff --git a/test/libsolidity/syntaxTests/functionCalls/calldata_struct_array_argument_with_internal_data_type_inside.sol b/test/libsolidity/syntaxTests/functionCalls/calldata_struct_array_argument_with_internal_data_type_inside.sol new file mode 100644 index 000000000..f618934e3 --- /dev/null +++ b/test/libsolidity/syntaxTests/functionCalls/calldata_struct_array_argument_with_internal_data_type_inside.sol @@ -0,0 +1,8 @@ +contract C { + struct S { + function() a; + } + function f(S[2] calldata) public {} +} +// ---- +// TypeError 4103: (56-69): Internal type is not allowed for public or external functions. diff --git a/test/libsolidity/syntaxTests/functionCalls/calldata_struct_array_argument_with_internal_data_type_inside_as_constructor_parameter.sol b/test/libsolidity/syntaxTests/functionCalls/calldata_struct_array_argument_with_internal_data_type_inside_as_constructor_parameter.sol new file mode 100644 index 000000000..796b0fc58 --- /dev/null +++ b/test/libsolidity/syntaxTests/functionCalls/calldata_struct_array_argument_with_internal_data_type_inside_as_constructor_parameter.sol @@ -0,0 +1,8 @@ +contract C { + struct S { + function() a; + } + constructor (S[2] storage) public {} +} +// ---- +// TypeError 3644: (58-70): This parameter has a type that can only be used internally. You can make the contract abstract to avoid this problem. diff --git a/test/libsolidity/syntaxTests/structs/calldata_struct_mapping_function.sol b/test/libsolidity/syntaxTests/structs/calldata_struct_mapping_function.sol index dcdbad68b..9ff30c6ec 100644 --- a/test/libsolidity/syntaxTests/structs/calldata_struct_mapping_function.sol +++ b/test/libsolidity/syntaxTests/structs/calldata_struct_mapping_function.sol @@ -12,4 +12,3 @@ contract test { } // ---- // TypeError 4103: (155-167): Types containing (nested) mappings can only be parameters or return variables of internal or library functions. -// TypeError 4061: (155-167): Type struct test.S is only valid in storage because it contains a (nested) mapping. diff --git a/test/libsolidity/syntaxTests/structs/recursion/recursive_struct_nested_mapping_memory.sol b/test/libsolidity/syntaxTests/structs/recursion/recursive_struct_nested_mapping_memory.sol index 6009ee94d..c8708e3e0 100644 --- a/test/libsolidity/syntaxTests/structs/recursion/recursive_struct_nested_mapping_memory.sol +++ b/test/libsolidity/syntaxTests/structs/recursion/recursive_struct_nested_mapping_memory.sol @@ -7,4 +7,3 @@ library a { } // ---- // TypeError 4103: (149-157): Recursive structs can only be passed as storage pointers to libraries, not as memory objects to contract functions. -// TypeError 4061: (149-157): Type struct a.b is only valid in storage because it contains a (nested) mapping. diff --git a/test/libsolidity/syntaxTests/types/mapping/mapping_array_data_location_function_param_external.sol b/test/libsolidity/syntaxTests/types/mapping/mapping_array_data_location_function_param_external.sol index 72c2a12a8..f959394d1 100644 --- a/test/libsolidity/syntaxTests/types/mapping/mapping_array_data_location_function_param_external.sol +++ b/test/libsolidity/syntaxTests/types/mapping/mapping_array_data_location_function_param_external.sol @@ -3,4 +3,3 @@ contract c { } // ---- // TypeError 4103: (29-61): Types containing (nested) mappings can only be parameters or return variables of internal or library functions. -// TypeError 4061: (29-61): Type mapping(uint256 => uint256)[] is only valid in storage because it contains a (nested) mapping. diff --git a/test/libsolidity/syntaxTests/types/mapping/mapping_data_location_function_param_external.sol b/test/libsolidity/syntaxTests/types/mapping/mapping_data_location_function_param_external.sol index 3bc5d7a29..1281e4b51 100644 --- a/test/libsolidity/syntaxTests/types/mapping/mapping_data_location_function_param_external.sol +++ b/test/libsolidity/syntaxTests/types/mapping/mapping_data_location_function_param_external.sol @@ -3,4 +3,3 @@ contract c { } // ---- // TypeError 4103: (29-59): Types containing (nested) mappings can only be parameters or return variables of internal or library functions. -// TypeError 4061: (29-59): Type mapping(uint256 => uint256) is only valid in storage because it contains a (nested) mapping. diff --git a/test/libsolidity/syntaxTests/types/mapping/mapping_data_location_function_param_public.sol b/test/libsolidity/syntaxTests/types/mapping/mapping_data_location_function_param_public.sol index f8a666675..667c0b101 100644 --- a/test/libsolidity/syntaxTests/types/mapping/mapping_data_location_function_param_public.sol +++ b/test/libsolidity/syntaxTests/types/mapping/mapping_data_location_function_param_public.sol @@ -3,4 +3,3 @@ contract c { } // ---- // TypeError 4103: (29-57): Types containing (nested) mappings can only be parameters or return variables of internal or library functions. -// TypeError 4061: (29-57): Type mapping(uint256 => uint256) is only valid in storage because it contains a (nested) mapping. diff --git a/test/libsolidity/syntaxTests/types/mapping/mapping_function_calldata.sol b/test/libsolidity/syntaxTests/types/mapping/mapping_function_calldata.sol index 1301a03c3..8b780ea8d 100644 --- a/test/libsolidity/syntaxTests/types/mapping/mapping_function_calldata.sol +++ b/test/libsolidity/syntaxTests/types/mapping/mapping_function_calldata.sol @@ -9,4 +9,3 @@ contract test { } // ---- // TypeError 4103: (121-133): Types containing (nested) mappings can only be parameters or return variables of internal or library functions. -// TypeError 4061: (121-133): Type struct test.S is only valid in storage because it contains a (nested) mapping. diff --git a/test/libsolidity/syntaxTests/types/mapping/mapping_return_public_memory.sol b/test/libsolidity/syntaxTests/types/mapping/mapping_return_public_memory.sol index 4d06bad5a..6594401c6 100644 --- a/test/libsolidity/syntaxTests/types/mapping/mapping_return_public_memory.sol +++ b/test/libsolidity/syntaxTests/types/mapping/mapping_return_public_memory.sol @@ -4,4 +4,3 @@ contract C { } // ---- // TypeError 4103: (51-79): Types containing (nested) mappings can only be parameters or return variables of internal or library functions. -// TypeError 4061: (51-79): Type mapping(uint256 => uint256) is only valid in storage because it contains a (nested) mapping. diff --git a/test/libsolidity/syntaxTests/types/mapping/mapping_struct_data_location_memory.sol b/test/libsolidity/syntaxTests/types/mapping/mapping_struct_data_location_memory.sol index 8208c2e2e..399f7c6ae 100644 --- a/test/libsolidity/syntaxTests/types/mapping/mapping_struct_data_location_memory.sol +++ b/test/libsolidity/syntaxTests/types/mapping/mapping_struct_data_location_memory.sol @@ -5,4 +5,3 @@ contract C { } // ---- // TypeError 4103: (104-112): Types containing (nested) mappings can only be parameters or return variables of internal or library functions. -// TypeError 4061: (104-112): Type struct C.S is only valid in storage because it contains a (nested) mapping. diff --git a/test/libsolidity/syntaxTests/types/mapping/mapping_struct_recusrive_data_location_memory.sol b/test/libsolidity/syntaxTests/types/mapping/mapping_struct_recusrive_data_location_memory.sol index fa09bdeae..49cf31487 100644 --- a/test/libsolidity/syntaxTests/types/mapping/mapping_struct_recusrive_data_location_memory.sol +++ b/test/libsolidity/syntaxTests/types/mapping/mapping_struct_recusrive_data_location_memory.sol @@ -7,4 +7,3 @@ contract C { } // ---- // TypeError 4103: (148-156): Types containing (nested) mappings can only be parameters or return variables of internal or library functions. -// TypeError 4061: (148-156): Type struct C.U is only valid in storage because it contains a (nested) mapping.