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

Bad error message when matching on a struct in a union #2000

Closed
dipinhora opened this issue Jul 2, 2017 · 4 comments · Fixed by #3746
Closed

Bad error message when matching on a struct in a union #2000

dipinhora opened this issue Jul 2, 2017 · 4 comments · Fixed by #3746
Labels
good first issue Good for newcomers help wanted Extra attention is needed

Comments

@dipinhora
Copy link
Contributor

Use case: I'm working with FFI calls where an argument can either be a pointer to a struct or NULL (where it will then use defaults). I set up a variable as either (struct | None) but I'm running into a compiler error when trying to craft the appropriate MaybePointer (I get a similar error when trying to cast it with an as also). It is quite possible that I'm going about this the wrong way (in which case a pointer in the right direction would be appreciated).

Pony Playpen link: http://pony-playpen.lietar.net/?gist=4d388470321b9585cbb33f22f9578b74

Code:

struct Z
  var a: U32 = 0

  new create() => None

actor Main
  new create(env:Env) =>
    let arg: (Z | None) = None

    let y = match arg
      | let x: Z => MaybePointer[Z](x)
      else
        MaybePointer[Z].none()
      end

Error:

0.14.0 [release]
compiled with: llvm 3.9.1 -- cc (Ubuntu 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609
Error:
main.pony:11:9: this capture violates capabilities
      | let x: Z => MaybePointer[Z](x)
        ^
    Info:
    main.pony:8:15: match type: (Z ref | None val)
        let arg: (Z | None) = None
                  ^
    main.pony:11:9: pattern type: Z ref
          | let x: Z => MaybePointer[Z](x)
            ^
@Praetonus
Copy link
Member

structs can't be part of unions because they don't have a type descriptor. I'm not sure why the compiler isn't telling you that, though.

You want your object to be a MaybePointer from the beginning when working with optional structs.

I'll keep the issue open for the error message.

@Praetonus Praetonus changed the title Error matching on a struct in a union Bad error message when matching on a struct in a union Jul 2, 2017
@dipinhora
Copy link
Contributor Author

@Praetonus Thanks for the quick response. I'll refactor my code accordingly.

@SeanTAllen
Copy link
Member

What should the error message for this be?

@Praetonus
Copy link
Member

It should be something like a struct cannot be part of a union type.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants