| 1 |
(* Comprehensive tests for all module signature and constraint mismatch errors *) |
| 2 |
|
| 3 |
(* ========== signature_mismatch_error tests ========== *) |
| 4 |
|
| 5 |
(* 1. InductiveFieldExpected - expected inductive but found definition *) |
| 6 |
Module Type IndFieldExpType. |
| 7 |
Inductive I : Type := c : I. |
| 8 |
End IndFieldExpType. |
| 9 |
Module IndFieldExpMod. |
| 10 |
Definition I : Type := nat. |
| 11 |
End IndFieldExpMod. |
| 12 |
Fail Module IndFieldExpTest : IndFieldExpType := IndFieldExpMod. |
| 13 |
|
| 14 |
(* 2. DefinitionFieldExpected - expected definition but found inductive *) |
| 15 |
Module Type DefFieldExpType. |
| 16 |
Definition x : Type := nat. |
| 17 |
End DefFieldExpType. |
| 18 |
Module DefFieldExpMod. |
| 19 |
Inductive x : Type := c : x. |
| 20 |
End DefFieldExpMod. |
| 21 |
Fail Module DefFieldExpTest : DefFieldExpType := DefFieldExpMod. |
| 22 |
|
| 23 |
(* 3. ModuleFieldExpected - expected module but found definition *) |
| 24 |
Module Type ModFieldExpType. |
| 25 |
Module M. |
| 26 |
Definition x := 0. |
| 27 |
End M. |
| 28 |
End ModFieldExpType. |
| 29 |
Module ModFieldExpMod. |
| 30 |
Module M. |
| 31 |
Inductive x : Type := c : x. |
| 32 |
End M. |
| 33 |
End ModFieldExpMod. |
| 34 |
Fail Module ModFieldExpTest : ModFieldExpType := ModFieldExpMod. |
| 35 |
|
| 36 |
(* 4. ModuleTypeFieldExpected - expected module type but found module *) |
| 37 |
Module Type ModTypeFieldExpType. |
| 38 |
Module Type T. |
| 39 |
Definition x := 0. |
| 40 |
End T. |
| 41 |
End ModTypeFieldExpType. |
| 42 |
Module ModTypeFieldExpMod. |
| 43 |
Module T. |
| 44 |
Definition x := 0. |
| 45 |
End T. |
| 46 |
End ModTypeFieldExpMod. |
| 47 |
Fail Module ModTypeFieldExpTest : ModTypeFieldExpType := ModTypeFieldExpMod. |
| 48 |
|
| 49 |
(* 5. NotConvertibleInductiveField - inductive types differ *) |
| 50 |
Module Type NotConvIndType. |
| 51 |
Inductive I : Type := c : nat -> I. |
| 52 |
End NotConvIndType. |
| 53 |
Module NotConvIndMod. |
| 54 |
Inductive I : Type := c : bool -> I. |
| 55 |
End NotConvIndMod. |
| 56 |
Fail Module NotConvIndTest : NotConvIndType := NotConvIndMod. |
| 57 |
|
| 58 |
(* 6. NotConvertibleConstructorField - constructor types differ *) |
| 59 |
Module Type NotConvConsType. |
| 60 |
Inductive I : Type := c1 : nat -> I | c2 : I. |
| 61 |
End NotConvConsType. |
| 62 |
Module NotConvConsMod. |
| 63 |
Inductive I : Type := c1 : bool -> I | c2 : I. |
| 64 |
End NotConvConsMod. |
| 65 |
Fail Module NotConvConsTest : NotConvConsType := NotConvConsMod. |
| 66 |
|
| 67 |
(* 7. NotConvertibleBodyField - definition bodies differ *) |
| 68 |
Module Type NotConvBodyType. |
| 69 |
Definition x := 42. |
| 70 |
End NotConvBodyType. |
| 71 |
Module NotConvBodyMod. |
| 72 |
Definition x := 0. |
| 73 |
End NotConvBodyMod. |
| 74 |
Fail Module NotConvBodyTest : NotConvBodyType := NotConvBodyMod. |
| 75 |
|
| 76 |
(* 8. NotConvertibleTypeField - definition types differ *) |
| 77 |
Module Type NotConvTypeType. |
| 78 |
Definition x : nat := 0. |
| 79 |
End NotConvTypeType. |
| 80 |
Module NotConvTypeMod. |
| 81 |
Definition x : bool := true. |
| 82 |
End NotConvTypeMod. |
| 83 |
Fail Module NotConvTypeTest : NotConvTypeType := NotConvTypeMod. |
| 84 |
|
| 85 |
(* 9. CumulativeStatusExpected - expected cumulative but got non-cumulative *) |
| 86 |
Module Type CumulExpType. |
| 87 |
Polymorphic Cumulative Inductive I@{u} : Type@{u} := c : I. |
| 88 |
End CumulExpType. |
| 89 |
Module CumulExpMod. |
| 90 |
Polymorphic Inductive I@{u} : Type@{u} := c : I. |
| 91 |
End CumulExpMod. |
| 92 |
Fail Module CumulExpTest : CumulExpType := CumulExpMod. |
| 93 |
|
| 94 |
(* 10. PolymorphicStatusExpected - expected polymorphic but got monomorphic *) |
| 95 |
Module Type PolyExpType. |
| 96 |
Polymorphic Definition x : Type := nat. |
| 97 |
End PolyExpType. |
| 98 |
Module PolyExpMod. |
| 99 |
Definition x : Type := nat. |
| 100 |
End PolyExpMod. |
| 101 |
Fail Module PolyExpTest : PolyExpType := PolyExpMod. |
| 102 |
|
| 103 |
(* 11. NotSameConstructorNamesField - constructor names differ *) |
| 104 |
Module Type ConsNamesType. |
| 105 |
Inductive I : Type := foo : I | bar : I. |
| 106 |
End ConsNamesType. |
| 107 |
Module ConsNamesMod. |
| 108 |
Inductive I : Type := baz : I | qux : I. |
| 109 |
End ConsNamesMod. |
| 110 |
Fail Module ConsNamesTest : ConsNamesType := ConsNamesMod. |
| 111 |
|
| 112 |
(* 12. NotSameInductiveNameInBlockField - mutual inductive names differ *) |
| 113 |
Module Type IndNamesType. |
| 114 |
Inductive A : Type := mkA : B -> A |
| 115 |
with B : Type := mkB : A -> B. |
| 116 |
End IndNamesType. |
| 117 |
Module IndNamesMod. |
| 118 |
Inductive A : Type := mkA : C -> A |
| 119 |
with C : Type := mkB : A -> C. |
| 120 |
End IndNamesMod. |
| 121 |
Fail Module IndNamesTest : IndNamesType := IndNamesMod. |
| 122 |
|
| 123 |
(* 13. FiniteInductiveFieldExpected - expected inductive but got coinductive *) |
| 124 |
Module Type FiniteType. |
| 125 |
Inductive I : Type := c : I. |
| 126 |
End FiniteType. |
| 127 |
Module FiniteMod. |
| 128 |
CoInductive I : Type := c : I. |
| 129 |
End FiniteMod. |
| 130 |
Fail Module FiniteTest : FiniteType := FiniteMod. |
| 131 |
|
| 132 |
(* 14. InductiveNumbersFieldExpected - number of mutual inductives differs *) |
| 133 |
Module Type NumIndType. |
| 134 |
Inductive I1 : Type := c1 : I1 |
| 135 |
with I2 : Type := c2 : I2. |
| 136 |
End NumIndType. |
| 137 |
Module NumIndMod. |
| 138 |
Inductive I1 : Type := c1 : I1. |
| 139 |
End NumIndMod. |
| 140 |
Fail Module NumIndTest : NumIndType := NumIndMod. |
| 141 |
|
| 142 |
(* 15. InductiveParamsNumberField - number of parameters differs *) |
| 143 |
Module Type ParamsType. |
| 144 |
Inductive I (A B : Type) : Type := c : A -> B -> I A B. |
| 145 |
End ParamsType. |
| 146 |
Module ParamsMod. |
| 147 |
Inductive I (A : Type) : Type := c : A -> A -> I A. |
| 148 |
End ParamsMod. |
| 149 |
Fail Module ParamsTest : ParamsType := ParamsMod. |
| 150 |
|
| 151 |
(* 16. RecordFieldExpected - expected record but got non-record *) |
| 152 |
Module Type RecExpType. |
| 153 |
Record R := { field : nat }. |
| 154 |
End RecExpType. |
| 155 |
Module RecExpMod. |
| 156 |
Inductive R := Build_R : nat -> R. |
| 157 |
End RecExpMod. |
| 158 |
Fail Module RecExpTest : RecExpType := RecExpMod. |
| 159 |
|
| 160 |
(* 17. RecordProjectionsExpected - projection names differ *) |
| 161 |
Module Type RecProjType. |
| 162 |
Record R := { foo : nat; bar : bool }. |
| 163 |
End RecProjType. |
| 164 |
Module RecProjMod. |
| 165 |
Record R := { baz : nat; qux : bool }. |
| 166 |
End RecProjMod. |
| 167 |
Fail Module RecProjTest : RecProjType := RecProjMod. |
| 168 |
|
| 169 |
(* 18. IncompatiblePolymorphism - polymorphic conversion generates constraints *) |
| 170 |
Module Type IncompatPolyType. |
| 171 |
Polymorphic Definition f@{u} : Type@{u} -> Type@{u} := fun x => x. |
| 172 |
End IncompatPolyType. |
| 173 |
Module IncompatPolyMod. |
| 174 |
Polymorphic Definition f@{u v} : Type@{u} -> Type@{v} := fun x => x. |
| 175 |
End IncompatPolyMod. |
| 176 |
Fail Module IncompatPolyTest : IncompatPolyType := IncompatPolyMod. |
| 177 |
|
| 178 |
(* 19. IncompatibleUnivConstraints - universe constraints incompatible *) |
| 179 |
Module Type UnivConsType. |
| 180 |
Polymorphic Definition f@{u v|u < v} : Type@{u} := nat. |
| 181 |
End UnivConsType. |
| 182 |
Module UnivConsMod. |
| 183 |
Polymorphic Definition f@{u v|v < u} : Type@{u} := nat. |
| 184 |
End UnivConsMod. |
| 185 |
Fail Module UnivConsTest : UnivConsType := UnivConsMod. |
| 186 |
|
| 187 |
(* 20. IncompatibleVariance - variance information incompatible |
| 188 |
Note: Variance subtyping is v1 <= v2 (module variance <= expected). |
| 189 |
Covariant (+) is more restrictive than Invariant (=). |
| 190 |
To trigger: module has Invariant but type expects Covariant. *) |
| 191 |
Module Type VarianceType. |
| 192 |
Polymorphic Cumulative Inductive I@{+u} : Type@{u} := c : I. |
| 193 |
End VarianceType. |
| 194 |
Module VarianceMod. |
| 195 |
Polymorphic Cumulative Inductive I@{=u} : Type@{u} := c : I. |
| 196 |
End VarianceMod. |
| 197 |
Fail Module VarianceTest : VarianceType := VarianceMod. |
| 198 |
|
| 199 |
(* NOTE: Some errors are not easily triggerable from this test file: |
| 200 |
- NoRewriteRulesSubtyping: requires -allow-rewrite-rules flag |
| 201 |
- NotEqualInductiveAliases: this error checks inductive aliasing through module resolvers; |
| 202 |
it may be dead code or only triggerable in very specific module functor contexts |
| 203 |
- IncompatibleUniverses in subtyping: tested above with Set/Type mismatch (Test4 in WithDefErrors) |
| 204 |
- IncompatibleQualities in subtyping: requires quality constraint conflicts during conversion |
| 205 |
- WithCannotConstrainPrimitive/Symbol: module types export primitives/symbols as Parameters, |
| 206 |
so "with Definition" finds a Parameter, not Primitive/Symbol *) |
| 207 |
|
| 208 |
(* ========== with_constraint_error tests ========== *) |
| 209 |
|
| 210 |
(* 22. WithTypeMismatch - type mismatch in with Definition *) |
| 211 |
Module Type WithTypeType. |
| 212 |
Parameter x : nat. |
| 213 |
End WithTypeType. |
| 214 |
Fail Module Type WithTypeTest := WithTypeType with Definition x := true. |
| 215 |
|
| 216 |
(* 23. WithBodyMismatch - body mismatch in with Definition *) |
| 217 |
Module Type WithBodyType. |
| 218 |
Definition x := 5. |
| 219 |
End WithBodyType. |
| 220 |
Fail Module Type WithBodyTest := WithBodyType with Definition x := 10. |
| 221 |
|
| 222 |
(* 24. WithUniverseMismatch - universe mismatch in with Definition *) |
| 223 |
Module Type WithUnivType. |
| 224 |
Parameter x : Set. |
| 225 |
End WithUnivType. |
| 226 |
Definition big_type := Type. |
| 227 |
Fail Module Type WithUnivTest := WithUnivType with Definition x := big_type. |
| 228 |
|
| 229 |
(* 25. WithConstraintsMismatch - polymorphic binders mismatch *) |
| 230 |
Module Type WithConsType. |
| 231 |
Polymorphic Parameter p@{u} : Type@{u}. |
| 232 |
End WithConsType. |
| 233 |
Fail Module Type WithConsTest := WithConsType with Definition p := nat. |
| 234 |
|
| 235 |
(* 26. WithTypeMismatch with abstract type - test where expected type references module *) |
| 236 |
Module Type WithAbsType. |
| 237 |
Parameter a : Type. |
| 238 |
Parameter b : a. |
| 239 |
End WithAbsType. |
| 240 |
Fail Module Type WithAbsTest := WithAbsType with Definition a := nat with Definition b := true. |