ponyc
ponyc copied to clipboard
`Foo iso` is outside constraint `Foo iso | Bar val`
interface Foo
interface Bar
class Baz
fun foo[X: (Foo iso | Bar val)]() =>
None
fun bar() =>
foo[Foo iso]()
Error:
main.pony:9:5: type argument is outside its constraint
foo[Foo iso]()
^
Info:
main.pony:9:9: argument: Foo iso
foo[Foo iso]()
^
main.pony:5:11: constraint: Bar val
fun foo[X: (Foo iso | Bar val)]() =>
^
main.pony:9:9: Foo iso is not in constraint Bar val: iso is not in constraint val
foo[Foo iso]()
https://is.gd/5upkoo
This error occurs with both iso and trn. It works with other capabilities.
I'm not completely sure whether this should be allowed or not, but I'd be inclined to say yes.
This is happening because union flattening is reducing the constraint to Bar val, which is of course wrong.
This can be solved by: during union flattening, check the current frame and see if we are in a constraint before invoking is_subtype - if we are we should invoke is_subtype_constraint instead.
Careful caveat though - we don't want to use is_subtype_constraint when the union is within the type arguments of a constraint type. For example, in [A: Array[(B | C)], we'd use is_subtype as normal - this is important to add a test case for when fixed.
@plietar says he has a non-flattening removing fix that can address this specifically.
At some point, this was fixed.