gfngfn / SATySFi

A statically-typed, functional typesetting system

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cannot report code positions for some error

gfngfn opened this issue · comments

Reported by @TonalidadeHidrica at https://satysfi.slack.com.

let f = 1
let a = f RGB(0.1, 0.2, 0.3)
 ---- ---- ---- ----
  target file: '2022-01-29-172058.pdf'
  dump file: '2022-01-29-172058.satysfi-aux' (will be created)
  parsing '2022-01-29-172058.satyh' ...
 ---- ---- ---- ----
  type checking '2022-01-29-172058.satyh' ...
! [Type Error] (cannot report position; 'constructor-unitvalue', 'product')
    this expression has type
      unit,
    but is expected of type
      float * float * float.

This case is roughly processed as below.

  1. Function application and constructor application are left associative, so the parser recognizes f RGB(0.1, 0.2, 0.3) as (f RGB) (0.1, 0.2, 0.3).
  2. In SATySFi, nullary data constructors internally take an unit argument, so the parser supplements an unit argument to RGB: (f RGB) (0.1, 0.2, 0.3) = (f (RGB ())) (0.1, 0.2, 0.3)
    | utast1=nxapp; constr=CONSTRUCTOR {
    let (rng, constrnm) = constr in
    make_standard (Ranged utast1) (Tok rng) (UTApply(utast1, (rng, UTConstructor(constrnm, (Range.dummy "constructor-unitvalue", UTUnitConstant)))))
    }
  3. But the type checker complains: it is a type error; RGB should take a float * float * float argument, not unit.
  4. The error cause is the unit argument, so the error should be reported based on it. But it was introduced by the parser, and has no position information. The implementation cannot report the error position.

There would be several ways fixing this: changing the representation of nullary data constuctors, attaching rough position information to dummy positions, ....