Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: don't treat non-atomic idents as pattern variables #6551

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions src/Lean/Elab/Match.lean
Original file line number Diff line number Diff line change
Expand Up @@ -1201,18 +1201,17 @@ private def elabMatchCore (stx : Syntax) (expectedType? : Option Expr) : TermEla
elabMatchAux gen? discrStxs altViews matchOptMotive expectedType

private def isPatternVar (stx : Syntax) : TermElabM Bool := do
if !stx.isIdent || !stx.getId.eraseMacroScopes.isAtomic then
return false
match (← resolveId? stx "pattern") with
| none => return isAtomicIdent stx
| none => return true
| some f => match f with
| Expr.const fName _ =>
match (← getEnv).find? fName with
| some (ConstantInfo.ctorInfo _) => return false
| some _ => return !hasMatchPatternAttribute (← getEnv) fName
| _ => return isAtomicIdent stx
| _ => return isAtomicIdent stx
where
isAtomicIdent (stx : Syntax) : Bool :=
stx.isIdent && stx.getId.eraseMacroScopes.isAtomic
| _ => return true
| _ => return true

@[builtin_term_elab «match»] def elabMatch : TermElab := fun stx expectedType? => do
match stx with
Expand Down
11 changes: 11 additions & 0 deletions tests/lean/6537.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/-! Non-atomic pattern variables should give an error -/

example : Nat → Nat | x.y => x.y

def x.y := ()

example : Nat → Nat | x.y => x.y

attribute [match_pattern] x.y

example : Nat → Nat | x.y => x.y
8 changes: 8 additions & 0 deletions tests/lean/6537.lean.expected.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
6537.lean:3:22-3:25: error: invalid pattern variable, must be atomic
6537.lean:7:22-7:25: error: invalid pattern variable, must be atomic
6537.lean:11:22-11:25: error: type mismatch
x.y
has type
Unit : Type
but is expected to have type
Nat : Type
Loading