ponyc icon indicating copy to clipboard operation
ponyc copied to clipboard

`Foo iso` is outside constraint `Foo iso | Bar val`

Open plietar opened this issue 8 years ago • 4 comments

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.

plietar avatar Apr 05 '17 10:04 plietar

This is happening because union flattening is reducing the constraint to Bar val, which is of course wrong.

sylvanc avatar Apr 26 '17 20:04 sylvanc

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.

jemc avatar Apr 26 '17 20:04 jemc

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.

jemc avatar Apr 26 '17 20:04 jemc

@plietar says he has a non-flattening removing fix that can address this specifically.

SeanTAllen avatar May 03 '17 20:05 SeanTAllen

At some point, this was fixed.

SeanTAllen avatar Oct 06 '23 00:10 SeanTAllen