Skip to content

Commit 4dd215c

Browse files
committed
Fix fromProduct synthesized code for parameter-dependent case classes
The parameter dependency test has to include also false dependencies that can be eliminated by de-aliasing. Fixes #22944
1 parent 7976598 commit 4dd215c

File tree

4 files changed

+53
-11
lines changed

4 files changed

+53
-11
lines changed

Diff for: compiler/src/dotty/tools/dotc/core/Types.scala

+6-5
Original file line numberDiff line numberDiff line change
@@ -4059,12 +4059,13 @@ object Types extends TypeUtils {
40594059
def isParamDependent(using Context): Boolean =
40604060
paramDependencyStatus == TrueDeps
40614061

4062-
/** Like resultDependent || paramDependent, but without attempt to eliminate
4063-
* dependencies with de-aliasing
4064-
*/
4065-
def looksDependent(using Context): Boolean =
4062+
/** Like isResultDependent, but without attempt to eliminate dependencies with de-aliasing */
4063+
def looksResultDependent(using Context): Boolean =
40664064
(dependencyStatus & StatusMask) != NoDeps
4067-
|| (paramDependencyStatus & StatusMask) != NoDeps
4065+
4066+
/** Like isParamDependent, but without attempt to eliminate dependencies with de-aliasing */
4067+
def looksParamDependent(using Context): Boolean =
4068+
(paramDependencyStatus & StatusMask) != NoDeps
40684069

40694070
def newParamRef(n: Int): TermParamRef = new TermParamRefImpl(this, n)
40704071

Diff for: compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala

+2-1
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,8 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
189189
val isContextual = tp.isImplicitMethod
190190
val capturesRoot = refs == rootSetText
191191
if cc.isCaptureCheckingOrSetup
192-
&& tp.allParamNamesSynthetic && !tp.looksDependent
192+
&& tp.allParamNamesSynthetic
193+
&& !tp.looksResultDependent && !tp.looksParamDependent
193194
&& !showUniqueIds && !printDebug && !printFresh
194195
then
195196
// cc.Setup converts all functions to dependent functions. Undo that when printing.

Diff for: compiler/src/dotty/tools/dotc/transform/SyntheticMembers.scala

+6-5
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,9 @@ class SyntheticMembers(thisPhase: DenotTransformer) {
8181
val existing = sym.matchingMember(clazz.thisType)
8282
if ctx.settings.YcompileScala2Library.value && clazz.isValueClass && (sym == defn.Any_equals || sym == defn.Any_hashCode) then
8383
NoSymbol
84-
else if existing != sym && !existing.is(Deferred) then
85-
existing
86-
else
84+
else if existing != sym && !existing.is(Deferred) then
85+
existing
86+
else
8787
NoSymbol
8888
end existingDef
8989

@@ -569,8 +569,9 @@ class SyntheticMembers(thisPhase: DenotTransformer) {
569569
newSymbol(ctx.owner, pref.paramName.freshened, Synthetic,
570570
pref.underlying.translateFromRepeated(toArray = false), coord = ctx.owner.span.focus)
571571
val bindingRefs = bindingSyms.map(TermRef(NoPrefix, _))
572-
// Fix the infos for dependent parameters
573-
if constrMeth.isParamDependent then
572+
// Fix the infos for dependent parameters. We also need to include false dependencies that would
573+
// be fixed by de-aliasing since we do no such de-aliasing here. See i22944.scala.
574+
if constrMeth.looksParamDependent then
574575
bindingSyms.foreach: bindingSym =>
575576
bindingSym.info = bindingSym.info.substParams(constrMeth, bindingRefs)
576577

Diff for: tests/pos/i22944.scala

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
trait Wrapper {
2+
type Member
3+
}
4+
5+
object Wrapper {
6+
7+
type Aux[M] =
8+
Wrapper {
9+
type Member = M
10+
}
11+
12+
}
13+
14+
// note: the `private` and `private val` are probably not necessary
15+
final case class Demo[M] private (
16+
private val service: Wrapper.Aux[M],
17+
private val endpoints: Vector[service.Member]
18+
)
19+
20+
trait Servo[Alg[_[_]]] {
21+
22+
type Operation[I]
23+
}
24+
25+
object Servo {
26+
27+
type Aux[Alg[_[_]], Op[_]] =
28+
Servo[Alg] {
29+
type Operation[I] = Op[I]
30+
}
31+
32+
}
33+
34+
trait MyEndpoint[Op[_]]
35+
36+
final case class BSPBuilder2[Alg[_[_]], Op[_]] private (
37+
private val service: Servo.Aux[Alg, Op],
38+
private val endpoints: Vector[MyEndpoint[service.Operation]]
39+
)

0 commit comments

Comments
 (0)