diff options
author | Ondrej Lhotak <olhotak@uwaterloo.ca> | 2014-10-08 16:21:31 +0200 |
---|---|---|
committer | Dmitry Petrashko <dmitry.petrashko@gmail.com> | 2014-11-22 20:10:21 +0100 |
commit | 07c4c96aff715a4ec856ccec405f92448a8610e0 (patch) | |
tree | ca54315362743479414794c4c4543ec7afbeab9c | |
parent | ade0565fcdf6cb95818f538a95f798c7456d4c72 (diff) | |
download | dotty-07c4c96aff715a4ec856ccec405f92448a8610e0.tar.gz dotty-07c4c96aff715a4ec856ccec405f92448a8610e0.tar.bz2 dotty-07c4c96aff715a4ec856ccec405f92448a8610e0.zip |
Java Select: try typing as both SelectFromTypeTree and Select
-rw-r--r-- | src/dotty/tools/dotc/typer/Typer.scala | 41 |
1 files changed, 36 insertions, 5 deletions
diff --git a/src/dotty/tools/dotc/typer/Typer.scala b/src/dotty/tools/dotc/typer/Typer.scala index 93a8dff7d..fa8ea6ec2 100644 --- a/src/dotty/tools/dotc/typer/Typer.scala +++ b/src/dotty/tools/dotc/typer/Typer.scala @@ -169,9 +169,9 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit selectors match { case Pair(Ident(from), Ident(Name)) :: rest => val selName = if (name.isTypeName) from.toTypeName else from - checkUnambiguous(selectionType(site, selName, tree.pos)) + checkUnambiguous(selectionType(site, selName, tree.pos)(refctx)) case Ident(Name) :: rest => - checkUnambiguous(selectionType(site, name, tree.pos)) + checkUnambiguous(selectionType(site, name, tree.pos)(refctx)) case _ :: rest => namedImportRef(site, rest) case nil => @@ -279,9 +279,40 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit } def typedSelect(tree: untpd.Select, pt: Type)(implicit ctx: Context): Tree = track("typedSelect") { - val qual1 = typedExpr(tree.qualifier, selectionProto(tree.name, pt, this)) - if (tree.name.isTypeName) checkStable(qual1.tpe, qual1.pos) - checkValue(assignType(cpy.Select(tree)(qual1, tree.name), qual1), pt) + def asSelect(implicit ctx: Context): Tree = { + val qual1 = typedExpr(tree.qualifier, selectionProto(tree.name, pt, this)) + if (tree.name.isTypeName) checkStable(qual1.tpe, qual1.pos) + checkValue(assignType(cpy.Select(tree)(qual1, tree.name), qual1), pt) + } + + def asJavaSelectFromTypeTree(implicit ctx: Context): Tree = { + // Translate names in Select/Ident nodes to type names. + def convertToTypeName(tree: untpd.Tree): Option[untpd.Tree] = tree match { + case Select(qual, name) => Some(untpd.Select(qual, name.toTypeName)) + case Ident(name) => Some(untpd.Ident(name.toTypeName)) + case _ => None + } + + // Try to convert Select(qual, name) to a SelectFromTypeTree. + def convertToSelectFromType(qual: untpd.Tree, origName: Name): Option[untpd.SelectFromTypeTree] = + convertToTypeName(qual) match { + case Some(qual1) => Some(untpd.SelectFromTypeTree(qual1 withPos qual.pos, origName.toTypeName)) + case _ => None + } + + convertToSelectFromType(tree.qualifier, tree.name) match { + case Some(sftt) => + println(s"$tree converted to $sftt") + typedSelectFromTypeTree(sftt, pt) + case _ => ctx.error(d"Could not convert $tree to a SelectFromTypeTree"); EmptyTree + } + } + + 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) } def typedSelectFromTypeTree(tree: untpd.SelectFromTypeTree, pt: Type)(implicit ctx: Context): Tree = track("typedSelectFromTypeTree") { |