Skip to content
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

Normalize reference to undet param in stabilizer #10760

Merged
merged 1 commit into from May 8, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/compiler/scala/tools/nsc/typechecker/Typers.scala
Expand Up @@ -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
})
Copy link
Member Author

Choose a reason for hiding this comment

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

In short, given a method def m(b: FT, o: Option[I]): Int and a stabilizer is inserted at some call site stabilizer$1.m(b, None)

If FT is a type parameter, stabilizer$1.m has a MethodType where the parameter type FT is subsituted by asSeenFrom.

If FT is a type member, the parameter type ends up being AliasNoArgsTypeRef(stabilizer$1.type, FT), which is equivalent in theory, but instantiateTypeParams doesn't see through this alias.

More details in scala/bug#12987.

}

val tree1 = tree match {
Expand Down
30 changes: 30 additions & 0 deletions 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)
}
}
}