-
Notifications
You must be signed in to change notification settings - Fork 463
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: check is valid structure projection when pretty printing (#4982)
For structure projections, the pretty printer assumed that the expression was type correct. Now it checks that the object being projected is of the correct type. Such terms appear in type mismatch errors. Also, fixes and improves `#print` for structures. The types of projections now use MessageData (so are now hoverable), and the type of `self` is now the correct type. Closes #4670
- Loading branch information
Showing
3 changed files
with
69 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/-! | ||
# Check types when pretty printing dot notation for structure projections | ||
In type mismatch errors, the 'object of dot notation' might not be valid for dot notation. | ||
-/ | ||
|
||
structure Foo : Type where | ||
out : Nat | ||
|
||
/-! | ||
Was printing `true.out`, but it should have been `Foo.out true`. | ||
-/ | ||
/-- | ||
error: application type mismatch | ||
Foo.out true | ||
argument | ||
true | ||
has type | ||
Bool : Type | ||
but is expected to have type | ||
Foo : Type | ||
--- | ||
info: (sorryAx Foo true).out : Nat | ||
-/ | ||
#guard_msgs in #check Foo.out true | ||
|
||
/-! | ||
Verifying that generalized field notation does not have this bug. | ||
-/ | ||
def Foo.out' (f : Foo) : Nat := f.out | ||
/-- | ||
error: application type mismatch | ||
Foo.out' true | ||
argument | ||
true | ||
has type | ||
Bool : Type | ||
but is expected to have type | ||
Foo : Type | ||
--- | ||
info: (sorryAx Foo true).out' : Nat | ||
-/ | ||
#guard_msgs in #check Foo.out' true | ||
|
||
/-! | ||
Verifying that projection notation still pretty prints as normal. | ||
-/ | ||
section | ||
variable (f : Foo) | ||
/-- info: f.out : Nat -/ | ||
#guard_msgs in #check f.out | ||
end | ||
|
||
/-! | ||
Verifying that projection notation still pretty prints through type synonys. | ||
-/ | ||
section | ||
def Baz := Foo | ||
variable (f : Baz) | ||
/-- info: f.out : Nat -/ | ||
#guard_msgs in #check f.out | ||
end |