diff --git a/sway-core/src/semantic_analysis/ast_node/declaration/impl_trait.rs b/sway-core/src/semantic_analysis/ast_node/declaration/impl_trait.rs index 35e03b4f75c..e1ab4aaf699 100644 --- a/sway-core/src/semantic_analysis/ast_node/declaration/impl_trait.rs +++ b/sway-core/src/semantic_analysis/ast_node/declaration/impl_trait.rs @@ -831,22 +831,28 @@ fn type_check_trait_implementation( None, ), }; - trait_type_mapping.extend(&TypeSubstMap::from_type_parameters_and_type_arguments( - vec![type_engine.insert( - engines, - old_type_decl_info1, - type_decl.name.span().source_id(), - )], - vec![type_decl.ty.clone().unwrap().type_id], - )); - trait_type_mapping.extend(&TypeSubstMap::from_type_parameters_and_type_arguments( - vec![type_engine.insert( - engines, - old_type_decl_info2, - type_decl.name.span().source_id(), - )], - vec![type_decl.ty.clone().unwrap().type_id], - )); + if let Some(type_arg) = type_decl.ty.clone() { + trait_type_mapping.extend( + &TypeSubstMap::from_type_parameters_and_type_arguments( + vec![type_engine.insert( + engines, + old_type_decl_info1, + type_decl.name.span().source_id(), + )], + vec![type_arg.type_id], + ), + ); + trait_type_mapping.extend( + &TypeSubstMap::from_type_parameters_and_type_arguments( + vec![type_engine.insert( + engines, + old_type_decl_info2, + type_decl.name.span().source_id(), + )], + vec![type_arg.type_id], + ), + ); + } } } } diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/associated_type_not_in_trait/Forc.lock b/test/src/e2e_vm_tests/test_programs/should_fail/associated_type_not_in_trait/Forc.lock new file mode 100644 index 00000000000..d6d5627a81d --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/associated_type_not_in_trait/Forc.lock @@ -0,0 +1,3 @@ +[[package]] +name = "associated_type_not_in_trait" +source = "member" diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/associated_type_not_in_trait/Forc.toml b/test/src/e2e_vm_tests/test_programs/should_fail/associated_type_not_in_trait/Forc.toml new file mode 100644 index 00000000000..800719114d2 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/associated_type_not_in_trait/Forc.toml @@ -0,0 +1,6 @@ +[project] +authors = ["Fuel Labs "] +entry = "main.sw" +license = "Apache-2.0" +name = "associated_type_not_in_trait" +implicit-std = false diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/associated_type_not_in_trait/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_fail/associated_type_not_in_trait/src/main.sw new file mode 100644 index 00000000000..5a1f41599ba --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/associated_type_not_in_trait/src/main.sw @@ -0,0 +1,4 @@ +script; +trait Trait{} +struct Struct0{} +impl Trait for Struct0{type u;const u=0;} \ No newline at end of file diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/associated_type_not_in_trait/test.toml b/test/src/e2e_vm_tests/test_programs/should_fail/associated_type_not_in_trait/test.toml new file mode 100644 index 00000000000..74ffd8a5f62 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/associated_type_not_in_trait/test.toml @@ -0,0 +1,3 @@ +category = "fail" + +# check: $()Type "u" is not a part of trait "Trait"'s interface surface.