Skip to content

Commit 9ff0d29

Browse files
committed
fix: emit diagnostic for member access on unreduced impl type instead of panicking
Fixes #9788
1 parent 44fa634 commit 9ff0d29

File tree

2 files changed

+46
-8
lines changed

2 files changed

+46
-8
lines changed

crates/cairo-lang-semantic/src/expr/compute.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use std::ops::Deref;
77
use std::sync::Arc;
88

99
use ast::PathSegment;
10-
use cairo_lang_debug::DebugWithDb;
1110
use cairo_lang_defs::db::{DefsGroup, get_all_path_leaves, validate_attributes_flat};
1211
use cairo_lang_defs::diagnostic_utils::StableLocation;
1312
use cairo_lang_defs::ids::{
@@ -3961,17 +3960,16 @@ fn member_access_expr<'db>(
39613960
TypeLongId::Closure(_) => {
39623961
Err(ctx.diagnostics.report(rhs_syntax.stable_ptr(db), Unsupported))
39633962
}
3964-
TypeLongId::ImplType(impl_type_id) => {
3965-
unreachable!("Impl type should've been reduced {:?}.", impl_type_id.debug(ctx.db))
3966-
}
39673963
TypeLongId::Var(_) => Err(ctx.diagnostics.report(
39683964
rhs_syntax.stable_ptr(db),
39693965
InternalInferenceError(InferenceError::TypeNotInferred(long_ty.intern(ctx.db))),
39703966
)),
3971-
TypeLongId::GenericParameter(_) | TypeLongId::Coupon(_) => Err(ctx.diagnostics.report(
3972-
rhs_syntax.stable_ptr(db),
3973-
TypeHasNoMembers { ty: long_ty.intern(ctx.db), member_name },
3974-
)),
3967+
TypeLongId::ImplType(_) | TypeLongId::GenericParameter(_) | TypeLongId::Coupon(_) => {
3968+
Err(ctx.diagnostics.report(
3969+
rhs_syntax.stable_ptr(db),
3970+
TypeHasNoMembers { ty: long_ty.intern(ctx.db), member_name },
3971+
))
3972+
}
39753973
TypeLongId::Missing(diag_added) => Err(*diag_added),
39763974
}
39773975
}

crates/cairo-lang-semantic/src/expr/test_data/structure

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,43 @@ error[E2023]: Base struct has no effect, all the fields in the struct have alrea
127127
--> lib.cairo:5:15
128128
A { a: 4, ..a }
129129
^^^
130+
131+
//! > ==========================================================================
132+
133+
//! > Member access on unreduced impl associated type.
134+
135+
//! > test_runner_name
136+
test_function_diagnostics(expect_diagnostics: true)
137+
138+
//! > function_code
139+
fn foo() {}
140+
141+
//! > function_name
142+
foo
143+
144+
//! > module_code
145+
struct S {
146+
val: felt252,
147+
}
148+
149+
trait T<X> {
150+
type A;
151+
fn f(self: @X) -> Self::A;
152+
}
153+
154+
impl I of T<S> {
155+
type A = S;
156+
fn f(self: @S) -> S {
157+
S { val: 0 }
158+
}
159+
}
160+
161+
fn g<X, impl H: T<X>>(x: @X) -> felt252 {
162+
H::f(x).val
163+
}
164+
165+
//! > expected_diagnostics
166+
error[E2057]: Type "H::A" has no members.
167+
--> lib.cairo:18:13
168+
H::f(x).val
169+
^^^

0 commit comments

Comments
 (0)