Skip to content

Commit 4886857

Browse files
authored
Merge pull request #2358 from dotty-staging/fix-2143
Fix #2143: remove widenForMatchSelector in typing patmat
2 parents 81a0b53 + c6d8310 commit 4886857

File tree

4 files changed

+32
-14
lines changed

4 files changed

+32
-14
lines changed

compiler/src/dotty/tools/dotc/transform/patmat/Space.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,8 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {
354354
case Bind(_, pat) => project(pat)
355355
case UnApply(_, _, pats) =>
356356
if (pat.tpe.classSymbol.is(CaseClass))
357-
Kon(pat.tpe.stripAnnots, pats.map(pat => project(pat, roundUp)))
357+
// FIXME: why dealias is needed here?
358+
Kon(pat.tpe.stripAnnots.dealias, pats.map(pat => project(pat, roundUp)))
358359
else if (roundUp) Typ(pat.tpe.stripAnnots, false)
359360
else Empty
360361
case Typed(pat @ UnApply(_, _, _), _) => project(pat)

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

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -187,17 +187,6 @@ object Inferencing {
187187
approxAbove - approxBelow
188188
}
189189

190-
/** Recursively widen and also follow type declarations and type aliases. */
191-
def widenForMatchSelector(tp: Type)(implicit ctx: Context): Type = tp.widen match {
192-
case tp: TypeRef if !tp.symbol.isClass =>
193-
widenForMatchSelector(tp.superType)
194-
case tp: HKApply =>
195-
widenForMatchSelector(tp.superType)
196-
case tp: AnnotatedType =>
197-
tp.derivedAnnotatedType(widenForMatchSelector(tp.tpe), tp.annot)
198-
case tp => tp
199-
}
200-
201190
/** Following type aliases and stripping refinements and annotations, if one arrives at a
202191
* class type reference where the class has a companion module, a reference to
203192
* that companion module. Otherwise NoType

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -834,8 +834,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
834834
typed(desugar.makeCaseLambda(tree.cases, protoFormals.length, unchecked) withPos tree.pos, pt)
835835
case _ =>
836836
val sel1 = typedExpr(tree.selector)
837-
val selType = widenForMatchSelector(
838-
fullyDefinedType(sel1.tpe, "pattern selector", tree.pos))
837+
val selType = fullyDefinedType(sel1.tpe, "pattern selector", tree.pos).widen
839838

840839
val cases1 = typedCases(tree.cases, selType, pt.notApplied)
841840
val cases2 = harmonize(cases1).asInstanceOf[List[CaseDef]]

tests/pos/i2378.scala

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
trait Cap
2+
3+
trait Toolbox {
4+
type Tree
5+
6+
val tpd: TypedTrees
7+
trait TypedTrees {
8+
type Tree
9+
}
10+
11+
val Apply: ApplyImpl
12+
trait ApplyImpl {
13+
def unapply(tree: Tree): Option[(Tree, Seq[Tree])]
14+
def unapply(tree: tpd.Tree)(implicit c: Cap): Option[(tpd.Tree, Seq[tpd.Tree])]
15+
}
16+
}
17+
18+
class Test(val tb: Toolbox) {
19+
import tb._
20+
implicit val cap: Cap = null
21+
22+
def foo(tree: Tree): Int = tree match {
23+
case Apply(fun, args) => 3
24+
}
25+
26+
def bar(tree: tpd.Tree): Int = tree match {
27+
case Apply(fun, args) => 3
28+
}
29+
}

0 commit comments

Comments
 (0)