From be0c915dbe79dc7529e870193c7a0e6c307cbbf4 Mon Sep 17 00:00:00 2001 From: Ary Borenszweig Date: Wed, 2 Oct 2024 11:59:52 -0300 Subject: [PATCH 1/2] Type variables by default should have Any kind --- compiler/noirc_frontend/src/hir_def/types.rs | 2 +- .../numeric_turbofish/Nargo.toml | 6 ++++++ .../numeric_turbofish/src/main.nr | 11 +++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 test_programs/compile_success_empty/numeric_turbofish/Nargo.toml create mode 100644 test_programs/compile_success_empty/numeric_turbofish/src/main.nr diff --git a/compiler/noirc_frontend/src/hir_def/types.rs b/compiler/noirc_frontend/src/hir_def/types.rs index 8f20fe1c685..b8c98428bb0 100644 --- a/compiler/noirc_frontend/src/hir_def/types.rs +++ b/compiler/noirc_frontend/src/hir_def/types.rs @@ -881,7 +881,7 @@ impl Type { } pub fn type_variable(id: TypeVariableId) -> Type { - let var = TypeVariable::unbound(id, Kind::Normal); + let var = TypeVariable::unbound(id, Kind::Any); Type::TypeVariable(var) } diff --git a/test_programs/compile_success_empty/numeric_turbofish/Nargo.toml b/test_programs/compile_success_empty/numeric_turbofish/Nargo.toml new file mode 100644 index 00000000000..487541ea474 --- /dev/null +++ b/test_programs/compile_success_empty/numeric_turbofish/Nargo.toml @@ -0,0 +1,6 @@ +[package] +name = "numeric_turbofish" +type = "bin" +authors = [""] + +[dependencies] diff --git a/test_programs/compile_success_empty/numeric_turbofish/src/main.nr b/test_programs/compile_success_empty/numeric_turbofish/src/main.nr new file mode 100644 index 00000000000..c31bf9e0c50 --- /dev/null +++ b/test_programs/compile_success_empty/numeric_turbofish/src/main.nr @@ -0,0 +1,11 @@ +struct Reader { +} + +impl Reader { + fn read(_self: Self) {} +} + +fn main() { + let reader: Reader<1234> = Reader {}; + let _ = reader.read::<1234>(); +} From 4c7e4f1a11a94d5e018abdec0644a60c388c3e96 Mon Sep 17 00:00:00 2001 From: Ary Borenszweig Date: Wed, 2 Oct 2024 12:24:40 -0300 Subject: [PATCH 2/2] Move test to frontend test --- compiler/noirc_frontend/src/tests/turbofish.rs | 18 ++++++++++++++++++ .../numeric_turbofish/Nargo.toml | 6 ------ .../numeric_turbofish/src/main.nr | 11 ----------- 3 files changed, 18 insertions(+), 17 deletions(-) delete mode 100644 test_programs/compile_success_empty/numeric_turbofish/Nargo.toml delete mode 100644 test_programs/compile_success_empty/numeric_turbofish/src/main.nr diff --git a/compiler/noirc_frontend/src/tests/turbofish.rs b/compiler/noirc_frontend/src/tests/turbofish.rs index 43d536fd196..b1156b20eb0 100644 --- a/compiler/noirc_frontend/src/tests/turbofish.rs +++ b/compiler/noirc_frontend/src/tests/turbofish.rs @@ -196,3 +196,21 @@ fn turbofish_in_struct_pattern_generic_count_mismatch() { assert_eq!(*expected, 1); assert_eq!(*found, 2); } + +#[test] +fn numeric_turbofish() { + let src = r#" + struct Reader { + } + + impl Reader { + fn read(_self: Self) {} + } + + fn main() { + let reader: Reader<1234> = Reader {}; + let _ = reader.read::<1234>(); + } + "#; + assert_no_errors(src); +} diff --git a/test_programs/compile_success_empty/numeric_turbofish/Nargo.toml b/test_programs/compile_success_empty/numeric_turbofish/Nargo.toml deleted file mode 100644 index 487541ea474..00000000000 --- a/test_programs/compile_success_empty/numeric_turbofish/Nargo.toml +++ /dev/null @@ -1,6 +0,0 @@ -[package] -name = "numeric_turbofish" -type = "bin" -authors = [""] - -[dependencies] diff --git a/test_programs/compile_success_empty/numeric_turbofish/src/main.nr b/test_programs/compile_success_empty/numeric_turbofish/src/main.nr deleted file mode 100644 index c31bf9e0c50..00000000000 --- a/test_programs/compile_success_empty/numeric_turbofish/src/main.nr +++ /dev/null @@ -1,11 +0,0 @@ -struct Reader { -} - -impl Reader { - fn read(_self: Self) {} -} - -fn main() { - let reader: Reader<1234> = Reader {}; - let _ = reader.read::<1234>(); -}