Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect array inference #4281

Open
chalcolith opened this issue Dec 20, 2022 · 3 comments
Open

Incorrect array inference #4281

chalcolith opened this issue Dec 20, 2022 · 3 comments
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@chalcolith
Copy link
Member

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^.

@chalcolith chalcolith added bug Something isn't working needs investigation This needs to be looked into before its "ready for work" labels Dec 20, 2022
@ponylang-main ponylang-main added the discuss during sync Should be discussed during an upcoming sync label Dec 20, 2022
@SeanTAllen SeanTAllen added the help wanted Extra attention is needed label Dec 21, 2022
@jemc
Copy link
Member

jemc commented Jan 3, 2023

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.

@jasoncarr0
Copy link
Contributor

Other way around, it's inadvertently adding a this->

@jemc
Copy link
Member

jemc commented Jan 3, 2023

Thanks for clarifying 😄

@SeanTAllen SeanTAllen removed discuss during sync Should be discussed during an upcoming sync needs investigation This needs to be looked into before its "ready for work" labels Jan 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

5 participants