Skip to content

Commit 2c54386

Browse files
authored
fix: Prop instances should be elaborated in the private scope (#10568)
1 parent 62fd973 commit 2c54386

File tree

2 files changed

+51
-6
lines changed

2 files changed

+51
-6
lines changed

src/Lean/Elab/MutualDef.lean

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1291,13 +1291,27 @@ where
12911291
logWarningAt attr.stx m!"Redundant `[expose]` attribute, it is meaningful on public \
12921292
definitions only"
12931293

1294+
-- Switch to private scope if...
12941295
withoutExporting (when :=
1295-
headers.all (fun header =>
1296-
header.modifiers.isMeta && !header.modifiers.attrs.any (·.name == `expose) ||
1297-
header.modifiers.attrs.any (·.name == `no_expose) ||
1298-
(!(header.kind == .def && sc.attrs.any (· matches `(attrInstance| expose))) &&
1299-
!header.modifiers.attrs.any (·.name == `expose) &&
1300-
!header.kind matches .abbrev | .instance))) do
1296+
(← headers.allM (fun header => do
1297+
-- ... there is a `@[no_expose]` attribute
1298+
if header.modifiers.attrs.any (·.name == `no_expose) then
1299+
return true
1300+
-- ... or NONE of the following:
1301+
-- ... this is a non-`meta` `def` inside a `@[expose] section`
1302+
if header.kind == .def && !header.modifiers.isMeta && sc.attrs.any (· matches `(attrInstance| expose)) then
1303+
return false
1304+
-- ... there is an `@[expose]` attribute directly on the def (of any kind or phase)
1305+
if header.modifiers.attrs.any (·.name == `expose) then
1306+
return false
1307+
-- ... this is an `abbrev`
1308+
if header.kind == .abbrev then
1309+
return false
1310+
-- ... this is a data instance
1311+
if header.kind == .instance then
1312+
if !(← isProp header.type) then
1313+
return false
1314+
return true))) do
13011315
let headers := headers.map fun header =>
13021316
{ header with modifiers.attrs := header.modifiers.attrs.filter (!·.name ∈ [`expose, `no_expose]) }
13031317
let values ← try

tests/pkg/module/Module/Basic.lean

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,3 +407,34 @@ inst✝
407407
-/
408408
#guard_msgs in
409409
#print instTypeNameFoo
410+
411+
/-! Prop `instance`s should have direct access to the private scope. -/
412+
413+
public class PropClass : Prop where
414+
proof : True
415+
416+
theorem privTrue : True := trivial
417+
public instance : PropClass := ⟨privTrue⟩
418+
419+
/-! Meta defs should only be exposed explicitly. -/
420+
421+
@[expose] section
422+
public meta def msec := 1
423+
@[expose] public meta def msecexp := 1
424+
end
425+
426+
/--
427+
info: meta def msec : Nat :=
428+
<not imported>
429+
-/
430+
#guard_msgs in
431+
#with_exporting
432+
#print msec
433+
434+
/--
435+
info: @[expose] meta def msecexp : Nat :=
436+
1
437+
-/
438+
#guard_msgs in
439+
#with_exporting
440+
#print msecexp

0 commit comments

Comments
 (0)