Skip to content

Commit e926038

Browse files
committed
Also freshen type arguments in parent classes
1 parent 39e05d6 commit e926038

File tree

4 files changed

+15
-16
lines changed

4 files changed

+15
-16
lines changed

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ class Setup extends PreRecheck, SymTransformer, SetupAPI:
167167
def mappedInfo =
168168
if toBeUpdated.contains(sym)
169169
then symd.info // don't transform symbols that will anyway be updated
170-
else transformExplicitType(symd.info, sym, freshen = true)
170+
else transformExplicitType(symd.info, sym)
171171
if Synthetics.needsTransform(symd) then
172172
Synthetics.transform(symd, mappedInfo)
173173
else if isPreCC(sym) then
@@ -349,7 +349,7 @@ class Setup extends PreRecheck, SymTransformer, SetupAPI:
349349
* 5. Schedule deferred well-formed tests for types with retains annotations.
350350
* 6. Perform normalizeCaptures
351351
*/
352-
private def transformExplicitType(tp: Type, sym: Symbol, freshen: Boolean, tptToCheck: Tree = EmptyTree)(using Context): Type =
352+
private def transformExplicitType(tp: Type, sym: Symbol, tptToCheck: Tree = EmptyTree)(using Context): Type =
353353

354354
def fail(msg: Message) =
355355
if !tptToCheck.isEmpty then report.error(msg, tptToCheck.srcPos)
@@ -483,9 +483,7 @@ class Setup extends PreRecheck, SymTransformer, SetupAPI:
483483
val tp3 =
484484
if sym.isType then stripImpliedCaptureSet(tp2)
485485
else tp2
486-
if freshen then
487-
capToFresh(tp3, Origin.InDecl(sym))
488-
else tp3
486+
capToFresh(tp3, Origin.InDecl(sym))
489487
end transformExplicitType
490488

491489
/** Update info of `sym` for CheckCaptures phase only */
@@ -516,7 +514,7 @@ class Setup extends PreRecheck, SymTransformer, SetupAPI:
516514
var transformed =
517515
if tree.isInferred
518516
then transformInferredType(tree.tpe)
519-
else transformExplicitType(tree.tpe, sym, freshen = true, tptToCheck = tree)
517+
else transformExplicitType(tree.tpe, sym, tptToCheck = tree)
520518
if boxed then transformed = transformed.boxDeeply
521519
tree.setNuType(
522520
if sym.hasAnnotation(defn.UncheckedCapturesAnnot) then makeUnchecked(transformed)

tests/neg-custom-args/captures/hk-param.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/** Concrete collection type: View */
22
trait View[+A] extends Itable[A], ILike[A, [X] =>> View[X]^]: // error
3-
override def fromIterable[B](c: Itable[B]^): View[B]^{c} = ???
3+
override def fromIterable[B](c: Itable[B]^): View[B]^{c} = ??? // error
44

55
trait IPolyTransforms[+A, +C[A]] extends Any:
66
def fromIterable[B](coll: Itable[B]^): C[B]

tests/neg-custom-args/captures/unsound-reach-4.check

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,20 @@
1212
| Required: Foo[File^]
1313
|
1414
| Note that capability cap is not included in capture set {cap²}
15-
| because cap is not visible from cap² in value backdoor.
15+
| because cap in class Bar is not visible from cap² in value backdoor.
1616
|
1717
| where: ^ and cap² refer to a fresh root capability in the type of value backdoor
18-
| cap is the universal root capability
18+
| cap is a fresh root capability created in class Bar
1919
|
2020
| longer explanation available when compiling with `-explain`
2121
-- [E164] Declaration Error: tests/neg-custom-args/captures/unsound-reach-4.scala:17:6 ---------------------------------
2222
17 | def use(consume x: F): File^ = x // error consume override
2323
| ^
24-
| error overriding method use in trait Foo of type (x: File^): File^;
25-
| method use of type (@consume x: File^): File^² has incompatible type
24+
| error overriding method use in trait Foo of type (x: File^): File^²;
25+
| method use of type (@consume x: File^): File^³ has incompatible type
2626
|
2727
| where: ^ refers to the universal root capability
28-
| ^² refers to a root capability associated with the result type of (@consume x: File^): File^²
28+
| ^² refers to a fresh root capability created in class Bar
29+
| ^³ refers to a root capability associated with the result type of (@consume x: File^): File^³
2930
|
3031
| longer explanation available when compiling with `-explain`

tests/neg-custom-args/captures/unsound-reach.check

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
| Required: Foo[File^]
1313
|
1414
| Note that capability cap is not included in capture set {cap²}
15-
| because cap is not visible from cap² in value backdoor.
15+
| because cap in class Bar is not visible from cap² in value backdoor.
1616
|
1717
| where: ^ and cap² refer to a fresh root capability in the type of value backdoor
18-
| cap is the universal root capability
18+
| cap is a fresh root capability created in class Bar
1919
|
2020
| longer explanation available when compiling with `-explain`
2121
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/unsound-reach.scala:27:32 --------------------------------
@@ -25,9 +25,9 @@
2525
| Required: Foo2[File^]
2626
|
2727
| Note that capability cap is not included in capture set {cap²}
28-
| because cap is not visible from cap² in value backdoor.
28+
| because cap in class Bar2 is not visible from cap² in value backdoor.
2929
|
3030
| where: ^ and cap² refer to a fresh root capability in the type of value backdoor
31-
| cap is the universal root capability
31+
| cap is a fresh root capability created in class Bar2
3232
|
3333
| longer explanation available when compiling with `-explain`

0 commit comments

Comments
 (0)