@@ -168,9 +168,9 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
168
168
selectors match {
169
169
case Pair (Ident (from), Ident (Name )) :: rest =>
170
170
val selName = if (name.isTypeName) from.toTypeName else from
171
- checkUnambiguous(selectionType(site, selName, tree.pos))
171
+ checkUnambiguous(selectionType(site, selName, tree.pos)(refctx) )
172
172
case Ident (Name ) :: rest =>
173
- checkUnambiguous(selectionType(site, name, tree.pos))
173
+ checkUnambiguous(selectionType(site, name, tree.pos)(refctx) )
174
174
case _ :: rest =>
175
175
namedImportRef(site, rest)
176
176
case nil =>
@@ -270,9 +270,40 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
270
270
}
271
271
272
272
def typedSelect (tree : untpd.Select , pt : Type )(implicit ctx : Context ): Tree = track(" typedSelect" ) {
273
- val qual1 = typedExpr(tree.qualifier, selectionProto(tree.name, pt, this ))
274
- if (tree.name.isTypeName) checkStable(qual1.tpe, qual1.pos)
275
- checkValue(assignType(cpy.Select (tree, qual1, tree.name), qual1), pt)
273
+ def asSelect (implicit ctx : Context ): Tree = {
274
+ val qual1 = typedExpr(tree.qualifier, selectionProto(tree.name, pt, this ))
275
+ if (tree.name.isTypeName) checkStable(qual1.tpe, qual1.pos)
276
+ checkValue(assignType(cpy.Select (tree, qual1, tree.name), qual1), pt)
277
+ }
278
+
279
+ def asJavaSelectFromTypeTree (implicit ctx : Context ): Tree = {
280
+ // Translate names in Select/Ident nodes to type names.
281
+ def convertToTypeName (tree : untpd.Tree ): Option [untpd.Tree ] = tree match {
282
+ case Select (qual, name) => Some (untpd.Select (qual, name.toTypeName))
283
+ case Ident (name) => Some (untpd.Ident (name.toTypeName))
284
+ case _ => None
285
+ }
286
+
287
+ // Try to convert Select(qual, name) to a SelectFromTypeTree.
288
+ def convertToSelectFromType (qual : untpd.Tree , origName : Name ): Option [untpd.SelectFromTypeTree ] =
289
+ convertToTypeName(qual) match {
290
+ case Some (qual1) => Some (untpd.SelectFromTypeTree (qual1 withPos qual.pos, origName.toTypeName))
291
+ case _ => None
292
+ }
293
+
294
+ convertToSelectFromType(tree.qualifier, tree.name) match {
295
+ case Some (sftt) =>
296
+ println(s " $tree converted to $sftt" )
297
+ typedSelectFromTypeTree(sftt, pt)
298
+ case _ => ctx.error(d " Could not convert $tree to a SelectFromTypeTree " ); EmptyTree
299
+ }
300
+ }
301
+
302
+ if (ctx.compilationUnit.isJava && tree.name.isTypeName) {
303
+ // SI-3120 Java uses the same syntax, A.B, to express selection from the
304
+ // value A and from the type A. We have to try both.
305
+ tryEither(tryCtx => asSelect(tryCtx))((_,_) => asJavaSelectFromTypeTree(ctx))
306
+ } else asSelect(ctx)
276
307
}
277
308
278
309
def typedSelectFromTypeTree (tree : untpd.SelectFromTypeTree , pt : Type )(implicit ctx : Context ): SelectFromTypeTree = track(" typedSelectFromTypeTree" ) {
0 commit comments