diff --git a/src/Lean/Elab/Inductive.lean b/src/Lean/Elab/Inductive.lean index 4b72613b0b..2acdeb2a8f 100644 --- a/src/Lean/Elab/Inductive.lean +++ b/src/Lean/Elab/Inductive.lean @@ -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; diff --git a/tests/lean/inductive1.lean b/tests/lean/inductive1.lean index 656d36d597..3acfe1030d 100644 --- a/tests/lean/inductive1.lean +++ b/tests/lean/inductive1.lean @@ -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 diff --git a/tests/lean/inductive1.lean.expected.out b/tests/lean/inductive1.lean.expected.out index 0927717760..65fe30abe4 100644 --- a/tests/lean/inductive1.lean.expected.out +++ b/tests/lean/inductive1.lean.expected.out @@ -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