ponyc
ponyc copied to clipboard
Incorrect array inference
When compiling the following code:
type Foo is (Bar box | Baz box | Bool)
class Bar
embed _items: Array[Foo] = _items.create()
new create(items: ReadSeq[Foo]) =>
for item in items.values() do
_items.push(item)
end
class Baz
actor Main
new create(env: Env) =>
let bar = Bar([
true
Bar([ false ])
])
env.out.print("done")
we get the errors:
Error:
main.pony:17:10: array element not a subtype of specified array type
Bar([ false ])
^
Info:
main.pony:6:29: array type: (this->Bar box | this->Baz box | Bool val)
new create(items: ReadSeq[Foo]) =>
^
main.pony:6:3: element type: Bar ref^
new create(items: ReadSeq[Foo]) =>
^
main.pony:6:3: Bar ref^ is not a subtype of Bar val: ref^ is not a subcap of val
new create(items: ReadSeq[Foo]) =>
^
main.pony:6:3: Bar ref^ is not a subtype of Baz box^
new create(items: ReadSeq[Foo]) =>
^
main.pony:6:3: Bar ref^ is not a subtype of Bool val^
new create(items: ReadSeq[Foo]) =>
^
main.pony:6:3: Bar ref^ is not a subtype of any element of (this->Bar box^ | this->Baz box^ | Bool val^)
new create(items: ReadSeq[Foo]) =>
^
Notice the the third info section erroneously says Bar ref^ is not a subtype of Bar val, where it should be checking against Bar box^, since type Foo is (Bar box | Baz box | Bool). Indeed in the next section it correctly checks against Baz box^.
As Jason pointed out in today's sync call, it looks like the array inference for ReadSeq is missing the this-> that it needs for that check.
Other way around, it's inadvertently adding a this->
Thanks for clarifying :smile: