I.e. we only support non-union arg + union constr but not vice versa
Ternary Case
Proper Ternary typing would be <T, Y> -> T | Y but that lead to problem - receiver won't be compatible with the union. Example: true ? {} : {a: 42} -> .... Let's say ... accepts {} (any structure). Compiler will return error because {} | {a int} is union argument and {} is non-union constraint - this is unsupported. Meanwhile it's obvious from common sense point of view that {} | {a int} is perfectly valid because both of them compatible with {}.
Possible Solution
Support areKindsDifferent not just when isConstraintUnion but also when isArgUnion. In that case what we should do is to iterate over each union member and check compatibility with the constraint. Kinda the same way we do right now for inverted case.
Generic Problem
This is valid TypeScript code:
But in Nevalang it won't compile according to current type-system implementation:
I.e. we only support non-union arg + union constr but not vice versa
Ternary Case
Proper
Ternary
typing would be<T, Y> -> T | Y
but that lead to problem - receiver won't be compatible with the union. Example:true ? {} : {a: 42} -> ...
. Let's say...
accepts{}
(any structure). Compiler will return error because{} | {a int}
is union argument and{}
is non-union constraint - this is unsupported. Meanwhile it's obvious from common sense point of view that{} | {a int}
is perfectly valid because both of them compatible with{}
.Possible Solution
Support
areKindsDifferent
not just whenisConstraintUnion
but also whenisArgUnion
. In that case what we should do is to iterate over each union member and check compatibility with the constraint. Kinda the same way we do right now for inverted case.