# HG changeset patch # Parent b77bf7f216f45ad37169c4f8d003feef5ca20a60 8218194: Qualified class name is erroneously rejected inside qualified instance creation expression diff -r b77bf7f216f4 src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java Fri May 03 14:38:58 2019 +0200 +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java Thu May 09 13:59:54 2019 -0400 @@ -2310,8 +2310,7 @@ attribExpr(tree.encl, env)); // TODO 308: in .new C, do we also want to add the type annotations // from expr to the combined type, or not? Yes, do this. - clazzid1 = make.at(clazz.pos).Select(make.Type(encltype), - ((JCIdent) clazzid).name); + clazzid1 = make.at(clazz.pos).Select(make.Type(encltype), TreeInfo.symbol(clazzid).name); EndPosTable endPosTable = this.env.toplevel.endPositions; endPosTable.storeEnd(clazzid1, tree.getEndPosition(endPosTable)); @@ -2351,7 +2350,15 @@ clazztype = chk.checkDiamond(tree, clazztype); chk.validate(clazz, localEnv); - if (tree.encl != null) { + if (tree.encl != null && clazzid.hasTag(SELECT)) { + try { + Type qualified = attribType(tree.clazz, env); + if (!types.isSameType(clazztype, qualified)) + log.error(tree.pos(), Errors.IncomparableTypes(clazztype, qualified)); + } finally { + env.info.isNewClass = false; + } + } else if (tree.encl != null) { // We have to work in this case to store // symbol + type back into the attributed tree. tree.clazz.type = clazztype; diff -r b77bf7f216f4 src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java Fri May 03 14:38:58 2019 +0200 +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java Thu May 09 13:59:54 2019 -0400 @@ -2269,7 +2269,7 @@ } } - /** InnerCreator = [Annotations] Ident [TypeArguments] ClassCreatorRest + /** InnerCreator = [Annotations] Ident {. [Annotations] Ident} [TypeArguments] ClassCreatorRest */ JCExpression innerCreator(int newpos, List typeArgs, JCExpression encl) { List newAnnotations = typeAnnotationsOpt(); @@ -2280,6 +2280,15 @@ t = toP(F.at(newAnnotations.head.pos).AnnotatedType(newAnnotations, t)); } + while (token.kind == DOT) { + nextToken(); + newAnnotations = typeAnnotationsOpt(); + t = toP(F.at(token.pos).Select(t, ident())); + if (newAnnotations.nonEmpty()) { + t = toP(F.at(newAnnotations.head.pos).AnnotatedType(newAnnotations, t)); + } + } + if (token.kind == LT) { int oldmode = mode; t = typeArguments(t, true); diff -r b77bf7f216f4 test/langtools/tools/javac/QualifiedAccess/QualifiedAccess_4.out --- a/test/langtools/tools/javac/QualifiedAccess/QualifiedAccess_4.out Fri May 03 14:38:58 2019 +0200 +++ b/test/langtools/tools/javac/QualifiedAccess/QualifiedAccess_4.out Thu May 09 13:59:54 2019 -0400 @@ -1,2 +1,2 @@ -QualifiedAccess_4.java:17:28: compiler.err.expected: '(' +QualifiedAccess_4.java:17:19: compiler.err.cant.resolve.location: kindname.variable, x, , , (compiler.misc.location: kindname.class, CMain, null) 1 error