Currently, `ll_infer_type` is responsible for telling the user about `noncomputable` when a definition depends on one without executable code. However, this is imperfect because type inference does not check every subexpression. This leads to errors later on that users find to be hard to interpret. Now, `Lean.IR.checkDecls` has a friendlier error message when it encounters constants without compiled definitions, suggesting to consider using `noncomputable`. While this function is an internal IR consistency check, it is also reasonable to have it give an informative error message in this particular case. The suggestion to use `noncomputable` is limited to just unknown constants. Some alternatives would be to either (1) create another checker just for missing constants, (2) change `ll_infer_type` to always visit every subexpression no matter if they are necessary for inferring the type, or (3) investigate whether `tests/lean/run/1785.lean` is due to a deeper issue. Closes #1785
21 lines
580 B
Text
21 lines
580 B
Text
/-!
|
|
# Improve compiler IR check message for users when constants are not compiled
|
|
-/
|
|
|
|
/-
|
|
This is a simplified version of the example in #1785.
|
|
Note that the error changes if the typeclass argument is removed.
|
|
-/
|
|
|
|
noncomputable
|
|
def char (R : Type) [∀ n, OfNat R n] : Nat := 0
|
|
|
|
/--
|
|
error: failed to compile definition, compiler IR check failed at 'bug._rarg'. Error: depends on
|
|
declaration 'char', which has no executable code; consider marking definition as 'noncomputable'
|
|
-/
|
|
#guard_msgs in
|
|
def bug (R : Type) [∀ n, OfNat R n] : R :=
|
|
match char R with
|
|
| 0 => 1
|
|
| _ => 0
|