From e918307912367ccd022b23bd0a034b2cdd89005b Mon Sep 17 00:00:00 2001 From: Lukas Rytz Date: Fri, 19 Apr 2024 15:13:29 +0200 Subject: [PATCH] Normalize reference to undet param in stabilizer Details in the ticket. --- .../scala/tools/nsc/typechecker/Typers.scala | 7 ++++- test/files/pos/t12987.scala | 30 +++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 test/files/pos/t12987.scala diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index 474cf78e672d..e4e8128cb369 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -5524,7 +5524,12 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper context.pendingStabilizers ::= vdef qual.changeOwner(context.owner -> vsym) val newQual = Ident(vsym) setType singleType(NoPrefix, vsym) setPos qual.pos.focus - return typedSelect(tree, newQual, name) + return typedSelect(tree, newQual, name).modifyType(_.map { + // very specific fix for scala/bug#12987 (details in the ticket) + case t: AliasTypeRef if t.pre.termSymbol == vsym && context.undetparams.contains(t.normalize.typeSymbol) => + t.normalize + case t => t + }) } val tree1 = tree match { diff --git a/test/files/pos/t12987.scala b/test/files/pos/t12987.scala new file mode 100644 index 000000000000..e9a866f4abc9 --- /dev/null +++ b/test/files/pos/t12987.scala @@ -0,0 +1,30 @@ +object typeMember { + class Foo { + type FT + class I + def m(b: FT, o: Option[I]): Int = 0 + } + + object Test { + def f[T]: Foo { type FT = T } = ??? + def t = { + val b: Any = ??? + f.m(b, None) + } + } +} + +object typeParam { + class Foo[FT] { + class I + def m(b: FT, o: Option[I]): Int = 0 + } + + object Test { + def f[T]: Foo[T] = ??? + def t = { + val b: Any = ??? + f.m(b, None) + } + } +}