Skip to content

Fix #2143: remove widenForMatchSelector in typing patmat #2358

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

Merged
merged 2 commits into from
May 6, 2017
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion compiler/src/dotty/tools/dotc/transform/patmat/Space.scala
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,8 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {
case Bind(_, pat) => project(pat)
case UnApply(_, _, pats) =>
if (pat.tpe.classSymbol.is(CaseClass))
Kon(pat.tpe.stripAnnots, pats.map(pat => project(pat, roundUp)))
// FIXME: why dealias is needed here?
Kon(pat.tpe.stripAnnots.dealias, pats.map(pat => project(pat, roundUp)))
else if (roundUp) Typ(pat.tpe.stripAnnots, false)
else Empty
case Typed(pat @ UnApply(_, _, _), _) => project(pat)
Expand Down
11 changes: 0 additions & 11 deletions compiler/src/dotty/tools/dotc/typer/Inferencing.scala
Original file line number Diff line number Diff line change
Expand Up @@ -187,17 +187,6 @@ object Inferencing {
approxAbove - approxBelow
}

/** Recursively widen and also follow type declarations and type aliases. */
def widenForMatchSelector(tp: Type)(implicit ctx: Context): Type = tp.widen match {
case tp: TypeRef if !tp.symbol.isClass =>
widenForMatchSelector(tp.superType)
case tp: HKApply =>
widenForMatchSelector(tp.superType)
case tp: AnnotatedType =>
tp.derivedAnnotatedType(widenForMatchSelector(tp.tpe), tp.annot)
case tp => tp
}

/** Following type aliases and stripping refinements and annotations, if one arrives at a
* class type reference where the class has a companion module, a reference to
* that companion module. Otherwise NoType
Expand Down
3 changes: 1 addition & 2 deletions compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -834,8 +834,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
typed(desugar.makeCaseLambda(tree.cases, protoFormals.length, unchecked) withPos tree.pos, pt)
case _ =>
val sel1 = typedExpr(tree.selector)
val selType = widenForMatchSelector(
fullyDefinedType(sel1.tpe, "pattern selector", tree.pos))
val selType = fullyDefinedType(sel1.tpe, "pattern selector", tree.pos).widen

val cases1 = typedCases(tree.cases, selType, pt.notApplied)
val cases2 = harmonize(cases1).asInstanceOf[List[CaseDef]]
Expand Down
29 changes: 29 additions & 0 deletions tests/pos/i2378.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
trait Cap

trait Toolbox {
type Tree

val tpd: TypedTrees
trait TypedTrees {
type Tree
}

val Apply: ApplyImpl
trait ApplyImpl {
def unapply(tree: Tree): Option[(Tree, Seq[Tree])]
def unapply(tree: tpd.Tree)(implicit c: Cap): Option[(tpd.Tree, Seq[tpd.Tree])]
}
}

class Test(val tb: Toolbox) {
import tb._
implicit val cap: Cap = null

def foo(tree: Tree): Int = tree match {
case Apply(fun, args) => 3
}

def bar(tree: tpd.Tree): Int = tree match {
case Apply(fun, args) => 3
}
}