Skip to content

Commit 47ed3e6

Browse files
wip
1 parent 0c81f24 commit 47ed3e6

File tree

6 files changed

+23
-32
lines changed

6 files changed

+23
-32
lines changed

compiler/src/dotty/tools/dotc/ast/TreeInfo.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -517,8 +517,8 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] =>
517517
val (meth, targs, argss) = decomposeCall(fn)
518518
(meth, targs, argss :+ args)
519519
case TypeApply(fn, targs) =>
520-
val (meth, targss, args) = decomposeCall(fn)
521-
(meth, targs ++ targss, args)
520+
val (meth, Nil, Nil) = decomposeCall(fn)
521+
(meth, targs, Nil)
522522
case _ =>
523523
(tree, Nil, Nil)
524524
}
@@ -718,4 +718,4 @@ object TreeInfo {
718718
val Pure = new PurityLevel(2)
719719
val Idempotent = new PurityLevel(1)
720720
val Impure = new PurityLevel(0)
721-
}
721+
}

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,9 @@ 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]
264267
case _: untpd.TypedSplice | _: untpd.Thicket | _: EmptyValDef[_] =>
265268
super.typedUnadapted(tree)
266269
case _ if tree.isType =>
@@ -288,7 +291,7 @@ class TreeChecker extends Phase with SymTransformer {
288291
}
289292

290293
def checkNotRepeated(tree: Tree)(implicit ctx: Context): tree.type = {
291-
def allowedRepeated = tree.tpe.widen.isRepeatedParam
294+
def allowedRepeated = (tree.symbol.flags is Case) && tree.tpe.widen.isRepeatedParam
292295

293296
assert(!tree.tpe.widen.isRepeatedParam || allowedRepeated, i"repeated parameter type not allowed here: $tree")
294297
tree

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -955,10 +955,9 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
955955

956956
val dummyArg = dummyTreeOfType(ownType)
957957
val unapplyApp = typedExpr(untpd.TypedSplice(Apply(unapplyFn, dummyArg :: Nil)))
958-
def unapplyImplicits(unapp: Tree): List[Tree] = unapp match {
958+
val unapplyImplicits = unapplyApp match {
959959
case Apply(Apply(unapply, `dummyArg` :: Nil), args2) => assert(args2.nonEmpty); args2
960960
case Apply(unapply, `dummyArg` :: Nil) => Nil
961-
case Inlined(u, _, _) => unapplyImplicits(u)
962961
}
963962

964963
var argTypes = unapplyArgs(unapplyApp.tpe, unapplyFn, args, tree.pos)
@@ -982,7 +981,7 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
982981
List.fill(argTypes.length - args.length)(WildcardType)
983982
}
984983
val unapplyPatterns = (bunchedArgs, argTypes).zipped map (typed(_, _))
985-
val result = assignType(cpy.UnApply(tree)(unapplyFn, unapplyImplicits(unapplyApp), unapplyPatterns), ownType)
984+
val result = assignType(cpy.UnApply(tree)(unapplyFn, unapplyImplicits, unapplyPatterns), ownType)
986985
unapp.println(s"unapply patterns = $unapplyPatterns")
987986
if ((ownType eq selType) || ownType.isError) result
988987
else tryWithClassTag(Typed(result, TypeTree(ownType)), selType)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ class Inliner(call: tpd.Tree, rhs: tpd.Tree)(implicit ctx: Context) {
478478
paramProxy.get(tree.tpe) match {
479479
case Some(t) if tree.isTerm && t.isSingleton => singleton(t).withPos(tree.pos)
480480
case Some(t) if tree.isType => TypeTree(t).withPos(tree.pos)
481-
case _ => tree
481+
case None => tree
482482
}
483483
case _ => tree
484484
}}

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

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import core._
55
import Contexts._
66
import Types._
77
import Symbols._
8-
import StdNames._
98
import Decorators._
109
import typer.ProtoTypes._
1110
import ast.{tpd, untpd}
@@ -25,20 +24,17 @@ import config.Printers.typr
2524
class ReTyper extends Typer {
2625
import tpd._
2726

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

3733
override def typedIdent(tree: untpd.Ident, pt: Type)(implicit ctx: Context): Tree =
3834
promote(tree)
3935

4036
override def typedSelect(tree: untpd.Select, pt: Type)(implicit ctx: Context): Tree = {
41-
assertTyped(tree)
37+
assert(tree.hasType, tree)
4238
val qual1 = typed(tree.qualifier, AnySelectionProto)
4339
untpd.cpy.Select(tree)(qual1, tree.name).withType(tree.typeOpt)
4440
}
@@ -52,22 +48,11 @@ class ReTyper extends Typer {
5248
override def typedSuper(tree: untpd.Super, pt: Type)(implicit ctx: Context): Tree =
5349
promote(tree)
5450

55-
override def typedTyped(tree: untpd.Typed, pt: Type)(implicit ctx: Context): Tree = {
56-
assertTyped(tree)
57-
val tpt1 = checkSimpleKinded(typedType(tree.tpt))
58-
val expr1 = 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(tpt1.tpe)
61-
case _ => typed(tree.expr)
62-
}
63-
untpd.cpy.Typed(tree)(expr1, tpt1).withType(tree.typeOpt)
64-
}
65-
6651
override def typedTypeTree(tree: untpd.TypeTree, pt: Type)(implicit ctx: Context): TypeTree =
6752
promote(tree)
6853

6954
override def typedBind(tree: untpd.Bind, pt: Type)(implicit ctx: Context): Bind = {
70-
assertTyped(tree)
55+
assert(tree.hasType)
7156
val body1 = typed(tree.body, pt)
7257
untpd.cpy.Bind(tree)(tree.name, body1).withType(tree.typeOpt)
7358
}
@@ -79,10 +64,6 @@ class ReTyper extends Typer {
7964
untpd.cpy.UnApply(tree)(fun1, implicits1, patterns1).withType(tree.tpe)
8065
}
8166

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

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

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,13 @@ class Typer extends Namer
645645

646646
def typedBlock(tree: untpd.Block, pt: Type)(implicit ctx: Context) = track("typedBlock") {
647647
val (exprCtx, stats1) = typedBlockStats(tree.stats)
648-
val expr1 = typedExpr(tree.expr, pt.notApplied)(exprCtx)
648+
val ept =
649+
if (tree.isInstanceOf[untpd.InfixOpBlock])
650+
// Right-binding infix operations are expanded to InfixBlocks, which may be followed by arguments.
651+
// Example: `(a /: bs)(op)` expands to `{ val x = a; bs./:(x) } (op)` where `{...}` is an InfixBlock.
652+
pt
653+
else pt.notApplied
654+
val expr1 = typedExpr(tree.expr, ept)(exprCtx)
649655
ensureNoLocalRefs(
650656
cpy.Block(tree)(stats1, expr1).withType(expr1.tpe), pt, localSyms(stats1))
651657
}
@@ -976,7 +982,9 @@ class Typer extends Namer
976982
cases mapconserve (typedCase(_, pt, selType, gadtSyms))
977983
}
978984

979-
/** Type a case. */
985+
/** Type a case. Overridden in ReTyper, that's why it's separate from
986+
* typedCases.
987+
*/
980988
def typedCase(tree: untpd.CaseDef, pt: Type, selType: Type, gadtSyms: Set[Symbol])(implicit ctx: Context): CaseDef = track("typedCase") {
981989
val originalCtx = ctx
982990

0 commit comments

Comments
 (0)