From e560cd2f56f78486d5add12bc6fce16b6b1d36f6 Mon Sep 17 00:00:00 2001 From: kevaundray Date: Wed, 21 Jun 2023 22:33:15 +0100 Subject: [PATCH] fix: Methods called after being passed through a generic type were not being detected (#1785) * add follow-bindings method * add regression test * delete contents of Prover.toml * chain call onto check_expression * use underscore --- .../Nargo.toml | 5 ++++ .../Prover.toml | 1 + .../src/main.nr | 23 +++++++++++++++++++ .../noirc_frontend/src/hir/type_check/expr.rs | 2 +- 4 files changed, 30 insertions(+), 1 deletion(-) 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..8b137891791 --- /dev/null +++ b/crates/nargo_cli/tests/test_data_ssa_refactor/regression_method_cannot_be_found/Prover.toml @@ -0,0 +1 @@ + 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..4c1f771ae6c --- /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(); +} diff --git a/crates/noirc_frontend/src/hir/type_check/expr.rs b/crates/noirc_frontend/src/hir/type_check/expr.rs index d0d3166a733..7160d1f153d 100644 --- a/crates/noirc_frontend/src/hir/type_check/expr.rs +++ b/crates/noirc_frontend/src/hir/type_check/expr.rs @@ -113,7 +113,7 @@ 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(); match self.lookup_method(object_type.clone(), method_name, expr_id) { Some(method_id) => {