Open Frityet opened 1 month ago
Can you reproduce this with types other than nil? Teal does not support discriminating nil in unions, so you cannot implement nil-strictness by hand, it will need to be added to the language eventually.
I've confirmed this misbehavior with a non-nil-related minimized example
local type Maybe<T> = T | boolean
local x: Maybe<string>
if not x is boolean then
print("Result: "..x)
end
Note to self: the solution to this bug is that union types need to be handled as generic types the same way as functions and records currently are — that is, the type object for the union needs to store type variables, so that resolve_decl_into_nominal
can run match_typevals
on it correctly — my current plan is to solve this by generalizing all generic types into a single internal $\Lambda$ type, so that we can do beta-reduction at the type level like $(Λα.t^α)(T) \rightarrow t[α := T]$.
Results in
x
being inferred asnil
, anderr
being inferred asnilable<string>
. I am using thenext
branch.