From 92273c3bee00f5c9a6413c4391f677b6d3524808 Mon Sep 17 00:00:00 2001 From: Christoph Burgdorf Date: Tue, 22 Nov 2022 10:06:15 +0100 Subject: [PATCH] Address PR feedback --- crates/analyzer/src/traversal/expressions.rs | 6 +++++- .../tests/snapshots/errors__bad_ingot.snap | 6 +++--- .../ingots/trait_no_ambiguity/src/foo.fe | 5 +++++ .../ingots/trait_no_ambiguity/src/main.fe | 17 +++++++++++++++++ crates/tests/src/ingots.rs | 7 +++++++ 5 files changed, 37 insertions(+), 4 deletions(-) create mode 100644 crates/test-files/fixtures/ingots/trait_no_ambiguity/src/foo.fe create mode 100644 crates/test-files/fixtures/ingots/trait_no_ambiguity/src/main.fe diff --git a/crates/analyzer/src/traversal/expressions.rs b/crates/analyzer/src/traversal/expressions.rs index d3b1461c71..e2d89badee 100644 --- a/crates/analyzer/src/traversal/expressions.rs +++ b/crates/analyzer/src/traversal/expressions.rs @@ -979,7 +979,7 @@ fn expr_call_path( generic_args: &Option>>, args: &Node>>, ) -> Result<(ExpressionAttributes, CallType), FatalError> { - match context.resolve_any_path(path) { + match context.resolve_visible_path(path) { Some(named_thing) => { check_visibility(context, &named_thing, func.span); validate_has_no_conflicting_trait_in_scope(context, &named_thing, path, func)?; @@ -1107,6 +1107,10 @@ fn expr_call_trait_associated_function( } } + // At this point, we will have an error so we run `resolve_path` to register any errors that we + // did not report yet + context.resolve_path(path, func.span)?; + Err(FatalError::new(context.error( "unresolved path item", func.span, diff --git a/crates/analyzer/tests/snapshots/errors__bad_ingot.snap b/crates/analyzer/tests/snapshots/errors__bad_ingot.snap index 349bd3bb75..df0b26d3a6 100644 --- a/crates/analyzer/tests/snapshots/errors__bad_ingot.snap +++ b/crates/analyzer/tests/snapshots/errors__bad_ingot.snap @@ -94,10 +94,10 @@ error: the struct `Foo` is private = `Foo` can only be used within `foo` = Hint: use `pub` to make `Foo` visible from outside of `foo` -error: incorrect type for `Foo` argument `my_num` - ┌─ compile_errors/bad_ingot/src/main.fe:8:33 +error: unresolved path item + ┌─ compile_errors/bad_ingot/src/main.fe:8:16 │ 8 │ return foo::Foo(my_num: true) - │ ^^^^ this has type `bool`; expected type `u256` + │ ^^^^^^^^ not found diff --git a/crates/test-files/fixtures/ingots/trait_no_ambiguity/src/foo.fe b/crates/test-files/fixtures/ingots/trait_no_ambiguity/src/foo.fe new file mode 100644 index 0000000000..81b93946a6 --- /dev/null +++ b/crates/test-files/fixtures/ingots/trait_no_ambiguity/src/foo.fe @@ -0,0 +1,5 @@ +pub struct MyS { + fn x() -> u256 { + return 10 + } +} \ No newline at end of file diff --git a/crates/test-files/fixtures/ingots/trait_no_ambiguity/src/main.fe b/crates/test-files/fixtures/ingots/trait_no_ambiguity/src/main.fe new file mode 100644 index 0000000000..fe7274ad2d --- /dev/null +++ b/crates/test-files/fixtures/ingots/trait_no_ambiguity/src/main.fe @@ -0,0 +1,17 @@ +use foo::MyS + +trait Trait { + fn x() -> u256; +} + +impl Trait for MyS { + fn x() -> u256 { + return 10 + } +} + +contract Foo { + pub fn main() -> u256 { + return MyS::x() + } +} diff --git a/crates/tests/src/ingots.rs b/crates/tests/src/ingots.rs index fe4d77edd1..db1141ac65 100644 --- a/crates/tests/src/ingots.rs +++ b/crates/tests/src/ingots.rs @@ -23,6 +23,13 @@ fn test_ingot_with_visibility() { }) } +#[test] +fn test_trait_no_ambiguity() { + with_executor(&|mut executor| { + let _harness = deploy_ingot(&mut executor, "trait_no_ambiguity", "Foo", &[]); + }) +} + #[test] fn test_ingot_pub_contract() { with_executor(&|mut executor| {