Skip to content

Commit c65bdb3

Browse files
committed
Move retry logic to one special case in typeParams
1 parent 2ef48d9 commit c65bdb3

File tree

3 files changed

+14
-13
lines changed

3 files changed

+14
-13
lines changed

compiler/src/dotty/tools/dotc/core/TypeApplications.scala

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,17 @@ class TypeApplications(val self: Type) extends AnyVal {
182182
val tsym = self.symbol
183183
if (tsym.isClass) tsym.typeParams
184184
else tsym.infoOrCompleter match {
185-
case info: LazyType if isTrivial(self.prefix, tsym) => info.completerTypeParams(tsym)
185+
case info: LazyType if isTrivial(self.prefix, tsym) =>
186+
val tparams = info.completerTypeParams(tsym)
187+
if tsym.isCompleted then tsym.info.typeParams
188+
// Completers sometimes represent parameters as symbols where
189+
// the completed type represents them as paramrefs. Make sure we get
190+
// a stable result by calling `typeParams` recursively. Test case
191+
// is pos/i19942.scala, where parameter F0 has initially a Namer#TypeDefCompleter.
192+
// After calling its completerTypeParams, we get a list of parameter symbols
193+
// and as a side effect F0 is completed. Calling typeParams on the completed
194+
// type gives a list of paramrefs.
195+
else tparams
186196
case _ => self.info.typeParams
187197
}
188198
case self: AppliedType =>

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

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

42824282
def adaptType(tp: Type): Tree = {
42834283
val tree1 =
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
4284+
if (pt eq AnyTypeConstructorProto) || tp.typeParamSymbols.isEmpty then tree
42944285
else {
42954286
if (ctx.isJava)
42964287
// Cook raw type

tests/neg-macros/quote-type-variable-no-inference-3.check

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
-- Warning: tests/neg-macros/quote-type-variable-no-inference-3.scala:5:22 ---------------------------------------------
22
5 | case '{ $_ : F[t, t]; () } => // warn // error
33
| ^
4-
| Ignored bound <: Comparable[U]
4+
| Ignored bound <: Comparable[Any]
55
|
66
| Consider defining bounds explicitly:
7-
| '{ type t <: Comparable[U]; ... }
7+
| '{ type t <: Comparable[Any]; ... }
88
-- Warning: tests/neg-macros/quote-type-variable-no-inference-3.scala:6:49 ---------------------------------------------
99
6 | case '{ type u <: Comparable[`u`]; $_ : F[u, u] } =>
1010
| ^

0 commit comments

Comments
 (0)