Skip to content

Commit 8335d4e

Browse files
committed
fix: collect level parameters in evalExpr
`elabEvalUnsafe` already does something similar.
1 parent 62c3e56 commit 8335d4e

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/Lean/Meta/Eval.lean

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,21 @@ Released under Apache 2.0 license as described in the file LICENSE.
44
Authors: Sebastian Ullrich, Leonardo de Moura
55
-/
66
import Lean.Meta.Check
7+
import Lean.Util.CollectLevelParams
78

89
namespace Lean.Meta
910

1011
unsafe def evalExprCore (α) (value : Expr) (checkType : Expr → MetaM Unit) (safety := DefinitionSafety.safe) : MetaM α :=
1112
withoutModifyingEnv do
1213
let name ← mkFreshUserName `_tmp
1314
let value ← instantiateMVars value
15+
let us := collectLevelParams {} value |>.params
1416
if value.hasMVar then
1517
throwError "failed to evaluate expression, it contains metavariables{indentExpr value}"
1618
let type ← inferType value
1719
checkType type
1820
let decl := Declaration.defnDecl {
19-
name, levelParams := [], type
21+
name, levelParams := us.toList, type
2022
value, hints := ReducibilityHints.opaque,
2123
safety
2224
}

tests/lean/run/3091.lean

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import Lean
2+
3+
open Lean
4+
5+
def foo.{u} : Nat := (ULift.up.{u} Nat.zero).down
6+
7+
universe u in
8+
#eval foo.{u}
9+
10+
-- this used to produce an error
11+
#eval do
12+
let u : Lean.Level := .param `u
13+
Meta.evalExpr Nat (.const ``Nat []) (.const ``foo [u])

0 commit comments

Comments
 (0)