Skip to content

Commit 4b98155

Browse files
committed
Enhancement: Don't count @constructorOnly parameters towards the self type of a class
1 parent 7740fb7 commit 4b98155

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

compiler/src/dotty/tools/dotc/cc/CheckCaptures.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,8 @@ class CheckCaptures extends Recheck, SymTransformer:
489489
/** Class-specific capture set relations:
490490
* 1. The capture set of a class includes the capture sets of its parents.
491491
* 2. The capture set of the self type of a class includes the capture set of the class.
492-
* 3. The capture set of the self type of a class includes the capture set of every class parameter.
492+
* 3. The capture set of the self type of a class includes the capture set of every class parameter,
493+
* unless the parameter is marked @constructorOnly.
493494
*/
494495
override def recheckClassDef(tree: TypeDef, impl: Template, cls: ClassSymbol)(using Context): Type =
495496
val saved = curEnv
@@ -501,7 +502,8 @@ class CheckCaptures extends Recheck, SymTransformer:
501502
val thisSet = cls.classInfo.selfType.captureSet.withDescription(i"of the self type of $cls")
502503
checkSubset(localSet, thisSet, tree.srcPos) // (2)
503504
for param <- cls.paramGetters do
504-
checkSubset(param.termRef.captureSet, thisSet, param.srcPos) // (3)
505+
if !param.hasAnnotation(defn.ConstructorOnlyAnnot) then
506+
checkSubset(param.termRef.captureSet, thisSet, param.srcPos) // (3)
505507
super.recheckClassDef(tree, impl, cls)
506508
finally
507509
curEnv = saved

0 commit comments

Comments
 (0)