Skip to content

Commit cec6307

Browse files
Update ReTyper to Ycheck patterns
1 parent ca58eaa commit cec6307

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

compiler/src/dotty/tools/dotc/transform/TreeChecker.scala

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -261,9 +261,6 @@ class TreeChecker extends Phase with SymTransformer {
261261

262262
override def typedUnadapted(tree: untpd.Tree, pt: Type)(implicit ctx: Context): tpd.Tree = {
263263
val res = tree match {
264-
case _: untpd.UnApply =>
265-
// can't recheck patterns
266-
tree.asInstanceOf[tpd.Tree]
267264
case _: untpd.TypedSplice | _: untpd.Thicket | _: EmptyValDef[_] =>
268265
super.typedUnadapted(tree)
269266
case _ if tree.isType =>

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

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import core._
55
import Contexts._
66
import Types._
77
import Symbols._
8+
import StdNames._
89
import Decorators._
910
import typer.ProtoTypes._
1011
import ast.{tpd, untpd}
@@ -24,18 +25,20 @@ import config.Printers.typr
2425
class ReTyper extends Typer {
2526
import tpd._
2627

28+
private def assertTyped(tree: untpd.Tree)(implicit ctx: Context): Unit =
29+
assert(tree.hasType, i"$tree ${tree.getClass} ${tree.uniqueId}")
30+
2731
/** Checks that the given tree has been typed */
2832
protected def promote(tree: untpd.Tree)(implicit ctx: Context): tree.ThisTree[Type] = {
29-
assert(tree.hasType, i"$tree ${tree.getClass} ${tree.uniqueId}")
33+
assertTyped(tree)
3034
tree.withType(tree.typeOpt)
3135
}
3236

3337
override def typedIdent(tree: untpd.Ident, pt: Type)(implicit ctx: Context): Tree =
3438
promote(tree)
3539

3640
override def typedSelect(tree: untpd.Select, pt: Type)(implicit ctx: Context): Tree = {
37-
assert(tree.hasType, tree)
38-
// a qualifier cannot be a pattern
41+
assertTyped(tree)
3942
val qual1 = typed(tree.qualifier, AnySelectionProto)(ctx.retractMode(Mode.Pattern))
4043
untpd.cpy.Select(tree)(qual1, tree.name).withType(tree.typeOpt)
4144
}
@@ -49,11 +52,22 @@ class ReTyper extends Typer {
4952
override def typedSuper(tree: untpd.Super, pt: Type)(implicit ctx: Context): Tree =
5053
promote(tree)
5154

55+
override def typedTyped(tree: untpd.Typed, pt: Type)(implicit ctx: Context): Tree = {
56+
assertTyped(tree)
57+
val type1 = checkSimpleKinded(typedType(tree.tpt))
58+
val tree1 = tree.expr match {
59+
case id: untpd.Ident if (ctx.mode is Mode.Pattern) && untpd.isVarPattern(id) && (id.name == nme.WILDCARD || id.name == nme.WILDCARD_STAR) =>
60+
tree.expr.withType(type1.tpe)
61+
case _ => typed(tree.expr)
62+
}
63+
untpd.cpy.Typed(tree)(tree1, type1).withType(tree.typeOpt)
64+
}
65+
5266
override def typedTypeTree(tree: untpd.TypeTree, pt: Type)(implicit ctx: Context): TypeTree =
5367
promote(tree)
5468

5569
override def typedBind(tree: untpd.Bind, pt: Type)(implicit ctx: Context): Bind = {
56-
assert(tree.hasType)
70+
assertTyped(tree)
5771
val body1 = typed(tree.body, pt)
5872
untpd.cpy.Bind(tree)(tree.name, body1).withType(tree.typeOpt)
5973
}
@@ -65,6 +79,10 @@ class ReTyper extends Typer {
6579
untpd.cpy.UnApply(tree)(fun1, implicits1, patterns1).withType(tree.tpe)
6680
}
6781

82+
override def typedUnApply(tree: untpd.Apply, selType: Type)(implicit ctx: Context): Tree = {
83+
typedApply(tree, selType)
84+
}
85+
6886
override def localDummy(cls: ClassSymbol, impl: untpd.Template)(implicit ctx: Context) = impl.symbol
6987

7088
override def retrieveSym(tree: untpd.Tree)(implicit ctx: Context): Symbol = tree.symbol

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,6 @@ trait TypeAssigner {
265265
* - typed child trees it needs to access to cpmpute that type,
266266
* - any further information it needs to access to compute that type.
267267
*/
268-
269268
def assignType(tree: untpd.Ident, tp: Type)(implicit ctx: Context) =
270269
tree.withType(tp)
271270

0 commit comments

Comments
 (0)