Skip to content

Fix secondary constructor capture checking#25841

Open
odersky wants to merge 2 commits intoscala:mainfrom
dotty-staging:fix-secondary-constrs
Open

Fix secondary constructor capture checking#25841
odersky wants to merge 2 commits intoscala:mainfrom
dotty-staging:fix-secondary-constrs

Conversation

@odersky
Copy link
Copy Markdown
Contributor

@odersky odersky commented Apr 17, 2026

Secondary constructors lost parameter captures. This is fixed now. As a result, scala.util.Random is now safe to use from safe mode.

Solution sketch: We keep track of which parameters in secondary constructors flow into a parameter of the primary constructor. For arguments of secondary constructors corresponding to such parameters we can use their actual capture sets. For primary constructor parameters that are not instantiated with an argument of a secondary constructors we assume that they keep their declared formal parameter capture set, which is a conservative appoximation.

Secondary constructors lost parameter captures. This is fixed now.
As a result, scala.util.Random is now safe to use from safe mode.
@odersky odersky requested a review from a team as a code owner April 17, 2026 11:22
The previous treatment was wrong if fields have LocalCaps with different
classifiers that have a common ancestor classifier class. In that case
we created an unclassified LocalCap instead of a LocalCap with the
common ancestor classifier.
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.

2 participants