Skip to content

Commit 4939f44

Browse files
authored
test: avoid testing colliding private inductives (#11041)
`prelude-injectivity.lean` was testing inj thm generation for all inductives in core, including private ones, which could lead to name clashes that should not be able to occur in actual files. Put it under the module system to not load private decls in the first place.
1 parent 3d30792 commit 4939f44

File tree

3 files changed

+17
-14
lines changed

3 files changed

+17
-14
lines changed

src/Lean/AddDecl.lean

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,11 @@ def addDecl (decl : Declaration) (forceExpose := false) : CoreM Unit :=
137137
trace[addDecl] "no matching async adding rules, adding synchronously"
138138
return (← doAdd)
139139

140+
-- Check early so we can avoid related env ext panics that would happen before the check in the
141+
-- kernel.
142+
if (← getEnv).containsOnBranch name then
143+
throwKernelException <| .alreadyDeclared (← getEnv).toKernelEnv name
144+
140145
if decl.getTopLevelNames.all isPrivateName then
141146
if (← ResolveName.backward.privateInPublic.getM) then
142147
trace[addDecl] "private decl under `privateInPublic`, exporting as is"
@@ -152,9 +157,9 @@ def addDecl (decl : Declaration) (forceExpose := false) : CoreM Unit :=
152157
trace[addDecl] "no matching exporting rules, exporting as is"
153158
exportedInfo? := some info
154159

160+
let env ← getEnv
155161
-- no environment extension changes to report after kernel checking; ensures we do not
156162
-- accidentally wait for this snapshot when querying extension states
157-
let env ← getEnv
158163
let async ← env.addConstAsync (reportExts := false) name kind
159164
(exportedKind? := exportedInfo?.map (.ofConstantInfo))
160165
-- report preliminary constant info immediately

tests/lean/run/bvarcrash.lean

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -629,17 +629,16 @@ def decl_9 : Lean.Declaration :=
629629
type := expr_443
630630
value := expr_0
631631
}
632-
run_meta Lean.addDecl decl_0
633-
run_meta Lean.addDecl decl_1
634-
run_meta Lean.addDecl decl_2
635-
run_meta Lean.addDecl decl_3
636-
run_meta Lean.addDecl decl_4
637-
run_meta Lean.addDecl decl_5
638-
run_meta Lean.addDecl decl_6
639-
run_meta Lean.addDecl decl_7
640-
run_meta Lean.addDecl decl_8
632+
633+
open Lean
634+
635+
-- We avoid `Lean.addDecl` as it may be doing additional checks that hide the expected error.
636+
run_meta do
637+
for decl in [decl_0, decl_1, decl_2, decl_3, decl_4, decl_5, decl_6, decl_7, decl_8] do
638+
setEnv (← ofExceptKernelException <| (← getEnv).addDeclCore 0 decl none)
641639
/--
642640
error: (kernel) type checker does not support loose bound variables, replace them with free variables before invoking it
643641
-/
644642
#guard_msgs in
645-
run_meta Lean.addDecl decl_9
643+
run_meta
644+
setEnv (← ofExceptKernelException <| (← getEnv).addDeclCore 0 decl_9 none)

tests/lean/run/prelude-injectivity.lean

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1+
module
2+
13
import Lean
24

35
open Lean Meta
46

57
-- without this, the catch below does not catch kernel errors
68
set_option Elab.async false
79

8-
#exit -- **TODO**: remove after fixing async panic
9-
1010
/--
1111
info: Possible candidates for Init/Core.lean (these do not need to be added if they are irrelevant for verification):
1212
gen_injective_theorems% MacroScopesView
@@ -16,7 +16,6 @@ gen_injective_theorems% TSyntax
1616
gen_injective_theorems% Macro.Context
1717
gen_injective_theorems% Macro.Exception
1818
gen_injective_theorems% Macro.Methods
19-
gen_injective_theorems% Macro.State
2019
gen_injective_theorems% Syntax.Preresolved
2120
gen_injective_theorems% Syntax.SepArray
2221
gen_injective_theorems% Syntax.TSepArray

0 commit comments

Comments
 (0)