diff --git a/sway-core/src/semantic_analysis/ast_node/expression/intrinsic_function.rs b/sway-core/src/semantic_analysis/ast_node/expression/intrinsic_function.rs index 86fb0546688..9166dead6c6 100644 --- a/sway-core/src/semantic_analysis/ast_node/expression/intrinsic_function.rs +++ b/sway-core/src/semantic_analysis/ast_node/expression/intrinsic_function.rs @@ -485,6 +485,14 @@ fn type_check_encode_append( _type_arguments: &[TypeArgument], span: Span, ) -> Result<(ty::TyIntrinsicFunctionKind, TypeId), ErrorEmitted> { + if arguments.len() != 2 { + return Err(handler.emit_err(CompileError::IntrinsicIncorrectNumArgs { + name: kind.to_string(), + expected: 2, + span, + })); + } + let type_engine = ctx.engines.te(); let engines = ctx.engines(); diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/encode_append_wrong_args/Forc.lock b/test/src/e2e_vm_tests/test_programs/should_fail/encode_append_wrong_args/Forc.lock new file mode 100644 index 00000000000..976b79b97d6 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/encode_append_wrong_args/Forc.lock @@ -0,0 +1,3 @@ +[[package]] +name = "encode_append_wrong_args" +source = "member" diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/encode_append_wrong_args/Forc.toml b/test/src/e2e_vm_tests/test_programs/should_fail/encode_append_wrong_args/Forc.toml new file mode 100644 index 00000000000..080346ed9b0 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/encode_append_wrong_args/Forc.toml @@ -0,0 +1,6 @@ +[project] +authors = ["Fuel Labs "] +entry = "main.sw" +license = "Apache-2.0" +name = "encode_append_wrong_args" +implicit-std = false diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/encode_append_wrong_args/json_abi_oracle.json b/test/src/e2e_vm_tests/test_programs/should_fail/encode_append_wrong_args/json_abi_oracle.json new file mode 100644 index 00000000000..0637a088a01 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/encode_append_wrong_args/json_abi_oracle.json @@ -0,0 +1 @@ +[] \ No newline at end of file diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/encode_append_wrong_args/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_fail/encode_append_wrong_args/src/main.sw new file mode 100644 index 00000000000..b5813db61d8 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/encode_append_wrong_args/src/main.sw @@ -0,0 +1,17 @@ +library; + +pub struct Buffer { + buffer: u64 +} + +pub trait T { + fn ar(buffer: Buffer) -> Buffer; +} + +impl T for str[10] { + fn ar(buffer: Buffer) -> Buffer { + Buffer { + buffer: __encode_buffer_append(buffer.buffer) + } + } +} \ No newline at end of file diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/encode_append_wrong_args/test.toml b/test/src/e2e_vm_tests/test_programs/should_fail/encode_append_wrong_args/test.toml new file mode 100644 index 00000000000..7c6ea4d2bde --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/encode_append_wrong_args/test.toml @@ -0,0 +1,7 @@ +category = "fail" + +# check: $()warning +# check: $()buffer: __encode_buffer_append(buffer.buffer) + +# check: $()buffer: __encode_buffer_append(buffer.buffer) +# nextln: $()Call to "encode_buffer_append" expects 2 arguments