aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/typer/Typer.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2016-09-25 18:10:52 +0200
committerMartin Odersky <odersky@gmail.com>2016-09-25 18:10:52 +0200
commitd096f004b5e6ad88ec406b4ca0163a9cdd4fcb17 (patch)
tree0ebb4bc5774d1ea56347713353d3e0844d2ed57e /src/dotty/tools/dotc/typer/Typer.scala
parentbb224fb4feb0f50dd99a80818ee76144e5b874ab (diff)
downloaddotty-d096f004b5e6ad88ec406b4ca0163a9cdd4fcb17.tar.gz
dotty-d096f004b5e6ad88ec406b4ca0163a9cdd4fcb17.tar.bz2
dotty-d096f004b5e6ad88ec406b4ca0163a9cdd4fcb17.zip
Simplify typedSelect logic
Diffstat (limited to 'src/dotty/tools/dotc/typer/Typer.scala')
-rw-r--r--src/dotty/tools/dotc/typer/Typer.scala47
1 files changed, 22 insertions, 25 deletions
diff --git a/src/dotty/tools/dotc/typer/Typer.scala b/src/dotty/tools/dotc/typer/Typer.scala
index 2550da793..562af75f6 100644
--- a/src/dotty/tools/dotc/typer/Typer.scala
+++ b/src/dotty/tools/dotc/typer/Typer.scala
@@ -363,45 +363,42 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
else tree
def typedSelect(tree: untpd.Select, pt: Type)(implicit ctx: Context): Tree = track("typedSelect") {
- def typeAsIs(implicit ctx: Context): Tree = {
- if (tree.qualifier.isType) {
- val qual1 = typedType(tree.qualifier, selectionProto(tree.name, pt, this))
- assignType(cpy.Select(tree)(qual1, tree.name), qual1)
- }
- else {
- val qual1 = typedExpr(tree.qualifier, selectionProto(tree.name, pt, this))
- if (tree.name.isTypeName) checkStable(qual1.tpe, qual1.pos)
- val select = typedSelect(tree, pt, qual1)
- if (select.tpe ne TryDynamicCallType) select
- else if (pt.isInstanceOf[PolyProto] || pt.isInstanceOf[FunProto] || pt == AssignProto) select
- else typedDynamicSelect(tree, Nil, pt)
- }
+ def typeSelectOnTerm(implicit ctx: Context): Tree = {
+ val qual1 = typedExpr(tree.qualifier, selectionProto(tree.name, pt, this))
+ if (tree.name.isTypeName) checkStable(qual1.tpe, qual1.pos)
+ val select = typedSelect(tree, pt, qual1)
+ if (select.tpe ne TryDynamicCallType) select
+ else if (pt.isInstanceOf[PolyProto] || pt.isInstanceOf[FunProto] || pt == AssignProto) select
+ else typedDynamicSelect(tree, Nil, pt)
}
- def asJavaSelectFromType(implicit ctx: Context): Tree = {
- def typeSelectOnType(qual: untpd.Tree) =
- typedSelect(untpd.cpy.Select(tree)(qual, tree.name.toTypeName), pt)
- tree.qualifier match {
- case Select(qual, name) => typeSelectOnType(untpd.Select(qual, name.toTypeName))
- case Ident(name) => typeSelectOnType(untpd.Ident(name.toTypeName))
- case _ => errorTree(tree, "cannot convert to type selection") // will never be printed due to fallback
- }
+ def typeSelectOnType(qual: untpd.Tree)(implicit ctx: Context) =
+ typedSelect(untpd.cpy.Select(tree)(qual, tree.name.toTypeName), pt)
+
+ def tryJavaSelectOnType(implicit ctx: Context): Tree = tree.qualifier match {
+ case Select(qual, name) => typeSelectOnType(untpd.Select(qual, name.toTypeName))
+ case Ident(name) => typeSelectOnType(untpd.Ident(name.toTypeName))
+ case _ => errorTree(tree, "cannot convert to type selection") // will never be printed due to fallback
}
def selectWithFallback(fallBack: Context => Tree) =
- tryAlternatively(typeAsIs(_))(fallBack)
+ tryAlternatively(typeSelectOnTerm(_))(fallBack)
- if (ctx.compilationUnit.isJava && tree.name.isTypeName)
+ if (tree.qualifier.isType) {
+ val qual1 = typedType(tree.qualifier, selectionProto(tree.name, pt, this))
+ assignType(cpy.Select(tree)(qual1, tree.name), qual1)
+ }
+ else 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.
- selectWithFallback(asJavaSelectFromType(_)) // !!! possibly exponential bcs of qualifier retyping
+ selectWithFallback(tryJavaSelectOnType(_)) // !!! possibly exponential bcs of qualifier retyping
else if (tree.name == nme.withFilter && tree.getAttachment(desugar.MaybeFilter).isDefined)
selectWithFallback {
implicit ctx =>
typedSelect(untpd.cpy.Select(tree)(tree.qualifier, nme.filter), pt) // !!! possibly exponential bcs of qualifier retyping
}
else
- typeAsIs(ctx)
+ typeSelectOnTerm(ctx)
}
def typedThis(tree: untpd.This)(implicit ctx: Context): Tree = track("typedThis") {