Skip to content

Commit deb5121

Browse files
committed
Removed too eager solver runners, preventing wrong type assumptions. (#7553)
1 parent 55e0abc commit deb5121

File tree

3 files changed

+33
-10
lines changed

3 files changed

+33
-10
lines changed

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

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1954,9 +1954,11 @@ fn compute_expr_indexed_semantic(
19541954
let expr = compute_expr_semantic(ctx, &syntax.expr(syntax_db));
19551955
let index_expr_syntax = &syntax.index_expr(syntax_db);
19561956
let index_expr = compute_expr_semantic(ctx, index_expr_syntax);
1957-
// Make sure the maximal amount of types is known when trying to access. Ignoring the returned
1958-
// value, as any errors will be reported later.
1959-
ctx.resolver.inference().solve().ok();
1957+
if !ctx.reduce_ty(expr.ty()).is_var_free(ctx.db) {
1958+
// Make sure the maximal amount of types is known when trying to access. Ignoring the
1959+
// returned value, as any errors will be reported later.
1960+
ctx.resolver.inference().solve().ok();
1961+
}
19601962
let info = ctx.db.core_info();
19611963
let candidate_traits = [info.index_trt, info.index_view_trt];
19621964
let (function_id, _, fixed_expr, mutability) = compute_method_function_call_data(
@@ -2964,8 +2966,13 @@ fn method_call_expr(
29642966
};
29652967
let func_name = segment.identifier(syntax_db);
29662968
let generic_args_syntax = segment.generic_args(syntax_db);
2967-
// Save some work. ignore the result. The error, if any, will be reported later.
2968-
ctx.resolver.inference().solve().ok();
2969+
2970+
if !ctx.reduce_ty(lexpr.ty()).is_var_free(ctx.db) {
2971+
// Run solver to get as much info on the type as possible.
2972+
// Ignore the result of the `solve()` call - the error, if any, will be
2973+
// reported later.
2974+
ctx.resolver.inference().solve().ok();
2975+
}
29692976

29702977
let mut candidate_traits = traits_in_context(ctx)?;
29712978

@@ -3168,11 +3175,14 @@ fn get_enriched_type_member_access(
31683175
stable_ptr: ast::ExprPtr,
31693176
accessed_member_name: &str,
31703177
) -> Maybe<Option<EnrichedTypeMemberAccess>> {
3171-
// Run solver to get as much info on the type as possible.
3172-
// Ignore the result of the `solve()` call - the error, if any, will be
3173-
// reported later.
3174-
ctx.resolver.inference().solve().ok();
3175-
let ty = ctx.reduce_ty(expr.ty());
3178+
let mut ty = ctx.reduce_ty(expr.ty());
3179+
if !ty.is_var_free(ctx.db) {
3180+
// Run solver to get as much info on the type as possible.
3181+
// Ignore the result of the `solve()` call - the error, if any, will be
3182+
// reported later.
3183+
ctx.resolver.inference().solve().ok();
3184+
ty = ctx.reduce_ty(ty);
3185+
}
31763186
let base_var = match &expr.expr {
31773187
Expr::Var(expr_var) => Some(expr_var.var),
31783188
Expr::MemberAccess(ExprMemberAccess { member_path: Some(member_path), .. }) => {

tests/bug_samples/issue7544.cairo

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
use core::circuit::u384;
2+
3+
pub fn foo(a: u384, b: u384) -> u384 {
4+
a
5+
}
6+
7+
#[test]
8+
fn test_into_() {
9+
let b = 1_u256.into();
10+
let a = 0_u256.into();
11+
let _r = foo(a, b);
12+
}

tests/bug_samples/lib.cairo

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ mod issue7095;
6262
mod issue7155;
6363
mod issue7233;
6464
mod issue7234;
65+
mod issue7544;
6566
mod loop_break_in_match;
6667
mod loop_only_change;
6768
mod partial_param_local;

0 commit comments

Comments
 (0)