Skip to content

Fix fromProduct synthesized code for parameter-dependent case classes #22961

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions compiler/src/dotty/tools/dotc/core/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4059,12 +4059,13 @@ object Types extends TypeUtils {
def isParamDependent(using Context): Boolean =
paramDependencyStatus == TrueDeps

/** Like resultDependent || paramDependent, but without attempt to eliminate
* dependencies with de-aliasing
*/
def looksDependent(using Context): Boolean =
/** Like isResultDependent, but without attempt to eliminate dependencies with de-aliasing */
def looksResultDependent(using Context): Boolean =
(dependencyStatus & StatusMask) != NoDeps
|| (paramDependencyStatus & StatusMask) != NoDeps

/** Like isParamDependent, but without attempt to eliminate dependencies with de-aliasing */
def looksParamDependent(using Context): Boolean =
(paramDependencyStatus & StatusMask) != NoDeps

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

Expand Down
3 changes: 2 additions & 1 deletion compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,8 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
val isContextual = tp.isImplicitMethod
val capturesRoot = refs == rootSetText
if cc.isCaptureCheckingOrSetup
&& tp.allParamNamesSynthetic && !tp.looksDependent
&& tp.allParamNamesSynthetic
&& !tp.looksResultDependent && !tp.looksParamDependent
&& !showUniqueIds && !printDebug && !printFresh
then
// cc.Setup converts all functions to dependent functions. Undo that when printing.
Expand Down
11 changes: 6 additions & 5 deletions compiler/src/dotty/tools/dotc/transform/SyntheticMembers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ class SyntheticMembers(thisPhase: DenotTransformer) {
val existing = sym.matchingMember(clazz.thisType)
if ctx.settings.YcompileScala2Library.value && clazz.isValueClass && (sym == defn.Any_equals || sym == defn.Any_hashCode) then
NoSymbol
else if existing != sym && !existing.is(Deferred) then
existing
else
else if existing != sym && !existing.is(Deferred) then
existing
else
NoSymbol
end existingDef

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

Expand Down
39 changes: 39 additions & 0 deletions tests/pos/i22944.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
trait Wrapper {
type Member
}

object Wrapper {

type Aux[M] =
Wrapper {
type Member = M
}

}

// note: the `private` and `private val` are probably not necessary
final case class Demo[M] private (
private val service: Wrapper.Aux[M],
private val endpoints: Vector[service.Member]
)

trait Servo[Alg[_[_]]] {

type Operation[I]
}

object Servo {

type Aux[Alg[_[_]], Op[_]] =
Servo[Alg] {
type Operation[I] = Op[I]
}

}

trait MyEndpoint[Op[_]]

final case class BSPBuilder2[Alg[_[_]], Op[_]] private (
private val service: Servo.Aux[Alg, Op],
private val endpoints: Vector[MyEndpoint[service.Operation]]
)
Loading