aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/typer/Typer.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2016-08-24 08:21:38 +0200
committerMartin Odersky <odersky@gmail.com>2016-08-26 11:13:16 +0200
commitfcea3d54dd016600f5a96cda5d03f2a5ee81e7f1 (patch)
tree271c60eb4ee439c89c3bc1eb86e86d270bd4203a /src/dotty/tools/dotc/typer/Typer.scala
parent6d4469a627244eb0620a51764a3494f8250a8e2b (diff)
downloaddotty-fcea3d54dd016600f5a96cda5d03f2a5ee81e7f1.tar.gz
dotty-fcea3d54dd016600f5a96cda5d03f2a5ee81e7f1.tar.bz2
dotty-fcea3d54dd016600f5a96cda5d03f2a5ee81e7f1.zip
Implement alternative desugaring of for-if to filter.
Fallback to .filter if a .withFilter is not available, but do this only for .withFilter calls generated from for expressions (this is different from what scalac does; the latter can also rewrite .withFilter calls given in source, which is not desirable.
Diffstat (limited to 'src/dotty/tools/dotc/typer/Typer.scala')
-rw-r--r--src/dotty/tools/dotc/typer/Typer.scala12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/dotty/tools/dotc/typer/Typer.scala b/src/dotty/tools/dotc/typer/Typer.scala
index 934ca556d..c9a2e4b48 100644
--- a/src/dotty/tools/dotc/typer/Typer.scala
+++ b/src/dotty/tools/dotc/typer/Typer.scala
@@ -346,11 +346,17 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
}
}
- if (ctx.compilationUnit.isJava && tree.name.isTypeName) {
+ def selectWithFallback(fallBack: => Tree) =
+ tryEither(tryCtx => asSelect(tryCtx))((_, _) => fallBack)
+
+ if (ctx.compilationUnit.isJava && tree.name.isTypeName)
// SI-3120 Java uses the same syntax, A.B, to express selection from the
// value A and from the type A. We have to try both.
- tryEither(tryCtx => asSelect(tryCtx))((_, _) => asJavaSelectFromTypeTree(ctx))
- } else asSelect(ctx)
+ selectWithFallback(asJavaSelectFromTypeTree(ctx))
+ else if (tree.name == nme.withFilter && tree.getAttachment(desugar.MaybeFilter).isDefined)
+ selectWithFallback(typedSelect(untpd.cpy.Select(tree)(tree.qualifier, nme.filter), pt))
+ else
+ asSelect(ctx)
}
def typedSelectFromTypeTree(tree: untpd.SelectFromTypeTree, pt: Type)(implicit ctx: Context): Tree = track("typedSelectFromTypeTree") {