diff -r 825f23a4f262 -r e2722bd43f3a src/share/classes/com/sun/tools/javac/comp/Attr.java --- a/src/share/classes/com/sun/tools/javac/comp/Attr.java Thu Apr 16 11:23:02 2009 -0700 +++ b/src/share/classes/com/sun/tools/javac/comp/Attr.java Mon May 04 21:04:04 2009 -0700 @@ -118,6 +118,7 @@ relax = (options.get("-retrofit") != null || options.get("-relax") != null); useBeforeDeclarationWarning = options.get("useBeforeDeclarationWarning") != null; + allowInvokedynamic = options.get("invokedynamic") != null; } /** Switch: relax some constraints for retrofit mode. @@ -149,6 +150,10 @@ */ boolean allowAnonOuterThis; + /** Switch: allow invokedynamic syntax + */ + boolean allowInvokedynamic; + /** * Switch: warn about use of variable before declaration? * RFE: 6425594 @@ -438,14 +443,22 @@ } /** Attribute a type argument list, returning a list of types. + * Caller is responsible for calling checkRefTypes. */ - List attribTypes(List trees, Env env) { + List attribAnyTypes(List trees, Env env) { ListBuffer argtypes = new ListBuffer(); for (List l = trees; l.nonEmpty(); l = l.tail) - argtypes.append(chk.checkRefType(l.head.pos(), attribType(l.head, env))); + argtypes.append(attribType(l.head, env)); return argtypes.toList(); } + /** Attribute a type argument list, returning a list of types. + * Check that all the types are references. + */ + List attribTypes(List trees, Env env) { + List types = attribAnyTypes(trees, env); + return chk.checkRefTypes(trees, types); + } /** * Attribute type variables (of generic classes or methods). @@ -1194,6 +1207,7 @@ // The types of the actual method type arguments. List typeargtypes = null; + boolean typeargtypesNonRefOK = false; Name methName = TreeInfo.name(tree.meth); @@ -1281,7 +1295,7 @@ // Otherwise, we are seeing a regular method call. // Attribute the arguments, yielding list of argument types, ... argtypes = attribArgs(tree.args, localEnv); - typeargtypes = attribTypes(tree.typeargs, localEnv); + typeargtypes = attribAnyTypes(tree.typeargs, localEnv); // ... and attribute the method using as a prototype a methodtype // whose formal argument types is exactly the list of actual @@ -1318,6 +1332,20 @@ restype.tsym); } + // as a special case, MethodHandle.invoke(abc) and InvokeDynamic.foo(abc) + // has type , and T can be a primitive type. + if (tree.meth.getTag() == JCTree.SELECT && !typeargtypes.isEmpty()) { + Type selt = ((JCFieldAccess) tree.meth).selected.type; + if ((selt == syms.methodHandleType && methName == names.invoke) || selt == syms.invokeDynamicType) { + assert types.isSameType(restype, typeargtypes.head) : mtype; + typeargtypesNonRefOK = true; + } + } + + if (!typeargtypesNonRefOK) { + chk.checkRefTypes(tree.typeargs, typeargtypes); + } + // Check that value of resulting type is admissible in the // current context. Also, capture the return type result = check(tree, capture(restype), VAL, pkind, pt);