jinko-core / jinko

Jinko is a small and safe interpreted language with fast Rust and C FFI
GNU General Public License v2.0
32 stars 6 forks source link

Flatten typesets #677

Closed CohenArthur closed 1 week ago

CohenArthur commented 1 month ago

Fixes #674

CohenArthur commented 1 month ago

One issue is that this code does work, when it should not:

type Nothing;
type NullableInt = 15 | Nothing;

func g(n: NullableInt) {}

where x = 16;

g(15);
g(x);
g(Nothing);

and replacing NullableInt's definition with a proper one (int | Nothing) causes the code to no longer work :upside_down_face:

CohenArthur commented 1 month ago

Getting closer. Another testcase we must handle before merging this:

type unit;
type bool;
type char;
type int;
type float;
type string;

func fifteen(inner: int) {}

where x = fifteen(14);
where y = fifteen(14 * 12);
CohenArthur commented 1 month ago
ext func magic() -> int;

type Nothing;
type NullableInt = int | Nothing;

func g(n: NullableInt) {}

g(magic());
CohenArthur commented 1 month ago

One other issue is that we show type errors with the flattened version of the type, so for example it'll show as "expected 15 | 16, got string"

CohenArthur commented 1 month ago

There is an issue when formatting empty typesets, for example the char type if there are no characters in the program. this will be fixed once we address the formatting issues

CohenArthur commented 1 month ago

the only blocker now is the handling of builtin types for arithmetic operations

CohenArthur commented 1 month ago

The issue with arithmetic builtins lie in the expected_arithmetic_types function, where we need to do something a little smarter than recreate our union types.