fix: make generalized field notation for abbreviation types handle optional parameters (#3746)

Closes #3745
This commit is contained in:
Kyle Miller 2024-03-27 17:59:09 -07:00 committed by GitHub
parent 5b7ec4434e
commit 520cd3f0d6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 32 additions and 1 deletions

View file

@ -1149,7 +1149,7 @@ private partial def mkBaseProjections (baseStructName : Name) (structName : Name
private def typeMatchesBaseName (type : Expr) (baseName : Name) : MetaM Bool := do
if baseName == `Function then
return (← whnfR type).isForall
else if type.consumeMData.isAppOf baseName then
else if type.cleanupAnnotations.isAppOf baseName then
return true
else
return (← whnfR type).isAppOf baseName

31
tests/lean/run/3745.lean Normal file
View file

@ -0,0 +1,31 @@
/-!
# Issue 3745
Field notation for abbreviations would fail if the argument for field notation was an optional parameter.
-/
structure A
abbrev B := A
def A.x (_ : A) := 1
def B.x (_ : B) := 2
def A.y (_ : A) := 1
def B.y (_ : B := {}) := 2
/-!
These were OK before the fix.
-/
/-- info: 1 -/
#guard_msgs in #eval (show A from {}).x
/-- info: 2 -/
#guard_msgs in #eval (show B from {}).x
/-!
The second of these failed before the fix.
-/
/-- info: 1 -/
#guard_msgs in #eval (show A from {}).y
/-- info: 2 -/
#guard_msgs in #eval (show B from {}).y