-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix Paths Referencing Consumed Parameters #24442
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?
Conversation
|
@odersky it seems to be stable now. I will add some more neg tests. Do you agree with the general direction, or should we try something else? |
|
I'm also surprised that reach capabilities would pop up where there are no boxes involved whatsoever. |
87012a8 to
a539295
Compare
| case _ => | ||
| acc | ||
|
|
||
| def capsFromConsumeFields(ref: TermRef): Refs = |
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.
Why do we need that? Would not the path root already contain the field consumed set?
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.
As discussed offline:
class B
class A(consume val b: B^)
class Holder(val a: A^) // Note: NOT consume
def test =
val b: B^ = B()
val a = A(b) // b is gone
val holder = Holder(a) // separation failure, but should be okAt the end of checkUse, we can see b is consumed and know a clashes with b. To conclude that the use of a is ok, we also need to inspect its consume constructor parameter to see that it has consumed b, so we should ignore the clash.
|
We came to the conclusion that the solution with fixing the logic at the end of |
|
#24470 now contains code to require consume parameters to be covered by a fresh of the class. Can you rebase the tests here and see what they see with these changes? |
- FreshCaps with Unscoped classifier are assumed to be owned by the enclosing toplevel class - FreshCaps with unscoped classifier are not turned into ResultCaps in the return types of anonymous functions.
Also: Improve consume message
Allow both .only[C] and .rd (in this order).
If a class has fresh fields and all fields are read-only, only imply `cap.rd`, not `cap`.
Treat it like an expression `e` instead.
a4f1c60 to
4636639
Compare
|
@odersky I only added the tests to #24470 here, and I'm seeing -- Error: tests/pos-custom-args/captures/paths-simple-suffix-consume.scala:9:20
9 |class A(consume val b: B^)
| ^
|A consume parameter is only allowed for classes producing a `cap` in their constructor.
|This can be achieved by having the class extend caps.Separate.and can't seem to be able to add -- [E008] Not Found Error: tests/pos-custom-args/captures/paths-simple-suffix-consume.scala:9:40
9 |class A(consume val b: B^) extends caps.Separate
| ^^^^^^^^^^^^^
| type Separate is not a member of capsIt's missing? |
|
Spying at your test cases, I changed it to class A(consume val b: B^) extends Mutable { var x: Int = 1 }in -- Error: tests/pos-custom-args/captures/paths-simple-suffix-consume.scala:19:12
19 | println(a.b) // OK - consumed field
| ^^^
|Separation failure: Illegal access to (a.b : B^{b²}), which was passed as a consume parameter to constructor of class A
|on line 16 and therefore is no longer available.
|
|where: b is a value in class A
| b² is a value in method test1But it should work, no? Edit: When we check for a clash in The instead? |
Builds on #24424
Tasks
checkUse.