Skip to content

Commit 55f3ada

Browse files
committed
Fix ordering of expected and found types in elaboration::convert
1 parent a74f45e commit 55f3ada

16 files changed

+79
-76
lines changed

fathom/src/surface/elaboration.rs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -456,8 +456,9 @@ impl<'interner, 'arena> Context<'interner, 'arena> {
456456
});
457457
}
458458

459-
let filtered_fields = (fields.iter().enumerate())
460-
.filter_map(move |(index, field)| (!duplicate_indices.contains(&index)).then_some(field));
459+
let filtered_fields = (fields.iter().enumerate()).filter_map(move |(index, field)| {
460+
(!duplicate_indices.contains(&index)).then_some(field)
461+
});
461462

462463
(labels.into(), filtered_fields)
463464
}
@@ -561,7 +562,7 @@ impl<'interner, 'arena> Context<'interner, 'arena> {
561562
}
562563
}
563564

564-
/// Conversion checking for `expr` under the types `type0` and `type1`.
565+
/// Conversion checking for `expr` under the types `from` and `to`.
565566
/// This will trigger unification, recording a unification error on failure.
566567
//
567568
// NOTE: We could eventually call this method `coerce` if we end up adding
@@ -570,8 +571,8 @@ impl<'interner, 'arena> Context<'interner, 'arena> {
570571
&mut self,
571572
surface_range: ByteRange, // TODO: could be removed if we never encounter empty spans in the core term
572573
expr: core::Term<'arena>,
573-
type0: &ArcValue<'arena>,
574-
type1: &ArcValue<'arena>,
574+
from: &ArcValue<'arena>,
575+
to: &ArcValue<'arena>,
575576
) -> core::Term<'arena> {
576577
let span = expr.span();
577578
let range = match span {
@@ -583,15 +584,15 @@ impl<'interner, 'arena> Context<'interner, 'arena> {
583584
surface_range
584585
}
585586
};
586-
match self.unification_context().unify(type0, type1) {
587+
match self.unification_context().unify(from, to) {
587588
Ok(()) => expr,
588589
Err(error) => {
589-
let lhs = self.pretty_print_value(type0);
590-
let rhs = self.pretty_print_value(type1);
590+
let from = self.pretty_print_value(from);
591+
let to = self.pretty_print_value(to);
591592
self.push_message(Message::FailedToUnify {
592593
range,
593-
lhs,
594-
rhs,
594+
found: from,
595+
expected: to,
595596
error,
596597
});
597598
core::Term::Prim(span, Prim::ReportedError)
@@ -835,8 +836,8 @@ impl<'interner, 'arena> Context<'interner, 'arena> {
835836
let rhs = self.pretty_print_value(expected_type);
836837
self.push_message(Message::FailedToUnify {
837838
range,
838-
lhs,
839-
rhs,
839+
found: lhs,
840+
expected: rhs,
840841
error,
841842
});
842843
CheckedPattern::ReportedError(range)

fathom/src/surface/elaboration/reporting.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ pub enum Message {
9494
/// Unification errors.
9595
FailedToUnify {
9696
range: ByteRange,
97-
lhs: String,
98-
rhs: String,
97+
found: String,
98+
expected: String,
9999
error: unification::Error,
100100
},
101101
BinOpMismatchedTypes {
@@ -212,9 +212,11 @@ impl Message {
212212
match type_labels.next() {
213213
None => {
214214
let expr_label = interner.resolve(*expr_label).unwrap();
215-
diagnostic_labels.push(primary_label(range).with_message(
216-
format!("unexpected field `{expr_label}`",),
217-
));
215+
diagnostic_labels.push(
216+
primary_label(range).with_message(format!(
217+
"unexpected field `{expr_label}`",
218+
)),
219+
);
218220
continue 'expr_labels;
219221
}
220222
Some(type_label) if expr_label == type_label => {
@@ -376,8 +378,8 @@ impl Message {
376378
]),
377379
Message::FailedToUnify {
378380
range,
379-
lhs,
380-
rhs,
381+
found,
382+
expected,
381383
error,
382384
} => {
383385
use unification::{Error, RenameError, SpineError};
@@ -387,11 +389,11 @@ impl Message {
387389
Error::Mismatch => Diagnostic::error()
388390
.with_message("mismatched types")
389391
.with_labels(vec![primary_label(range).with_message(format!(
390-
"type mismatch, expected `{lhs}`, found `{rhs}`"
392+
"type mismatch, expected `{expected}`, found `{found}`"
391393
))])
392394
.with_notes(vec![[
393-
format!("expected `{lhs}`"),
394-
format!(" found `{rhs}`"),
395+
format!("expected `{expected}`"),
396+
format!(" found `{found}`"),
395397
]
396398
.join("\n")]),
397399
// TODO: reduce confusion around ‘problem spines’

tests/cmd/fathom-data.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -266,10 +266,10 @@ error: mismatched types
266266
┌─ <FORMAT>:1:1
267267
268268
1 │ { x : U64 }
269-
│ ^^^^^^^^^^^ type mismatch, expected `Type`, found `Format`
269+
│ ^^^^^^^^^^^ type mismatch, expected `Format`, found `Type`
270270
271-
= expected `Type`
272-
found `Format`
271+
= expected `Format`
272+
found `Type`
273273

274274

275275
```
@@ -284,10 +284,10 @@ error: mismatched types
284284
┌─ <FORMAT>:1:1
285285
286286
1 │ offset16
287-
│ ^^^^^^^^ type mismatch, expected `Pos -> Format -> Format`, found `Format`
287+
│ ^^^^^^^^ type mismatch, expected `Format`, found `Pos -> Format -> Format`
288288
289-
= expected `Pos -> Format -> Format`
290-
found `Format`
289+
= expected `Format`
290+
found `Pos -> Format -> Format`
291291

292292

293293
```

tests/fail/elaboration/boolean-literal/type-mismatch.snap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ error: mismatched types
44
┌─ tests/fail/elaboration/boolean-literal/type-mismatch.fathom:3:1
55
66
3true : Void
7-
^^^^ type mismatch, expected `Bool`, found `Void`
7+
^^^^ type mismatch, expected `Void`, found `Bool`
88
9-
= expected `Bool`
10-
found `Void`
9+
= expected `Void`
10+
found `Bool`
1111

1212
'''

tests/fail/elaboration/unification/mismatch/arrow-body-type.snap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ error: mismatched types
44
┌─ tests/fail/elaboration/unification/mismatch/arrow-body-type.fathom:3:39
55
66
3fun (A : Type) -> fun (a : A) -> A -> a
7-
^ type mismatch, expected `A`, found `Type`
7+
^ type mismatch, expected `Type`, found `A`
88
9-
= expected `A`
10-
found `Type`
9+
= expected `Type`
10+
found `A`
1111

1212
'''

tests/fail/elaboration/unification/mismatch/arrow-both.snap

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@ error: mismatched types
44
┌─ tests/fail/elaboration/unification/mismatch/arrow-both.fathom:3:34
55
66
3fun (A : Type) -> fun (a : A) -> a -> a
7-
^ type mismatch, expected `A`, found `Type`
7+
^ type mismatch, expected `Type`, found `A`
88
9-
= expected `A`
10-
found `Type`
9+
= expected `Type`
10+
found `A`
1111

1212
error: mismatched types
1313
┌─ tests/fail/elaboration/unification/mismatch/arrow-both.fathom:3:39
1414
1515
3fun (A : Type) -> fun (a : A) -> a -> a
16-
│ ^ type mismatch, expected `A`, found `Type`
16+
│ ^ type mismatch, expected `Type`, found `A`
1717
18-
= expected `A`
19-
found `Type`
18+
= expected `Type`
19+
found `A`
2020

2121
'''

tests/fail/elaboration/unification/mismatch/arrow-param-type.snap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ error: mismatched types
44
┌─ tests/fail/elaboration/unification/mismatch/arrow-param-type.fathom:3:34
55
66
3fun (A : Type) -> fun (a : A) -> a -> A
7-
^ type mismatch, expected `A`, found `Type`
7+
^ type mismatch, expected `Type`, found `A`
88
9-
= expected `A`
10-
found `Type`
9+
= expected `Type`
10+
found `A`
1111

1212
'''

tests/fail/elaboration/unification/mismatch/fun-literal-body-expr.snap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ error: mismatched types
44
┌─ tests/fail/elaboration/unification/mismatch/fun-literal-body-expr.fathom:3:19
55
66
3fun A => fun a => A : fun (A : Type) -> A -> A
7-
^ type mismatch, expected `Type`, found `A`
7+
^ type mismatch, expected `A`, found `Type`
88
9-
= expected `Type`
10-
found `A`
9+
= expected `A`
10+
found `Type`
1111

1212
'''

tests/fail/elaboration/unification/mismatch/fun-literal-param-ann.snap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ error: mismatched types
44
┌─ tests/fail/elaboration/unification/mismatch/fun-literal-param-ann.fathom:3:19
55
66
3fun A => fun (a : Type) => a : fun (A : Type) -> A -> A
7-
^^^^ type mismatch, expected `Type`, found `A`
7+
^^^^ type mismatch, expected `A`, found `Type`
88
9-
= expected `Type`
10-
found `A`
9+
= expected `A`
10+
found `Type`
1111

1212
error: cannot find `a` in scope
1313
┌─ tests/fail/elaboration/unification/mismatch/fun-literal-param-ann.fathom:3:28

tests/fail/elaboration/unification/mismatch/fun-type-body-type.snap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ error: mismatched types
44
┌─ tests/fail/elaboration/unification/mismatch/fun-type-body-type.fathom:3:34
55
66
3fun (A : Type) -> fun (a : A) -> a
7-
^ type mismatch, expected `A`, found `Type`
7+
^ type mismatch, expected `Type`, found `A`
88
9-
= expected `A`
10-
found `Type`
9+
= expected `Type`
10+
found `A`
1111

1212
'''

0 commit comments

Comments
 (0)