diff --git a/sway-core/src/transform/to_parsed_lang/convert_parse_tree.rs b/sway-core/src/transform/to_parsed_lang/convert_parse_tree.rs index 18e0b945370..8fcedefb7b7 100644 --- a/sway-core/src/transform/to_parsed_lang/convert_parse_tree.rs +++ b/sway-core/src/transform/to_parsed_lang/convert_parse_tree.rs @@ -3483,36 +3483,6 @@ fn statement_let_to_ast_nodes( let tuple_name = Ident::new_with_override(tuple_name, span.clone()); - // Parse the type ascription and the type ascription span. - // In the event that the user did not provide a type ascription, - // it is set to TypeInfo::Unknown and the span to None. - let type_ascription = match &ty_opt { - Some(ty) => ty_to_type_argument(context, handler, engines, ty.clone())?, - None => { - let type_id = engines.te().insert(engines, TypeInfo::Unknown, None); - TypeArgument { - type_id, - initial_type_id: type_id, - span: tuple_name.span(), - call_path_tree: None, - } - } - }; - - // Save the tuple to the new name as a new variable declaration. - let save_body_first = VariableDeclaration { - name: tuple_name.clone(), - type_ascription, - body: expression, - is_mutable: false, - }; - ast_nodes.push(AstNode { - content: AstNodeContent::Declaration(Declaration::VariableDeclaration( - save_body_first, - )), - span: span.clone(), - }); - // Acript a second declaration to a tuple of placeholders to check that the tuple // is properly sized to the pattern let placeholders_type_ascription = { @@ -3561,6 +3531,28 @@ fn statement_let_to_ast_nodes( } }; + // Parse the type ascription and the type ascription span. + // In the event that the user did not provide a type ascription, + // it is set to TypeInfo::Unknown and the span to None. + let type_ascription = match &ty_opt { + Some(ty) => ty_to_type_argument(context, handler, engines, ty.clone())?, + None => placeholders_type_ascription.clone(), + }; + + // Save the tuple to the new name as a new variable declaration. + let save_body_first = VariableDeclaration { + name: tuple_name.clone(), + type_ascription, + body: expression, + is_mutable: false, + }; + ast_nodes.push(AstNode { + content: AstNodeContent::Declaration(Declaration::VariableDeclaration( + save_body_first, + )), + span: span.clone(), + }); + // create a variable expression that points to the new tuple name that we just created let new_expr = Expression { kind: ExpressionKind::Variable(tuple_name.clone()), diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/generic_trait_tuple_without_type_ascription/Forc.lock b/test/src/e2e_vm_tests/test_programs/should_fail/generic_trait_tuple_without_type_ascription/Forc.lock new file mode 100644 index 00000000000..78dab8d06cf --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/generic_trait_tuple_without_type_ascription/Forc.lock @@ -0,0 +1,13 @@ +[[package]] +name = "core" +source = "path+from-root-B089E2A459F9A9B9" + +[[package]] +name = "generic_trait_tuple_without_type_ascription" +source = "member" +dependencies = ["std"] + +[[package]] +name = "std" +source = "path+from-root-B089E2A459F9A9B9" +dependencies = ["core"] diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/generic_trait_tuple_without_type_ascription/Forc.toml b/test/src/e2e_vm_tests/test_programs/should_fail/generic_trait_tuple_without_type_ascription/Forc.toml new file mode 100644 index 00000000000..6dd1246fb39 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/generic_trait_tuple_without_type_ascription/Forc.toml @@ -0,0 +1,8 @@ +[project] +authors = ["Fuel Labs "] +entry = "main.sw" +license = "Apache-2.0" +name = "generic_trait_tuple_without_type_ascription" + +[dependencies] +std = { path = "../../../../../../sway-lib-std" } diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/generic_trait_tuple_without_type_ascription/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_fail/generic_trait_tuple_without_type_ascription/src/main.sw new file mode 100644 index 00000000000..ba09633eb3b --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/generic_trait_tuple_without_type_ascription/src/main.sw @@ -0,0 +1,32 @@ +script; + +pub trait MyFrom { + fn from(b: T) -> Self; +} + + +pub trait MyInto { + fn into(self) -> T; +} + + +impl MyInto for T +where + U: MyFrom, +{ + fn into(self) -> U { + U::from(self) + } +} + +impl MyFrom for (u64, u64, u64, u64) { + fn from(_val: u256) -> (u64, u64, u64, u64) { + (42, 0, 0, 0) + } +} + +fn main() -> bool { + let (_a, _b, _c, _d) = u256::min().into(); + + true +} \ No newline at end of file diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/generic_trait_tuple_without_type_ascription/test.toml b/test/src/e2e_vm_tests/test_programs/should_fail/generic_trait_tuple_without_type_ascription/test.toml new file mode 100644 index 00000000000..1cd2ae6fde6 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/generic_trait_tuple_without_type_ascription/test.toml @@ -0,0 +1,7 @@ +category = "fail" + +# check: $()let (_a, _b, _c, _d) = u256::min().into(); +# nextln: $()Trait "MyFrom" is not implemented for type "(_, _, _, _)". + +# check: $()let (_a, _b, _c, _d) = u256::min().into(); +# nextln: $()Cannot infer type for type parameter "_". Insufficient type information provided. Try annotating its type.