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

Don't GLB binders of type patterns, use the type directly #10247

Merged
merged 1 commit into from Jan 11, 2023
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
Expand Up @@ -68,11 +68,10 @@ trait MatchTranslation {
def pos = tree.pos
def tpe = binder.info.dealias // the type of the variable bound to the pattern
def pt = unbound match {
case Star(tpt) => this glbWith seqType(tpt.tpe)
case Star(tpt) => seqType(tpt.tpe)
case TypeBound(tpe) => tpe
case tree => tree.tpe
}
def glbWith(other: Type) = glb(tpe :: other :: Nil).normalize

object SymbolAndTypeBound {
def unapply(tree: Tree): Option[(Symbol, Type)] = tree match {
Expand All @@ -94,7 +93,7 @@ trait MatchTranslation {

private def bindingStep(sub: Symbol, subpattern: Tree) = step(SubstOnlyTreeMaker(sub, binder))(rebindTo(subpattern))
private def equalityTestStep() = step(EqualityTestTreeMaker(binder, tree, pos))()
private def typeTestStep(sub: Symbol, subPt: Type) = step(TypeTestTreeMaker(sub, binder, subPt, glbWith(subPt))(pos))()
private def typeTestStep(sub: Symbol, subPt: Type) = step(TypeTestTreeMaker(sub, binder, subPt, subPt)(pos))()
private def alternativesStep(alts: List[Tree]) = step(AlternativesTreeMaker(binder, translatedAlts(alts), alts.head.pos))()
private def translatedAlts(alts: List[Tree]) = alts map (alt => rebindTo(alt).translate())
private def noStep() = step()()
Expand Down
2 changes: 2 additions & 0 deletions test/files/run/t12702.check
@@ -0,0 +1,2 @@
warning: 1 feature warning; re-run with -feature for details
IOS
17 changes: 17 additions & 0 deletions test/files/run/t12702.scala
@@ -0,0 +1,17 @@
object Test {
trait MFSS[X <: MFSS[_]]
trait CS extends MFSS[CS]
trait MFI { type ST }
case class MFSD[S](mFI: MFI {type ST = S})
case object IOS extends MFI { type ST = CS }
type SD = MFSD[S] forSome {
type S <: MFSS[S]
}
def bad(sd: SD) = sd.mFI match {
case ios: IOS.type => println(ios)
}
def main(args: Array[String]): Unit = {
val x = MFSD(IOS)
bad(x)
}
}
29 changes: 29 additions & 0 deletions test/junit/scala/tools/nsc/symtab/SymbolTableTest.scala
Expand Up @@ -49,4 +49,33 @@ class SymbolTableTest {
import symbolTable._
assertEquals(NoSymbol, NoSymbol.outerClass)
}

@Test def t12702_glb(): Unit = {
import symbolTable._
import SymbolTableTest.t12702._
val t1 = typeOf[IOS.type]
val t2 = {
val sd = typeOf[SD]
sd.memberType(sd.member(TermName("mFI"))).finalResultType
}
// t1: Test.IOS.type
// t2: Test.MFI{type +ST = S}

// Ends up in `throw GlbFailure` in glb => Null
assertTrue(definitions.NullTpe =:= glb(t1 :: t2 :: Nil))
}
}

object SymbolTableTest {
object t12702 {
import scala.language.existentials
trait MFSS[X <: MFSS[_]]
trait CS extends MFSS[CS]
trait MFI { type ST }
case class MFSD[S](mFI: MFI {type ST = S})
case object IOS extends MFI { type ST = CS }
type SD = MFSD[S] forSome {
type S <: MFSS[S]
}
}
}