Skip to content

Commit 9180c55

Browse files
committed
Also freshen type arguments in parent classes
1 parent bd324f6 commit 9180c55

File tree

4 files changed

+16
-17
lines changed

4 files changed

+16
-17
lines changed

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ class Setup extends PreRecheck, SymTransformer, SetupAPI:
158158
def mappedInfo =
159159
if toBeUpdated.contains(sym)
160160
then symd.info // don't transform symbols that will anyway be updated
161-
else transformExplicitType(symd.info, sym, freshen = true)
161+
else transformExplicitType(symd.info, sym)
162162
if Synthetics.needsTransform(symd) then
163163
Synthetics.transform(symd, mappedInfo)
164164
else if isPreCC(sym) then
@@ -340,7 +340,7 @@ class Setup extends PreRecheck, SymTransformer, SetupAPI:
340340
* 5. Schedule deferred well-formed tests for types with retains annotations.
341341
* 6. Perform normalizeCaptures
342342
*/
343-
private def transformExplicitType(tp: Type, sym: Symbol, freshen: Boolean, tptToCheck: Tree = EmptyTree)(using Context): Type =
343+
private def transformExplicitType(tp: Type, sym: Symbol, tptToCheck: Tree = EmptyTree)(using Context): Type =
344344

345345
def fail(msg: Message) =
346346
if !tptToCheck.isEmpty then report.error(msg, tptToCheck.srcPos)
@@ -474,9 +474,7 @@ class Setup extends PreRecheck, SymTransformer, SetupAPI:
474474
val tp3 =
475475
if sym.isType then stripImpliedCaptureSet(tp2)
476476
else tp2
477-
if freshen then
478-
capToFresh(tp3, Origin.InDecl(sym))
479-
else tp3
477+
capToFresh(tp3, Origin.InDecl(sym))
480478
end transformExplicitType
481479

482480
/** Update info of `sym` for CheckCaptures phase only */
@@ -501,7 +499,7 @@ class Setup extends PreRecheck, SymTransformer, SetupAPI:
501499
var transformed =
502500
if tree.isInferred
503501
then transformInferredType(tree.tpe)
504-
else transformExplicitType(tree.tpe, sym, freshen = true, tptToCheck = tree)
502+
else transformExplicitType(tree.tpe, sym, tptToCheck = tree)
505503
if boxed then transformed = transformed.boxDeeply
506504
tree.setNuType(
507505
if sym.hasAnnotation(defn.UncheckedCapturesAnnot) then makeUnchecked(transformed)
@@ -725,7 +723,7 @@ class Setup extends PreRecheck, SymTransformer, SetupAPI:
725723

726724
// Compute new parent types
727725
val ps1 = inContext(ctx.withOwner(cls)):
728-
ps.mapConserve(transformExplicitType(_, NoSymbol, freshen = false))
726+
ps.mapConserve(transformExplicitType(_, NoSymbol))
729727

730728
// Install new types and if it is a module class also update module object
731729
if (selfInfo1 ne selfInfo) || (ps1 ne ps) then

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)