Skip to content

Conversation

@bracevac
Copy link
Contributor

@bracevac bracevac commented Oct 26, 2025

Fixes #21601

Treat lazy vals similarly to parameterless methods.

TODOs

  • Basic lazy vals support under vanilla CC
    • More spec tests
  • Support for lazy vals under separation checking (mental model: transparent ref cell + pure/rdonly init function)

@bracevac
Copy link
Contributor Author

bracevac commented Oct 27, 2025

Under this scheme, private lazy val _sorted: Seq[A] in scala/collection/SeqView.scala will (rightfully) capture var underlying : SomeSeqOps[A]^, which in turn will blow up on this line

override def to[C1](factory: Factory[A, C1]): C1 = _sorted.to(factory)

Because we expect to return a pure C1, whereas in fact it isn't now.

(I'm glad that this appears to be the only place in the library that causes trouble).

@bracevac
Copy link
Contributor Author

After some more thought, it's actually quite puzzling that the _sorted.to(factory) call would be impure. We'd expect the result to be pure, and only charge the _sorted initializer's capture set to the context.

I've now reverted to the previous solution with just includeCallCaptures. This version does not support treating a lazy val x: Foo = ... with impure initializer as a trackable resource. E.g., () => x is not of type () ->{x} Foo, but () ->{<init>} Foo, and we can't say that {x} <: {<init>}.

@bracevac bracevac force-pushed the cc-lazy-vals branch 2 times, most recently from 50ebe3b to a479fd3 Compare October 28, 2025 15:48
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

Successfully merging this pull request may close these issues.

Implement correct capture check for lazy vals

1 participant