Sitelet https://github.com/starkware-libs/cairo/commit/0dd4cbcd7a26bce163e4eb20466d8315e3ff1c55
Skip to content

Commit 0dd4cbc

Browse files
authored
bugfix(semantic): Fixed suggested crate:: context paths. (#10044)
1 parent 219825c commit 0dd4cbc

2 files changed

Lines changed: 46 additions & 0 deletions

File tree

‎crates/cairo-lang-semantic/src/path.rs‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,10 @@ fn get_contextualized_path<'db>(
145145
}
146146

147147
if owning_crate == context_module.owning_crate(db) {
148+
// Removing the crate name for the provided path, as `crate::` prefix already denotes the
149+
// crate root.
150+
let mut path_items = path_items;
151+
path_items.pop();
148152
return Ok(ItemAccessInfo::new(ItemAccessKind::ViaCrate, path_items, item_name));
149153
}
150154

‎crates/cairo-lang-semantic/src/path_test_data/tests‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,45 @@
1+
//! > Path via crate does not double-encode the crate name.
2+
3+
//! > test_runner_name
4+
test_path_diagnostics(expect_diagnostics: true)
5+
6+
//! > crate_settings
7+
edition = "2024_07"
8+
9+
//! > module_code
10+
mod provider1 {
11+
pub trait T {
12+
fn foo(self: @felt252);
13+
}
14+
impl I of T {
15+
fn foo(self: @felt252) {}
16+
}
17+
}
18+
mod provider2 {
19+
pub trait T {
20+
fn foo(self: @felt252);
21+
}
22+
impl I of T {
23+
fn foo(self: @felt252) {}
24+
}
25+
}
26+
mod caller {
27+
use crate::provider1::*;
28+
use crate::provider2::*;
29+
fn go() {
30+
let x = 1_felt252;
31+
x.foo();
32+
}
33+
}
34+
35+
//! > expected_diagnostics
36+
error[E2046]: Ambiguous method call. More than one applicable trait function with a suitable self type was found: crate::provider1::T::foo and crate::provider2::T::foo. Consider adding type annotations or explicitly refer to the impl function.
37+
--> lib.cairo:22:11
38+
x.foo();
39+
^^^
40+
41+
//! > ==========================================================================
42+
143
//! > Ambiguous trait function via glob use
244

345
//! > test_runner_name

0 commit comments

Comments
 (0)