Sitelet https://github.com/starkware-libs/cairo/commit/53098f7a2cef966970a1a95be95b8befaa598e2e
Skip to content

Commit 53098f7

Browse files
committed
fix(semantic): don't ICE on a wrong generic-argument count through a local use alias
`specialize_generic_statement_arg` unwrapped the `Maybe` returned by `specialize_generic_module_item`, which errors on e.g. `TooManyGenericArguments`. Every sibling resolution path propagates that error with `?`; only the statement-`use` path (`ResolvedBase::StatementEnvironment`) unwrapped, so `use Pair as P; P::<felt252, u8, u16> { .. }` panicked instead of emitting E2163. Return `Maybe` and propagate with `?`.
1 parent daff9bc commit 53098f7

2 files changed

Lines changed: 37 additions & 12 deletions

File tree

  • crates/cairo-lang-semantic/src

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1651,3 +1651,30 @@ error[E2099]: Item is not visible in this context through any of the modules: `t
16511651
--> lib.cairo:11:1
16521652
AMBIGUOUS
16531653
^^^^^^^^^
1654+
1655+
//! > ==========================================================================
1656+
1657+
//! > Local use alias with a wrong generic-argument count is diagnosed, not an ICE.
1658+
1659+
//! > test_runner_name
1660+
test_expr_diagnostics(expect_diagnostics: true)
1661+
1662+
//! > module_code
1663+
struct Pair<S, T> {
1664+
a: S,
1665+
b: T,
1666+
}
1667+
1668+
//! > function_body
1669+
use Pair as P;
1670+
1671+
//! > expr_code
1672+
P::<felt252, u8, u16> { a: 0, b: 0 }
1673+
1674+
//! > expected_semantics
1675+
1676+
//! > expected_diagnostics
1677+
error[E2163]: Expected 2 generic arguments, found 3.
1678+
--> lib.cairo:6:18
1679+
P::<felt252, u8, u16> { a: 0, b: 0 }
1680+
^^^

‎crates/cairo-lang-semantic/src/resolve/mod.rs‎

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1560,23 +1560,21 @@ impl<'db> Resolver<'db> {
15601560
identifier: &ast::TerminalIdentifier<'db>,
15611561
inner_generic_item: ResolvedGenericItem<'db>,
15621562
generic_args_syntax: Option<Vec<ast::GenericArg<'db>>>,
1563-
) -> ResolvedConcreteItem<'db> {
1563+
) -> Maybe<ResolvedConcreteItem<'db>> {
15641564
let segment_stable_ptr = segment.stable_ptr(self.db).untyped();
1565-
let mut specialized_item = self
1566-
.specialize_generic_module_item(
1567-
diagnostics,
1568-
identifier,
1569-
inner_generic_item,
1570-
generic_args_syntax.clone(),
1571-
)
1572-
.unwrap();
1565+
let mut specialized_item = self.specialize_generic_module_item(
1566+
diagnostics,
1567+
identifier,
1568+
inner_generic_item,
1569+
generic_args_syntax.clone(),
1570+
)?;
15731571
self.handle_same_impl_trait(
15741572
diagnostics,
15751573
&mut specialized_item,
15761574
&generic_args_syntax.unwrap_or_default(),
15771575
segment_stable_ptr,
15781576
);
1579-
specialized_item
1577+
Ok(specialized_item)
15801578
}
15811579
}
15821580

@@ -1899,7 +1897,7 @@ impl<'db, 'a> Resolution<'db, 'a> {
18991897
&identifier,
19001898
generic_item,
19011899
segment.generic_args(db),
1902-
);
1900+
)?;
19031901
self.resolver.resolved_items.mark_concrete(db, &segment, concrete_item)
19041902
}
19051903
ResolvedBase::FoundThroughGlobalUse {
@@ -1974,7 +1972,7 @@ impl<'db, 'a> Resolution<'db, 'a> {
19741972
&identifier,
19751973
generic_item,
19761974
segment.generic_args(db),
1977-
);
1975+
)?;
19781976
self.resolver.resolved_items.mark_concrete(db, &segment, concrete_item)
19791977
}
19801978
ResolvedBase::FoundThroughGlobalUse {

0 commit comments

Comments
 (0)