Skip to content

Commit f8e4dce

Browse files
committed
feat: simpler error message when sorries complicate universe inference
1 parent 5f561bf commit f8e4dce

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

src/Lean/Elab/MutualInductive.lean

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,10 @@ private def collectUniverses (views : Array InductiveView) (r : Level) (rOffset
614614
let (_, acc) ← go |>.run {}
615615
if !acc.badLevels.isEmpty then
616616
withViewTypeRef views do
617+
if indTypes.any (·.ctors.any (·.type.hasSyntheticSorry)) then
618+
throwError "Type cannot be determined: some part of the definition contains an error"
619+
if indTypes.any (·.ctors.any (·.type.hasSorry)) then
620+
throwError "Type cannot be determined: some part of the definition contains `sorry`"
617621
let goodPart := Level.addOffset (Level.mkNaryMax acc.levels.toList) rOffset
618622
let badPart := Level.mkNaryMax (acc.badLevels.toList.map fun (u, k) => Level.max (Level.ofNat rOffset) (Level.addOffset u (rOffset - k)))
619623
let inferred := (Level.max goodPart badPart).normalize

tests/lean/univInference.lean

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,15 @@ def ex7 (h : Stx = Nat) : True :=
9090
trivial
9191

9292
end Induct
93+
94+
inductive Sorry1 where
95+
| x (a : Bool)
96+
| y (b : sorry)
97+
98+
inductive Sorry2 where
99+
| x (a : Array Sorry2)
100+
| y (b : sorry)
101+
102+
inductive Sorry3 where
103+
| x (a : Array Sorry3)
104+
| y {x} (b : x Err3)

tests/lean/univInference.lean.expected.out

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,26 @@ univInference.lean:81:48-81:62: error: Invalid universe polymorphic resulting ty
3131
Sort (max u v)
3232

3333
Hint: A possible solution is to use levels of the form `max 1 _` or `_ + 1` to ensure the universe is of the form `Type _`
34+
univInference.lean:94:0-96:17: warning: declaration uses 'sorry'
35+
univInference.lean:94:0-96:17: warning: declaration uses 'sorry'
36+
univInference.lean:94:0-96:17: warning: declaration uses 'sorry'
37+
univInference.lean:94:0-96:17: warning: declaration uses 'sorry'
38+
univInference.lean:94:0-96:17: warning: declaration uses 'sorry'
39+
univInference.lean:94:0-96:17: warning: declaration uses 'sorry'
40+
univInference.lean:94:0-96:17: warning: declaration uses 'sorry'
41+
univInference.lean:94:0-96:17: warning: declaration uses 'sorry'
42+
univInference.lean:94:0-96:17: warning: declaration uses 'sorry'
43+
univInference.lean:94:0-96:17: warning: declaration uses 'sorry'
44+
univInference.lean:94:0-96:17: warning: declaration uses 'sorry'
45+
univInference.lean:94:0-96:17: warning: declaration uses 'sorry'
46+
univInference.lean:94:0-96:17: warning: declaration uses 'sorry'
47+
univInference.lean:94:0-96:17: warning: declaration uses 'sorry'
48+
univInference.lean:98:0-100:17: error: Type cannot be determined: some part of the definition contains `sorry`
49+
univInference.lean:104:15-104:21: error: Function expected at
50+
x
51+
but this term has type
52+
?m
53+
54+
Note: Expected a function because this term is being applied to the argument
55+
Err3
56+
univInference.lean:102:0-104:22: error: Type cannot be determined: some part of the definition contains an error

0 commit comments

Comments
 (0)