Skip to content

Commit 3abfbf8

Browse files
fix: defining an impl on a type alias (#11068)
1 parent 094a57c commit 3abfbf8

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

compiler/noirc_frontend/src/elaborator/impls.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ impl Elaborator<'_> {
154154

155155
let function_ids = functions.function_ids();
156156

157-
if let Type::DataType(data_type, _) = &self_type {
157+
if let Type::DataType(data_type, _) = &self_type.follow_bindings() {
158158
let data_ref = data_type.borrow();
159159

160160
// `impl`s are only allowed on types defined within the current crate

compiler/noirc_frontend/src/tests/aliases.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,3 +395,41 @@ fn regression_10415_without_alias() {
395395
"#;
396396
assert_no_errors(src);
397397
}
398+
399+
#[test]
400+
fn regression_10429() {
401+
let src = r#"
402+
struct Struct {}
403+
404+
type Alias = Struct;
405+
406+
impl Alias {}
407+
408+
fn main() {}
409+
"#;
410+
assert_no_errors(src);
411+
}
412+
413+
#[test]
414+
fn regression_10429_with_trait() {
415+
let src = r#"
416+
struct Struct {}
417+
418+
type Alias = Struct;
419+
420+
trait Foo {
421+
fn foo() -> Self;
422+
}
423+
424+
impl Foo for Alias {
425+
fn foo() -> Self {
426+
Struct {}
427+
}
428+
}
429+
430+
fn main() {
431+
let _alias: Alias = <Alias as Foo>::foo();
432+
}
433+
"#;
434+
assert_no_errors(src);
435+
}

0 commit comments

Comments
 (0)