Skip to content

Commit 9f359c7

Browse files
committed
moar
1 parent 289886e commit 9f359c7

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed

crates/filament/src/ast_passes/desugar_conditionals.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::ast_visitor::{Action, Visitor};
22
use fil_ast as ast;
33
use fil_ast::Loc;
4-
use fil_utils::{Error, FilamentResult};
4+
use fil_utils::{Error, FilamentResult, GPosIdx};
55

66
/// Desugars conditional constraints into assume statements
77
#[derive(Default)]
@@ -48,6 +48,8 @@ impl DesugarConditionals {
4848
) -> FilamentResult<Vec<ast::Command>> {
4949
use ast::FCons;
5050

51+
let original_loc = constraint.pos(); // Capture original location
52+
5153
match &**constraint {
5254
FCons::ConditionalC {
5355
condition,
@@ -57,12 +59,12 @@ impl DesugarConditionals {
5759
let mut facts = Vec::new();
5860

5961
// Create: assume condition => then_constraint
60-
let then_fact = self.create_assume_fact(condition.clone(), then_constraint)?;
62+
let then_fact = self.create_assume_fact(condition.clone(), then_constraint, original_loc)?;
6163
facts.push(ast::Command::Fact(then_fact));
6264

6365
// Create: assume !condition => else_constraint
6466
let negated_condition = self.negate_condition(condition)?;
65-
let else_fact = self.create_assume_fact(negated_condition, else_constraint)?;
67+
let else_fact = self.create_assume_fact(negated_condition, else_constraint, original_loc)?;
6668
facts.push(ast::Command::Fact(else_fact));
6769

6870
Ok(facts)
@@ -79,15 +81,16 @@ impl DesugarConditionals {
7981
&self,
8082
condition: ast::OrderConstraint<ast::Expr>,
8183
constraint: &ast::FCons,
84+
original_loc: GPosIdx,
8285
) -> FilamentResult<ast::Fact> {
8386
// Convert FCons to OrderConstraint
8487
let constraint_oc = self.fcons_to_order_constraint(constraint)?;
8588

8689
// Create implication: condition => constraint
8790
let implication = ast::Implication::implies(condition, constraint_oc);
8891

89-
// Create assume fact
90-
Ok(ast::Fact::assume(Loc::unknown(implication)))
92+
// Create assume fact with original location
93+
Ok(ast::Fact::assume(Loc::new(implication, original_loc)))
9194
}
9295

9396
fn fcons_to_order_constraint(

tests/errors/conditional/complex-equality-error.expect

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@
22
1
33
---STDERR---
44
error: cannot prove source-level fact
5-
= Elaborated during monomorphization.
5+
┌─ tests/errors/conditional/complex-equality-error.fil:2:54
6+
7+
2 │ comp ComplexEqualityError[A, B]<'G: 1>() -> () where A + B == B * 2 ? A == 1 : A == 0 {
8+
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot prove source-level fact
9+
10+
= Elaborated during monomorphization.
611

712
Compilation failed with 1 errors.
813
Run with --show-models to generate assignments for failing constraints.

tests/errors/constraints/conditional-lt-violation.expect

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@
22
1
33
---STDERR---
44
error: cannot prove source-level fact
5-
= Elaborated during monomorphization.
5+
┌─ tests/errors/constraints/conditional-lt-violation.fil:2:56
6+
7+
2 │ comp ConditionalLtViolation[W, L]<'G: 1>() -> () where W < 10 ? L == 1 : L == 2 {
8+
│ ^^^^^^^^^^^^^^^^^^^^^^^^^ cannot prove source-level fact
9+
10+
= Elaborated during monomorphization.
611

712
Compilation failed with 1 errors.
813
Run with --show-models to generate assignments for failing constraints.

0 commit comments

Comments
 (0)