CatalaLang / catala

Programming language for literate programming law specification

Home Page:https://catala-lang.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Type error fails at runtime when subtracting duration from date

pierregoutagny opened this issue · comments

Hi,

I think I've found an error in the typing of the operation that subtracts durations from dates.
Indeed, consider the following code:

declaration scope A:
  output o content boolean

scope A:
  definition o equals |2024-01-16| - 0 day <= 0 day

When interpreted, it passes the type check but fails at runtime, raising an exception that "should not happen if the term was well typed":

Operator <=^ applied to the wrong arguments
(should not happen if the term was well-typed)
2024-01-15
<= [0 years, 0 months, 1 days]

Operator (value <=^):
┌─⯈ sub_dat_dur.catala_en:6.23-6.52:
└─┐
6 │   definition o equals |2024-01-16| - 1 day <= 1 day
  │                       ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾

Argument n°1, value 2024-01-15
┌─⯈ sub_dat_dur.catala_en:6.23-6.43:
└─┐
6 │   definition o equals |2024-01-16| - 1 day <= 1 day
  │                       ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾

Argument n°2, value [1 day]
┌─⯈ sub_dat_dur.catala_en:6.47-6.52:
└─┐
6 │   definition o equals |2024-01-16| - 1 day <= 1 day
  │                                               ‾‾‾‾‾

This does not happen when simply comparing dates to durations (the type checker catches it), which is why I think the problem has to do with how the specific Sub_dat_dur operator is typed.

Also, note that because of the way the interpreter handles equality, using = instead of <= silently returns false without raising any exception.

You're right there was an error with | Sub_dat_dur -> [TDate; TDuration], TDuration, it should return TDate and not TDuration. Fixing this!