From 0881ef51b1c525c63997169f546032febc1b6b5f Mon Sep 17 00:00:00 2001 From: kevaundray Date: Wed, 21 Jun 2023 20:23:30 +0000 Subject: [PATCH 1/5] add follow-bindings method --- crates/noirc_frontend/src/hir/type_check/expr.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/noirc_frontend/src/hir/type_check/expr.rs b/crates/noirc_frontend/src/hir/type_check/expr.rs index d0d3166a733..87ee335572d 100644 --- a/crates/noirc_frontend/src/hir/type_check/expr.rs +++ b/crates/noirc_frontend/src/hir/type_check/expr.rs @@ -115,6 +115,7 @@ impl<'interner> TypeChecker<'interner> { HirExpression::MethodCall(method_call) => { let object_type = self.check_expression(&method_call.object); let method_name = method_call.method.0.contents.as_str(); + let object_type = object_type.follow_bindings(); match self.lookup_method(object_type.clone(), method_name, expr_id) { Some(method_id) => { let mut args = From 7e3abd56127fab0d960e1a2e8da17b797d37a00c Mon Sep 17 00:00:00 2001 From: kevaundray Date: Wed, 21 Jun 2023 20:23:39 +0000 Subject: [PATCH 2/5] add regression test --- .../Nargo.toml | 5 +++ .../Prover.toml | 35 +++++++++++++++++++ .../src/main.nr | 23 ++++++++++++ 3 files changed, 63 insertions(+) create mode 100644 crates/nargo_cli/tests/test_data_ssa_refactor/regression_method_cannot_be_found/Nargo.toml create mode 100644 crates/nargo_cli/tests/test_data_ssa_refactor/regression_method_cannot_be_found/Prover.toml create mode 100644 crates/nargo_cli/tests/test_data_ssa_refactor/regression_method_cannot_be_found/src/main.nr diff --git a/crates/nargo_cli/tests/test_data_ssa_refactor/regression_method_cannot_be_found/Nargo.toml b/crates/nargo_cli/tests/test_data_ssa_refactor/regression_method_cannot_be_found/Nargo.toml new file mode 100644 index 00000000000..e0b467ce5da --- /dev/null +++ b/crates/nargo_cli/tests/test_data_ssa_refactor/regression_method_cannot_be_found/Nargo.toml @@ -0,0 +1,5 @@ +[package] +authors = [""] +compiler_version = "0.1" + +[dependencies] \ No newline at end of file diff --git a/crates/nargo_cli/tests/test_data_ssa_refactor/regression_method_cannot_be_found/Prover.toml b/crates/nargo_cli/tests/test_data_ssa_refactor/regression_method_cannot_be_found/Prover.toml new file mode 100644 index 00000000000..d65c4011d3f --- /dev/null +++ b/crates/nargo_cli/tests/test_data_ssa_refactor/regression_method_cannot_be_found/Prover.toml @@ -0,0 +1,35 @@ +x = 0xbd +result = [ + 0x5a, + 0x50, + 0x2f, + 0x9f, + 0xca, + 0x46, + 0x7b, + 0x26, + 0x6d, + 0x5b, + 0x78, + 0x33, + 0x65, + 0x19, + 0x37, + 0xe8, + 0x05, + 0x27, + 0x0c, + 0xa3, + 0xf3, + 0xaf, + 0x1c, + 0x0d, + 0xd2, + 0x46, + 0x2d, + 0xca, + 0x4b, + 0x3b, + 0x1a, + 0xbf, +] diff --git a/crates/nargo_cli/tests/test_data_ssa_refactor/regression_method_cannot_be_found/src/main.nr b/crates/nargo_cli/tests/test_data_ssa_refactor/regression_method_cannot_be_found/src/main.nr new file mode 100644 index 00000000000..52bd61a437d --- /dev/null +++ b/crates/nargo_cli/tests/test_data_ssa_refactor/regression_method_cannot_be_found/src/main.nr @@ -0,0 +1,23 @@ +use dep::std; +struct Item { + id: Field, +} + +impl Item { + fn log(self) { + let id = self.id; + std::println(id); + } +} + +fn create(something: V) -> V { + something +} + +fn main() { + let a = Item { id: 1 }; + let b = create(a); + let id = b.id; + // Regression for: cannot find this method + b.log(); +} From 92fcfeca13851e07faefe96a8c6f9c0daa4ef822 Mon Sep 17 00:00:00 2001 From: kevaundray Date: Wed, 21 Jun 2023 20:26:00 +0000 Subject: [PATCH 3/5] delete contents of Prover.toml --- .../Prover.toml | 36 +------------------ 1 file changed, 1 insertion(+), 35 deletions(-) diff --git a/crates/nargo_cli/tests/test_data_ssa_refactor/regression_method_cannot_be_found/Prover.toml b/crates/nargo_cli/tests/test_data_ssa_refactor/regression_method_cannot_be_found/Prover.toml index d65c4011d3f..8b137891791 100644 --- a/crates/nargo_cli/tests/test_data_ssa_refactor/regression_method_cannot_be_found/Prover.toml +++ b/crates/nargo_cli/tests/test_data_ssa_refactor/regression_method_cannot_be_found/Prover.toml @@ -1,35 +1 @@ -x = 0xbd -result = [ - 0x5a, - 0x50, - 0x2f, - 0x9f, - 0xca, - 0x46, - 0x7b, - 0x26, - 0x6d, - 0x5b, - 0x78, - 0x33, - 0x65, - 0x19, - 0x37, - 0xe8, - 0x05, - 0x27, - 0x0c, - 0xa3, - 0xf3, - 0xaf, - 0x1c, - 0x0d, - 0xd2, - 0x46, - 0x2d, - 0xca, - 0x4b, - 0x3b, - 0x1a, - 0xbf, -] + From 11a36bce0732eb9984dd43c45316a835d648a71c Mon Sep 17 00:00:00 2001 From: kevaundray Date: Wed, 21 Jun 2023 20:28:05 +0000 Subject: [PATCH 4/5] chain call onto check_expression --- crates/noirc_frontend/src/hir/type_check/expr.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/crates/noirc_frontend/src/hir/type_check/expr.rs b/crates/noirc_frontend/src/hir/type_check/expr.rs index 87ee335572d..7160d1f153d 100644 --- a/crates/noirc_frontend/src/hir/type_check/expr.rs +++ b/crates/noirc_frontend/src/hir/type_check/expr.rs @@ -113,9 +113,8 @@ impl<'interner> TypeChecker<'interner> { self.bind_function_type(function, args, span) } HirExpression::MethodCall(method_call) => { - let object_type = self.check_expression(&method_call.object); + let object_type = self.check_expression(&method_call.object).follow_bindings(); let method_name = method_call.method.0.contents.as_str(); - let object_type = object_type.follow_bindings(); match self.lookup_method(object_type.clone(), method_name, expr_id) { Some(method_id) => { let mut args = From f743f592b95812aed1351815c93cc5b5315a7a6d Mon Sep 17 00:00:00 2001 From: kevaundray Date: Wed, 21 Jun 2023 20:28:14 +0000 Subject: [PATCH 5/5] use underscore --- .../regression_method_cannot_be_found/src/main.nr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/nargo_cli/tests/test_data_ssa_refactor/regression_method_cannot_be_found/src/main.nr b/crates/nargo_cli/tests/test_data_ssa_refactor/regression_method_cannot_be_found/src/main.nr index 52bd61a437d..4c1f771ae6c 100644 --- a/crates/nargo_cli/tests/test_data_ssa_refactor/regression_method_cannot_be_found/src/main.nr +++ b/crates/nargo_cli/tests/test_data_ssa_refactor/regression_method_cannot_be_found/src/main.nr @@ -17,7 +17,7 @@ fn create(something: V) -> V { fn main() { let a = Item { id: 1 }; let b = create(a); - let id = b.id; + let _id = b.id; // Regression for: cannot find this method b.log(); }