Debian Codegraph @

test-suite/bugs/bug_21702.v

raw
1 (* Regression test for check_with_def universe constraint dropping bug.
2 Bug: mod_typing.ml stored with Definition result using the WITH body's
3 (weaker) universe constraints instead of the spec's (stronger) constraints.
4 This allowed creating a coerce function Type@{u} -> Type@{v} with no
5 constraint between u and v, leading to a proof of False via Girard's paradox. *)
6
7 Set Universe Polymorphism.
8
9 Module Type SIG.
10 Section S.
11 Universe u v.
12 Constraint u <= v.
13 Parameter coerce@{} : Type@{u} -> Type@{v}.
14 End S.
15 End SIG.
16
17 (* The identity function satisfies coerce's type only when u <= v.
18 The bug dropped this constraint from the result. *)
19 Module Type SIG2 := SIG with Definition coerce@{u v} := fun (x : Type@{u}) => x.
20 Declare Module M : SIG2.
21
22 (* After the fix, M.coerce should retain the Type@{u} -> Type@{u} type.
23 Therefore, using it to push Type@{u} into a smaller universe should fail. *)
24 Section Test.
25 Universe big small.
26 Constraint small < big.
27
28 (* This should fail: M.coerce@{big+1, small} would require big+1 <= small,
29 but we have small < big, contradiction. *)
30 Fail Definition A : Type@{small} := M.coerce Type@{big}.
31 End Test.