fmease / lushui

The reference compiler of the Lushui programming language
Apache License 2.0
5 stars 0 forks source link

Misleading span when reporting type mismatch #33

Open fmease opened 3 years ago

fmease commented 3 years ago

Example:

use extern.core.unit.(Unit unit)
use extern.core.bool.(Bool false true)

Lazy (A: Type): Type = Unit -> A

Lazy-Bool: Type = Lazy Bool

;;;and (a: Bool) (b: Unit -> Bool): Bool =
and (a: Bool) (b: Lazy Bool): Bool =
    case a of
        false => false
        true => b unit

;;; @Bug span: "expected due to this" points to normalization of _lazy Bool_ instead of the pre-normalized for
main: Lazy Bool = and true (\(unit: Unit) => true)
;;;main: Bool = and true (\(unit: Unit) => true)

Output:

error[E032]: expected type `extern.core.unit.Unit -> extern.core.bool.Bool` but got type `extern.core.bool.Bool`
  --> /home/fmease/programming/main_projects/lushui/bugs/x.lushui:4:24
   |
 4 | Lazy (A: Type): Type = Unit -> A
   |                        --------- expected due to this
   |
  --> /home/fmease/programming/main_projects/lushui/bugs/x.lushui:15:19
   |
15 | main: Lazy Bool = and true (\(unit: Unit) => true)
   |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ has the wrong type
   |

Task: Minimize reproducer.

Related (instance of a similar issue): #31. We should use the span of the unevaluated expression (smh).