essential-contributions / pint

Pint, the constraint-based programming language for declarative blockchains
Apache License 2.0
17 stars 3 forks source link

type check before evaluating `consts` #913

Open lethalgem opened 3 days ago

lethalgem commented 3 days ago

const f = true in 3..2 will make it to the evaluation stage even though it should result in

Error: value type and array element type in range differ
   ╭─[test.pnt:7:22]
   │
 7 │     const f = true in [1, 2];
   │                        ┬
   │                        ╰── array element type mismatch; expecting `bool` type, found `int` type
───╯

... A user can still write const f = true in 3..2; without an error occurring before this stage.

FWIW, if it is not a const then we type check the range. Ex.

predicate Test {
    var l = true in 1..2;
}

Error: value type and range type differ
    ╭─[test.pnt:18:21]
    │
 18 │     var l = true in 1..2;
    │                     ┬
    │                     ╰── range type mismatch; expecting `bool` type, found `int` type
────╯

_Originally posted by @lethalgem in https://github.com/essential-contributions/pint/pull/911#discussion_r1790795496_

otrho commented 3 days ago

WTF? Are we not type checking const initialisers?

mohammadfawaz commented 2 days ago

Haha yes we evaluate constants before type checking exprs.