fix: check type mismatch at dependent pattern matching compiler

see issue #1057
This commit is contained in:
Leonardo de Moura 2022-03-21 09:28:02 -07:00
parent 9944feb095
commit 3d9e587862
3 changed files with 20 additions and 1 deletions

View file

@ -51,7 +51,13 @@ where
loop lhss alts minors
def assignGoalOf (p : Problem) (e : Expr) : MetaM Unit :=
withGoalOf p (assignExprMVar p.mvarId e)
withGoalOf p do
let mvar := mkMVar p.mvarId
let mvarType ← inferType mvar
let eType ← inferType e
unless (← isDefEq mvarType eType) do
throwError "dependent elimination failed, type mismatch when solving alternative with type{indentExpr eType}\nbut expected{indentExpr mvarType}"
assignExprMVar p.mvarId e
structure State where
used : Std.HashSet Nat := {} -- used alternatives

9
tests/lean/1057.lean Normal file
View file

@ -0,0 +1,9 @@
inductive T
| t : T
@[reducible] def T.eval : T → Type
| T.t => Int
def T.default (τ : T) : τ.eval :=
match τ, τ.eval with
| T.t, .(Int) => (0 : Int)

View file

@ -0,0 +1,4 @@
1057.lean:8:2-9:28: error: dependent elimination failed, type mismatch when solving alternative with type
motive t Int
but expected
motive t x✝