-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Improve handling of consume in class constructors #24424
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| -- Error: tests/neg-custom-args/captures/consume-in-constructor.scala:18:10 -------------------------------------------- | ||
| 18 | println(b) // error | ||
| | ^ | ||
| | Separation failure: Illegal access to {b} which is hidden by the previous definition | ||
| | of value a2 with type A2{val b: B^{b²}}^. | ||
| | This type hides capabilities {cap, b²} | ||
| | | ||
| | where: ^ refers to a fresh root capability in the type of value a2 | ||
| | b is a value in class A2 | ||
| | b² is a value in method Test | ||
| | cap is a fresh root capability created in value a2 when constructing instance A2 | ||
| -- Error: tests/neg-custom-args/captures/consume-in-constructor.scala:19:10 -------------------------------------------- | ||
| 19 | println(a1) // error, since `b` was consumed before | ||
| | ^^ | ||
| | Separation failure: Illegal access to {b} which is hidden by the previous definition | ||
| | of value a2 with type A2{val b: B^{b²}}^. | ||
| | This type hides capabilities {cap, b²} | ||
| | | ||
| | where: ^ refers to a fresh root capability in the type of value a2 | ||
| | b is a value in class A2 | ||
| | b² is a value in method Test | ||
| | cap is a fresh root capability created in value a2 when constructing instance A2 | ||
| -- Error: tests/neg-custom-args/captures/consume-in-constructor.scala:25:10 -------------------------------------------- | ||
| 25 | println(b) // error, b is hidden in the type of a1 | ||
| | ^ | ||
| | Separation failure: Illegal access to {b} which is hidden by the previous definition | ||
| | of value a1 with type A1^. | ||
| | This type hides capabilities {cap, b} | ||
| | | ||
| | where: ^ refers to a fresh root capability in the type of value a1 | ||
| | cap is a fresh root capability created in value a1 when constructing instance A1 |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,30 @@ | ||||||
| import caps.cap | ||||||
|
|
||||||
| class B | ||||||
|
|
||||||
| class A1(val b: B^): | ||||||
| val bb: B^ = B() | ||||||
|
|
||||||
| class A2(consume val b: B^): | ||||||
| val bb: B^ = B() | ||||||
|
|
||||||
| def Test = | ||||||
| val b: B^ = B() | ||||||
| val a1 = A1(b) | ||||||
| val _: A1^{cap, b} = a1 | ||||||
| println(b) // OK since a1's type mentions `b` explicitly | ||||||
| val a2 = A2(b) | ||||||
| val _: A2^{cap, b} = a2 | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this intentional? It doesn't seem to matter if it's |
||||||
| println(b) // error | ||||||
| println(a1) // error, since `b` was consumed before | ||||||
| println(a2) // OK since b belongs to a2 | ||||||
|
|
||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Trying |
||||||
| def Test2 = | ||||||
| val b: B^ = B() | ||||||
| val a1: A1^ = A1(b) | ||||||
| println(b) // error, b is hidden in the type of a1 | ||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm trying to understand what should happen when the
if there is onepart is not true.Say, in the below test file, if we let
A1andA2have no implied fresh (IIUC):Then it exhibits the expected errors, plus it complains about
val _: A2^{cap, b} = a2andprintln(a2)with the same error message:Why is accessing
a2forbidden now?Independently of whether an error is expected or not: The error message itself is confusing, because
a2neither was "passed to a consume parameter" nor "was used as a prefix to a consume method".