Skip to content

Fix #9088: Fix problematic code in productMirror #9089

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

Closed
wants to merge 3 commits into from
Closed
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
7 changes: 6 additions & 1 deletion compiler/src/dotty/tools/dotc/typer/Synthesizer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -277,9 +277,14 @@ class Synthesizer(typer: Typer)(using @constructorOnly c: Context):
val elemLabels = accessors.map(acc => ConstantType(Constant(acc.name.toString)))
val (monoType, elemsType) = mirroredType match
case mirroredType: HKTypeLambda =>
def accessorType(acc: Symbol) =
if cls.typeParams.hasSameLengthAs(mirroredType.paramRefs) then
acc.info.subst(cls.typeParams, mirroredType.paramRefs)
else
acc.info
val elems =
mirroredType.derivedLambdaType(
resType = TypeOps.nestedPairs(accessors.map(mirroredType.memberInfo(_).widenExpr))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mirroredType.memberInfo(_) makes no sense here. mirroredType is a type lambda, and as such not a legal prefix on which we can take a memberInfo. So I changed to just _.info which avoids the crash. However, I have no idea whether that's correct.

resType = TypeOps.nestedPairs(accessors.map(accessorType))
)
(mkMirroredMonoType(mirroredType), elems)
case _ =>
Expand Down
6 changes: 3 additions & 3 deletions tests/run/poly-kinded-derives.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ object Test extends App {
given t2 [T] as Functor[[U] =>> (T, U)] {}
given t3 [T, U] as Functor[[V] =>> (T, U, V)] {}

def derived[F[_]](using m: Mirror { type MirroredType = F ; type MirroredElemTypes[_] }, r: Functor[m.MirroredElemTypes]): Functor[F] = new Functor[F] {}
def derived[F[_]](using m: Mirror { type MirroredType[X] = F[X] ; type MirroredElemTypes[_] }, r: Functor[m.MirroredElemTypes]): Functor[F] = new Functor[F] {}
}

case class Mono(i: Int) derives Functor
Expand All @@ -43,7 +43,7 @@ object Test extends App {
given [C] as FunctorK[[F[_]] =>> C] {}
given [T] as FunctorK[[F[_]] =>> Tuple1[F[T]]]

def derived[F[_[_]]](using m: Mirror { type MirroredType = F ; type MirroredElemTypes[_[_]] }, r: FunctorK[m.MirroredElemTypes]): FunctorK[F] = new FunctorK[F] {}
def derived[F[_[_]]](using m: Mirror { type MirroredType[X[_]] = F[X] ; type MirroredElemTypes[_[_]] }, r: FunctorK[m.MirroredElemTypes]): FunctorK[F] = new FunctorK[F] {}
}

case class Mono(i: Int) derives FunctorK
Expand All @@ -61,7 +61,7 @@ object Test extends App {
given t2 as Bifunctor[[T, U] =>> (T, U)] {}
given t3 [T] as Bifunctor[[U, V] =>> (T, U, V)] {}

def derived[F[_, _]](using m: Mirror { type MirroredType = F ; type MirroredElemTypes[_, _] }, r: Bifunctor[m.MirroredElemTypes]): Bifunctor[F] = ???
def derived[F[_, _]](using m: Mirror { type MirroredType[X, Y] = F[X, Y] ; type MirroredElemTypes[_, _] }, r: Bifunctor[m.MirroredElemTypes]): Bifunctor[F] = ???
}

case class Mono(i: Int) derives Bifunctor
Expand Down