feat: check given constructor resulting type

This commit is contained in:
Leonardo de Moura 2020-07-13 16:17:54 -07:00
parent 920343d36b
commit d4ae4da222
3 changed files with 17 additions and 1 deletions

View file

@ -203,7 +203,11 @@ r.view.ctors.toList.mapM fun ctorView => Term.elabBinders ctorView.binders.getAr
pure indFVar
| some ctorType => do {
type ← Term.elabTerm ctorType none;
-- TODO: check whether resulting type is indFVar
resultingType ← getResultingType ref type;
unless (resultingType.getAppFn == indFVar) $
Term.throwError ref ("unexpected constructor resulting type" ++ indentExpr resultingType);
unlessM (Term.isType ref resultingType) $
Term.throwError ref ("unexpected constructor resulting type, type expected" ++ indentExpr resultingType);
pure type
};
type ← Term.mkForall ref ctorParams type;

View file

@ -98,3 +98,11 @@ end
inductive T1 : Nat → Type
| z1 : T1 0
| z2 -- constructor resulting type must be specified in inductive family declaration
-- Test12
inductive T1 : Nat → Type
| z1 : T1 -- unexpected constructor resulting type
inductive T1 : Nat → Type
| z1 : Nat -- unexpected constructor resulting type

View file

@ -22,3 +22,7 @@ inductive1.lean:82:10: error: invalid use of attributes in inductive declaration
inductive1.lean:85:0: error: invalid 'private' constructor in a 'private' inductive datatype
inductive1.lean:93:7: error: invalid inductive type, cannot mix unsafe and safe declarations in a mutually inductive datatypes
inductive1.lean:100:0: error: constructor resulting type must be specified in inductive family declaration
inductive1.lean:105:0: error: unexpected constructor resulting type, type expected
T1
inductive1.lean:108:0: error: unexpected constructor resulting type
Nat