Skip to content

Commit cf520a0

Browse files
dwijnandodersky
authored andcommitted
Fix eta-expanding guards in adaptType
1 parent 3694d95 commit cf520a0

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4281,7 +4281,16 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
42814281

42824282
def adaptType(tp: Type): Tree = {
42834283
val tree1 =
4284-
if ((pt eq AnyTypeConstructorProto) || tp.typeParamSymbols.isEmpty) tree
4284+
if pt eq AnyTypeConstructorProto then tree
4285+
else if tp.typeParamSymbols.isEmpty || tp.typeParamSymbols.isEmpty then
4286+
// call typeParamSymbols twice, to get the stable results
4287+
// (see also note inside typeParamSymbols)
4288+
// given `type LifecycleF = [_] =>> Any` in pos/i19942.scala
4289+
// with an Ident of LifecycleF, calling typeParams will return:
4290+
// 1. [type _] a list of the symbol _ in the type def tree, on the first call
4291+
// 2. [+_] a list of a lambda param, afterwards
4292+
// we only want to eta-expand if there are real type param symbols, so we check twice
4293+
tree
42854294
else {
42864295
if (ctx.isJava)
42874296
// Cook raw type

tests/pos/i19942.scala

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
type LifecycleF = [_] =>> Any
2+
trait Lifecycle[+F[_], +A]
3+
4+
trait LifecycleTag[R]
5+
object LifecycleTag:
6+
implicit def resourceTag[R <: Lifecycle[F0, A0], F0[_], A0]: LifecycleTag[R] = ???
7+
8+
trait MakeDSL[T]:
9+
final def fromResource[R <: Lifecycle[LifecycleF, T]](implicit tag: LifecycleTag[R]): Any = ???
10+
11+
object distage:
12+
// Cannot be defined in the same scope as rest of code
13+
final type Identity[+A] = A
14+
import distage.*
15+
16+
trait Resource
17+
trait DependentResource() extends Lifecycle[Identity, Resource]
18+
19+
@main def Test = {
20+
val dsl: MakeDSL[Resource] = ???
21+
val fails = dsl.fromResource[DependentResource]
22+
val works = dsl.fromResource[DependentResource](using LifecycleTag.resourceTag[DependentResource, Identity, Resource])
23+
}

0 commit comments

Comments
 (0)