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

Confusing error message with iso parameters #2958

Open
andrenth opened this issue Dec 14, 2018 · 1 comment
Open

Confusing error message with iso parameters #2958

andrenth opened this issue Dec 14, 2018 · 1 comment

Comments

@andrenth
Copy link

Hi

As discussed with @SeanTAllen on IRC, we have found an instance of a confusing error message related to iso parameters:

use "random"
use "time"

class C
  let _v: U8
  
  new val create(rand: (Random iso | None) = None) =>
    let rng =
      match rand
      | let r: Random => r
      | None =>
        let now = Time.now()
        Rand(now._1.u64(), now._2.u64())
      end
    _v = rng.u8()

This leads to the following error:

Error:
main.pony:10:9: this capture violates capabilities, because the match would need to differentiate by capability at runtime instead of matching on type alone
      | let r: Random => r
        ^
    Info:
    main.pony:7:36: the match type allows for more than one possibility with the same type as pattern type, but different capabilities. match type: (Random iso! | None val)
      new val create(rand: (Random iso | None) = None) =>
                                       ^
    main.pony:10:9: pattern type: Random ref
          | let r: Random => r
            ^
    main.pony:10:16: matching Random iso! with Random ref could violate capabilities: iso! isn't a subcap of ref
          | let r: Random => r
                   ^
    main.pony:10:16: matching (Random iso! | None val) with Random ref could violate capabilities
          | let r: Random => r

The issue is fixed by adding the missing consume:

...
let rng =
    match consume rand
...

If the rand parameter's type is specified as Random iso^ (i.e. making it ephemeral), the code compiles, either with or without consume.

@jemc
Copy link
Member

jemc commented Dec 18, 2018

Probably the most consistent way to improve this would be to amend the third info message to say:

    main.pony:10:16: matching Random iso! with Random ref could violate capabilities: iso! isn't a subcap of ref (did you forget to consume?)
          | let r: Random => r
                   ^

That is, just adding a "(did you forget to consume?)" to any error message where we say "[iso|trn]! is not a subtype of [some other cap]".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants