Skip to content

Commit

Permalink
fix: don't treat non-atomic idents as pattern variables
Browse files Browse the repository at this point in the history
  • Loading branch information
cppio committed Jan 7, 2025
1 parent 78ddee9 commit 6419f1b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
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

0 comments on commit 6419f1b

Please sign in to comment.