Thu, 11 Oct 2012 17:00:54 -0700
Merge
1.1 --- a/src/share/classes/com/sun/tools/doclets/formats/html/ClassUseWriter.java Thu Oct 11 09:50:52 2012 -0700 1.2 +++ b/src/share/classes/com/sun/tools/doclets/formats/html/ClassUseWriter.java Thu Oct 11 17:00:54 2012 -0700 1.3 @@ -1,5 +1,5 @@ 1.4 /* 1.5 - * Copyright (c) 1998, 2011, Oracle and/or its affiliates. All rights reserved. 1.6 + * Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved. 1.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.8 * 1.9 * This code is free software; you can redistribute it and/or modify it 1.10 @@ -195,10 +195,7 @@ 1.11 ClassUseWriter clsgen; 1.12 String path = DirectoryManager.getDirectoryPath(classdoc. 1.13 containingPackage()); 1.14 - if (path.length() > 0) { 1.15 - path += File.separator; 1.16 - } 1.17 - path += "class-use"; 1.18 + path += "class-use" + DirectoryManager.URL_FILE_SEPARATOR; 1.19 String filename = classdoc.name() + ".html"; 1.20 String pkgname = classdoc.containingPackage().name(); 1.21 pkgname += (pkgname.length() > 0)? ".class-use": "class-use";
2.1 --- a/src/share/classes/com/sun/tools/doclets/formats/html/HelpWriter.java Thu Oct 11 09:50:52 2012 -0700 2.2 +++ b/src/share/classes/com/sun/tools/doclets/formats/html/HelpWriter.java Thu Oct 11 17:00:54 2012 -0700 2.3 @@ -1,5 +1,5 @@ 2.4 /* 2.5 - * Copyright (c) 1998, 2011, Oracle and/or its affiliates. All rights reserved. 2.6 + * Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved. 2.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 2.8 * 2.9 * This code is free software; you can redistribute it and/or modify it 2.10 @@ -302,7 +302,9 @@ 2.11 Content constHead = HtmlTree.HEADING(HtmlConstants.CONTENT_HEADING, 2.12 getResource("doclet.Constants_Summary")); 2.13 Content liConst = HtmlTree.LI(HtmlStyle.blockList, constHead); 2.14 - Content line29 = getResource("doclet.Help_line_29"); 2.15 + Content line29 = getResource("doclet.Help_line_29", 2.16 + getHyperLinkString("constant-values.html", 2.17 + configuration.getText("doclet.Constants_Summary"))); 2.18 Content constPara = HtmlTree.P(line29); 2.19 liConst.addContent(constPara); 2.20 ul.addContent(liConst);
3.1 --- a/src/share/classes/com/sun/tools/doclets/formats/html/resources/standard.properties Thu Oct 11 09:50:52 2012 -0700 3.2 +++ b/src/share/classes/com/sun/tools/doclets/formats/html/resources/standard.properties Thu Oct 11 17:00:54 2012 -0700 3.3 @@ -160,7 +160,7 @@ 3.4 doclet.Help_line_26=These links show and hide the HTML frames. All pages are available with or without frames. 3.5 doclet.Help_line_27=The {0} link shows all classes and interfaces except non-static nested types. 3.6 doclet.Help_line_28=Each serializable or externalizable class has a description of its serialization fields and methods. This information is of interest to re-implementors, not to developers using the API. While there is no link in the navigation bar, you can get to this information by going to any serialized class and clicking "Serialized Form" in the "See also" section of the class description. 3.7 -doclet.Help_line_29=The <a href="constant-values.html">Constant Field Values</a> page lists the static final fields and their values. 3.8 +doclet.Help_line_29=The {0} page lists the static final fields and their values. 3.9 doclet.Help_line_30=This help file applies to API documentation generated using the standard doclet. 3.10 doclet.Help_enum_line_1=Each enum has its own separate page with the following sections: 3.11 doclet.Help_enum_line_2=Enum declaration
4.1 --- a/src/share/classes/com/sun/tools/doclets/internal/toolkit/Configuration.java Thu Oct 11 09:50:52 2012 -0700 4.2 +++ b/src/share/classes/com/sun/tools/doclets/internal/toolkit/Configuration.java Thu Oct 11 17:00:54 2012 -0700 4.3 @@ -488,17 +488,18 @@ 4.4 } 4.5 4.6 /** 4.7 - * Add a traliling file separator, if not found or strip off extra trailing 4.8 - * file separators if any. 4.9 + * Add a trailing file separator, if not found. Remove superfluous 4.10 + * file separators if any. Preserve the front double file separator for 4.11 + * UNC paths. 4.12 * 4.13 * @param path Path under consideration. 4.14 * @return String Properly constructed path string. 4.15 */ 4.16 - String addTrailingFileSep(String path) { 4.17 + public static String addTrailingFileSep(String path) { 4.18 String fs = System.getProperty("file.separator"); 4.19 String dblfs = fs + fs; 4.20 int indexDblfs; 4.21 - while ((indexDblfs = path.indexOf(dblfs)) >= 0) { 4.22 + while ((indexDblfs = path.indexOf(dblfs, 1)) >= 0) { 4.23 path = path.substring(0, indexDblfs) + 4.24 path.substring(indexDblfs + fs.length()); 4.25 }
5.1 --- a/src/share/classes/com/sun/tools/doclets/internal/toolkit/taglets/TagletManager.java Thu Oct 11 09:50:52 2012 -0700 5.2 +++ b/src/share/classes/com/sun/tools/doclets/internal/toolkit/taglets/TagletManager.java Thu Oct 11 17:00:54 2012 -0700 5.3 @@ -262,11 +262,7 @@ 5.4 urls[count++] = url; 5.5 } 5.6 } 5.7 - if (urls.length != count) { 5.8 - URL[] tmp = new URL[count]; 5.9 - System.arraycopy(urls, 0, tmp, 0, count); 5.10 - urls = tmp; 5.11 - } 5.12 + urls = Arrays.copyOf(urls, count); 5.13 return urls; 5.14 } 5.15
6.1 --- a/src/share/classes/com/sun/tools/javac/api/BasicJavacTask.java Thu Oct 11 09:50:52 2012 -0700 6.2 +++ b/src/share/classes/com/sun/tools/javac/api/BasicJavacTask.java Thu Oct 11 17:00:54 2012 -0700 6.3 @@ -136,4 +136,11 @@ 6.4 throw new IllegalStateException(); 6.5 } 6.6 6.7 + /** 6.8 + * For internal use only. This method will be 6.9 + * removed without warning. 6.10 + */ 6.11 + public void updateContext(Context newContext) { 6.12 + context = newContext; 6.13 + } 6.14 }
7.1 --- a/src/share/classes/com/sun/tools/javac/api/MultiTaskListener.java Thu Oct 11 09:50:52 2012 -0700 7.2 +++ b/src/share/classes/com/sun/tools/javac/api/MultiTaskListener.java Thu Oct 11 17:00:54 2012 -0700 7.3 @@ -79,10 +79,8 @@ 7.4 if (ccw.unwrap(l) == listener) 7.5 throw new IllegalStateException(); 7.6 } 7.7 - TaskListener[] newListeners = new TaskListener[listeners.length + 1]; 7.8 - System.arraycopy(listeners, 0, newListeners, 0, listeners.length); 7.9 - newListeners[newListeners.length - 1] = ccw.wrap(listener); 7.10 - listeners = newListeners; 7.11 + listeners = Arrays.copyOf(listeners, listeners.length + 1); 7.12 + listeners[listeners.length - 1] = ccw.wrap(listener); 7.13 } 7.14 7.15 public void remove(TaskListener listener) {
8.1 --- a/src/share/classes/com/sun/tools/javac/code/Kinds.java Thu Oct 11 09:50:52 2012 -0700 8.2 +++ b/src/share/classes/com/sun/tools/javac/code/Kinds.java Thu Oct 11 17:00:54 2012 -0700 8.3 @@ -28,6 +28,7 @@ 8.4 import java.util.EnumSet; 8.5 import java.util.Locale; 8.6 8.7 +import com.sun.source.tree.MemberReferenceTree; 8.8 import com.sun.tools.javac.api.Formattable; 8.9 import com.sun.tools.javac.api.Messages; 8.10 8.11 @@ -85,11 +86,12 @@ 8.12 public static final int AMBIGUOUS = ERRONEOUS+1; // ambiguous reference 8.13 public static final int HIDDEN = ERRONEOUS+2; // hidden method or field 8.14 public static final int STATICERR = ERRONEOUS+3; // nonstatic member from static context 8.15 - public static final int ABSENT_VAR = ERRONEOUS+4; // missing variable 8.16 - public static final int WRONG_MTHS = ERRONEOUS+5; // methods with wrong arguments 8.17 - public static final int WRONG_MTH = ERRONEOUS+6; // one method with wrong arguments 8.18 - public static final int ABSENT_MTH = ERRONEOUS+7; // missing method 8.19 - public static final int ABSENT_TYP = ERRONEOUS+8; // missing type 8.20 + public static final int MISSING_ENCL = ERRONEOUS+4; // missing enclosing class 8.21 + public static final int ABSENT_VAR = ERRONEOUS+5; // missing variable 8.22 + public static final int WRONG_MTHS = ERRONEOUS+6; // methods with wrong arguments 8.23 + public static final int WRONG_MTH = ERRONEOUS+7; // one method with wrong arguments 8.24 + public static final int ABSENT_MTH = ERRONEOUS+8; // missing method 8.25 + public static final int ABSENT_TYP = ERRONEOUS+9; // missing type 8.26 8.27 public enum KindName implements Formattable { 8.28 ANNOTATION("kindname.annotation"), 8.29 @@ -140,6 +142,14 @@ 8.30 } 8.31 } 8.32 8.33 + public static KindName kindName(MemberReferenceTree.ReferenceMode mode) { 8.34 + switch (mode) { 8.35 + case INVOKE: return KindName.METHOD; 8.36 + case NEW: return KindName.CONSTRUCTOR; 8.37 + default : throw new AssertionError("Unexpected mode: "+ mode); 8.38 + } 8.39 + } 8.40 + 8.41 /** A KindName representing a given symbol 8.42 */ 8.43 public static KindName kindName(Symbol sym) {
9.1 --- a/src/share/classes/com/sun/tools/javac/code/Printer.java Thu Oct 11 09:50:52 2012 -0700 9.2 +++ b/src/share/classes/com/sun/tools/javac/code/Printer.java Thu Oct 11 17:00:54 2012 -0700 9.3 @@ -30,6 +30,10 @@ 9.4 import com.sun.tools.javac.api.Messages; 9.5 import com.sun.tools.javac.code.Type.*; 9.6 import com.sun.tools.javac.code.Symbol.*; 9.7 +import com.sun.tools.javac.comp.DeferredAttr.DeferredType; 9.8 +import com.sun.tools.javac.tree.JCTree; 9.9 +import com.sun.tools.javac.tree.Pretty; 9.10 +import com.sun.tools.javac.util.Assert; 9.11 import com.sun.tools.javac.util.List; 9.12 import com.sun.tools.javac.util.ListBuffer; 9.13 9.14 @@ -51,6 +55,8 @@ 9.15 List<Type> seenCaptured = List.nil(); 9.16 static final int PRIME = 997; // largest prime less than 1000 9.17 9.18 + protected Printer() { } 9.19 + 9.20 /** 9.21 * This method should be overriden in order to provide proper i18n support. 9.22 *
10.1 --- a/src/share/classes/com/sun/tools/javac/code/Source.java Thu Oct 11 09:50:52 2012 -0700 10.2 +++ b/src/share/classes/com/sun/tools/javac/code/Source.java Thu Oct 11 17:00:54 2012 -0700 10.3 @@ -194,6 +194,9 @@ 10.4 public boolean allowObjectToPrimitiveCast() { 10.5 return compareTo(JDK1_7) >= 0; 10.6 } 10.7 + public boolean allowPoly() { 10.8 + return compareTo(JDK1_8) >= 0; 10.9 + } 10.10 public boolean allowLambda() { 10.11 return compareTo(JDK1_8) >= 0; 10.12 }
11.1 --- a/src/share/classes/com/sun/tools/javac/code/Symbol.java Thu Oct 11 09:50:52 2012 -0700 11.2 +++ b/src/share/classes/com/sun/tools/javac/code/Symbol.java Thu Oct 11 17:00:54 2012 -0700 11.3 @@ -168,6 +168,10 @@ 11.4 return owner; 11.5 } 11.6 11.7 + public Symbol baseSymbol() { 11.8 + return this; 11.9 + } 11.10 + 11.11 /** The symbol's erased type. 11.12 */ 11.13 public Type erasure(Types types) { 11.14 @@ -918,7 +922,12 @@ 11.15 /** Clone this symbol with new owner. 11.16 */ 11.17 public VarSymbol clone(Symbol newOwner) { 11.18 - VarSymbol v = new VarSymbol(flags_field, name, type, newOwner); 11.19 + VarSymbol v = new VarSymbol(flags_field, name, type, newOwner) { 11.20 + @Override 11.21 + public Symbol baseSymbol() { 11.22 + return VarSymbol.this; 11.23 + } 11.24 + }; 11.25 v.pos = pos; 11.26 v.adr = adr; 11.27 v.data = data; 11.28 @@ -1045,7 +1054,12 @@ 11.29 /** Clone this symbol with new owner. 11.30 */ 11.31 public MethodSymbol clone(Symbol newOwner) { 11.32 - MethodSymbol m = new MethodSymbol(flags_field, name, type, newOwner); 11.33 + MethodSymbol m = new MethodSymbol(flags_field, name, type, newOwner) { 11.34 + @Override 11.35 + public Symbol baseSymbol() { 11.36 + return MethodSymbol.this; 11.37 + } 11.38 + }; 11.39 m.code = code; 11.40 return m; 11.41 } 11.42 @@ -1068,6 +1082,10 @@ 11.43 } 11.44 } 11.45 11.46 + public boolean isDynamic() { 11.47 + return false; 11.48 + } 11.49 + 11.50 /** find a symbol that this (proxy method) symbol implements. 11.51 * @param c The class whose members are searched for 11.52 * implementations 11.53 @@ -1356,6 +1374,27 @@ 11.54 } 11.55 } 11.56 11.57 + /** A class for invokedynamic method calls. 11.58 + */ 11.59 + public static class DynamicMethodSymbol extends MethodSymbol { 11.60 + 11.61 + public Object[] staticArgs; 11.62 + public Symbol bsm; 11.63 + public int bsmKind; 11.64 + 11.65 + public DynamicMethodSymbol(Name name, Symbol owner, int bsmKind, MethodSymbol bsm, Type type, Object[] staticArgs) { 11.66 + super(0, name, type, owner); 11.67 + this.bsm = bsm; 11.68 + this.bsmKind = bsmKind; 11.69 + this.staticArgs = staticArgs; 11.70 + } 11.71 + 11.72 + @Override 11.73 + public boolean isDynamic() { 11.74 + return true; 11.75 + } 11.76 + } 11.77 + 11.78 /** A class for predefined operators. 11.79 */ 11.80 public static class OperatorSymbol extends MethodSymbol {
12.1 --- a/src/share/classes/com/sun/tools/javac/code/Symtab.java Thu Oct 11 09:50:52 2012 -0700 12.2 +++ b/src/share/classes/com/sun/tools/javac/code/Symtab.java Thu Oct 11 17:00:54 2012 -0700 12.3 @@ -126,6 +126,7 @@ 12.4 public final Type cloneableType; 12.5 public final Type serializableType; 12.6 public final Type methodHandleType; 12.7 + public final Type methodTypeType; 12.8 public final Type nativeHeaderType; 12.9 public final Type throwableType; 12.10 public final Type errorType; 12.11 @@ -182,6 +183,10 @@ 12.12 */ 12.13 public final Name[] boxedName = new Name[TypeTags.TypeTagCount]; 12.14 12.15 + /** A set containing all operator names. 12.16 + */ 12.17 + public final Set<Name> operatorNames = new HashSet<Name>(); 12.18 + 12.19 /** A hashtable containing the encountered top-level and member classes, 12.20 * indexed by flat names. The table does not contain local classes. 12.21 * It should be updated from the outside to reflect classes defined 12.22 @@ -243,7 +248,7 @@ 12.23 int opcode) { 12.24 predefClass.members().enter( 12.25 new OperatorSymbol( 12.26 - names.fromString(name), 12.27 + makeOperatorName(name), 12.28 new MethodType(List.of(left, right), res, 12.29 List.<Type>nil(), methodClass), 12.30 opcode, 12.31 @@ -274,7 +279,7 @@ 12.32 Type res, 12.33 int opcode) { 12.34 OperatorSymbol sym = 12.35 - new OperatorSymbol(names.fromString(name), 12.36 + new OperatorSymbol(makeOperatorName(name), 12.37 new MethodType(List.of(arg), 12.38 res, 12.39 List.<Type>nil(), 12.40 @@ -285,6 +290,16 @@ 12.41 return sym; 12.42 } 12.43 12.44 + /** 12.45 + * Create a new operator name from corresponding String representation 12.46 + * and add the name to the set of known operator names. 12.47 + */ 12.48 + private Name makeOperatorName(String name) { 12.49 + Name opName = names.fromString(name); 12.50 + operatorNames.add(opName); 12.51 + return opName; 12.52 + } 12.53 + 12.54 /** Enter a class into symbol table. 12.55 * @param The name of the class. 12.56 */ 12.57 @@ -440,6 +455,7 @@ 12.58 throwableType = enterClass("java.lang.Throwable"); 12.59 serializableType = enterClass("java.io.Serializable"); 12.60 methodHandleType = enterClass("java.lang.invoke.MethodHandle"); 12.61 + methodTypeType = enterClass("java.lang.invoke.MethodType"); 12.62 errorType = enterClass("java.lang.Error"); 12.63 illegalArgumentExceptionType = enterClass("java.lang.IllegalArgumentException"); 12.64 interruptedExceptionType = enterClass("java.lang.InterruptedException");
13.1 --- a/src/share/classes/com/sun/tools/javac/code/Type.java Thu Oct 11 09:50:52 2012 -0700 13.2 +++ b/src/share/classes/com/sun/tools/javac/code/Type.java Thu Oct 11 17:00:54 2012 -0700 13.3 @@ -27,14 +27,19 @@ 13.4 13.5 import java.util.Collections; 13.6 13.7 +import com.sun.tools.javac.code.Symbol.*; 13.8 import com.sun.tools.javac.util.*; 13.9 -import com.sun.tools.javac.code.Symbol.*; 13.10 + 13.11 +import java.util.EnumMap; 13.12 +import java.util.EnumSet; 13.13 +import java.util.Map; 13.14 +import java.util.Set; 13.15 13.16 import javax.lang.model.type.*; 13.17 13.18 +import static com.sun.tools.javac.code.BoundKind.*; 13.19 import static com.sun.tools.javac.code.Flags.*; 13.20 import static com.sun.tools.javac.code.Kinds.*; 13.21 -import static com.sun.tools.javac.code.BoundKind.*; 13.22 import static com.sun.tools.javac.code.TypeTags.*; 13.23 13.24 /** This class represents Java types. The class itself defines the behavior of 13.25 @@ -70,6 +75,9 @@ 13.26 /** Constant type: no type at all. */ 13.27 public static final JCNoType noType = new JCNoType(NONE); 13.28 13.29 + /** Constant type: special type to be used during recovery of deferred expressions. */ 13.30 + public static final JCNoType recoveryType = new JCNoType(NONE); 13.31 + 13.32 /** If this switch is turned on, the names of type variables 13.33 * and anonymous classes are printed with hashcodes appended. 13.34 */ 13.35 @@ -1168,22 +1176,59 @@ 13.36 } 13.37 } 13.38 13.39 - /** A class for instantiatable variables, for use during type 13.40 - * inference. 13.41 + /** A class for inference variables, for use during method/diamond type 13.42 + * inference. An inference variable has upper/lower bounds and a set 13.43 + * of equality constraints. Such bounds are set during subtyping, type-containment, 13.44 + * type-equality checks, when the types being tested contain inference variables. 13.45 + * A change listener can be attached to an inference variable, to receive notifications 13.46 + * whenever the bounds of an inference variable change. 13.47 */ 13.48 public static class UndetVar extends DelegatedType { 13.49 - public List<Type> lobounds = List.nil(); 13.50 - public List<Type> hibounds = List.nil(); 13.51 - public List<Type> eq = List.nil(); 13.52 + 13.53 + /** Inference variable change listener. The listener method is called 13.54 + * whenever a change to the inference variable's bounds occurs 13.55 + */ 13.56 + public interface UndetVarListener { 13.57 + /** called when some inference variable bounds (of given kinds ibs) change */ 13.58 + void varChanged(UndetVar uv, Set<InferenceBound> ibs); 13.59 + } 13.60 + 13.61 + /** 13.62 + * Inference variable bound kinds 13.63 + */ 13.64 + public enum InferenceBound { 13.65 + /** upper bounds */ 13.66 + UPPER, 13.67 + /** lower bounds */ 13.68 + LOWER, 13.69 + /** equality constraints */ 13.70 + EQ; 13.71 + } 13.72 + 13.73 + /** inference variable bounds */ 13.74 + private Map<InferenceBound, List<Type>> bounds; 13.75 + 13.76 + /** inference variable's inferred type (set from Infer.java) */ 13.77 public Type inst = null; 13.78 13.79 + /** inference variable's change listener */ 13.80 + public UndetVarListener listener = null; 13.81 + 13.82 @Override 13.83 public <R,S> R accept(Type.Visitor<R,S> v, S s) { 13.84 return v.visitUndetVar(this, s); 13.85 } 13.86 13.87 - public UndetVar(Type origin) { 13.88 + public UndetVar(TypeVar origin, Types types) { 13.89 + this(origin, types, true); 13.90 + } 13.91 + 13.92 + public UndetVar(TypeVar origin, Types types, boolean includeBounds) { 13.93 super(UNDETVAR, origin); 13.94 + bounds = new EnumMap<InferenceBound, List<Type>>(InferenceBound.class); 13.95 + bounds.put(InferenceBound.UPPER, includeBounds ? types.getBounds(origin) : List.<Type>nil()); 13.96 + bounds.put(InferenceBound.LOWER, List.<Type>nil()); 13.97 + bounds.put(InferenceBound.EQ, List.<Type>nil()); 13.98 } 13.99 13.100 public String toString() { 13.101 @@ -1195,6 +1240,48 @@ 13.102 if (inst != null) return inst.baseType(); 13.103 else return this; 13.104 } 13.105 + 13.106 + /** get all bounds of a given kind */ 13.107 + public List<Type> getBounds(InferenceBound ib) { 13.108 + return bounds.get(ib); 13.109 + } 13.110 + 13.111 + /** add a bound of a given kind - this might trigger listener notification */ 13.112 + public void addBound(InferenceBound ib, Type bound, Types types) { 13.113 + List<Type> prevBounds = bounds.get(ib); 13.114 + for (Type b : prevBounds) { 13.115 + if (types.isSameType(b, bound)) { 13.116 + return; 13.117 + } 13.118 + } 13.119 + bounds.put(ib, prevBounds.prepend(bound)); 13.120 + notifyChange(EnumSet.of(ib)); 13.121 + } 13.122 + 13.123 + /** replace types in all bounds - this might trigger listener notification */ 13.124 + public void substBounds(List<Type> from, List<Type> to, Types types) { 13.125 + EnumSet<InferenceBound> changed = EnumSet.noneOf(InferenceBound.class); 13.126 + Map<InferenceBound, List<Type>> bounds2 = new EnumMap<InferenceBound, List<Type>>(InferenceBound.class); 13.127 + for (Map.Entry<InferenceBound, List<Type>> _entry : bounds.entrySet()) { 13.128 + InferenceBound ib = _entry.getKey(); 13.129 + List<Type> prevBounds = _entry.getValue(); 13.130 + List<Type> newBounds = types.subst(prevBounds, from, to); 13.131 + bounds2.put(ib, newBounds); 13.132 + if (prevBounds != newBounds) { 13.133 + changed.add(ib); 13.134 + } 13.135 + } 13.136 + if (!changed.isEmpty()) { 13.137 + bounds = bounds2; 13.138 + notifyChange(changed); 13.139 + } 13.140 + } 13.141 + 13.142 + private void notifyChange(EnumSet<InferenceBound> ibs) { 13.143 + if (listener != null) { 13.144 + listener.varChanged(this, ibs); 13.145 + } 13.146 + } 13.147 } 13.148 13.149 /** Represents VOID or NONE.
14.1 --- a/src/share/classes/com/sun/tools/javac/code/TypeTags.java Thu Oct 11 09:50:52 2012 -0700 14.2 +++ b/src/share/classes/com/sun/tools/javac/code/TypeTags.java Thu Oct 11 17:00:54 2012 -0700 14.3 @@ -102,9 +102,13 @@ 14.4 */ 14.5 public static final int FORALL = WILDCARD+1; 14.6 14.7 + /** The tag of deferred expression types in method context 14.8 + */ 14.9 + public static final int DEFERRED = FORALL+1; 14.10 + 14.11 /** The tag of the bottom type <null>. 14.12 */ 14.13 - public static final int BOT = FORALL+1; 14.14 + public static final int BOT = DEFERRED+1; 14.15 14.16 /** The tag of a missing type. 14.17 */
15.1 --- a/src/share/classes/com/sun/tools/javac/code/Types.java Thu Oct 11 09:50:52 2012 -0700 15.2 +++ b/src/share/classes/com/sun/tools/javac/code/Types.java Thu Oct 11 17:00:54 2012 -0700 15.3 @@ -34,6 +34,7 @@ 15.4 import com.sun.tools.javac.jvm.ClassReader; 15.5 import com.sun.tools.javac.code.Attribute.RetentionPolicy; 15.6 import com.sun.tools.javac.code.Lint.LintCategory; 15.7 +import com.sun.tools.javac.code.Type.UndetVar.InferenceBound; 15.8 import com.sun.tools.javac.comp.Check; 15.9 15.10 import static com.sun.tools.javac.code.Scope.*; 15.11 @@ -78,8 +79,10 @@ 15.12 final boolean allowObjectToPrimitiveCast; 15.13 final ClassReader reader; 15.14 final Check chk; 15.15 + JCDiagnostic.Factory diags; 15.16 List<Warner> warnStack = List.nil(); 15.17 final Name capturedName; 15.18 + private final FunctionDescriptorLookupError functionDescriptorLookupError; 15.19 15.20 // <editor-fold defaultstate="collapsed" desc="Instantiating"> 15.21 public static Types instance(Context context) { 15.22 @@ -101,6 +104,8 @@ 15.23 chk = Check.instance(context); 15.24 capturedName = names.fromString("<captured wildcard>"); 15.25 messages = JavacMessages.instance(context); 15.26 + diags = JCDiagnostic.Factory.instance(context); 15.27 + functionDescriptorLookupError = new FunctionDescriptorLookupError(); 15.28 } 15.29 // </editor-fold> 15.30 15.31 @@ -295,6 +300,294 @@ 15.32 } 15.33 // </editor-fold> 15.34 15.35 + // <editor-fold defaultstate="collapsed" desc="findSam"> 15.36 + 15.37 + /** 15.38 + * Exception used to report a function descriptor lookup failure. The exception 15.39 + * wraps a diagnostic that can be used to generate more details error 15.40 + * messages. 15.41 + */ 15.42 + public static class FunctionDescriptorLookupError extends RuntimeException { 15.43 + private static final long serialVersionUID = 0; 15.44 + 15.45 + JCDiagnostic diagnostic; 15.46 + 15.47 + FunctionDescriptorLookupError() { 15.48 + this.diagnostic = null; 15.49 + } 15.50 + 15.51 + FunctionDescriptorLookupError setMessage(JCDiagnostic diag) { 15.52 + this.diagnostic = diag; 15.53 + return this; 15.54 + } 15.55 + 15.56 + public JCDiagnostic getDiagnostic() { 15.57 + return diagnostic; 15.58 + } 15.59 + } 15.60 + 15.61 + /** 15.62 + * A cache that keeps track of function descriptors associated with given 15.63 + * functional interfaces. 15.64 + */ 15.65 + class DescriptorCache { 15.66 + 15.67 + private WeakHashMap<TypeSymbol, Entry> _map = new WeakHashMap<TypeSymbol, Entry>(); 15.68 + 15.69 + class FunctionDescriptor { 15.70 + Symbol descSym; 15.71 + 15.72 + FunctionDescriptor(Symbol descSym) { 15.73 + this.descSym = descSym; 15.74 + } 15.75 + 15.76 + public Symbol getSymbol() { 15.77 + return descSym; 15.78 + } 15.79 + 15.80 + public Type getType(Type origin) { 15.81 + return memberType(origin, descSym); 15.82 + } 15.83 + } 15.84 + 15.85 + class Entry { 15.86 + final FunctionDescriptor cachedDescRes; 15.87 + final int prevMark; 15.88 + 15.89 + public Entry(FunctionDescriptor cachedDescRes, 15.90 + int prevMark) { 15.91 + this.cachedDescRes = cachedDescRes; 15.92 + this.prevMark = prevMark; 15.93 + } 15.94 + 15.95 + boolean matches(int mark) { 15.96 + return this.prevMark == mark; 15.97 + } 15.98 + } 15.99 + 15.100 + FunctionDescriptor get(TypeSymbol origin) throws FunctionDescriptorLookupError { 15.101 + Entry e = _map.get(origin); 15.102 + CompoundScope members = membersClosure(origin.type, false); 15.103 + if (e == null || 15.104 + !e.matches(members.getMark())) { 15.105 + FunctionDescriptor descRes = findDescriptorInternal(origin, members); 15.106 + _map.put(origin, new Entry(descRes, members.getMark())); 15.107 + return descRes; 15.108 + } 15.109 + else { 15.110 + return e.cachedDescRes; 15.111 + } 15.112 + } 15.113 + 15.114 + /** 15.115 + * Scope filter used to skip methods that should be ignored during 15.116 + * function interface conversion (such as methods overridden by 15.117 + * j.l.Object) 15.118 + */ 15.119 + class DescriptorFilter implements Filter<Symbol> { 15.120 + 15.121 + TypeSymbol origin; 15.122 + 15.123 + DescriptorFilter(TypeSymbol origin) { 15.124 + this.origin = origin; 15.125 + } 15.126 + 15.127 + @Override 15.128 + public boolean accepts(Symbol sym) { 15.129 + return sym.kind == Kinds.MTH && 15.130 + (sym.flags() & ABSTRACT) != 0 && 15.131 + !overridesObjectMethod(origin, sym) && 15.132 + notOverridden(sym); 15.133 + } 15.134 + 15.135 + private boolean notOverridden(Symbol msym) { 15.136 + Symbol impl = ((MethodSymbol)msym).implementation(origin, Types.this, false); 15.137 + return impl == null || (impl.flags() & ABSTRACT) != 0; 15.138 + } 15.139 + }; 15.140 + 15.141 + /** 15.142 + * Compute the function descriptor associated with a given functional interface 15.143 + */ 15.144 + public FunctionDescriptor findDescriptorInternal(TypeSymbol origin, CompoundScope membersCache) throws FunctionDescriptorLookupError { 15.145 + if (!origin.isInterface()) { 15.146 + //t must be an interface 15.147 + throw failure("not.a.functional.intf"); 15.148 + } 15.149 + 15.150 + final ListBuffer<Symbol> abstracts = ListBuffer.lb(); 15.151 + for (Symbol sym : membersCache.getElements(new DescriptorFilter(origin))) { 15.152 + Type mtype = memberType(origin.type, sym); 15.153 + if (abstracts.isEmpty() || 15.154 + (sym.name == abstracts.first().name && 15.155 + overrideEquivalent(mtype, memberType(origin.type, abstracts.first())))) { 15.156 + abstracts.append(sym); 15.157 + } else { 15.158 + //the target method(s) should be the only abstract members of t 15.159 + throw failure("not.a.functional.intf.1", 15.160 + diags.fragment("incompatible.abstracts", Kinds.kindName(origin), origin)); 15.161 + } 15.162 + } 15.163 + if (abstracts.isEmpty()) { 15.164 + //t must define a suitable non-generic method 15.165 + throw failure("not.a.functional.intf.1", 15.166 + diags.fragment("no.abstracts", Kinds.kindName(origin), origin)); 15.167 + } else if (abstracts.size() == 1) { 15.168 + if (abstracts.first().type.tag == FORALL) { 15.169 + throw failure("invalid.generic.desc.in.functional.intf", 15.170 + abstracts.first(), 15.171 + Kinds.kindName(origin), 15.172 + origin); 15.173 + } else { 15.174 + return new FunctionDescriptor(abstracts.first()); 15.175 + } 15.176 + } else { // size > 1 15.177 + for (Symbol msym : abstracts) { 15.178 + if (msym.type.tag == FORALL) { 15.179 + throw failure("invalid.generic.desc.in.functional.intf", 15.180 + abstracts.first(), 15.181 + Kinds.kindName(origin), 15.182 + origin); 15.183 + } 15.184 + } 15.185 + FunctionDescriptor descRes = mergeDescriptors(origin, abstracts.toList()); 15.186 + if (descRes == null) { 15.187 + //we can get here if the functional interface is ill-formed 15.188 + ListBuffer<JCDiagnostic> descriptors = ListBuffer.lb(); 15.189 + for (Symbol desc : abstracts) { 15.190 + String key = desc.type.getThrownTypes().nonEmpty() ? 15.191 + "descriptor.throws" : "descriptor"; 15.192 + descriptors.append(diags.fragment(key, desc.name, 15.193 + desc.type.getParameterTypes(), 15.194 + desc.type.getReturnType(), 15.195 + desc.type.getThrownTypes())); 15.196 + } 15.197 + JCDiagnostic.MultilineDiagnostic incompatibleDescriptors = 15.198 + new JCDiagnostic.MultilineDiagnostic(diags.fragment("incompatible.descs.in.functional.intf", 15.199 + Kinds.kindName(origin), origin), descriptors.toList()); 15.200 + throw failure(incompatibleDescriptors); 15.201 + } 15.202 + return descRes; 15.203 + } 15.204 + } 15.205 + 15.206 + /** 15.207 + * Compute a synthetic type for the target descriptor given a list 15.208 + * of override-equivalent methods in the functional interface type. 15.209 + * The resulting method type is a method type that is override-equivalent 15.210 + * and return-type substitutable with each method in the original list. 15.211 + */ 15.212 + private FunctionDescriptor mergeDescriptors(TypeSymbol origin, List<Symbol> methodSyms) { 15.213 + //pick argument types - simply take the signature that is a 15.214 + //subsignature of all other signatures in the list (as per JLS 8.4.2) 15.215 + List<Symbol> mostSpecific = List.nil(); 15.216 + outer: for (Symbol msym1 : methodSyms) { 15.217 + Type mt1 = memberType(origin.type, msym1); 15.218 + for (Symbol msym2 : methodSyms) { 15.219 + Type mt2 = memberType(origin.type, msym2); 15.220 + if (!isSubSignature(mt1, mt2)) { 15.221 + continue outer; 15.222 + } 15.223 + } 15.224 + mostSpecific = mostSpecific.prepend(msym1); 15.225 + } 15.226 + if (mostSpecific.isEmpty()) { 15.227 + return null; 15.228 + } 15.229 + 15.230 + 15.231 + //pick return types - this is done in two phases: (i) first, the most 15.232 + //specific return type is chosen using strict subtyping; if this fails, 15.233 + //a second attempt is made using return type substitutability (see JLS 8.4.5) 15.234 + boolean phase2 = false; 15.235 + Symbol bestSoFar = null; 15.236 + while (bestSoFar == null) { 15.237 + outer: for (Symbol msym1 : mostSpecific) { 15.238 + Type mt1 = memberType(origin.type, msym1); 15.239 + for (Symbol msym2 : methodSyms) { 15.240 + Type mt2 = memberType(origin.type, msym2); 15.241 + if (phase2 ? 15.242 + !returnTypeSubstitutable(mt1, mt2) : 15.243 + !isSubtypeInternal(mt1.getReturnType(), mt2.getReturnType())) { 15.244 + continue outer; 15.245 + } 15.246 + } 15.247 + bestSoFar = msym1; 15.248 + } 15.249 + if (phase2) { 15.250 + break; 15.251 + } else { 15.252 + phase2 = true; 15.253 + } 15.254 + } 15.255 + if (bestSoFar == null) return null; 15.256 + 15.257 + //merge thrown types - form the intersection of all the thrown types in 15.258 + //all the signatures in the list 15.259 + List<Type> thrown = null; 15.260 + for (Symbol msym1 : methodSyms) { 15.261 + Type mt1 = memberType(origin.type, msym1); 15.262 + thrown = (thrown == null) ? 15.263 + mt1.getThrownTypes() : 15.264 + chk.intersect(mt1.getThrownTypes(), thrown); 15.265 + } 15.266 + 15.267 + final List<Type> thrown1 = thrown; 15.268 + return new FunctionDescriptor(bestSoFar) { 15.269 + @Override 15.270 + public Type getType(Type origin) { 15.271 + Type mt = memberType(origin, getSymbol()); 15.272 + return new MethodType(mt.getParameterTypes(), mt.getReturnType(), thrown1, syms.methodClass); 15.273 + } 15.274 + }; 15.275 + } 15.276 + 15.277 + boolean isSubtypeInternal(Type s, Type t) { 15.278 + return (s.isPrimitive() && t.isPrimitive()) ? 15.279 + isSameType(t, s) : 15.280 + isSubtype(s, t); 15.281 + } 15.282 + 15.283 + FunctionDescriptorLookupError failure(String msg, Object... args) { 15.284 + return failure(diags.fragment(msg, args)); 15.285 + } 15.286 + 15.287 + FunctionDescriptorLookupError failure(JCDiagnostic diag) { 15.288 + return functionDescriptorLookupError.setMessage(diag); 15.289 + } 15.290 + } 15.291 + 15.292 + private DescriptorCache descCache = new DescriptorCache(); 15.293 + 15.294 + /** 15.295 + * Find the method descriptor associated to this class symbol - if the 15.296 + * symbol 'origin' is not a functional interface, an exception is thrown. 15.297 + */ 15.298 + public Symbol findDescriptorSymbol(TypeSymbol origin) throws FunctionDescriptorLookupError { 15.299 + return descCache.get(origin).getSymbol(); 15.300 + } 15.301 + 15.302 + /** 15.303 + * Find the type of the method descriptor associated to this class symbol - 15.304 + * if the symbol 'origin' is not a functional interface, an exception is thrown. 15.305 + */ 15.306 + public Type findDescriptorType(Type origin) throws FunctionDescriptorLookupError { 15.307 + return descCache.get(origin.tsym).getType(origin); 15.308 + } 15.309 + 15.310 + /** 15.311 + * Is given type a functional interface? 15.312 + */ 15.313 + public boolean isFunctionalInterface(TypeSymbol tsym) { 15.314 + try { 15.315 + findDescriptorSymbol(tsym); 15.316 + return true; 15.317 + } catch (FunctionDescriptorLookupError ex) { 15.318 + return false; 15.319 + } 15.320 + } 15.321 + // </editor-fold> 15.322 + 15.323 // <editor-fold defaultstate="collapsed" desc="isSubtype"> 15.324 /** 15.325 * Is t an unchecked subtype of s? 15.326 @@ -510,7 +803,7 @@ 15.327 return false; 15.328 } 15.329 15.330 - t.hibounds = t.hibounds.prepend(s); 15.331 + t.addBound(InferenceBound.UPPER, s, Types.this); 15.332 return true; 15.333 } 15.334 15.335 @@ -578,7 +871,7 @@ 15.336 undet.qtype == s || 15.337 s.tag == ERROR || 15.338 s.tag == BOT) return true; 15.339 - undet.lobounds = undet.lobounds.prepend(s); 15.340 + undet.addBound(InferenceBound.LOWER, s, this); 15.341 return true; 15.342 } 15.343 default: 15.344 @@ -723,7 +1016,7 @@ 15.345 if (t == s || t.qtype == s || s.tag == ERROR || s.tag == UNKNOWN) 15.346 return true; 15.347 15.348 - t.eq = t.eq.prepend(s); 15.349 + t.addBound(InferenceBound.EQ, s, Types.this); 15.350 15.351 return true; 15.352 } 15.353 @@ -735,19 +1028,6 @@ 15.354 }; 15.355 // </editor-fold> 15.356 15.357 - // <editor-fold defaultstate="collapsed" desc="fromUnknownFun"> 15.358 - /** 15.359 - * A mapping that turns all unknown types in this type to fresh 15.360 - * unknown variables. 15.361 - */ 15.362 - public Mapping fromUnknownFun = new Mapping("fromUnknownFun") { 15.363 - public Type apply(Type t) { 15.364 - if (t.tag == UNKNOWN) return new UndetVar(t); 15.365 - else return t.map(this); 15.366 - } 15.367 - }; 15.368 - // </editor-fold> 15.369 - 15.370 // <editor-fold defaultstate="collapsed" desc="Contains Type"> 15.371 public boolean containedBy(Type t, Type s) { 15.372 switch (t.tag) { 15.373 @@ -759,12 +1039,12 @@ 15.374 case UNBOUND: //similar to ? extends Object 15.375 case EXTENDS: { 15.376 Type bound = upperBound(s); 15.377 - undetvar.hibounds = undetvar.hibounds.prepend(bound); 15.378 + undetvar.addBound(InferenceBound.UPPER, bound, this); 15.379 break; 15.380 } 15.381 case SUPER: { 15.382 Type bound = lowerBound(s); 15.383 - undetvar.lobounds = undetvar.lobounds.prepend(bound); 15.384 + undetvar.addBound(InferenceBound.LOWER, bound, this); 15.385 break; 15.386 } 15.387 } 15.388 @@ -1227,7 +1507,10 @@ 15.389 * Returns the lower bounds of the formals of a method. 15.390 */ 15.391 public List<Type> lowerBoundArgtypes(Type t) { 15.392 - return map(t.getParameterTypes(), lowerBoundMapping); 15.393 + return lowerBounds(t.getParameterTypes()); 15.394 + } 15.395 + public List<Type> lowerBounds(List<Type> ts) { 15.396 + return map(ts, lowerBoundMapping); 15.397 } 15.398 private final Mapping lowerBoundMapping = new Mapping("lowerBound") { 15.399 public Type apply(Type t) { 15.400 @@ -2019,6 +2302,15 @@ 15.401 hasSameArgs(t, erasure(s)) || hasSameArgs(erasure(t), s); 15.402 } 15.403 15.404 + public boolean overridesObjectMethod(TypeSymbol origin, Symbol msym) { 15.405 + for (Scope.Entry e = syms.objectType.tsym.members().lookup(msym.name) ; e.scope != null ; e = e.next()) { 15.406 + if (msym.overrides(e.sym, origin, Types.this, true)) { 15.407 + return true; 15.408 + } 15.409 + } 15.410 + return false; 15.411 + } 15.412 + 15.413 // <editor-fold defaultstate="collapsed" desc="Determining method implementation in given site"> 15.414 class ImplementationCache { 15.415 15.416 @@ -3166,6 +3458,14 @@ 15.417 } 15.418 return Type.noType; 15.419 } 15.420 + 15.421 + /** 15.422 + * Return the unboxed type if 't' is a boxed class, otherwise return 't' itself. 15.423 + */ 15.424 + public Type unboxedTypeOrType(Type t) { 15.425 + Type unboxedType = unboxedType(t); 15.426 + return unboxedType.tag == NONE ? t : unboxedType; 15.427 + } 15.428 // </editor-fold> 15.429 15.430 // <editor-fold defaultstate="collapsed" desc="Capture conversion">
16.1 --- a/src/share/classes/com/sun/tools/javac/comp/Annotate.java Thu Oct 11 09:50:52 2012 -0700 16.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Annotate.java Thu Oct 11 17:00:54 2012 -0700 16.3 @@ -514,22 +514,6 @@ 16.4 expectedType); 16.5 fatalError = true; 16.6 } 16.7 - 16.8 - // validate that all other elements of containing type has defaults 16.9 - scope = targetContainerType.tsym.members(); 16.10 - error = false; 16.11 - for(Symbol elm : scope.getElements()) { 16.12 - if (elm.name != names.value && 16.13 - elm.kind == Kinds.MTH && 16.14 - ((MethodSymbol)elm).defaultValue == null) { 16.15 - log.error(pos, 16.16 - "invalid.containedby.annotation.elem.nondefault", 16.17 - targetContainerType, 16.18 - elm); 16.19 - containerValueSymbol = null; 16.20 - error = true; 16.21 - } 16.22 - } 16.23 if (error) { 16.24 fatalError = true; 16.25 }
17.1 --- a/src/share/classes/com/sun/tools/javac/comp/Attr.java Thu Oct 11 09:50:52 2012 -0700 17.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Attr.java Thu Oct 11 17:00:54 2012 -0700 17.3 @@ -25,12 +25,10 @@ 17.4 17.5 package com.sun.tools.javac.comp; 17.6 17.7 -import java.util.*; 17.8 -import java.util.Set; 17.9 -import javax.lang.model.element.ElementKind; 17.10 -import javax.tools.JavaFileObject; 17.11 - 17.12 import com.sun.tools.javac.code.*; 17.13 +import com.sun.tools.javac.comp.DeferredAttr.AttrMode; 17.14 +import com.sun.tools.javac.comp.Infer.InferenceContext; 17.15 +import com.sun.tools.javac.comp.Infer.InferenceContext.FreeTypeListener; 17.16 import com.sun.tools.javac.jvm.*; 17.17 import com.sun.tools.javac.tree.*; 17.18 import com.sun.tools.javac.util.*; 17.19 @@ -45,10 +43,16 @@ 17.20 import com.sun.tools.javac.comp.Check.CheckContext; 17.21 17.22 import com.sun.source.tree.IdentifierTree; 17.23 +import com.sun.source.tree.MemberReferenceTree.ReferenceMode; 17.24 import com.sun.source.tree.MemberSelectTree; 17.25 import com.sun.source.tree.TreeVisitor; 17.26 import com.sun.source.util.SimpleTreeVisitor; 17.27 17.28 +import java.util.*; 17.29 +import java.util.Set; 17.30 +import javax.lang.model.element.ElementKind; 17.31 +import javax.tools.JavaFileObject; 17.32 + 17.33 import static com.sun.tools.javac.code.Flags.*; 17.34 import static com.sun.tools.javac.code.Flags.ANNOTATION; 17.35 import static com.sun.tools.javac.code.Flags.BLOCK; 17.36 @@ -80,7 +84,9 @@ 17.37 final Symtab syms; 17.38 final Resolve rs; 17.39 final Infer infer; 17.40 + final DeferredAttr deferredAttr; 17.41 final Check chk; 17.42 + final Flow flow; 17.43 final MemberEnter memberEnter; 17.44 final TreeMaker make; 17.45 final ConstFold cfolder; 17.46 @@ -106,10 +112,12 @@ 17.47 syms = Symtab.instance(context); 17.48 rs = Resolve.instance(context); 17.49 chk = Check.instance(context); 17.50 + flow = Flow.instance(context); 17.51 memberEnter = MemberEnter.instance(context); 17.52 make = TreeMaker.instance(context); 17.53 enter = Enter.instance(context); 17.54 infer = Infer.instance(context); 17.55 + deferredAttr = DeferredAttr.instance(context); 17.56 cfolder = ConstFold.instance(context); 17.57 target = Target.instance(context); 17.58 types = Types.instance(context); 17.59 @@ -127,23 +135,31 @@ 17.60 allowCovariantReturns = source.allowCovariantReturns(); 17.61 allowAnonOuterThis = source.allowAnonOuterThis(); 17.62 allowStringsInSwitch = source.allowStringsInSwitch(); 17.63 + allowPoly = source.allowPoly() && options.isSet("allowPoly"); 17.64 + allowLambda = source.allowLambda(); 17.65 sourceName = source.name; 17.66 relax = (options.isSet("-retrofit") || 17.67 options.isSet("-relax")); 17.68 findDiamonds = options.get("findDiamond") != null && 17.69 source.allowDiamond(); 17.70 useBeforeDeclarationWarning = options.isSet("useBeforeDeclarationWarning"); 17.71 + identifyLambdaCandidate = options.getBoolean("identifyLambdaCandidate", false); 17.72 17.73 statInfo = new ResultInfo(NIL, Type.noType); 17.74 varInfo = new ResultInfo(VAR, Type.noType); 17.75 unknownExprInfo = new ResultInfo(VAL, Type.noType); 17.76 unknownTypeInfo = new ResultInfo(TYP, Type.noType); 17.77 + recoveryInfo = new RecoveryInfo(deferredAttr.emptyDeferredAttrContext); 17.78 } 17.79 17.80 /** Switch: relax some constraints for retrofit mode. 17.81 */ 17.82 boolean relax; 17.83 17.84 + /** Switch: support target-typing inference 17.85 + */ 17.86 + boolean allowPoly; 17.87 + 17.88 /** Switch: support generics? 17.89 */ 17.90 boolean allowGenerics; 17.91 @@ -164,6 +180,10 @@ 17.92 */ 17.93 boolean allowCovariantReturns; 17.94 17.95 + /** Switch: support lambda expressions ? 17.96 + */ 17.97 + boolean allowLambda; 17.98 + 17.99 /** Switch: allow references to surrounding object from anonymous 17.100 * objects during constructor call? 17.101 */ 17.102 @@ -186,6 +206,12 @@ 17.103 boolean useBeforeDeclarationWarning; 17.104 17.105 /** 17.106 + * Switch: generate warnings whenever an anonymous inner class that is convertible 17.107 + * to a lambda expression is found 17.108 + */ 17.109 + boolean identifyLambdaCandidate; 17.110 + 17.111 + /** 17.112 * Switch: allow strings in switch? 17.113 */ 17.114 boolean allowStringsInSwitch; 17.115 @@ -207,15 +233,29 @@ 17.116 * @param ownkind The computed kind of the tree 17.117 * @param resultInfo The expected result of the tree 17.118 */ 17.119 - Type check(JCTree tree, Type owntype, int ownkind, ResultInfo resultInfo) { 17.120 + Type check(final JCTree tree, final Type found, final int ownkind, final ResultInfo resultInfo) { 17.121 + InferenceContext inferenceContext = resultInfo.checkContext.inferenceContext(); 17.122 + Type owntype = found; 17.123 if (owntype.tag != ERROR && resultInfo.pt.tag != METHOD && resultInfo.pt.tag != FORALL) { 17.124 - if ((ownkind & ~resultInfo.pkind) == 0) { 17.125 - owntype = resultInfo.check(tree, owntype); 17.126 + if (inferenceContext.free(found)) { 17.127 + inferenceContext.addFreeTypeListener(List.of(found, resultInfo.pt), new FreeTypeListener() { 17.128 + @Override 17.129 + public void typesInferred(InferenceContext inferenceContext) { 17.130 + ResultInfo pendingResult = 17.131 + resultInfo.dup(inferenceContext.asInstType(resultInfo.pt, types)); 17.132 + check(tree, inferenceContext.asInstType(found, types), ownkind, pendingResult); 17.133 + } 17.134 + }); 17.135 + return tree.type = resultInfo.pt; 17.136 } else { 17.137 - log.error(tree.pos(), "unexpected.type", 17.138 - kindNames(resultInfo.pkind), 17.139 - kindName(ownkind)); 17.140 - owntype = types.createErrorType(owntype); 17.141 + if ((ownkind & ~resultInfo.pkind) == 0) { 17.142 + owntype = resultInfo.check(tree, owntype); 17.143 + } else { 17.144 + log.error(tree.pos(), "unexpected.type", 17.145 + kindNames(resultInfo.pkind), 17.146 + kindName(ownkind)); 17.147 + owntype = types.createErrorType(owntype); 17.148 + } 17.149 } 17.150 } 17.151 tree.type = owntype; 17.152 @@ -262,6 +302,9 @@ 17.153 case CLASSDEF: 17.154 //class def is always an owner 17.155 return ((JCClassDecl)env.tree).sym; 17.156 + case LAMBDA: 17.157 + //a lambda is an owner - return a fresh synthetic method symbol 17.158 + return new MethodSymbol(0, names.empty, null, syms.methodClass); 17.159 case BLOCK: 17.160 //static/instance init blocks are owner 17.161 Symbol blockSym = env.info.scope.owner; 17.162 @@ -297,8 +340,6 @@ 17.163 } else { 17.164 log.error(pos, "cant.assign.val.to.final.var", v); 17.165 } 17.166 - } else if ((v.flags() & EFFECTIVELY_FINAL) != 0) { 17.167 - v.flags_field &= ~EFFECTIVELY_FINAL; 17.168 } 17.169 } 17.170 17.171 @@ -431,14 +472,38 @@ 17.172 static final long serialVersionUID = -6924771130405446405L; 17.173 private Env<AttrContext> env; 17.174 private BreakAttr(Env<AttrContext> env) { 17.175 - this.env = env; 17.176 + this.env = copyEnv(env); 17.177 + } 17.178 + 17.179 + private Env<AttrContext> copyEnv(Env<AttrContext> env) { 17.180 + Env<AttrContext> newEnv = 17.181 + env.dup(env.tree, env.info.dup(copyScope(env.info.scope))); 17.182 + if (newEnv.outer != null) { 17.183 + newEnv.outer = copyEnv(newEnv.outer); 17.184 + } 17.185 + return newEnv; 17.186 + } 17.187 + 17.188 + private Scope copyScope(Scope sc) { 17.189 + Scope newScope = new Scope(sc.owner); 17.190 + List<Symbol> elemsList = List.nil(); 17.191 + while (sc != null) { 17.192 + for (Scope.Entry e = sc.elems ; e != null ; e = e.sibling) { 17.193 + elemsList = elemsList.prepend(e.sym); 17.194 + } 17.195 + sc = sc.next; 17.196 + } 17.197 + for (Symbol s : elemsList) { 17.198 + newScope.enter(s); 17.199 + } 17.200 + return newScope; 17.201 } 17.202 } 17.203 17.204 class ResultInfo { 17.205 - int pkind; 17.206 - Type pt; 17.207 - CheckContext checkContext; 17.208 + final int pkind; 17.209 + final Type pt; 17.210 + final CheckContext checkContext; 17.211 17.212 ResultInfo(int pkind, Type pt) { 17.213 this(pkind, pt, chk.basicHandler); 17.214 @@ -450,15 +515,45 @@ 17.215 this.checkContext = checkContext; 17.216 } 17.217 17.218 - protected Type check(DiagnosticPosition pos, Type found) { 17.219 + protected Type check(final DiagnosticPosition pos, final Type found) { 17.220 return chk.checkType(pos, found, pt, checkContext); 17.221 } 17.222 + 17.223 + protected ResultInfo dup(Type newPt) { 17.224 + return new ResultInfo(pkind, newPt, checkContext); 17.225 + } 17.226 } 17.227 17.228 - private final ResultInfo statInfo; 17.229 - private final ResultInfo varInfo; 17.230 - private final ResultInfo unknownExprInfo; 17.231 - private final ResultInfo unknownTypeInfo; 17.232 + class RecoveryInfo extends ResultInfo { 17.233 + 17.234 + public RecoveryInfo(final DeferredAttr.DeferredAttrContext deferredAttrContext) { 17.235 + super(Kinds.VAL, Type.recoveryType, new Check.NestedCheckContext(chk.basicHandler) { 17.236 + @Override 17.237 + public DeferredAttr.DeferredAttrContext deferredAttrContext() { 17.238 + return deferredAttrContext; 17.239 + } 17.240 + @Override 17.241 + public boolean compatible(Type found, Type req, Warner warn) { 17.242 + return true; 17.243 + } 17.244 + @Override 17.245 + public void report(DiagnosticPosition pos, JCDiagnostic details) { 17.246 + //do nothing 17.247 + } 17.248 + }); 17.249 + } 17.250 + 17.251 + @Override 17.252 + protected Type check(DiagnosticPosition pos, Type found) { 17.253 + return chk.checkNonVoid(pos, super.check(pos, found)); 17.254 + } 17.255 + } 17.256 + 17.257 + final ResultInfo statInfo; 17.258 + final ResultInfo varInfo; 17.259 + final ResultInfo unknownExprInfo; 17.260 + final ResultInfo unknownTypeInfo; 17.261 + final ResultInfo recoveryInfo; 17.262 17.263 Type pt() { 17.264 return resultInfo.pt; 17.265 @@ -491,7 +586,7 @@ 17.266 * @param env The environment visitor argument. 17.267 * @param resultInfo The result info visitor argument. 17.268 */ 17.269 - private Type attribTree(JCTree tree, Env<AttrContext> env, ResultInfo resultInfo) { 17.270 + Type attribTree(JCTree tree, Env<AttrContext> env, ResultInfo resultInfo) { 17.271 Env<AttrContext> prevEnv = this.env; 17.272 ResultInfo prevResult = this.resultInfo; 17.273 try { 17.274 @@ -563,9 +658,12 @@ 17.275 */ 17.276 List<Type> attribArgs(List<JCExpression> trees, Env<AttrContext> env) { 17.277 ListBuffer<Type> argtypes = new ListBuffer<Type>(); 17.278 - for (List<JCExpression> l = trees; l.nonEmpty(); l = l.tail) 17.279 - argtypes.append(chk.checkNonVoid( 17.280 - l.head.pos(), types.upperBound(attribExpr(l.head, env, Infer.anyPoly)))); 17.281 + for (JCExpression arg : trees) { 17.282 + Type argtype = allowPoly && TreeInfo.isPoly(arg, env.tree) ? 17.283 + deferredAttr.new DeferredType(arg, env) : 17.284 + chk.checkNonVoid(arg, attribExpr(arg, env, Infer.anyPoly)); 17.285 + argtypes.append(argtype); 17.286 + } 17.287 return argtypes.toList(); 17.288 } 17.289 17.290 @@ -934,7 +1032,10 @@ 17.291 chk.checkDeprecatedAnnotation(tree.pos(), v); 17.292 17.293 if (tree.init != null) { 17.294 - if ((v.flags_field & FINAL) != 0 && !tree.init.hasTag(NEWCLASS)) { 17.295 + if ((v.flags_field & FINAL) != 0 && 17.296 + !tree.init.hasTag(NEWCLASS) && 17.297 + !tree.init.hasTag(LAMBDA) && 17.298 + !tree.init.hasTag(REFERENCE)) { 17.299 // In this case, `v' is final. Ensure that it's initializer is 17.300 // evaluated. 17.301 v.getConstValue(); // ensure initializer is evaluated 17.302 @@ -979,8 +1080,11 @@ 17.303 // Create a new local environment with a local scope. 17.304 Env<AttrContext> localEnv = 17.305 env.dup(tree, env.info.dup(env.info.scope.dup())); 17.306 - attribStats(tree.stats, localEnv); 17.307 - localEnv.info.scope.leave(); 17.308 + try { 17.309 + attribStats(tree.stats, localEnv); 17.310 + } finally { 17.311 + localEnv.info.scope.leave(); 17.312 + } 17.313 } 17.314 result = null; 17.315 } 17.316 @@ -1000,43 +1104,51 @@ 17.317 public void visitForLoop(JCForLoop tree) { 17.318 Env<AttrContext> loopEnv = 17.319 env.dup(env.tree, env.info.dup(env.info.scope.dup())); 17.320 - attribStats(tree.init, loopEnv); 17.321 - if (tree.cond != null) attribExpr(tree.cond, loopEnv, syms.booleanType); 17.322 - loopEnv.tree = tree; // before, we were not in loop! 17.323 - attribStats(tree.step, loopEnv); 17.324 - attribStat(tree.body, loopEnv); 17.325 - loopEnv.info.scope.leave(); 17.326 - result = null; 17.327 + try { 17.328 + attribStats(tree.init, loopEnv); 17.329 + if (tree.cond != null) attribExpr(tree.cond, loopEnv, syms.booleanType); 17.330 + loopEnv.tree = tree; // before, we were not in loop! 17.331 + attribStats(tree.step, loopEnv); 17.332 + attribStat(tree.body, loopEnv); 17.333 + result = null; 17.334 + } 17.335 + finally { 17.336 + loopEnv.info.scope.leave(); 17.337 + } 17.338 } 17.339 17.340 public void visitForeachLoop(JCEnhancedForLoop tree) { 17.341 Env<AttrContext> loopEnv = 17.342 env.dup(env.tree, env.info.dup(env.info.scope.dup())); 17.343 - attribStat(tree.var, loopEnv); 17.344 - Type exprType = types.upperBound(attribExpr(tree.expr, loopEnv)); 17.345 - chk.checkNonVoid(tree.pos(), exprType); 17.346 - Type elemtype = types.elemtype(exprType); // perhaps expr is an array? 17.347 - if (elemtype == null) { 17.348 - // or perhaps expr implements Iterable<T>? 17.349 - Type base = types.asSuper(exprType, syms.iterableType.tsym); 17.350 - if (base == null) { 17.351 - log.error(tree.expr.pos(), 17.352 - "foreach.not.applicable.to.type", 17.353 - exprType, 17.354 - diags.fragment("type.req.array.or.iterable")); 17.355 - elemtype = types.createErrorType(exprType); 17.356 - } else { 17.357 - List<Type> iterableParams = base.allparams(); 17.358 - elemtype = iterableParams.isEmpty() 17.359 - ? syms.objectType 17.360 - : types.upperBound(iterableParams.head); 17.361 + try { 17.362 + attribStat(tree.var, loopEnv); 17.363 + Type exprType = types.upperBound(attribExpr(tree.expr, loopEnv)); 17.364 + chk.checkNonVoid(tree.pos(), exprType); 17.365 + Type elemtype = types.elemtype(exprType); // perhaps expr is an array? 17.366 + if (elemtype == null) { 17.367 + // or perhaps expr implements Iterable<T>? 17.368 + Type base = types.asSuper(exprType, syms.iterableType.tsym); 17.369 + if (base == null) { 17.370 + log.error(tree.expr.pos(), 17.371 + "foreach.not.applicable.to.type", 17.372 + exprType, 17.373 + diags.fragment("type.req.array.or.iterable")); 17.374 + elemtype = types.createErrorType(exprType); 17.375 + } else { 17.376 + List<Type> iterableParams = base.allparams(); 17.377 + elemtype = iterableParams.isEmpty() 17.378 + ? syms.objectType 17.379 + : types.upperBound(iterableParams.head); 17.380 + } 17.381 } 17.382 + chk.checkType(tree.expr.pos(), elemtype, tree.var.sym.type); 17.383 + loopEnv.tree = tree; // before, we were not in loop! 17.384 + attribStat(tree.body, loopEnv); 17.385 + result = null; 17.386 } 17.387 - chk.checkType(tree.expr.pos(), elemtype, tree.var.sym.type); 17.388 - loopEnv.tree = tree; // before, we were not in loop! 17.389 - attribStat(tree.body, loopEnv); 17.390 - loopEnv.info.scope.leave(); 17.391 - result = null; 17.392 + finally { 17.393 + loopEnv.info.scope.leave(); 17.394 + } 17.395 } 17.396 17.397 public void visitLabelled(JCLabeledStatement tree) { 17.398 @@ -1062,61 +1174,69 @@ 17.399 Env<AttrContext> switchEnv = 17.400 env.dup(tree, env.info.dup(env.info.scope.dup())); 17.401 17.402 - boolean enumSwitch = 17.403 - allowEnums && 17.404 - (seltype.tsym.flags() & Flags.ENUM) != 0; 17.405 - boolean stringSwitch = false; 17.406 - if (types.isSameType(seltype, syms.stringType)) { 17.407 - if (allowStringsInSwitch) { 17.408 - stringSwitch = true; 17.409 - } else { 17.410 - log.error(tree.selector.pos(), "string.switch.not.supported.in.source", sourceName); 17.411 + try { 17.412 + 17.413 + boolean enumSwitch = 17.414 + allowEnums && 17.415 + (seltype.tsym.flags() & Flags.ENUM) != 0; 17.416 + boolean stringSwitch = false; 17.417 + if (types.isSameType(seltype, syms.stringType)) { 17.418 + if (allowStringsInSwitch) { 17.419 + stringSwitch = true; 17.420 + } else { 17.421 + log.error(tree.selector.pos(), "string.switch.not.supported.in.source", sourceName); 17.422 + } 17.423 } 17.424 + if (!enumSwitch && !stringSwitch) 17.425 + seltype = chk.checkType(tree.selector.pos(), seltype, syms.intType); 17.426 + 17.427 + // Attribute all cases and 17.428 + // check that there are no duplicate case labels or default clauses. 17.429 + Set<Object> labels = new HashSet<Object>(); // The set of case labels. 17.430 + boolean hasDefault = false; // Is there a default label? 17.431 + for (List<JCCase> l = tree.cases; l.nonEmpty(); l = l.tail) { 17.432 + JCCase c = l.head; 17.433 + Env<AttrContext> caseEnv = 17.434 + switchEnv.dup(c, env.info.dup(switchEnv.info.scope.dup())); 17.435 + try { 17.436 + if (c.pat != null) { 17.437 + if (enumSwitch) { 17.438 + Symbol sym = enumConstant(c.pat, seltype); 17.439 + if (sym == null) { 17.440 + log.error(c.pat.pos(), "enum.label.must.be.unqualified.enum"); 17.441 + } else if (!labels.add(sym)) { 17.442 + log.error(c.pos(), "duplicate.case.label"); 17.443 + } 17.444 + } else { 17.445 + Type pattype = attribExpr(c.pat, switchEnv, seltype); 17.446 + if (pattype.tag != ERROR) { 17.447 + if (pattype.constValue() == null) { 17.448 + log.error(c.pat.pos(), 17.449 + (stringSwitch ? "string.const.req" : "const.expr.req")); 17.450 + } else if (labels.contains(pattype.constValue())) { 17.451 + log.error(c.pos(), "duplicate.case.label"); 17.452 + } else { 17.453 + labels.add(pattype.constValue()); 17.454 + } 17.455 + } 17.456 + } 17.457 + } else if (hasDefault) { 17.458 + log.error(c.pos(), "duplicate.default.label"); 17.459 + } else { 17.460 + hasDefault = true; 17.461 + } 17.462 + attribStats(c.stats, caseEnv); 17.463 + } finally { 17.464 + caseEnv.info.scope.leave(); 17.465 + addVars(c.stats, switchEnv.info.scope); 17.466 + } 17.467 + } 17.468 + 17.469 + result = null; 17.470 } 17.471 - if (!enumSwitch && !stringSwitch) 17.472 - seltype = chk.checkType(tree.selector.pos(), seltype, syms.intType); 17.473 - 17.474 - // Attribute all cases and 17.475 - // check that there are no duplicate case labels or default clauses. 17.476 - Set<Object> labels = new HashSet<Object>(); // The set of case labels. 17.477 - boolean hasDefault = false; // Is there a default label? 17.478 - for (List<JCCase> l = tree.cases; l.nonEmpty(); l = l.tail) { 17.479 - JCCase c = l.head; 17.480 - Env<AttrContext> caseEnv = 17.481 - switchEnv.dup(c, env.info.dup(switchEnv.info.scope.dup())); 17.482 - if (c.pat != null) { 17.483 - if (enumSwitch) { 17.484 - Symbol sym = enumConstant(c.pat, seltype); 17.485 - if (sym == null) { 17.486 - log.error(c.pat.pos(), "enum.label.must.be.unqualified.enum"); 17.487 - } else if (!labels.add(sym)) { 17.488 - log.error(c.pos(), "duplicate.case.label"); 17.489 - } 17.490 - } else { 17.491 - Type pattype = attribExpr(c.pat, switchEnv, seltype); 17.492 - if (pattype.tag != ERROR) { 17.493 - if (pattype.constValue() == null) { 17.494 - log.error(c.pat.pos(), 17.495 - (stringSwitch ? "string.const.req" : "const.expr.req")); 17.496 - } else if (labels.contains(pattype.constValue())) { 17.497 - log.error(c.pos(), "duplicate.case.label"); 17.498 - } else { 17.499 - labels.add(pattype.constValue()); 17.500 - } 17.501 - } 17.502 - } 17.503 - } else if (hasDefault) { 17.504 - log.error(c.pos(), "duplicate.default.label"); 17.505 - } else { 17.506 - hasDefault = true; 17.507 - } 17.508 - attribStats(c.stats, caseEnv); 17.509 - caseEnv.info.scope.leave(); 17.510 - addVars(c.stats, switchEnv.info.scope); 17.511 + finally { 17.512 + switchEnv.info.scope.leave(); 17.513 } 17.514 - 17.515 - switchEnv.info.scope.leave(); 17.516 - result = null; 17.517 } 17.518 // where 17.519 /** Add any variables defined in stats to the switch scope. */ 17.520 @@ -1158,63 +1278,72 @@ 17.521 public void visitTry(JCTry tree) { 17.522 // Create a new local environment with a local 17.523 Env<AttrContext> localEnv = env.dup(tree, env.info.dup(env.info.scope.dup())); 17.524 - boolean isTryWithResource = tree.resources.nonEmpty(); 17.525 - // Create a nested environment for attributing the try block if needed 17.526 - Env<AttrContext> tryEnv = isTryWithResource ? 17.527 - env.dup(tree, localEnv.info.dup(localEnv.info.scope.dup())) : 17.528 - localEnv; 17.529 - // Attribute resource declarations 17.530 - for (JCTree resource : tree.resources) { 17.531 - CheckContext twrContext = new Check.NestedCheckContext(resultInfo.checkContext) { 17.532 - @Override 17.533 - public void report(DiagnosticPosition pos, JCDiagnostic details) { 17.534 - chk.basicHandler.report(pos, diags.fragment("try.not.applicable.to.type", details)); 17.535 + try { 17.536 + boolean isTryWithResource = tree.resources.nonEmpty(); 17.537 + // Create a nested environment for attributing the try block if needed 17.538 + Env<AttrContext> tryEnv = isTryWithResource ? 17.539 + env.dup(tree, localEnv.info.dup(localEnv.info.scope.dup())) : 17.540 + localEnv; 17.541 + try { 17.542 + // Attribute resource declarations 17.543 + for (JCTree resource : tree.resources) { 17.544 + CheckContext twrContext = new Check.NestedCheckContext(resultInfo.checkContext) { 17.545 + @Override 17.546 + public void report(DiagnosticPosition pos, JCDiagnostic details) { 17.547 + chk.basicHandler.report(pos, diags.fragment("try.not.applicable.to.type", details)); 17.548 + } 17.549 + }; 17.550 + ResultInfo twrResult = new ResultInfo(VAL, syms.autoCloseableType, twrContext); 17.551 + if (resource.hasTag(VARDEF)) { 17.552 + attribStat(resource, tryEnv); 17.553 + twrResult.check(resource, resource.type); 17.554 + 17.555 + //check that resource type cannot throw InterruptedException 17.556 + checkAutoCloseable(resource.pos(), localEnv, resource.type); 17.557 + 17.558 + VarSymbol var = (VarSymbol)TreeInfo.symbolFor(resource); 17.559 + var.setData(ElementKind.RESOURCE_VARIABLE); 17.560 + } else { 17.561 + attribTree(resource, tryEnv, twrResult); 17.562 + } 17.563 } 17.564 - }; 17.565 - ResultInfo twrResult = new ResultInfo(VAL, syms.autoCloseableType, twrContext); 17.566 - if (resource.hasTag(VARDEF)) { 17.567 - attribStat(resource, tryEnv); 17.568 - twrResult.check(resource, resource.type); 17.569 - 17.570 - //check that resource type cannot throw InterruptedException 17.571 - checkAutoCloseable(resource.pos(), localEnv, resource.type); 17.572 - 17.573 - VarSymbol var = (VarSymbol)TreeInfo.symbolFor(resource); 17.574 - var.setData(ElementKind.RESOURCE_VARIABLE); 17.575 - } else { 17.576 - attribTree(resource, tryEnv, twrResult); 17.577 + // Attribute body 17.578 + attribStat(tree.body, tryEnv); 17.579 + } finally { 17.580 + if (isTryWithResource) 17.581 + tryEnv.info.scope.leave(); 17.582 } 17.583 + 17.584 + // Attribute catch clauses 17.585 + for (List<JCCatch> l = tree.catchers; l.nonEmpty(); l = l.tail) { 17.586 + JCCatch c = l.head; 17.587 + Env<AttrContext> catchEnv = 17.588 + localEnv.dup(c, localEnv.info.dup(localEnv.info.scope.dup())); 17.589 + try { 17.590 + Type ctype = attribStat(c.param, catchEnv); 17.591 + if (TreeInfo.isMultiCatch(c)) { 17.592 + //multi-catch parameter is implicitly marked as final 17.593 + c.param.sym.flags_field |= FINAL | UNION; 17.594 + } 17.595 + if (c.param.sym.kind == Kinds.VAR) { 17.596 + c.param.sym.setData(ElementKind.EXCEPTION_PARAMETER); 17.597 + } 17.598 + chk.checkType(c.param.vartype.pos(), 17.599 + chk.checkClassType(c.param.vartype.pos(), ctype), 17.600 + syms.throwableType); 17.601 + attribStat(c.body, catchEnv); 17.602 + } finally { 17.603 + catchEnv.info.scope.leave(); 17.604 + } 17.605 + } 17.606 + 17.607 + // Attribute finalizer 17.608 + if (tree.finalizer != null) attribStat(tree.finalizer, localEnv); 17.609 + result = null; 17.610 } 17.611 - // Attribute body 17.612 - attribStat(tree.body, tryEnv); 17.613 - if (isTryWithResource) 17.614 - tryEnv.info.scope.leave(); 17.615 - 17.616 - // Attribute catch clauses 17.617 - for (List<JCCatch> l = tree.catchers; l.nonEmpty(); l = l.tail) { 17.618 - JCCatch c = l.head; 17.619 - Env<AttrContext> catchEnv = 17.620 - localEnv.dup(c, localEnv.info.dup(localEnv.info.scope.dup())); 17.621 - Type ctype = attribStat(c.param, catchEnv); 17.622 - if (TreeInfo.isMultiCatch(c)) { 17.623 - //multi-catch parameter is implicitly marked as final 17.624 - c.param.sym.flags_field |= FINAL | UNION; 17.625 - } 17.626 - if (c.param.sym.kind == Kinds.VAR) { 17.627 - c.param.sym.setData(ElementKind.EXCEPTION_PARAMETER); 17.628 - } 17.629 - chk.checkType(c.param.vartype.pos(), 17.630 - chk.checkClassType(c.param.vartype.pos(), ctype), 17.631 - syms.throwableType); 17.632 - attribStat(c.body, catchEnv); 17.633 - catchEnv.info.scope.leave(); 17.634 + finally { 17.635 + localEnv.info.scope.leave(); 17.636 } 17.637 - 17.638 - // Attribute finalizer 17.639 - if (tree.finalizer != null) attribStat(tree.finalizer, localEnv); 17.640 - 17.641 - localEnv.info.scope.leave(); 17.642 - result = null; 17.643 } 17.644 17.645 void checkAutoCloseable(DiagnosticPosition pos, Env<AttrContext> env, Type resource) { 17.646 @@ -1222,10 +1351,10 @@ 17.647 types.asSuper(resource, syms.autoCloseableType.tsym) != null && 17.648 !types.isSameType(resource, syms.autoCloseableType)) { // Don't emit warning for AutoCloseable itself 17.649 Symbol close = syms.noSymbol; 17.650 - boolean prevDeferDiags = log.deferDiagnostics; 17.651 + Filter<JCDiagnostic> prevDeferDiagsFilter = log.deferredDiagFilter; 17.652 Queue<JCDiagnostic> prevDeferredDiags = log.deferredDiagnostics; 17.653 try { 17.654 - log.deferDiagnostics = true; 17.655 + log.deferAll(); 17.656 log.deferredDiagnostics = ListBuffer.lb(); 17.657 close = rs.resolveQualifiedMethod(pos, 17.658 env, 17.659 @@ -1235,7 +1364,7 @@ 17.660 List.<Type>nil()); 17.661 } 17.662 finally { 17.663 - log.deferDiagnostics = prevDeferDiags; 17.664 + log.deferredDiagFilter = prevDeferDiagsFilter; 17.665 log.deferredDiagnostics = prevDeferredDiags; 17.666 } 17.667 if (close.kind == MTH && 17.668 @@ -1248,50 +1377,71 @@ 17.669 } 17.670 17.671 public void visitConditional(JCConditional tree) { 17.672 - attribExpr(tree.cond, env, syms.booleanType); 17.673 - attribExpr(tree.truepart, env); 17.674 - attribExpr(tree.falsepart, env); 17.675 - result = check(tree, 17.676 - capture(condType(tree.pos(), tree.cond.type, 17.677 - tree.truepart.type, tree.falsepart.type)), 17.678 - VAL, resultInfo); 17.679 + Type condtype = attribExpr(tree.cond, env, syms.booleanType); 17.680 + 17.681 + boolean standaloneConditional = !allowPoly || 17.682 + pt().tag == NONE && pt() != Type.recoveryType || 17.683 + isBooleanOrNumeric(env, tree); 17.684 + 17.685 + if (!standaloneConditional && resultInfo.pt.tag == VOID) { 17.686 + //cannot get here (i.e. it means we are returning from void method - which is already an error) 17.687 + result = tree.type = types.createErrorType(resultInfo.pt); 17.688 + return; 17.689 + } 17.690 + 17.691 + ResultInfo condInfo = standaloneConditional ? 17.692 + unknownExprInfo : 17.693 + new ResultInfo(VAL, pt(), new Check.NestedCheckContext(resultInfo.checkContext) { 17.694 + //this will use enclosing check context to check compatibility of 17.695 + //subexpression against target type; if we are in a method check context, 17.696 + //depending on whether boxing is allowed, we could have incompatibilities 17.697 + @Override 17.698 + public void report(DiagnosticPosition pos, JCDiagnostic details) { 17.699 + enclosingContext.report(pos, diags.fragment("incompatible.type.in.conditional", details)); 17.700 + } 17.701 + }); 17.702 + 17.703 + Type truetype = attribTree(tree.truepart, env, condInfo); 17.704 + Type falsetype = attribTree(tree.falsepart, env, condInfo); 17.705 + 17.706 + Type owntype = standaloneConditional ? condType(tree, truetype, falsetype) : pt(); 17.707 + if (condtype.constValue() != null && 17.708 + truetype.constValue() != null && 17.709 + falsetype.constValue() != null) { 17.710 + //constant folding 17.711 + owntype = cfolder.coerce(condtype.isTrue() ? truetype : falsetype, owntype); 17.712 + } 17.713 + result = check(tree, owntype, VAL, resultInfo); 17.714 } 17.715 //where 17.716 + @SuppressWarnings("fallthrough") 17.717 + private boolean isBooleanOrNumeric(Env<AttrContext> env, JCExpression tree) { 17.718 + switch (tree.getTag()) { 17.719 + case LITERAL: return ((JCLiteral)tree).typetag < CLASS; 17.720 + case LAMBDA: case REFERENCE: return false; 17.721 + case PARENS: return isBooleanOrNumeric(env, ((JCParens)tree).expr); 17.722 + case CONDEXPR: 17.723 + JCConditional condTree = (JCConditional)tree; 17.724 + return isBooleanOrNumeric(env, condTree.truepart) && 17.725 + isBooleanOrNumeric(env, condTree.falsepart); 17.726 + default: 17.727 + Type speculativeType = deferredAttr.attribSpeculative(tree, env, unknownExprInfo).type; 17.728 + speculativeType = types.unboxedTypeOrType(speculativeType); 17.729 + return speculativeType.tag <= BOOLEAN; 17.730 + } 17.731 + } 17.732 + 17.733 /** Compute the type of a conditional expression, after 17.734 - * checking that it exists. See Spec 15.25. 17.735 - * 17.736 - * @param pos The source position to be used for 17.737 - * error diagnostics. 17.738 - * @param condtype The type of the expression's condition. 17.739 - * @param thentype The type of the expression's then-part. 17.740 - * @param elsetype The type of the expression's else-part. 17.741 - */ 17.742 - private Type condType(DiagnosticPosition pos, 17.743 - Type condtype, 17.744 - Type thentype, 17.745 - Type elsetype) { 17.746 - Type ctype = condType1(pos, condtype, thentype, elsetype); 17.747 - 17.748 - // If condition and both arms are numeric constants, 17.749 - // evaluate at compile-time. 17.750 - return ((condtype.constValue() != null) && 17.751 - (thentype.constValue() != null) && 17.752 - (elsetype.constValue() != null)) 17.753 - ? cfolder.coerce(condtype.isTrue()?thentype:elsetype, ctype) 17.754 - : ctype; 17.755 - } 17.756 - /** Compute the type of a conditional expression, after 17.757 - * checking that it exists. Does not take into 17.758 + * checking that it exists. See JLS 15.25. Does not take into 17.759 * account the special case where condition and both arms 17.760 * are constants. 17.761 * 17.762 * @param pos The source position to be used for error 17.763 * diagnostics. 17.764 - * @param condtype The type of the expression's condition. 17.765 * @param thentype The type of the expression's then-part. 17.766 * @param elsetype The type of the expression's else-part. 17.767 */ 17.768 - private Type condType1(DiagnosticPosition pos, Type condtype, 17.769 + private Type condType(DiagnosticPosition pos, 17.770 Type thentype, Type elsetype) { 17.771 // If same type, that is the result 17.772 if (types.isSameType(thentype, elsetype)) 17.773 @@ -1399,37 +1549,38 @@ 17.774 LOOP: 17.775 while (env1 != null) { 17.776 switch (env1.tree.getTag()) { 17.777 - case LABELLED: 17.778 - JCLabeledStatement labelled = (JCLabeledStatement)env1.tree; 17.779 - if (label == labelled.label) { 17.780 - // If jump is a continue, check that target is a loop. 17.781 - if (tag == CONTINUE) { 17.782 - if (!labelled.body.hasTag(DOLOOP) && 17.783 - !labelled.body.hasTag(WHILELOOP) && 17.784 - !labelled.body.hasTag(FORLOOP) && 17.785 - !labelled.body.hasTag(FOREACHLOOP)) 17.786 - log.error(pos, "not.loop.label", label); 17.787 - // Found labelled statement target, now go inwards 17.788 - // to next non-labelled tree. 17.789 - return TreeInfo.referencedStatement(labelled); 17.790 - } else { 17.791 - return labelled; 17.792 + case LABELLED: 17.793 + JCLabeledStatement labelled = (JCLabeledStatement)env1.tree; 17.794 + if (label == labelled.label) { 17.795 + // If jump is a continue, check that target is a loop. 17.796 + if (tag == CONTINUE) { 17.797 + if (!labelled.body.hasTag(DOLOOP) && 17.798 + !labelled.body.hasTag(WHILELOOP) && 17.799 + !labelled.body.hasTag(FORLOOP) && 17.800 + !labelled.body.hasTag(FOREACHLOOP)) 17.801 + log.error(pos, "not.loop.label", label); 17.802 + // Found labelled statement target, now go inwards 17.803 + // to next non-labelled tree. 17.804 + return TreeInfo.referencedStatement(labelled); 17.805 + } else { 17.806 + return labelled; 17.807 + } 17.808 } 17.809 - } 17.810 - break; 17.811 - case DOLOOP: 17.812 - case WHILELOOP: 17.813 - case FORLOOP: 17.814 - case FOREACHLOOP: 17.815 - if (label == null) return env1.tree; 17.816 - break; 17.817 - case SWITCH: 17.818 - if (label == null && tag == BREAK) return env1.tree; 17.819 - break; 17.820 - case METHODDEF: 17.821 - case CLASSDEF: 17.822 - break LOOP; 17.823 - default: 17.824 + break; 17.825 + case DOLOOP: 17.826 + case WHILELOOP: 17.827 + case FORLOOP: 17.828 + case FOREACHLOOP: 17.829 + if (label == null) return env1.tree; 17.830 + break; 17.831 + case SWITCH: 17.832 + if (label == null && tag == BREAK) return env1.tree; 17.833 + break; 17.834 + case LAMBDA: 17.835 + case METHODDEF: 17.836 + case CLASSDEF: 17.837 + break LOOP; 17.838 + default: 17.839 } 17.840 env1 = env1.next; 17.841 } 17.842 @@ -1445,22 +1596,19 @@ 17.843 public void visitReturn(JCReturn tree) { 17.844 // Check that there is an enclosing method which is 17.845 // nested within than the enclosing class. 17.846 - if (env.enclMethod == null || 17.847 - env.enclMethod.sym.owner != env.enclClass.sym) { 17.848 + if (env.info.returnResult == null) { 17.849 log.error(tree.pos(), "ret.outside.meth"); 17.850 - 17.851 } else { 17.852 // Attribute return expression, if it exists, and check that 17.853 // it conforms to result type of enclosing method. 17.854 - Symbol m = env.enclMethod.sym; 17.855 - if (m.type.getReturnType().tag == VOID) { 17.856 - if (tree.expr != null) 17.857 + if (tree.expr != null) { 17.858 + if (env.info.returnResult.pt.tag == VOID) { 17.859 log.error(tree.expr.pos(), 17.860 "cant.ret.val.from.meth.decl.void"); 17.861 - } else if (tree.expr == null) { 17.862 + } 17.863 + attribTree(tree.expr, env, env.info.returnResult); 17.864 + } else if (env.info.returnResult.pt.tag != VOID) { 17.865 log.error(tree.pos(), "missing.ret.val"); 17.866 - } else { 17.867 - attribExpr(tree.expr, env, m.type.getReturnType()); 17.868 } 17.869 } 17.870 result = null; 17.871 @@ -1562,7 +1710,7 @@ 17.872 // current instance (JLS ???). 17.873 boolean selectSuperPrev = localEnv.info.selectSuper; 17.874 localEnv.info.selectSuper = true; 17.875 - localEnv.info.varArgs = false; 17.876 + localEnv.info.pendingResolutionPhase = null; 17.877 Symbol sym = rs.resolveConstructor( 17.878 tree.meth.pos(), localEnv, site, argtypes, typeargtypes); 17.879 localEnv.info.selectSuper = selectSuperPrev; 17.880 @@ -1573,8 +1721,7 @@ 17.881 // ...and check that it is legal in the current context. 17.882 // (this will also set the tree's type) 17.883 Type mpt = newMethodTemplate(resultInfo.pt, argtypes, typeargtypes); 17.884 - checkId(tree.meth, site, sym, localEnv, new ResultInfo(MTH, mpt), 17.885 - tree.varargsElement != null); 17.886 + checkId(tree.meth, site, sym, localEnv, new ResultInfo(MTH, mpt)); 17.887 } 17.888 // Otherwise, `site' is an error type and we do nothing 17.889 } 17.890 @@ -1589,35 +1736,18 @@ 17.891 // whose formal argument types is exactly the list of actual 17.892 // arguments (this will also set the method symbol). 17.893 Type mpt = newMethodTemplate(resultInfo.pt, argtypes, typeargtypes); 17.894 - localEnv.info.varArgs = false; 17.895 - Type mtype = attribExpr(tree.meth, localEnv, mpt); 17.896 + localEnv.info.pendingResolutionPhase = null; 17.897 + Type mtype = attribTree(tree.meth, localEnv, new ResultInfo(VAL, mpt, resultInfo.checkContext)); 17.898 17.899 // Compute the result type. 17.900 Type restype = mtype.getReturnType(); 17.901 if (restype.tag == WILDCARD) 17.902 throw new AssertionError(mtype); 17.903 17.904 - // as a special case, array.clone() has a result that is 17.905 - // the same as static type of the array being cloned 17.906 - if (tree.meth.hasTag(SELECT) && 17.907 - allowCovariantReturns && 17.908 - methName == names.clone && 17.909 - types.isArray(((JCFieldAccess) tree.meth).selected.type)) 17.910 - restype = ((JCFieldAccess) tree.meth).selected.type; 17.911 - 17.912 - // as a special case, x.getClass() has type Class<? extends |X|> 17.913 - if (allowGenerics && 17.914 - methName == names.getClass && tree.args.isEmpty()) { 17.915 - Type qualifier = (tree.meth.hasTag(SELECT)) 17.916 + Type qualifier = (tree.meth.hasTag(SELECT)) 17.917 ? ((JCFieldAccess) tree.meth).selected.type 17.918 : env.enclClass.sym.type; 17.919 - restype = new 17.920 - ClassType(restype.getEnclosingType(), 17.921 - List.<Type>of(new WildcardType(types.erasure(qualifier), 17.922 - BoundKind.EXTENDS, 17.923 - syms.boundClass)), 17.924 - restype.tsym); 17.925 - } 17.926 + restype = adjustMethodReturnType(qualifier, methName, argtypes, restype); 17.927 17.928 chk.checkRefTypes(tree.typeargs, typeargtypes); 17.929 17.930 @@ -1625,12 +1755,33 @@ 17.931 // current context. Also, capture the return type 17.932 result = check(tree, capture(restype), VAL, resultInfo); 17.933 17.934 - if (localEnv.info.varArgs) 17.935 + if (localEnv.info.lastResolveVarargs()) 17.936 Assert.check(result.isErroneous() || tree.varargsElement != null); 17.937 } 17.938 chk.validate(tree.typeargs, localEnv); 17.939 } 17.940 //where 17.941 + Type adjustMethodReturnType(Type qualifierType, Name methodName, List<Type> argtypes, Type restype) { 17.942 + if (allowCovariantReturns && 17.943 + methodName == names.clone && 17.944 + types.isArray(qualifierType)) { 17.945 + // as a special case, array.clone() has a result that is 17.946 + // the same as static type of the array being cloned 17.947 + return qualifierType; 17.948 + } else if (allowGenerics && 17.949 + methodName == names.getClass && 17.950 + argtypes.isEmpty()) { 17.951 + // as a special case, x.getClass() has type Class<? extends |X|> 17.952 + return new ClassType(restype.getEnclosingType(), 17.953 + List.<Type>of(new WildcardType(types.erasure(qualifierType), 17.954 + BoundKind.EXTENDS, 17.955 + syms.boundClass)), 17.956 + restype.tsym); 17.957 + } else { 17.958 + return restype; 17.959 + } 17.960 + } 17.961 + 17.962 /** Check that given application node appears as first statement 17.963 * in a constructor call. 17.964 * @param tree The application node 17.965 @@ -1652,11 +1803,11 @@ 17.966 /** Obtain a method type with given argument types. 17.967 */ 17.968 Type newMethodTemplate(Type restype, List<Type> argtypes, List<Type> typeargtypes) { 17.969 - MethodType mt = new MethodType(argtypes, restype, null, syms.methodClass); 17.970 + MethodType mt = new MethodType(argtypes, restype, List.<Type>nil(), syms.methodClass); 17.971 return (typeargtypes == null) ? mt : (Type)new ForAll(typeargtypes, mt); 17.972 } 17.973 17.974 - public void visitNewClass(JCNewClass tree) { 17.975 + public void visitNewClass(final JCNewClass tree) { 17.976 Type owntype = types.createErrorType(tree.type); 17.977 17.978 // The local environment of a class creation is 17.979 @@ -1729,42 +1880,6 @@ 17.980 List<Type> argtypes = attribArgs(tree.args, localEnv); 17.981 List<Type> typeargtypes = attribTypes(tree.typeargs, localEnv); 17.982 17.983 - if (TreeInfo.isDiamond(tree) && !clazztype.isErroneous()) { 17.984 - clazztype = attribDiamond(localEnv, tree, clazztype, argtypes, typeargtypes); 17.985 - clazz.type = clazztype; 17.986 - } else if (allowDiamondFinder && 17.987 - tree.def == null && 17.988 - !clazztype.isErroneous() && 17.989 - clazztype.getTypeArguments().nonEmpty() && 17.990 - findDiamonds) { 17.991 - boolean prevDeferDiags = log.deferDiagnostics; 17.992 - Queue<JCDiagnostic> prevDeferredDiags = log.deferredDiagnostics; 17.993 - Type inferred = null; 17.994 - try { 17.995 - //disable diamond-related diagnostics 17.996 - log.deferDiagnostics = true; 17.997 - log.deferredDiagnostics = ListBuffer.lb(); 17.998 - inferred = attribDiamond(localEnv, 17.999 - tree, 17.1000 - clazztype, 17.1001 - argtypes, 17.1002 - typeargtypes); 17.1003 - } 17.1004 - finally { 17.1005 - log.deferDiagnostics = prevDeferDiags; 17.1006 - log.deferredDiagnostics = prevDeferredDiags; 17.1007 - } 17.1008 - if (inferred != null && 17.1009 - !inferred.isErroneous() && 17.1010 - inferred.tag == CLASS && 17.1011 - types.isAssignable(inferred, pt().tag == NONE ? clazztype : pt(), Warner.noWarnings)) { 17.1012 - String key = types.isSameType(clazztype, inferred) ? 17.1013 - "diamond.redundant.args" : 17.1014 - "diamond.redundant.args.1"; 17.1015 - log.warning(tree.clazz.pos(), key, clazztype, inferred); 17.1016 - } 17.1017 - } 17.1018 - 17.1019 // If we have made no mistakes in the class type... 17.1020 if (clazztype.tag == CLASS) { 17.1021 // Enums may not be instantiated except implicitly 17.1022 @@ -1791,6 +1906,45 @@ 17.1023 // Error recovery: pretend no arguments were supplied. 17.1024 argtypes = List.nil(); 17.1025 typeargtypes = List.nil(); 17.1026 + } else if (TreeInfo.isDiamond(tree)) { 17.1027 + ClassType site = new ClassType(clazztype.getEnclosingType(), 17.1028 + clazztype.tsym.type.getTypeArguments(), 17.1029 + clazztype.tsym); 17.1030 + 17.1031 + Env<AttrContext> diamondEnv = localEnv.dup(tree); 17.1032 + diamondEnv.info.selectSuper = cdef != null; 17.1033 + diamondEnv.info.pendingResolutionPhase = null; 17.1034 + 17.1035 + //if the type of the instance creation expression is a class type 17.1036 + //apply method resolution inference (JLS 15.12.2.7). The return type 17.1037 + //of the resolved constructor will be a partially instantiated type 17.1038 + Symbol constructor = rs.resolveDiamond(tree.pos(), 17.1039 + diamondEnv, 17.1040 + site, 17.1041 + argtypes, 17.1042 + typeargtypes); 17.1043 + tree.constructor = constructor.baseSymbol(); 17.1044 + 17.1045 + final TypeSymbol csym = clazztype.tsym; 17.1046 + ResultInfo diamondResult = new ResultInfo(MTH, newMethodTemplate(resultInfo.pt, argtypes, typeargtypes), new Check.NestedCheckContext(resultInfo.checkContext) { 17.1047 + @Override 17.1048 + public void report(DiagnosticPosition _unused, JCDiagnostic details) { 17.1049 + enclosingContext.report(tree.clazz, 17.1050 + diags.fragment("cant.apply.diamond.1", diags.fragment("diamond", csym), details)); 17.1051 + } 17.1052 + }); 17.1053 + Type constructorType = tree.constructorType = types.createErrorType(clazztype); 17.1054 + constructorType = checkId(tree, site, 17.1055 + constructor, 17.1056 + diamondEnv, 17.1057 + diamondResult); 17.1058 + 17.1059 + tree.clazz.type = types.createErrorType(clazztype); 17.1060 + if (!constructorType.isErroneous()) { 17.1061 + tree.clazz.type = clazztype = constructorType.getReturnType(); 17.1062 + tree.constructorType = types.createMethodTypeWithReturn(constructorType, syms.voidType); 17.1063 + } 17.1064 + clazztype = chk.checkClassType(tree.clazz, tree.clazz.type, true); 17.1065 } 17.1066 17.1067 // Resolve the called constructor under the assumption 17.1068 @@ -1802,20 +1956,19 @@ 17.1069 //order to avoid downstream failures 17.1070 Env<AttrContext> rsEnv = localEnv.dup(tree); 17.1071 rsEnv.info.selectSuper = cdef != null; 17.1072 - rsEnv.info.varArgs = false; 17.1073 + rsEnv.info.pendingResolutionPhase = null; 17.1074 tree.constructor = rs.resolveConstructor( 17.1075 tree.pos(), rsEnv, clazztype, argtypes, typeargtypes); 17.1076 - tree.constructorType = tree.constructor.type.isErroneous() ? 17.1077 - syms.errType : 17.1078 - checkConstructor(clazztype, 17.1079 - tree.constructor, 17.1080 - rsEnv, 17.1081 - tree.args, 17.1082 - argtypes, 17.1083 - typeargtypes, 17.1084 - rsEnv.info.varArgs); 17.1085 - if (rsEnv.info.varArgs) 17.1086 - Assert.check(tree.constructorType.isErroneous() || tree.varargsElement != null); 17.1087 + if (cdef == null) { //do not check twice! 17.1088 + tree.constructorType = checkId(tree, 17.1089 + clazztype, 17.1090 + tree.constructor, 17.1091 + rsEnv, 17.1092 + new ResultInfo(MTH, newMethodTemplate(syms.voidType, argtypes, typeargtypes))); 17.1093 + if (rsEnv.info.lastResolveVarargs()) 17.1094 + Assert.check(tree.constructorType.isErroneous() || tree.varargsElement != null); 17.1095 + } 17.1096 + findDiamondIfNeeded(localEnv, tree, clazztype); 17.1097 } 17.1098 17.1099 if (cdef != null) { 17.1100 @@ -1861,6 +2014,8 @@ 17.1101 17.1102 attribStat(cdef, localEnv); 17.1103 17.1104 + checkLambdaCandidate(tree, cdef.sym, clazztype); 17.1105 + 17.1106 // If an outer instance is given, 17.1107 // prefix it to the constructor arguments 17.1108 // and delete it from the new expression 17.1109 @@ -1872,24 +2027,15 @@ 17.1110 17.1111 // Reassign clazztype and recompute constructor. 17.1112 clazztype = cdef.sym.type; 17.1113 - boolean useVarargs = tree.varargsElement != null; 17.1114 - Symbol sym = rs.resolveConstructor( 17.1115 - tree.pos(), localEnv, clazztype, argtypes, 17.1116 - typeargtypes, true, useVarargs); 17.1117 - Assert.check(sym.kind < AMBIGUOUS || tree.constructor.type.isErroneous()); 17.1118 + Symbol sym = tree.constructor = rs.resolveConstructor( 17.1119 + tree.pos(), localEnv, clazztype, argtypes, typeargtypes); 17.1120 + Assert.check(sym.kind < AMBIGUOUS); 17.1121 tree.constructor = sym; 17.1122 - if (tree.constructor.kind > ERRONEOUS) { 17.1123 - tree.constructorType = syms.errType; 17.1124 - } 17.1125 - else { 17.1126 - tree.constructorType = checkConstructor(clazztype, 17.1127 - tree.constructor, 17.1128 - localEnv, 17.1129 - tree.args, 17.1130 - argtypes, 17.1131 - typeargtypes, 17.1132 - useVarargs); 17.1133 - } 17.1134 + tree.constructorType = checkId(tree, 17.1135 + clazztype, 17.1136 + tree.constructor, 17.1137 + localEnv, 17.1138 + new ResultInfo(VAL, newMethodTemplate(syms.voidType, argtypes, typeargtypes))); 17.1139 } 17.1140 17.1141 if (tree.constructor != null && tree.constructor.kind == MTH) 17.1142 @@ -1898,57 +2044,58 @@ 17.1143 result = check(tree, owntype, VAL, resultInfo); 17.1144 chk.validate(tree.typeargs, localEnv); 17.1145 } 17.1146 - 17.1147 - Type attribDiamond(Env<AttrContext> env, 17.1148 - final JCNewClass tree, 17.1149 - final Type clazztype, 17.1150 - List<Type> argtypes, 17.1151 - List<Type> typeargtypes) { 17.1152 - if (clazztype.isErroneous() || 17.1153 - clazztype.isInterface()) { 17.1154 - //if the type of the instance creation expression is erroneous, 17.1155 - //or if it's an interface, or if something prevented us to form a valid 17.1156 - //mapping, return the (possibly erroneous) type unchanged 17.1157 - return clazztype; 17.1158 + //where 17.1159 + void findDiamondIfNeeded(Env<AttrContext> env, JCNewClass tree, Type clazztype) { 17.1160 + if (tree.def == null && 17.1161 + !clazztype.isErroneous() && 17.1162 + clazztype.getTypeArguments().nonEmpty() && 17.1163 + findDiamonds) { 17.1164 + JCTypeApply ta = (JCTypeApply)tree.clazz; 17.1165 + List<JCExpression> prevTypeargs = ta.arguments; 17.1166 + try { 17.1167 + //create a 'fake' diamond AST node by removing type-argument trees 17.1168 + ta.arguments = List.nil(); 17.1169 + ResultInfo findDiamondResult = new ResultInfo(VAL, 17.1170 + resultInfo.checkContext.inferenceContext().free(resultInfo.pt) ? Type.noType : pt()); 17.1171 + Type inferred = deferredAttr.attribSpeculative(tree, env, findDiamondResult).type; 17.1172 + if (!inferred.isErroneous() && 17.1173 + types.isAssignable(inferred, pt().tag == NONE ? syms.objectType : pt(), Warner.noWarnings)) { 17.1174 + String key = types.isSameType(clazztype, inferred) ? 17.1175 + "diamond.redundant.args" : 17.1176 + "diamond.redundant.args.1"; 17.1177 + log.warning(tree.clazz.pos(), key, clazztype, inferred); 17.1178 + } 17.1179 + } finally { 17.1180 + ta.arguments = prevTypeargs; 17.1181 + } 17.1182 + } 17.1183 } 17.1184 17.1185 - //dup attribution environment and augment the set of inference variables 17.1186 - Env<AttrContext> localEnv = env.dup(tree); 17.1187 - 17.1188 - ClassType site = new ClassType(clazztype.getEnclosingType(), 17.1189 - clazztype.tsym.type.getTypeArguments(), 17.1190 - clazztype.tsym); 17.1191 - 17.1192 - //if the type of the instance creation expression is a class type 17.1193 - //apply method resolution inference (JLS 15.12.2.7). The return type 17.1194 - //of the resolved constructor will be a partially instantiated type 17.1195 - Symbol constructor = rs.resolveDiamond(tree.pos(), 17.1196 - localEnv, 17.1197 - site, 17.1198 - argtypes, 17.1199 - typeargtypes); 17.1200 - 17.1201 - Type owntype = types.createErrorType(clazztype); 17.1202 - if (constructor.kind == MTH) { 17.1203 - ResultInfo diamondResult = new ResultInfo(VAL, resultInfo.pt, new Check.NestedCheckContext(resultInfo.checkContext) { 17.1204 - @Override 17.1205 - public void report(DiagnosticPosition pos, JCDiagnostic details) { 17.1206 - enclosingContext.report(tree.clazz.pos(), 17.1207 - diags.fragment("cant.apply.diamond.1", diags.fragment("diamond", clazztype.tsym), details)); 17.1208 + private void checkLambdaCandidate(JCNewClass tree, ClassSymbol csym, Type clazztype) { 17.1209 + if (allowLambda && 17.1210 + identifyLambdaCandidate && 17.1211 + clazztype.tag == CLASS && 17.1212 + pt().tag != NONE && 17.1213 + types.isFunctionalInterface(clazztype.tsym)) { 17.1214 + Symbol descriptor = types.findDescriptorSymbol(clazztype.tsym); 17.1215 + int count = 0; 17.1216 + boolean found = false; 17.1217 + for (Symbol sym : csym.members().getElements()) { 17.1218 + if ((sym.flags() & SYNTHETIC) != 0 || 17.1219 + sym.isConstructor()) continue; 17.1220 + count++; 17.1221 + if (sym.kind != MTH || 17.1222 + !sym.name.equals(descriptor.name)) continue; 17.1223 + Type mtype = types.memberType(clazztype, sym); 17.1224 + if (types.overrideEquivalent(mtype, types.memberType(clazztype, descriptor))) { 17.1225 + found = true; 17.1226 + } 17.1227 + } 17.1228 + if (found && count == 1) { 17.1229 + log.note(tree.def, "potential.lambda.found"); 17.1230 + } 17.1231 } 17.1232 - }); 17.1233 - owntype = checkMethod(site, 17.1234 - constructor, 17.1235 - diamondResult, 17.1236 - localEnv, 17.1237 - tree.args, 17.1238 - argtypes, 17.1239 - typeargtypes, 17.1240 - localEnv.info.varArgs).getReturnType(); 17.1241 - } 17.1242 - 17.1243 - return chk.checkClassType(tree.clazz.pos(), owntype, true); 17.1244 - } 17.1245 + } 17.1246 17.1247 /** Make an attributed null check tree. 17.1248 */ 17.1249 @@ -1966,13 +2113,14 @@ 17.1250 17.1251 public void visitNewArray(JCNewArray tree) { 17.1252 Type owntype = types.createErrorType(tree.type); 17.1253 + Env<AttrContext> localEnv = env.dup(tree); 17.1254 Type elemtype; 17.1255 if (tree.elemtype != null) { 17.1256 - elemtype = attribType(tree.elemtype, env); 17.1257 - chk.validate(tree.elemtype, env); 17.1258 + elemtype = attribType(tree.elemtype, localEnv); 17.1259 + chk.validate(tree.elemtype, localEnv); 17.1260 owntype = elemtype; 17.1261 for (List<JCExpression> l = tree.dims; l.nonEmpty(); l = l.tail) { 17.1262 - attribExpr(l.head, env, syms.intType); 17.1263 + attribExpr(l.head, localEnv, syms.intType); 17.1264 owntype = new ArrayType(owntype, syms.arrayClass); 17.1265 } 17.1266 } else { 17.1267 @@ -1989,7 +2137,7 @@ 17.1268 } 17.1269 } 17.1270 if (tree.elems != null) { 17.1271 - attribExprs(tree.elems, env, elemtype); 17.1272 + attribExprs(tree.elems, localEnv, elemtype); 17.1273 owntype = new ArrayType(elemtype, syms.arrayClass); 17.1274 } 17.1275 if (!types.isReifiable(elemtype)) 17.1276 @@ -1997,14 +2145,394 @@ 17.1277 result = check(tree, owntype, VAL, resultInfo); 17.1278 } 17.1279 17.1280 + /* 17.1281 + * A lambda expression can only be attributed when a target-type is available. 17.1282 + * In addition, if the target-type is that of a functional interface whose 17.1283 + * descriptor contains inference variables in argument position the lambda expression 17.1284 + * is 'stuck' (see DeferredAttr). 17.1285 + */ 17.1286 @Override 17.1287 - public void visitLambda(JCLambda that) { 17.1288 - throw new UnsupportedOperationException("Lambda expression not supported yet"); 17.1289 + public void visitLambda(final JCLambda that) { 17.1290 + if (pt().isErroneous() || (pt().tag == NONE && pt() != Type.recoveryType)) { 17.1291 + if (pt().tag == NONE) { 17.1292 + //lambda only allowed in assignment or method invocation/cast context 17.1293 + log.error(that.pos(), "unexpected.lambda"); 17.1294 + } 17.1295 + result = that.type = types.createErrorType(pt()); 17.1296 + return; 17.1297 + } 17.1298 + //create an environment for attribution of the lambda expression 17.1299 + final Env<AttrContext> localEnv = lambdaEnv(that, env); 17.1300 + boolean needsRecovery = resultInfo.checkContext.deferredAttrContext() == deferredAttr.emptyDeferredAttrContext || 17.1301 + resultInfo.checkContext.deferredAttrContext().mode == DeferredAttr.AttrMode.CHECK; 17.1302 + try { 17.1303 + List<Type> explicitParamTypes = null; 17.1304 + if (TreeInfo.isExplicitLambda(that)) { 17.1305 + //attribute lambda parameters 17.1306 + attribStats(that.params, localEnv); 17.1307 + explicitParamTypes = TreeInfo.types(that.params); 17.1308 + } 17.1309 + 17.1310 + Type target = infer.instantiateFunctionalInterface(that, pt(), explicitParamTypes, resultInfo.checkContext); 17.1311 + Type lambdaType = (target == Type.recoveryType) ? 17.1312 + fallbackDescriptorType(that) : 17.1313 + types.findDescriptorType(target); 17.1314 + 17.1315 + if (!TreeInfo.isExplicitLambda(that)) { 17.1316 + //add param type info in the AST 17.1317 + List<Type> actuals = lambdaType.getParameterTypes(); 17.1318 + List<JCVariableDecl> params = that.params; 17.1319 + 17.1320 + boolean arityMismatch = false; 17.1321 + 17.1322 + while (params.nonEmpty()) { 17.1323 + if (actuals.isEmpty()) { 17.1324 + //not enough actuals to perform lambda parameter inference 17.1325 + arityMismatch = true; 17.1326 + } 17.1327 + //reset previously set info 17.1328 + Type argType = arityMismatch ? 17.1329 + syms.errType : 17.1330 + actuals.head; 17.1331 + params.head.vartype = make.Type(argType); 17.1332 + params.head.sym = null; 17.1333 + actuals = actuals.isEmpty() ? 17.1334 + actuals : 17.1335 + actuals.tail; 17.1336 + params = params.tail; 17.1337 + } 17.1338 + 17.1339 + //attribute lambda parameters 17.1340 + attribStats(that.params, localEnv); 17.1341 + 17.1342 + if (arityMismatch) { 17.1343 + resultInfo.checkContext.report(that, diags.fragment("incompatible.arg.types.in.lambda")); 17.1344 + result = that.type = types.createErrorType(target); 17.1345 + return; 17.1346 + } 17.1347 + } 17.1348 + 17.1349 + //from this point on, no recovery is needed; if we are in assignment context 17.1350 + //we will be able to attribute the whole lambda body, regardless of errors; 17.1351 + //if we are in a 'check' method context, and the lambda is not compatible 17.1352 + //with the target-type, it will be recovered anyway in Attr.checkId 17.1353 + needsRecovery = false; 17.1354 + 17.1355 + ResultInfo bodyResultInfo = lambdaType.getReturnType() == Type.recoveryType ? 17.1356 + recoveryInfo : 17.1357 + new ResultInfo(VAL, lambdaType.getReturnType(), new LambdaReturnContext(resultInfo.checkContext)); 17.1358 + localEnv.info.returnResult = bodyResultInfo; 17.1359 + 17.1360 + if (that.getBodyKind() == JCLambda.BodyKind.EXPRESSION) { 17.1361 + attribTree(that.getBody(), localEnv, bodyResultInfo); 17.1362 + } else { 17.1363 + JCBlock body = (JCBlock)that.body; 17.1364 + attribStats(body.stats, localEnv); 17.1365 + } 17.1366 + 17.1367 + result = check(that, target, VAL, resultInfo); 17.1368 + 17.1369 + boolean isSpeculativeRound = 17.1370 + resultInfo.checkContext.deferredAttrContext().mode == DeferredAttr.AttrMode.SPECULATIVE; 17.1371 + 17.1372 + postAttr(that); 17.1373 + flow.analyzeLambda(env, that, make, isSpeculativeRound); 17.1374 + 17.1375 + checkLambdaCompatible(that, lambdaType, resultInfo.checkContext, isSpeculativeRound); 17.1376 + 17.1377 + if (!isSpeculativeRound) { 17.1378 + checkAccessibleFunctionalDescriptor(that, localEnv, resultInfo.checkContext.inferenceContext(), lambdaType); 17.1379 + } 17.1380 + result = check(that, target, VAL, resultInfo); 17.1381 + } catch (Types.FunctionDescriptorLookupError ex) { 17.1382 + JCDiagnostic cause = ex.getDiagnostic(); 17.1383 + resultInfo.checkContext.report(that, cause); 17.1384 + result = that.type = types.createErrorType(pt()); 17.1385 + return; 17.1386 + } finally { 17.1387 + localEnv.info.scope.leave(); 17.1388 + if (needsRecovery) { 17.1389 + attribTree(that, env, recoveryInfo); 17.1390 + } 17.1391 + } 17.1392 } 17.1393 + //where 17.1394 + private Type fallbackDescriptorType(JCExpression tree) { 17.1395 + switch (tree.getTag()) { 17.1396 + case LAMBDA: 17.1397 + JCLambda lambda = (JCLambda)tree; 17.1398 + List<Type> argtypes = List.nil(); 17.1399 + for (JCVariableDecl param : lambda.params) { 17.1400 + argtypes = param.vartype != null ? 17.1401 + argtypes.append(param.vartype.type) : 17.1402 + argtypes.append(syms.errType); 17.1403 + } 17.1404 + return new MethodType(argtypes, Type.recoveryType, List.<Type>nil(), syms.methodClass); 17.1405 + case REFERENCE: 17.1406 + return new MethodType(List.<Type>nil(), Type.recoveryType, List.<Type>nil(), syms.methodClass); 17.1407 + default: 17.1408 + Assert.error("Cannot get here!"); 17.1409 + } 17.1410 + return null; 17.1411 + } 17.1412 + 17.1413 + private void checkAccessibleFunctionalDescriptor(final DiagnosticPosition pos, 17.1414 + final Env<AttrContext> env, final InferenceContext inferenceContext, final Type desc) { 17.1415 + if (inferenceContext.free(desc)) { 17.1416 + inferenceContext.addFreeTypeListener(List.of(desc), new FreeTypeListener() { 17.1417 + @Override 17.1418 + public void typesInferred(InferenceContext inferenceContext) { 17.1419 + checkAccessibleFunctionalDescriptor(pos, env, inferenceContext, inferenceContext.asInstType(desc, types)); 17.1420 + } 17.1421 + }); 17.1422 + } else { 17.1423 + chk.checkAccessibleFunctionalDescriptor(pos, env, desc); 17.1424 + } 17.1425 + } 17.1426 + 17.1427 + /** 17.1428 + * Lambda/method reference have a special check context that ensures 17.1429 + * that i.e. a lambda return type is compatible with the expected 17.1430 + * type according to both the inherited context and the assignment 17.1431 + * context. 17.1432 + */ 17.1433 + class LambdaReturnContext extends Check.NestedCheckContext { 17.1434 + public LambdaReturnContext(CheckContext enclosingContext) { 17.1435 + super(enclosingContext); 17.1436 + } 17.1437 + 17.1438 + @Override 17.1439 + public boolean compatible(Type found, Type req, Warner warn) { 17.1440 + //return type must be compatible in both current context and assignment context 17.1441 + return types.isAssignable(found, inferenceContext().asFree(req, types), warn) && 17.1442 + super.compatible(found, req, warn); 17.1443 + } 17.1444 + @Override 17.1445 + public void report(DiagnosticPosition pos, JCDiagnostic details) { 17.1446 + enclosingContext.report(pos, diags.fragment("incompatible.ret.type.in.lambda", details)); 17.1447 + } 17.1448 + } 17.1449 + 17.1450 + /** 17.1451 + * Lambda compatibility. Check that given return types, thrown types, parameter types 17.1452 + * are compatible with the expected functional interface descriptor. This means that: 17.1453 + * (i) parameter types must be identical to those of the target descriptor; (ii) return 17.1454 + * types must be compatible with the return type of the expected descriptor; 17.1455 + * (iii) thrown types must be 'included' in the thrown types list of the expected 17.1456 + * descriptor. 17.1457 + */ 17.1458 + private void checkLambdaCompatible(JCLambda tree, Type descriptor, CheckContext checkContext, boolean speculativeAttr) { 17.1459 + Type returnType = checkContext.inferenceContext().asFree(descriptor.getReturnType(), types); 17.1460 + 17.1461 + //return values have already been checked - but if lambda has no return 17.1462 + //values, we must ensure that void/value compatibility is correct; 17.1463 + //this amounts at checking that, if a lambda body can complete normally, 17.1464 + //the descriptor's return type must be void 17.1465 + if (tree.getBodyKind() == JCLambda.BodyKind.STATEMENT && tree.canCompleteNormally && 17.1466 + returnType.tag != VOID && returnType != Type.recoveryType) { 17.1467 + checkContext.report(tree, diags.fragment("incompatible.ret.type.in.lambda", 17.1468 + diags.fragment("missing.ret.val", returnType))); 17.1469 + } 17.1470 + 17.1471 + List<Type> argTypes = checkContext.inferenceContext().asFree(descriptor.getParameterTypes(), types); 17.1472 + if (!types.isSameTypes(argTypes, TreeInfo.types(tree.params))) { 17.1473 + checkContext.report(tree, diags.fragment("incompatible.arg.types.in.lambda")); 17.1474 + } 17.1475 + 17.1476 + if (!speculativeAttr) { 17.1477 + List<Type> thrownTypes = checkContext.inferenceContext().asFree(descriptor.getThrownTypes(), types); 17.1478 + if (chk.unhandled(tree.inferredThrownTypes == null ? List.<Type>nil() : tree.inferredThrownTypes, thrownTypes).nonEmpty()) { 17.1479 + log.error(tree, "incompatible.thrown.types.in.lambda", tree.inferredThrownTypes); 17.1480 + } 17.1481 + } 17.1482 + } 17.1483 + 17.1484 + private Env<AttrContext> lambdaEnv(JCLambda that, Env<AttrContext> env) { 17.1485 + Env<AttrContext> lambdaEnv; 17.1486 + Symbol owner = env.info.scope.owner; 17.1487 + if (owner.kind == VAR && owner.owner.kind == TYP) { 17.1488 + //field initializer 17.1489 + lambdaEnv = env.dup(that, env.info.dup(env.info.scope.dupUnshared())); 17.1490 + lambdaEnv.info.scope.owner = 17.1491 + new MethodSymbol(0, names.empty, null, 17.1492 + env.info.scope.owner); 17.1493 + } else { 17.1494 + lambdaEnv = env.dup(that, env.info.dup(env.info.scope.dup())); 17.1495 + } 17.1496 + return lambdaEnv; 17.1497 + } 17.1498 17.1499 @Override 17.1500 - public void visitReference(JCMemberReference that) { 17.1501 - throw new UnsupportedOperationException("Member references not supported yet"); 17.1502 + public void visitReference(final JCMemberReference that) { 17.1503 + if (pt().isErroneous() || (pt().tag == NONE && pt() != Type.recoveryType)) { 17.1504 + if (pt().tag == NONE) { 17.1505 + //method reference only allowed in assignment or method invocation/cast context 17.1506 + log.error(that.pos(), "unexpected.mref"); 17.1507 + } 17.1508 + result = that.type = types.createErrorType(pt()); 17.1509 + return; 17.1510 + } 17.1511 + final Env<AttrContext> localEnv = env.dup(that); 17.1512 + try { 17.1513 + //attribute member reference qualifier - if this is a constructor 17.1514 + //reference, the expected kind must be a type 17.1515 + Type exprType = attribTree(that.expr, 17.1516 + env, new ResultInfo(that.getMode() == ReferenceMode.INVOKE ? VAL | TYP : TYP, Type.noType)); 17.1517 + 17.1518 + if (that.getMode() == JCMemberReference.ReferenceMode.NEW) { 17.1519 + exprType = chk.checkConstructorRefType(that.expr, exprType); 17.1520 + } 17.1521 + 17.1522 + if (exprType.isErroneous()) { 17.1523 + //if the qualifier expression contains problems, 17.1524 + //give up atttribution of method reference 17.1525 + result = that.type = exprType; 17.1526 + return; 17.1527 + } 17.1528 + 17.1529 + if (TreeInfo.isStaticSelector(that.expr, names) && 17.1530 + (that.getMode() != ReferenceMode.NEW || !that.expr.type.isRaw())) { 17.1531 + //if the qualifier is a type, validate it 17.1532 + chk.validate(that.expr, env); 17.1533 + } 17.1534 + 17.1535 + //attrib type-arguments 17.1536 + List<Type> typeargtypes = null; 17.1537 + if (that.typeargs != null) { 17.1538 + typeargtypes = attribTypes(that.typeargs, localEnv); 17.1539 + } 17.1540 + 17.1541 + Type target = infer.instantiateFunctionalInterface(that, pt(), null, resultInfo.checkContext); 17.1542 + Type desc = (target == Type.recoveryType) ? 17.1543 + fallbackDescriptorType(that) : 17.1544 + types.findDescriptorType(target); 17.1545 + 17.1546 + List<Type> argtypes = desc.getParameterTypes(); 17.1547 + 17.1548 + boolean allowBoxing = 17.1549 + resultInfo.checkContext.deferredAttrContext() == deferredAttr.emptyDeferredAttrContext || 17.1550 + resultInfo.checkContext.deferredAttrContext().phase.isBoxingRequired(); 17.1551 + Pair<Symbol, Resolve.ReferenceLookupHelper> refResult = rs.resolveMemberReference(that.pos(), localEnv, that, 17.1552 + that.expr.type, that.name, argtypes, typeargtypes, allowBoxing); 17.1553 + 17.1554 + Symbol refSym = refResult.fst; 17.1555 + Resolve.ReferenceLookupHelper lookupHelper = refResult.snd; 17.1556 + 17.1557 + if (refSym.kind != MTH) { 17.1558 + boolean targetError; 17.1559 + switch (refSym.kind) { 17.1560 + case ABSENT_MTH: 17.1561 + targetError = false; 17.1562 + break; 17.1563 + case WRONG_MTH: 17.1564 + case WRONG_MTHS: 17.1565 + case AMBIGUOUS: 17.1566 + case HIDDEN: 17.1567 + case STATICERR: 17.1568 + case MISSING_ENCL: 17.1569 + targetError = true; 17.1570 + break; 17.1571 + default: 17.1572 + Assert.error("unexpected result kind " + refSym.kind); 17.1573 + targetError = false; 17.1574 + } 17.1575 + 17.1576 + JCDiagnostic detailsDiag = ((Resolve.ResolveError)refSym).getDiagnostic(JCDiagnostic.DiagnosticType.FRAGMENT, 17.1577 + that, exprType.tsym, exprType, that.name, argtypes, typeargtypes); 17.1578 + 17.1579 + JCDiagnostic.DiagnosticType diagKind = targetError ? 17.1580 + JCDiagnostic.DiagnosticType.FRAGMENT : JCDiagnostic.DiagnosticType.ERROR; 17.1581 + 17.1582 + JCDiagnostic diag = diags.create(diagKind, log.currentSource(), that, 17.1583 + "invalid.mref", Kinds.kindName(that.getMode()), detailsDiag); 17.1584 + 17.1585 + if (targetError) { 17.1586 + resultInfo.checkContext.report(that, diag); 17.1587 + } else { 17.1588 + log.report(diag); 17.1589 + } 17.1590 + result = that.type = types.createErrorType(target); 17.1591 + return; 17.1592 + } 17.1593 + 17.1594 + if (desc.getReturnType() == Type.recoveryType) { 17.1595 + // stop here 17.1596 + result = that.type = types.createErrorType(target); 17.1597 + return; 17.1598 + } 17.1599 + 17.1600 + that.sym = refSym.baseSymbol(); 17.1601 + that.kind = lookupHelper.referenceKind(that.sym); 17.1602 + 17.1603 + ResultInfo checkInfo = 17.1604 + resultInfo.dup(newMethodTemplate( 17.1605 + desc.getReturnType().tag == VOID ? Type.noType : desc.getReturnType(), 17.1606 + lookupHelper.argtypes, 17.1607 + typeargtypes)); 17.1608 + 17.1609 + Type refType = checkId(that, lookupHelper.site, refSym, localEnv, checkInfo); 17.1610 + 17.1611 + if (!refType.isErroneous()) { 17.1612 + refType = types.createMethodTypeWithReturn(refType, 17.1613 + adjustMethodReturnType(lookupHelper.site, that.name, checkInfo.pt.getParameterTypes(), refType.getReturnType())); 17.1614 + } 17.1615 + 17.1616 + //go ahead with standard method reference compatibility check - note that param check 17.1617 + //is a no-op (as this has been taken care during method applicability) 17.1618 + boolean isSpeculativeRound = 17.1619 + resultInfo.checkContext.deferredAttrContext().mode == DeferredAttr.AttrMode.SPECULATIVE; 17.1620 + checkReferenceCompatible(that, desc, refType, resultInfo.checkContext, isSpeculativeRound); 17.1621 + if (!isSpeculativeRound) { 17.1622 + checkAccessibleFunctionalDescriptor(that, localEnv, resultInfo.checkContext.inferenceContext(), desc); 17.1623 + } 17.1624 + result = check(that, target, VAL, resultInfo); 17.1625 + } catch (Types.FunctionDescriptorLookupError ex) { 17.1626 + JCDiagnostic cause = ex.getDiagnostic(); 17.1627 + resultInfo.checkContext.report(that, cause); 17.1628 + result = that.type = types.createErrorType(pt()); 17.1629 + return; 17.1630 + } 17.1631 + } 17.1632 + 17.1633 + @SuppressWarnings("fallthrough") 17.1634 + void checkReferenceCompatible(JCMemberReference tree, Type descriptor, Type refType, CheckContext checkContext, boolean speculativeAttr) { 17.1635 + Type returnType = checkContext.inferenceContext().asFree(descriptor.getReturnType(), types); 17.1636 + 17.1637 + Type resType; 17.1638 + switch (tree.getMode()) { 17.1639 + case NEW: 17.1640 + if (!tree.expr.type.isRaw()) { 17.1641 + resType = tree.expr.type; 17.1642 + break; 17.1643 + } 17.1644 + default: 17.1645 + resType = refType.getReturnType(); 17.1646 + } 17.1647 + 17.1648 + Type incompatibleReturnType = resType; 17.1649 + 17.1650 + if (returnType.tag == VOID) { 17.1651 + incompatibleReturnType = null; 17.1652 + } 17.1653 + 17.1654 + if (returnType.tag != VOID && resType.tag != VOID) { 17.1655 + if (resType.isErroneous() || 17.1656 + new LambdaReturnContext(checkContext).compatible(resType, returnType, Warner.noWarnings)) { 17.1657 + incompatibleReturnType = null; 17.1658 + } 17.1659 + } 17.1660 + 17.1661 + if (incompatibleReturnType != null) { 17.1662 + checkContext.report(tree, diags.fragment("incompatible.ret.type.in.mref", 17.1663 + diags.fragment("inconvertible.types", resType, descriptor.getReturnType()))); 17.1664 + } 17.1665 + 17.1666 + if (!speculativeAttr) { 17.1667 + List<Type> thrownTypes = checkContext.inferenceContext().asFree(descriptor.getThrownTypes(), types); 17.1668 + if (chk.unhandled(refType.getThrownTypes(), thrownTypes).nonEmpty()) { 17.1669 + log.error(tree, "incompatible.thrown.types.in.mref", refType.getThrownTypes()); 17.1670 + } 17.1671 + } 17.1672 } 17.1673 17.1674 public void visitParens(JCParens tree) { 17.1675 @@ -2138,18 +2666,34 @@ 17.1676 result = check(tree, owntype, VAL, resultInfo); 17.1677 } 17.1678 17.1679 - public void visitTypeCast(JCTypeCast tree) { 17.1680 + public void visitTypeCast(final JCTypeCast tree) { 17.1681 Type clazztype = attribType(tree.clazz, env); 17.1682 chk.validate(tree.clazz, env, false); 17.1683 //a fresh environment is required for 292 inference to work properly --- 17.1684 //see Infer.instantiatePolymorphicSignatureInstance() 17.1685 Env<AttrContext> localEnv = env.dup(tree); 17.1686 - Type exprtype = attribExpr(tree.expr, localEnv, Infer.anyPoly); 17.1687 - Type owntype = chk.checkCastable(tree.expr.pos(), exprtype, clazztype); 17.1688 + //should we propagate the target type? 17.1689 + final ResultInfo castInfo; 17.1690 + final boolean isPoly = TreeInfo.isPoly(tree.expr, tree); 17.1691 + if (isPoly) { 17.1692 + //expression is a poly - we need to propagate target type info 17.1693 + castInfo = new ResultInfo(VAL, clazztype, new Check.NestedCheckContext(resultInfo.checkContext) { 17.1694 + @Override 17.1695 + public boolean compatible(Type found, Type req, Warner warn) { 17.1696 + return types.isCastable(found, req, warn); 17.1697 + } 17.1698 + }); 17.1699 + } else { 17.1700 + //standalone cast - target-type info is not propagated 17.1701 + castInfo = unknownExprInfo; 17.1702 + } 17.1703 + Type exprtype = attribTree(tree.expr, localEnv, castInfo); 17.1704 + Type owntype = isPoly ? clazztype : chk.checkCastable(tree.expr.pos(), exprtype, clazztype); 17.1705 if (exprtype.constValue() != null) 17.1706 owntype = cfolder.coerce(exprtype, owntype); 17.1707 result = check(tree, capture(owntype), VAL, resultInfo); 17.1708 - chk.checkRedundantCast(localEnv, tree); 17.1709 + if (!isPoly) 17.1710 + chk.checkRedundantCast(localEnv, tree); 17.1711 } 17.1712 17.1713 public void visitTypeTest(JCInstanceOf tree) { 17.1714 @@ -2176,15 +2720,13 @@ 17.1715 17.1716 public void visitIdent(JCIdent tree) { 17.1717 Symbol sym; 17.1718 - boolean varArgs = false; 17.1719 17.1720 // Find symbol 17.1721 if (pt().tag == METHOD || pt().tag == FORALL) { 17.1722 // If we are looking for a method, the prototype `pt' will be a 17.1723 // method type with the type of the call's arguments as parameters. 17.1724 - env.info.varArgs = false; 17.1725 + env.info.pendingResolutionPhase = null; 17.1726 sym = rs.resolveMethod(tree.pos(), env, tree.name, pt().getParameterTypes(), pt().getTypeArguments()); 17.1727 - varArgs = env.info.varArgs; 17.1728 } else if (tree.sym != null && tree.sym.kind != VAR) { 17.1729 sym = tree.sym; 17.1730 } else { 17.1731 @@ -2246,7 +2788,7 @@ 17.1732 while (env1.outer != null && !rs.isAccessible(env, env1.enclClass.sym.type, sym)) 17.1733 env1 = env1.outer; 17.1734 } 17.1735 - result = checkId(tree, env1.enclClass.sym.type, sym, env, resultInfo, varArgs); 17.1736 + result = checkId(tree, env1.enclClass.sym.type, sym, env, resultInfo); 17.1737 } 17.1738 17.1739 public void visitSelect(JCFieldAccess tree) { 17.1740 @@ -2289,13 +2831,13 @@ 17.1741 sitesym.name == names._super; 17.1742 17.1743 // Determine the symbol represented by the selection. 17.1744 - env.info.varArgs = false; 17.1745 + env.info.pendingResolutionPhase = null; 17.1746 Symbol sym = selectSym(tree, sitesym, site, env, resultInfo); 17.1747 if (sym.exists() && !isType(sym) && (pkind() & (PCK | TYP)) != 0) { 17.1748 site = capture(site); 17.1749 sym = selectSym(tree, sitesym, site, env, resultInfo); 17.1750 } 17.1751 - boolean varArgs = env.info.varArgs; 17.1752 + boolean varArgs = env.info.lastResolveVarargs(); 17.1753 tree.sym = sym; 17.1754 17.1755 if (site.tag == TYPEVAR && !isType(sym) && sym.kind != ERR) { 17.1756 @@ -2344,9 +2886,10 @@ 17.1757 } else { 17.1758 // Check if type-qualified fields or methods are static (JLS) 17.1759 if ((sym.flags() & STATIC) == 0 && 17.1760 + !env.next.tree.hasTag(REFERENCE) && 17.1761 sym.name != names._super && 17.1762 (sym.kind == VAR || sym.kind == MTH)) { 17.1763 - rs.access(rs.new StaticError(sym), 17.1764 + rs.accessBase(rs.new StaticError(sym), 17.1765 tree.pos(), site, sym.name, true); 17.1766 } 17.1767 } 17.1768 @@ -2370,7 +2913,7 @@ 17.1769 } 17.1770 17.1771 env.info.selectSuper = selectSuperPrev; 17.1772 - result = checkId(tree, site, sym, env, resultInfo, varArgs); 17.1773 + result = checkId(tree, site, sym, env, resultInfo); 17.1774 } 17.1775 //where 17.1776 /** Determine symbol referenced by a Select expression, 17.1777 @@ -2389,7 +2932,7 @@ 17.1778 Name name = tree.name; 17.1779 switch (site.tag) { 17.1780 case PACKAGE: 17.1781 - return rs.access( 17.1782 + return rs.accessBase( 17.1783 rs.findIdentInPackage(env, site.tsym, name, resultInfo.pkind), 17.1784 pos, location, site, name, true); 17.1785 case ARRAY: 17.1786 @@ -2413,7 +2956,7 @@ 17.1787 // We are seeing a plain identifier as selector. 17.1788 Symbol sym = rs.findIdentInType(env, site, name, resultInfo.pkind); 17.1789 if ((resultInfo.pkind & ERRONEOUS) == 0) 17.1790 - sym = rs.access(sym, pos, location, site, name, true); 17.1791 + sym = rs.accessBase(sym, pos, location, site, name, true); 17.1792 return sym; 17.1793 } 17.1794 case WILDCARD: 17.1795 @@ -2435,7 +2978,7 @@ 17.1796 Symbol sym2 = (sym.flags() & Flags.PRIVATE) != 0 ? 17.1797 rs.new AccessError(env, site, sym) : 17.1798 sym; 17.1799 - rs.access(sym2, pos, location, site, name, true); 17.1800 + rs.accessBase(sym2, pos, location, site, name, true); 17.1801 return sym; 17.1802 } 17.1803 case ERROR: 17.1804 @@ -2486,9 +3029,18 @@ 17.1805 Type site, 17.1806 Symbol sym, 17.1807 Env<AttrContext> env, 17.1808 - ResultInfo resultInfo, 17.1809 - boolean useVarargs) { 17.1810 - if (resultInfo.pt.isErroneous()) return types.createErrorType(site); 17.1811 + ResultInfo resultInfo) { 17.1812 + Type pt = resultInfo.pt.tag == FORALL || resultInfo.pt.tag == METHOD ? 17.1813 + resultInfo.pt.map(deferredAttr.new DeferredTypeMap(AttrMode.SPECULATIVE, sym, env.info.pendingResolutionPhase)) : 17.1814 + resultInfo.pt; 17.1815 + 17.1816 + DeferredAttr.DeferredTypeMap recoveryMap = 17.1817 + deferredAttr.new RecoveryDeferredTypeMap(AttrMode.CHECK, sym, env.info.pendingResolutionPhase); 17.1818 + 17.1819 + if (pt.isErroneous()) { 17.1820 + Type.map(resultInfo.pt.getParameterTypes(), recoveryMap); 17.1821 + return types.createErrorType(site); 17.1822 + } 17.1823 Type owntype; // The computed type of this identifier occurrence. 17.1824 switch (sym.kind) { 17.1825 case TYP: 17.1826 @@ -2563,14 +3115,14 @@ 17.1827 } 17.1828 break; 17.1829 case MTH: { 17.1830 - JCMethodInvocation app = (JCMethodInvocation)env.tree; 17.1831 owntype = checkMethod(site, sym, 17.1832 new ResultInfo(VAL, resultInfo.pt.getReturnType(), resultInfo.checkContext), 17.1833 - env, app.args, resultInfo.pt.getParameterTypes(), 17.1834 - resultInfo.pt.getTypeArguments(), env.info.varArgs); 17.1835 + env, TreeInfo.args(env.tree), resultInfo.pt.getParameterTypes(), 17.1836 + resultInfo.pt.getTypeArguments()); 17.1837 break; 17.1838 } 17.1839 case PCK: case ERR: 17.1840 + Type.map(resultInfo.pt.getParameterTypes(), recoveryMap); 17.1841 owntype = sym.type; 17.1842 break; 17.1843 default: 17.1844 @@ -2710,8 +3262,7 @@ 17.1845 Env<AttrContext> env, 17.1846 final List<JCExpression> argtrees, 17.1847 List<Type> argtypes, 17.1848 - List<Type> typeargtypes, 17.1849 - boolean useVarargs) { 17.1850 + List<Type> typeargtypes) { 17.1851 // Test (5): if symbol is an instance method of a raw type, issue 17.1852 // an unchecked warning if its argument types change under erasure. 17.1853 if (allowGenerics && 17.1854 @@ -2733,18 +3284,16 @@ 17.1855 // any type arguments and value arguments. 17.1856 noteWarner.clear(); 17.1857 try { 17.1858 - Type owntype = rs.rawInstantiate( 17.1859 + Type owntype = rs.checkMethod( 17.1860 env, 17.1861 site, 17.1862 sym, 17.1863 resultInfo, 17.1864 argtypes, 17.1865 typeargtypes, 17.1866 - allowBoxing, 17.1867 - useVarargs, 17.1868 noteWarner); 17.1869 17.1870 - return chk.checkMethod(owntype, sym, env, argtrees, argtypes, useVarargs, 17.1871 + return chk.checkMethod(owntype, sym, env, argtrees, argtypes, env.info.lastResolveVarargs(), 17.1872 noteWarner.hasNonSilentLint(LintCategory.UNCHECKED)); 17.1873 } catch (Infer.InferenceException ex) { 17.1874 //invalid target type - propagate exception outwards or report error 17.1875 @@ -2752,26 +3301,11 @@ 17.1876 resultInfo.checkContext.report(env.tree.pos(), ex.getDiagnostic()); 17.1877 return types.createErrorType(site); 17.1878 } catch (Resolve.InapplicableMethodException ex) { 17.1879 - Assert.error(); 17.1880 + Assert.error(ex.getDiagnostic().getMessage(Locale.getDefault())); 17.1881 return null; 17.1882 } 17.1883 } 17.1884 17.1885 - /** 17.1886 - * Check that constructor arguments conform to its instantiation. 17.1887 - **/ 17.1888 - public Type checkConstructor(Type site, 17.1889 - Symbol sym, 17.1890 - Env<AttrContext> env, 17.1891 - final List<JCExpression> argtrees, 17.1892 - List<Type> argtypes, 17.1893 - List<Type> typeargtypes, 17.1894 - boolean useVarargs) { 17.1895 - Type owntype = checkMethod(site, sym, new ResultInfo(VAL, syms.voidType), env, argtrees, argtypes, typeargtypes, useVarargs); 17.1896 - chk.checkType(env.tree.pos(), owntype.getReturnType(), syms.voidType); 17.1897 - return owntype; 17.1898 - } 17.1899 - 17.1900 public void visitLiteral(JCLiteral tree) { 17.1901 result = check( 17.1902 tree, litType(tree.typetag).constType(tree.value), VAL, resultInfo); 17.1903 @@ -3075,8 +3609,10 @@ 17.1904 17.1905 Lint prevLint = chk.setLint(env.info.lint); 17.1906 JavaFileObject prev = log.useSource(c.sourcefile); 17.1907 + ResultInfo prevReturnRes = env.info.returnResult; 17.1908 17.1909 try { 17.1910 + env.info.returnResult = null; 17.1911 // java.lang.Enum may not be subclassed by a non-enum 17.1912 if (st.tsym == syms.enumSym && 17.1913 ((c.flags_field & (Flags.ENUM|Flags.COMPOUND)) == 0)) 17.1914 @@ -3093,6 +3629,7 @@ 17.1915 17.1916 chk.checkDeprecatedAnnotation(env.tree.pos(), c); 17.1917 } finally { 17.1918 + env.info.returnResult = prevReturnRes; 17.1919 log.useSource(prev); 17.1920 chk.setLint(prevLint); 17.1921 } 17.1922 @@ -3280,8 +3817,8 @@ 17.1923 * mode (e.g. by an IDE) and the AST contains semantic errors, this routine 17.1924 * prevents NPE to be progagated during subsequent compilation steps. 17.1925 */ 17.1926 - public void postAttr(Env<AttrContext> env) { 17.1927 - new PostAttrAnalyzer().scan(env.tree); 17.1928 + public void postAttr(JCTree tree) { 17.1929 + new PostAttrAnalyzer().scan(tree); 17.1930 } 17.1931 17.1932 class PostAttrAnalyzer extends TreeScanner { 17.1933 @@ -3375,6 +3912,14 @@ 17.1934 that.operator = new OperatorSymbol(names.empty, syms.unknownType, -1, syms.noSymbol); 17.1935 super.visitUnary(that); 17.1936 } 17.1937 + 17.1938 + @Override 17.1939 + public void visitReference(JCMemberReference that) { 17.1940 + super.visitReference(that); 17.1941 + if (that.sym == null) { 17.1942 + that.sym = new MethodSymbol(0, names.empty, syms.unknownType, syms.noSymbol); 17.1943 + } 17.1944 + } 17.1945 } 17.1946 // </editor-fold> 17.1947 }
18.1 --- a/src/share/classes/com/sun/tools/javac/comp/AttrContext.java Thu Oct 11 09:50:52 2012 -0700 18.2 +++ b/src/share/classes/com/sun/tools/javac/comp/AttrContext.java Thu Oct 11 17:00:54 2012 -0700 18.3 @@ -56,7 +56,7 @@ 18.4 18.5 /** Are arguments to current function applications boxed into an array for varargs? 18.6 */ 18.7 - boolean varArgs = false; 18.8 + Resolve.MethodResolutionPhase pendingResolutionPhase = null; 18.9 18.10 /** A record of the lint/SuppressWarnings currently in effect 18.11 */ 18.12 @@ -67,6 +67,11 @@ 18.13 */ 18.14 Symbol enclVar = null; 18.15 18.16 + /** ResultInfo to be used for attributing 'return' statement expressions 18.17 + * (set by Attr.visitMethod and Attr.visitLambda) 18.18 + */ 18.19 + Attr.ResultInfo returnResult = null; 18.20 + 18.21 /** Duplicate this context, replacing scope field and copying all others. 18.22 */ 18.23 AttrContext dup(Scope scope) { 18.24 @@ -75,9 +80,10 @@ 18.25 info.staticLevel = staticLevel; 18.26 info.isSelfCall = isSelfCall; 18.27 info.selectSuper = selectSuper; 18.28 - info.varArgs = varArgs; 18.29 + info.pendingResolutionPhase = pendingResolutionPhase; 18.30 info.lint = lint; 18.31 info.enclVar = enclVar; 18.32 + info.returnResult = returnResult; 18.33 return info; 18.34 } 18.35 18.36 @@ -93,6 +99,11 @@ 18.37 return scope.getElements(); 18.38 } 18.39 18.40 + boolean lastResolveVarargs() { 18.41 + return pendingResolutionPhase != null && 18.42 + pendingResolutionPhase.isVarargsRequired(); 18.43 + } 18.44 + 18.45 public String toString() { 18.46 return "AttrContext[" + scope.toString() + "]"; 18.47 }
19.1 --- a/src/share/classes/com/sun/tools/javac/comp/Check.java Thu Oct 11 09:50:52 2012 -0700 19.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Check.java Thu Oct 11 17:00:54 2012 -0700 19.3 @@ -40,6 +40,9 @@ 19.4 import com.sun.tools.javac.code.Lint.LintCategory; 19.5 import com.sun.tools.javac.code.Type.*; 19.6 import com.sun.tools.javac.code.Symbol.*; 19.7 +import com.sun.tools.javac.comp.DeferredAttr.DeferredAttrContext; 19.8 +import com.sun.tools.javac.comp.Infer.InferenceContext; 19.9 +import com.sun.tools.javac.comp.Infer.InferenceContext.FreeTypeListener; 19.10 19.11 import static com.sun.tools.javac.code.Flags.*; 19.12 import static com.sun.tools.javac.code.Flags.ANNOTATION; 19.13 @@ -66,6 +69,7 @@ 19.14 private final Resolve rs; 19.15 private final Symtab syms; 19.16 private final Enter enter; 19.17 + private final DeferredAttr deferredAttr; 19.18 private final Infer infer; 19.19 private final Types types; 19.20 private final JCDiagnostic.Factory diags; 19.21 @@ -98,6 +102,7 @@ 19.22 rs = Resolve.instance(context); 19.23 syms = Symtab.instance(context); 19.24 enter = Enter.instance(context); 19.25 + deferredAttr = DeferredAttr.instance(context); 19.26 infer = Infer.instance(context); 19.27 this.types = Types.instance(context); 19.28 diags = JCDiagnostic.Factory.instance(context); 19.29 @@ -416,7 +421,7 @@ 19.30 * checks - depending on the check context, meaning of 'compatibility' might 19.31 * vary significantly. 19.32 */ 19.33 - interface CheckContext { 19.34 + public interface CheckContext { 19.35 /** 19.36 * Is type 'found' compatible with type 'req' in given context 19.37 */ 19.38 @@ -429,6 +434,12 @@ 19.39 * Obtain a warner for this check context 19.40 */ 19.41 public Warner checkWarner(DiagnosticPosition pos, Type found, Type req); 19.42 + 19.43 + public Infer.InferenceContext inferenceContext(); 19.44 + 19.45 + public DeferredAttr.DeferredAttrContext deferredAttrContext(); 19.46 + 19.47 + public boolean allowBoxing(); 19.48 } 19.49 19.50 /** 19.51 @@ -455,6 +466,18 @@ 19.52 public Warner checkWarner(DiagnosticPosition pos, Type found, Type req) { 19.53 return enclosingContext.checkWarner(pos, found, req); 19.54 } 19.55 + 19.56 + public Infer.InferenceContext inferenceContext() { 19.57 + return enclosingContext.inferenceContext(); 19.58 + } 19.59 + 19.60 + public DeferredAttrContext deferredAttrContext() { 19.61 + return enclosingContext.deferredAttrContext(); 19.62 + } 19.63 + 19.64 + public boolean allowBoxing() { 19.65 + return enclosingContext.allowBoxing(); 19.66 + } 19.67 } 19.68 19.69 /** 19.70 @@ -471,6 +494,18 @@ 19.71 public Warner checkWarner(DiagnosticPosition pos, Type found, Type req) { 19.72 return convertWarner(pos, found, req); 19.73 } 19.74 + 19.75 + public InferenceContext inferenceContext() { 19.76 + return infer.emptyContext; 19.77 + } 19.78 + 19.79 + public DeferredAttrContext deferredAttrContext() { 19.80 + return deferredAttr.emptyDeferredAttrContext; 19.81 + } 19.82 + 19.83 + public boolean allowBoxing() { 19.84 + return true; 19.85 + } 19.86 }; 19.87 19.88 /** Check that a given type is assignable to a given proto-type. 19.89 @@ -483,7 +518,16 @@ 19.90 return checkType(pos, found, req, basicHandler); 19.91 } 19.92 19.93 - Type checkType(final DiagnosticPosition pos, Type found, Type req, CheckContext checkContext) { 19.94 + Type checkType(final DiagnosticPosition pos, final Type found, final Type req, final CheckContext checkContext) { 19.95 + final Infer.InferenceContext inferenceContext = checkContext.inferenceContext(); 19.96 + if (inferenceContext.free(req)) { 19.97 + inferenceContext.addFreeTypeListener(List.of(req), new FreeTypeListener() { 19.98 + @Override 19.99 + public void typesInferred(InferenceContext inferenceContext) { 19.100 + checkType(pos, found, inferenceContext.asInstType(req, types), checkContext); 19.101 + } 19.102 + }); 19.103 + } 19.104 if (req.tag == ERROR) 19.105 return req; 19.106 if (req.tag == NONE) 19.107 @@ -523,9 +567,9 @@ 19.108 */ 19.109 public void checkRedundantCast(Env<AttrContext> env, JCTypeCast tree) { 19.110 if (!tree.type.isErroneous() && 19.111 - (env.info.lint == null || env.info.lint.isEnabled(Lint.LintCategory.CAST)) 19.112 - && types.isSameType(tree.expr.type, tree.clazz.type) 19.113 - && !is292targetTypeCast(tree)) { 19.114 + (env.info.lint == null || env.info.lint.isEnabled(Lint.LintCategory.CAST)) 19.115 + && types.isSameType(tree.expr.type, tree.clazz.type) 19.116 + && !is292targetTypeCast(tree)) { 19.117 log.warning(Lint.LintCategory.CAST, 19.118 tree.pos(), "redundant.cast", tree.expr.type); 19.119 } 19.120 @@ -604,6 +648,22 @@ 19.121 return t; 19.122 } 19.123 19.124 + /** Check that type is a valid qualifier for a constructor reference expression 19.125 + */ 19.126 + Type checkConstructorRefType(DiagnosticPosition pos, Type t) { 19.127 + t = checkClassType(pos, t); 19.128 + if (t.tag == CLASS) { 19.129 + if ((t.tsym.flags() & (ABSTRACT | INTERFACE)) != 0) { 19.130 + log.error(pos, "abstract.cant.be.instantiated"); 19.131 + t = types.createErrorType(t); 19.132 + } else if ((t.tsym.flags() & ENUM) != 0) { 19.133 + log.error(pos, "enum.cant.be.instantiated"); 19.134 + t = types.createErrorType(t); 19.135 + } 19.136 + } 19.137 + return t; 19.138 + } 19.139 + 19.140 /** Check that type is a class or interface type. 19.141 * @param pos Position to be used for error reporting. 19.142 * @param t The type to be checked. 19.143 @@ -796,29 +856,34 @@ 19.144 sym.owner == syms.enumSym) 19.145 formals = formals.tail.tail; 19.146 List<JCExpression> args = argtrees; 19.147 - while (formals.head != last) { 19.148 - JCTree arg = args.head; 19.149 - Warner warn = convertWarner(arg.pos(), arg.type, formals.head); 19.150 - assertConvertible(arg, arg.type, formals.head, warn); 19.151 - args = args.tail; 19.152 - formals = formals.tail; 19.153 - } 19.154 - if (useVarargs) { 19.155 - Type varArg = types.elemtype(last); 19.156 - while (args.tail != null) { 19.157 + DeferredAttr.DeferredTypeMap checkDeferredMap = 19.158 + deferredAttr.new DeferredTypeMap(DeferredAttr.AttrMode.CHECK, sym, env.info.pendingResolutionPhase); 19.159 + if (args != null) { 19.160 + //this is null when type-checking a method reference 19.161 + while (formals.head != last) { 19.162 JCTree arg = args.head; 19.163 - Warner warn = convertWarner(arg.pos(), arg.type, varArg); 19.164 - assertConvertible(arg, arg.type, varArg, warn); 19.165 + Warner warn = convertWarner(arg.pos(), arg.type, formals.head); 19.166 + assertConvertible(arg, arg.type, formals.head, warn); 19.167 args = args.tail; 19.168 + formals = formals.tail; 19.169 } 19.170 - } else if ((sym.flags() & VARARGS) != 0 && allowVarargs) { 19.171 - // non-varargs call to varargs method 19.172 - Type varParam = owntype.getParameterTypes().last(); 19.173 - Type lastArg = argtypes.last(); 19.174 - if (types.isSubtypeUnchecked(lastArg, types.elemtype(varParam)) && 19.175 - !types.isSameType(types.erasure(varParam), types.erasure(lastArg))) 19.176 - log.warning(argtrees.last().pos(), "inexact.non-varargs.call", 19.177 - types.elemtype(varParam), varParam); 19.178 + if (useVarargs) { 19.179 + Type varArg = types.elemtype(last); 19.180 + while (args.tail != null) { 19.181 + JCTree arg = args.head; 19.182 + Warner warn = convertWarner(arg.pos(), arg.type, varArg); 19.183 + assertConvertible(arg, arg.type, varArg, warn); 19.184 + args = args.tail; 19.185 + } 19.186 + } else if ((sym.flags() & VARARGS) != 0 && allowVarargs) { 19.187 + // non-varargs call to varargs method 19.188 + Type varParam = owntype.getParameterTypes().last(); 19.189 + Type lastArg = checkDeferredMap.apply(argtypes.last()); 19.190 + if (types.isSubtypeUnchecked(lastArg, types.elemtype(varParam)) && 19.191 + !types.isSameType(types.erasure(varParam), types.erasure(lastArg))) 19.192 + log.warning(argtrees.last().pos(), "inexact.non-varargs.call", 19.193 + types.elemtype(varParam), varParam); 19.194 + } 19.195 } 19.196 if (unchecked) { 19.197 warnUnchecked(env.tree.pos(), 19.198 @@ -826,7 +891,7 @@ 19.199 kindName(sym), 19.200 sym.name, 19.201 rs.methodArguments(sym.type.getParameterTypes()), 19.202 - rs.methodArguments(argtypes), 19.203 + rs.methodArguments(Type.map(argtypes, checkDeferredMap)), 19.204 kindName(sym.location()), 19.205 sym.location()); 19.206 owntype = new MethodType(owntype.getParameterTypes(), 19.207 @@ -853,6 +918,9 @@ 19.208 case NEWCLASS: 19.209 ((JCNewClass) tree).varargsElement = elemtype; 19.210 break; 19.211 + case REFERENCE: 19.212 + ((JCMemberReference) tree).varargsElement = elemtype; 19.213 + break; 19.214 default: 19.215 throw new AssertionError(""+tree); 19.216 } 19.217 @@ -870,6 +938,65 @@ 19.218 return; 19.219 } 19.220 19.221 + void checkAccessibleFunctionalDescriptor(DiagnosticPosition pos, Env<AttrContext> env, Type desc) { 19.222 + AccessChecker accessChecker = new AccessChecker(env); 19.223 + //check args accessibility (only if implicit parameter types) 19.224 + for (Type arg : desc.getParameterTypes()) { 19.225 + if (!accessChecker.visit(arg)) { 19.226 + log.error(pos, "cant.access.arg.type.in.functional.desc", arg); 19.227 + return; 19.228 + } 19.229 + } 19.230 + //check return type accessibility 19.231 + if (!accessChecker.visit(desc.getReturnType())) { 19.232 + log.error(pos, "cant.access.return.in.functional.desc", desc.getReturnType()); 19.233 + return; 19.234 + } 19.235 + //check thrown types accessibility 19.236 + for (Type thrown : desc.getThrownTypes()) { 19.237 + if (!accessChecker.visit(thrown)) { 19.238 + log.error(pos, "cant.access.thrown.in.functional.desc", thrown); 19.239 + return; 19.240 + } 19.241 + } 19.242 + } 19.243 + 19.244 + class AccessChecker extends Types.UnaryVisitor<Boolean> { 19.245 + 19.246 + Env<AttrContext> env; 19.247 + 19.248 + AccessChecker(Env<AttrContext> env) { 19.249 + this.env = env; 19.250 + } 19.251 + 19.252 + Boolean visit(List<Type> ts) { 19.253 + for (Type t : ts) { 19.254 + if (!visit(t)) 19.255 + return false; 19.256 + } 19.257 + return true; 19.258 + } 19.259 + 19.260 + public Boolean visitType(Type t, Void s) { 19.261 + return true; 19.262 + } 19.263 + 19.264 + @Override 19.265 + public Boolean visitArrayType(ArrayType t, Void s) { 19.266 + return visit(t.elemtype); 19.267 + } 19.268 + 19.269 + @Override 19.270 + public Boolean visitClassType(ClassType t, Void s) { 19.271 + return rs.isAccessible(env, t, true) && 19.272 + visit(t.getTypeArguments()); 19.273 + } 19.274 + 19.275 + @Override 19.276 + public Boolean visitWildcardType(WildcardType t, Void s) { 19.277 + return visit(t.type); 19.278 + } 19.279 + }; 19.280 /** 19.281 * Check that type 't' is a valid instantiation of a generic class 19.282 * (see JLS 4.5) 19.283 @@ -2470,6 +2597,7 @@ 19.284 validateDocumented(t.tsym, s, pos); 19.285 validateInherited(t.tsym, s, pos); 19.286 validateTarget(t.tsym, s, pos); 19.287 + validateDefault(t.tsym, s, pos); 19.288 } 19.289 19.290 /** 19.291 @@ -2650,6 +2778,21 @@ 19.292 return true; 19.293 } 19.294 19.295 + private void validateDefault(Symbol container, Symbol contained, DiagnosticPosition pos) { 19.296 + // validate that all other elements of containing type has defaults 19.297 + Scope scope = container.members(); 19.298 + for(Symbol elm : scope.getElements()) { 19.299 + if (elm.name != names.value && 19.300 + elm.kind == Kinds.MTH && 19.301 + ((MethodSymbol)elm).defaultValue == null) { 19.302 + log.error(pos, 19.303 + "invalid.containedby.annotation.elem.nondefault", 19.304 + container, 19.305 + elm); 19.306 + } 19.307 + } 19.308 + } 19.309 + 19.310 /** Is s a method symbol that overrides a method in a superclass? */ 19.311 boolean isOverrider(Symbol s) { 19.312 if (s.kind != MTH || s.isStatic())
20.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 20.2 +++ b/src/share/classes/com/sun/tools/javac/comp/DeferredAttr.java Thu Oct 11 17:00:54 2012 -0700 20.3 @@ -0,0 +1,640 @@ 20.4 +/* 20.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 20.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 20.7 + * 20.8 + * This code is free software; you can redistribute it and/or modify it 20.9 + * under the terms of the GNU General Public License version 2 only, as 20.10 + * published by the Free Software Foundation. Oracle designates this 20.11 + * particular file as subject to the "Classpath" exception as provided 20.12 + * by Oracle in the LICENSE file that accompanied this code. 20.13 + * 20.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 20.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 20.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 20.17 + * version 2 for more details (a copy is included in the LICENSE file that 20.18 + * accompanied this code). 20.19 + * 20.20 + * You should have received a copy of the GNU General Public License version 20.21 + * 2 along with this work; if not, write to the Free Software Foundation, 20.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20.23 + * 20.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20.25 + * or visit www.oracle.com if you need additional information or have any 20.26 + * questions. 20.27 + */ 20.28 + 20.29 +package com.sun.tools.javac.comp; 20.30 + 20.31 +import com.sun.tools.javac.code.*; 20.32 +import com.sun.tools.javac.tree.*; 20.33 +import com.sun.tools.javac.util.*; 20.34 +import com.sun.tools.javac.code.Symbol.*; 20.35 +import com.sun.tools.javac.code.Type.*; 20.36 +import com.sun.tools.javac.comp.Attr.ResultInfo; 20.37 +import com.sun.tools.javac.comp.Infer.InferenceContext; 20.38 +import com.sun.tools.javac.comp.Resolve.MethodResolutionPhase; 20.39 +import com.sun.tools.javac.tree.JCTree.*; 20.40 + 20.41 +import javax.tools.JavaFileObject; 20.42 + 20.43 +import java.util.ArrayList; 20.44 +import java.util.HashSet; 20.45 +import java.util.Map; 20.46 +import java.util.Queue; 20.47 +import java.util.Set; 20.48 +import java.util.WeakHashMap; 20.49 + 20.50 +import static com.sun.tools.javac.code.TypeTags.*; 20.51 +import static com.sun.tools.javac.tree.JCTree.Tag.*; 20.52 +import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; 20.53 + 20.54 +/** 20.55 + * This is an helper class that is used to perform deferred type-analysis. 20.56 + * Each time a poly expression occurs in argument position, javac attributes it 20.57 + * with a temporary 'deferred type' that is checked (possibly multiple times) 20.58 + * against an expected formal type. 20.59 + * 20.60 + * <p><b>This is NOT part of any supported API. 20.61 + * If you write code that depends on this, you do so at your own risk. 20.62 + * This code and its internal interfaces are subject to change or 20.63 + * deletion without notice.</b> 20.64 + */ 20.65 +public class DeferredAttr extends JCTree.Visitor { 20.66 + protected static final Context.Key<DeferredAttr> deferredAttrKey = 20.67 + new Context.Key<DeferredAttr>(); 20.68 + 20.69 + final Attr attr; 20.70 + final Check chk; 20.71 + final Enter enter; 20.72 + final Infer infer; 20.73 + final Log log; 20.74 + final Symtab syms; 20.75 + final TreeMaker make; 20.76 + final Types types; 20.77 + 20.78 + public static DeferredAttr instance(Context context) { 20.79 + DeferredAttr instance = context.get(deferredAttrKey); 20.80 + if (instance == null) 20.81 + instance = new DeferredAttr(context); 20.82 + return instance; 20.83 + } 20.84 + 20.85 + protected DeferredAttr(Context context) { 20.86 + context.put(deferredAttrKey, this); 20.87 + attr = Attr.instance(context); 20.88 + chk = Check.instance(context); 20.89 + enter = Enter.instance(context); 20.90 + infer = Infer.instance(context); 20.91 + log = Log.instance(context); 20.92 + syms = Symtab.instance(context); 20.93 + make = TreeMaker.instance(context); 20.94 + types = Types.instance(context); 20.95 + } 20.96 + 20.97 + /** 20.98 + * This type represents a deferred type. A deferred type starts off with 20.99 + * no information on the underlying expression type. Such info needs to be 20.100 + * discovered through type-checking the deferred type against a target-type. 20.101 + * Every deferred type keeps a pointer to the AST node from which it originated. 20.102 + */ 20.103 + public class DeferredType extends Type { 20.104 + 20.105 + public JCExpression tree; 20.106 + Env<AttrContext> env; 20.107 + AttrMode mode; 20.108 + SpeculativeCache speculativeCache; 20.109 + 20.110 + DeferredType(JCExpression tree, Env<AttrContext> env) { 20.111 + super(DEFERRED, null); 20.112 + this.tree = tree; 20.113 + this.env = env.dup(tree, env.info.dup()); 20.114 + this.speculativeCache = new SpeculativeCache(); 20.115 + } 20.116 + 20.117 + /** 20.118 + * A speculative cache is used to keep track of all overload resolution rounds 20.119 + * that triggered speculative attribution on a given deferred type. Each entry 20.120 + * stores a pointer to the speculative tree and the resolution phase in which the entry 20.121 + * has been added. 20.122 + */ 20.123 + class SpeculativeCache { 20.124 + 20.125 + private Map<Symbol, List<Entry>> cache = 20.126 + new WeakHashMap<Symbol, List<Entry>>(); 20.127 + 20.128 + class Entry { 20.129 + JCTree speculativeTree; 20.130 + Resolve.MethodResolutionPhase phase; 20.131 + 20.132 + public Entry(JCTree speculativeTree, MethodResolutionPhase phase) { 20.133 + this.speculativeTree = speculativeTree; 20.134 + this.phase = phase; 20.135 + } 20.136 + 20.137 + boolean matches(Resolve.MethodResolutionPhase phase) { 20.138 + return this.phase == phase; 20.139 + } 20.140 + } 20.141 + 20.142 + /** 20.143 + * Clone a speculative cache entry as a fresh entry associated 20.144 + * with a new method (this maybe required to fixup speculative cache 20.145 + * misses after Resolve.access()) 20.146 + */ 20.147 + void dupAllTo(Symbol from, Symbol to) { 20.148 + Assert.check(cache.get(to) == null); 20.149 + List<Entry> entries = cache.get(from); 20.150 + if (entries != null) { 20.151 + cache.put(to, entries); 20.152 + } 20.153 + } 20.154 + 20.155 + /** 20.156 + * Retrieve a speculative cache entry corresponding to given symbol 20.157 + * and resolution phase 20.158 + */ 20.159 + Entry get(Symbol msym, MethodResolutionPhase phase) { 20.160 + List<Entry> entries = cache.get(msym); 20.161 + if (entries == null) return null; 20.162 + for (Entry e : entries) { 20.163 + if (e.matches(phase)) return e; 20.164 + } 20.165 + return null; 20.166 + } 20.167 + 20.168 + /** 20.169 + * Stores a speculative cache entry corresponding to given symbol 20.170 + * and resolution phase 20.171 + */ 20.172 + void put(Symbol msym, JCTree speculativeTree, MethodResolutionPhase phase) { 20.173 + List<Entry> entries = cache.get(msym); 20.174 + if (entries == null) { 20.175 + entries = List.nil(); 20.176 + } 20.177 + cache.put(msym, entries.prepend(new Entry(speculativeTree, phase))); 20.178 + } 20.179 + } 20.180 + 20.181 + /** 20.182 + * Get the type that has been computed during a speculative attribution round 20.183 + */ 20.184 + Type speculativeType(Symbol msym, MethodResolutionPhase phase) { 20.185 + SpeculativeCache.Entry e = speculativeCache.get(msym, phase); 20.186 + return e != null ? e.speculativeTree.type : Type.noType; 20.187 + } 20.188 + 20.189 + /** 20.190 + * Check a deferred type against a potential target-type. Depending on 20.191 + * the current attribution mode, a normal vs. speculative attribution 20.192 + * round is performed on the underlying AST node. There can be only one 20.193 + * speculative round for a given target method symbol; moreover, a normal 20.194 + * attribution round must follow one or more speculative rounds. 20.195 + */ 20.196 + Type check(ResultInfo resultInfo) { 20.197 + DeferredAttrContext deferredAttrContext = 20.198 + resultInfo.checkContext.deferredAttrContext(); 20.199 + Assert.check(deferredAttrContext != emptyDeferredAttrContext); 20.200 + List<Type> stuckVars = stuckVars(tree, resultInfo); 20.201 + if (stuckVars.nonEmpty()) { 20.202 + deferredAttrContext.addDeferredAttrNode(this, resultInfo, stuckVars); 20.203 + return Type.noType; 20.204 + } else { 20.205 + try { 20.206 + switch (deferredAttrContext.mode) { 20.207 + case SPECULATIVE: 20.208 + Assert.check(mode == null || 20.209 + (mode == AttrMode.SPECULATIVE && 20.210 + speculativeType(deferredAttrContext.msym, deferredAttrContext.phase).tag == NONE)); 20.211 + JCTree speculativeTree = attribSpeculative(tree, env, resultInfo); 20.212 + speculativeCache.put(deferredAttrContext.msym, speculativeTree, deferredAttrContext.phase); 20.213 + return speculativeTree.type; 20.214 + case CHECK: 20.215 + Assert.check(mode == AttrMode.SPECULATIVE); 20.216 + return attr.attribTree(tree, env, resultInfo); 20.217 + } 20.218 + Assert.error(); 20.219 + return null; 20.220 + } finally { 20.221 + mode = deferredAttrContext.mode; 20.222 + } 20.223 + } 20.224 + } 20.225 + } 20.226 + 20.227 + /** 20.228 + * The 'mode' in which the deferred type is to be type-checked 20.229 + */ 20.230 + public enum AttrMode { 20.231 + /** 20.232 + * A speculative type-checking round is used during overload resolution 20.233 + * mainly to generate constraints on inference variables. Side-effects 20.234 + * arising from type-checking the expression associated with the deferred 20.235 + * type are reversed after the speculative round finishes. This means the 20.236 + * expression tree will be left in a blank state. 20.237 + */ 20.238 + SPECULATIVE, 20.239 + /** 20.240 + * This is the plain type-checking mode. Produces side-effects on the underlying AST node 20.241 + */ 20.242 + CHECK; 20.243 + } 20.244 + 20.245 + /** 20.246 + * Routine that performs speculative type-checking; the input AST node is 20.247 + * cloned (to avoid side-effects cause by Attr) and compiler state is 20.248 + * restored after type-checking. All diagnostics (but critical ones) are 20.249 + * disabled during speculative type-checking. 20.250 + */ 20.251 + JCTree attribSpeculative(JCTree tree, Env<AttrContext> env, ResultInfo resultInfo) { 20.252 + JCTree newTree = new TreeCopier<Object>(make).copy(tree); 20.253 + Env<AttrContext> speculativeEnv = env.dup(newTree, env.info.dup(env.info.scope.dupUnshared())); 20.254 + speculativeEnv.info.scope.owner = env.info.scope.owner; 20.255 + Filter<JCDiagnostic> prevDeferDiagsFilter = log.deferredDiagFilter; 20.256 + Queue<JCDiagnostic> prevDeferredDiags = log.deferredDiagnostics; 20.257 + final JavaFileObject currentSource = log.currentSourceFile(); 20.258 + try { 20.259 + log.deferredDiagnostics = new ListBuffer<JCDiagnostic>(); 20.260 + log.deferredDiagFilter = new Filter<JCDiagnostic>() { 20.261 + public boolean accepts(JCDiagnostic t) { 20.262 + return t.getDiagnosticSource().getFile().equals(currentSource); 20.263 + } 20.264 + }; 20.265 + attr.attribTree(newTree, speculativeEnv, resultInfo); 20.266 + unenterScanner.scan(newTree); 20.267 + return newTree; 20.268 + } catch (Abort ex) { 20.269 + //if some very bad condition occurred during deferred attribution 20.270 + //we should dump all errors before killing javac 20.271 + log.reportDeferredDiagnostics(); 20.272 + throw ex; 20.273 + } finally { 20.274 + unenterScanner.scan(newTree); 20.275 + log.deferredDiagFilter = prevDeferDiagsFilter; 20.276 + log.deferredDiagnostics = prevDeferredDiags; 20.277 + } 20.278 + } 20.279 + //where 20.280 + protected TreeScanner unenterScanner = new TreeScanner() { 20.281 + @Override 20.282 + public void visitClassDef(JCClassDecl tree) { 20.283 + ClassSymbol csym = tree.sym; 20.284 + enter.typeEnvs.remove(csym); 20.285 + chk.compiled.remove(csym.flatname); 20.286 + syms.classes.remove(csym.flatname); 20.287 + super.visitClassDef(tree); 20.288 + } 20.289 + }; 20.290 + 20.291 + /** 20.292 + * A deferred context is created on each method check. A deferred context is 20.293 + * used to keep track of information associated with the method check, such as 20.294 + * the symbol of the method being checked, the overload resolution phase, 20.295 + * the kind of attribution mode to be applied to deferred types and so forth. 20.296 + * As deferred types are processed (by the method check routine) stuck AST nodes 20.297 + * are added (as new deferred attribution nodes) to this context. The complete() 20.298 + * routine makes sure that all pending nodes are properly processed, by 20.299 + * progressively instantiating all inference variables on which one or more 20.300 + * deferred attribution node is stuck. 20.301 + */ 20.302 + class DeferredAttrContext { 20.303 + 20.304 + /** attribution mode */ 20.305 + final AttrMode mode; 20.306 + 20.307 + /** symbol of the method being checked */ 20.308 + final Symbol msym; 20.309 + 20.310 + /** method resolution step */ 20.311 + final Resolve.MethodResolutionPhase phase; 20.312 + 20.313 + /** inference context */ 20.314 + final InferenceContext inferenceContext; 20.315 + 20.316 + /** list of deferred attribution nodes to be processed */ 20.317 + ArrayList<DeferredAttrNode> deferredAttrNodes = new ArrayList<DeferredAttrNode>(); 20.318 + 20.319 + DeferredAttrContext(AttrMode mode, Symbol msym, MethodResolutionPhase phase, InferenceContext inferenceContext) { 20.320 + this.mode = mode; 20.321 + this.msym = msym; 20.322 + this.phase = phase; 20.323 + this.inferenceContext = inferenceContext; 20.324 + } 20.325 + 20.326 + /** 20.327 + * Adds a node to the list of deferred attribution nodes - used by Resolve.rawCheckArgumentsApplicable 20.328 + * Nodes added this way act as 'roots' for the out-of-order method checking process. 20.329 + */ 20.330 + void addDeferredAttrNode(final DeferredType dt, ResultInfo resultInfo, List<Type> stuckVars) { 20.331 + deferredAttrNodes.add(new DeferredAttrNode(dt, resultInfo, stuckVars)); 20.332 + } 20.333 + 20.334 + /** 20.335 + * Incrementally process all nodes, by skipping 'stuck' nodes and attributing 20.336 + * 'unstuck' ones. If at any point no progress can be made (no 'unstuck' nodes) 20.337 + * some inference variable might get eagerly instantiated so that all nodes 20.338 + * can be type-checked. 20.339 + */ 20.340 + void complete() { 20.341 + while (!deferredAttrNodes.isEmpty()) { 20.342 + Set<Type> stuckVars = new HashSet<Type>(); 20.343 + boolean progress = false; 20.344 + //scan a defensive copy of the node list - this is because a deferred 20.345 + //attribution round can add new nodes to the list 20.346 + for (DeferredAttrNode deferredAttrNode : List.from(deferredAttrNodes)) { 20.347 + if (!deferredAttrNode.isStuck()) { 20.348 + deferredAttrNode.process(); 20.349 + deferredAttrNodes.remove(deferredAttrNode); 20.350 + progress = true; 20.351 + } else { 20.352 + stuckVars.addAll(deferredAttrNode.stuckVars); 20.353 + } 20.354 + } 20.355 + if (!progress) { 20.356 + //remove all variables that have already been instantiated 20.357 + //from the list of stuck variables 20.358 + inferenceContext.solveAny(inferenceContext.freeVarsIn(List.from(stuckVars)), types, infer); 20.359 + inferenceContext.notifyChange(types); 20.360 + } 20.361 + } 20.362 + } 20.363 + 20.364 + /** 20.365 + * Class representing a deferred attribution node. It keeps track of 20.366 + * a deferred type, along with the expected target type information. 20.367 + */ 20.368 + class DeferredAttrNode implements Infer.InferenceContext.FreeTypeListener { 20.369 + 20.370 + /** underlying deferred type */ 20.371 + DeferredType dt; 20.372 + 20.373 + /** underlying target type information */ 20.374 + ResultInfo resultInfo; 20.375 + 20.376 + /** list of uninferred inference variables causing this node to be stuck */ 20.377 + List<Type> stuckVars; 20.378 + 20.379 + DeferredAttrNode(DeferredType dt, ResultInfo resultInfo, List<Type> stuckVars) { 20.380 + this.dt = dt; 20.381 + this.resultInfo = resultInfo; 20.382 + this.stuckVars = stuckVars; 20.383 + if (!stuckVars.isEmpty()) { 20.384 + resultInfo.checkContext.inferenceContext().addFreeTypeListener(stuckVars, this); 20.385 + } 20.386 + } 20.387 + 20.388 + @Override 20.389 + public void typesInferred(InferenceContext inferenceContext) { 20.390 + stuckVars = List.nil(); 20.391 + resultInfo = resultInfo.dup(inferenceContext.asInstType(resultInfo.pt, types)); 20.392 + } 20.393 + 20.394 + /** 20.395 + * is this node stuck? 20.396 + */ 20.397 + boolean isStuck() { 20.398 + return stuckVars.nonEmpty(); 20.399 + } 20.400 + 20.401 + /** 20.402 + * Process a deferred attribution node. 20.403 + * Invariant: a stuck node cannot be processed. 20.404 + */ 20.405 + void process() { 20.406 + if (isStuck()) { 20.407 + throw new IllegalStateException("Cannot process a stuck deferred node"); 20.408 + } 20.409 + dt.check(resultInfo); 20.410 + } 20.411 + } 20.412 + } 20.413 + 20.414 + /** an empty deferred attribution context - all methods throw exceptions */ 20.415 + final DeferredAttrContext emptyDeferredAttrContext = 20.416 + new DeferredAttrContext(null, null, null, null) { 20.417 + @Override 20.418 + void addDeferredAttrNode(DeferredType dt, ResultInfo ri, List<Type> stuckVars) { 20.419 + Assert.error("Empty deferred context!"); 20.420 + } 20.421 + @Override 20.422 + void complete() { 20.423 + Assert.error("Empty deferred context!"); 20.424 + } 20.425 + }; 20.426 + 20.427 + /** 20.428 + * Map a list of types possibly containing one or more deferred types 20.429 + * into a list of ordinary types. Each deferred type D is mapped into a type T, 20.430 + * where T is computed by retrieving the type that has already been 20.431 + * computed for D during a previous deferred attribution round of the given kind. 20.432 + */ 20.433 + class DeferredTypeMap extends Type.Mapping { 20.434 + 20.435 + DeferredAttrContext deferredAttrContext; 20.436 + 20.437 + protected DeferredTypeMap(AttrMode mode, Symbol msym, MethodResolutionPhase phase) { 20.438 + super(String.format("deferredTypeMap[%s]", mode)); 20.439 + this.deferredAttrContext = new DeferredAttrContext(mode, msym, phase, infer.emptyContext); 20.440 + } 20.441 + 20.442 + protected boolean validState(DeferredType dt) { 20.443 + return dt.mode != null && 20.444 + deferredAttrContext.mode.ordinal() <= dt.mode.ordinal(); 20.445 + } 20.446 + 20.447 + @Override 20.448 + public Type apply(Type t) { 20.449 + if (t.tag != DEFERRED) { 20.450 + return t.map(this); 20.451 + } else { 20.452 + DeferredType dt = (DeferredType)t; 20.453 + Assert.check(validState(dt)); 20.454 + return typeOf(dt); 20.455 + } 20.456 + } 20.457 + 20.458 + protected Type typeOf(DeferredType dt) { 20.459 + switch (deferredAttrContext.mode) { 20.460 + case CHECK: 20.461 + return dt.tree.type == null ? Type.noType : dt.tree.type; 20.462 + case SPECULATIVE: 20.463 + return dt.speculativeType(deferredAttrContext.msym, deferredAttrContext.phase); 20.464 + } 20.465 + Assert.error(); 20.466 + return null; 20.467 + } 20.468 + } 20.469 + 20.470 + /** 20.471 + * Specialized recovery deferred mapping. 20.472 + * Each deferred type D is mapped into a type T, where T is computed either by 20.473 + * (i) retrieving the type that has already been computed for D during a previous 20.474 + * attribution round (as before), or (ii) by synthesizing a new type R for D 20.475 + * (the latter step is useful in a recovery scenario). 20.476 + */ 20.477 + public class RecoveryDeferredTypeMap extends DeferredTypeMap { 20.478 + 20.479 + public RecoveryDeferredTypeMap(AttrMode mode, Symbol msym, MethodResolutionPhase phase) { 20.480 + super(mode, msym, phase); 20.481 + } 20.482 + 20.483 + @Override 20.484 + protected Type typeOf(DeferredType dt) { 20.485 + Type owntype = super.typeOf(dt); 20.486 + return owntype.tag == NONE ? 20.487 + recover(dt) : owntype; 20.488 + } 20.489 + 20.490 + @Override 20.491 + protected boolean validState(DeferredType dt) { 20.492 + return true; 20.493 + } 20.494 + 20.495 + /** 20.496 + * Synthesize a type for a deferred type that hasn't been previously 20.497 + * reduced to an ordinary type. Functional deferred types and conditionals 20.498 + * are mapped to themselves, in order to have a richer diagnostic 20.499 + * representation. Remaining deferred types are attributed using 20.500 + * a default expected type (j.l.Object). 20.501 + */ 20.502 + private Type recover(DeferredType dt) { 20.503 + dt.check(attr.new RecoveryInfo(deferredAttrContext)); 20.504 + switch (TreeInfo.skipParens(dt.tree).getTag()) { 20.505 + case LAMBDA: 20.506 + case REFERENCE: 20.507 + case CONDEXPR: 20.508 + //propagate those deferred types to the 20.509 + //diagnostic formatter 20.510 + return dt; 20.511 + default: 20.512 + return super.apply(dt); 20.513 + } 20.514 + } 20.515 + } 20.516 + 20.517 + /** 20.518 + * Retrieves the list of inference variables that need to be inferred before 20.519 + * an AST node can be type-checked 20.520 + */ 20.521 + @SuppressWarnings("fallthrough") 20.522 + List<Type> stuckVars(JCTree tree, ResultInfo resultInfo) { 20.523 + if (resultInfo.pt.tag == NONE || resultInfo.pt.isErroneous()) { 20.524 + return List.nil(); 20.525 + } else { 20.526 + StuckChecker sc = new StuckChecker(resultInfo); 20.527 + sc.scan(tree); 20.528 + return List.from(sc.stuckVars); 20.529 + } 20.530 + } 20.531 + 20.532 + /** 20.533 + * This visitor is used to check that structural expressions conform 20.534 + * to their target - this step is required as inference could end up 20.535 + * inferring types that make some of the nested expressions incompatible 20.536 + * with their corresponding instantiated target 20.537 + */ 20.538 + class StuckChecker extends TreeScanner { 20.539 + 20.540 + Type pt; 20.541 + Filter<JCTree> treeFilter; 20.542 + Infer.InferenceContext inferenceContext; 20.543 + Set<Type> stuckVars = new HashSet<Type>(); 20.544 + 20.545 + final Filter<JCTree> argsFilter = new Filter<JCTree>() { 20.546 + public boolean accepts(JCTree t) { 20.547 + switch (t.getTag()) { 20.548 + case CONDEXPR: 20.549 + case LAMBDA: 20.550 + case PARENS: 20.551 + case REFERENCE: 20.552 + return true; 20.553 + default: 20.554 + return false; 20.555 + } 20.556 + } 20.557 + }; 20.558 + 20.559 + final Filter<JCTree> lambdaBodyFilter = new Filter<JCTree>() { 20.560 + public boolean accepts(JCTree t) { 20.561 + switch (t.getTag()) { 20.562 + case BLOCK: case CASE: case CATCH: case DOLOOP: 20.563 + case FOREACHLOOP: case FORLOOP: case RETURN: 20.564 + case SYNCHRONIZED: case SWITCH: case TRY: case WHILELOOP: 20.565 + return true; 20.566 + default: 20.567 + return false; 20.568 + } 20.569 + } 20.570 + }; 20.571 + 20.572 + StuckChecker(ResultInfo resultInfo) { 20.573 + this.pt = resultInfo.pt; 20.574 + this.inferenceContext = resultInfo.checkContext.inferenceContext(); 20.575 + this.treeFilter = argsFilter; 20.576 + } 20.577 + 20.578 + @Override 20.579 + public void scan(JCTree tree) { 20.580 + if (tree != null && treeFilter.accepts(tree)) { 20.581 + super.scan(tree); 20.582 + } 20.583 + } 20.584 + 20.585 + @Override 20.586 + public void visitLambda(JCLambda tree) { 20.587 + Type prevPt = pt; 20.588 + Filter<JCTree> prevFilter = treeFilter; 20.589 + try { 20.590 + if (inferenceContext.inferenceVars().contains(pt)) { 20.591 + stuckVars.add(pt); 20.592 + } 20.593 + if (!types.isFunctionalInterface(pt.tsym)) { 20.594 + return; 20.595 + } 20.596 + Type descType = types.findDescriptorType(pt); 20.597 + List<Type> freeArgVars = inferenceContext.freeVarsIn(descType.getParameterTypes()); 20.598 + if (!TreeInfo.isExplicitLambda(tree) && 20.599 + freeArgVars.nonEmpty()) { 20.600 + stuckVars.addAll(freeArgVars); 20.601 + } 20.602 + pt = descType.getReturnType(); 20.603 + if (tree.getBodyKind() == JCTree.JCLambda.BodyKind.EXPRESSION) { 20.604 + scan(tree.getBody()); 20.605 + } else { 20.606 + treeFilter = lambdaBodyFilter; 20.607 + super.visitLambda(tree); 20.608 + } 20.609 + } finally { 20.610 + pt = prevPt; 20.611 + treeFilter = prevFilter; 20.612 + } 20.613 + } 20.614 + 20.615 + @Override 20.616 + public void visitReference(JCMemberReference tree) { 20.617 + scan(tree.expr); 20.618 + if (inferenceContext.inferenceVars().contains(pt)) { 20.619 + stuckVars.add(pt); 20.620 + return; 20.621 + } 20.622 + if (!types.isFunctionalInterface(pt.tsym)) { 20.623 + return; 20.624 + } 20.625 + Type descType = types.findDescriptorType(pt); 20.626 + List<Type> freeArgVars = inferenceContext.freeVarsIn(descType.getParameterTypes()); 20.627 + stuckVars.addAll(freeArgVars); 20.628 + } 20.629 + 20.630 + @Override 20.631 + public void visitReturn(JCReturn tree) { 20.632 + Filter<JCTree> prevFilter = treeFilter; 20.633 + try { 20.634 + treeFilter = argsFilter; 20.635 + if (tree.expr != null) { 20.636 + scan(tree.expr); 20.637 + } 20.638 + } finally { 20.639 + treeFilter = prevFilter; 20.640 + } 20.641 + } 20.642 + } 20.643 +}
21.1 --- a/src/share/classes/com/sun/tools/javac/comp/Flow.java Thu Oct 11 09:50:52 2012 -0700 21.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Flow.java Thu Oct 11 17:00:54 2012 -0700 21.3 @@ -50,8 +50,8 @@ 21.4 * (see AssignAnalyzer) ensures that each variable is assigned when used. Definite 21.5 * unassignment analysis (see AssignAnalyzer) in ensures that no final variable 21.6 * is assigned more than once. Finally, local variable capture analysis (see CaptureAnalyzer) 21.7 - * determines that local variables accessed within the scope of an inner class are 21.8 - * either final or effectively-final. 21.9 + * determines that local variables accessed within the scope of an inner class/lambda 21.10 + * are either final or effectively-final. 21.11 * 21.12 * <p>The JLS has a number of problems in the 21.13 * specification of these flow analysis problems. This implementation 21.14 @@ -211,6 +211,29 @@ 21.15 new CaptureAnalyzer().analyzeTree(env, make); 21.16 } 21.17 21.18 + public void analyzeLambda(Env<AttrContext> env, JCLambda that, TreeMaker make, boolean speculative) { 21.19 + java.util.Queue<JCDiagnostic> prevDeferredDiagnostics = log.deferredDiagnostics; 21.20 + Filter<JCDiagnostic> prevDeferDiagsFilter = log.deferredDiagFilter; 21.21 + //we need to disable diagnostics temporarily; the problem is that if 21.22 + //a lambda expression contains e.g. an unreachable statement, an error 21.23 + //message will be reported and will cause compilation to skip the flow analyis 21.24 + //step - if we suppress diagnostics, we won't stop at Attr for flow-analysis 21.25 + //related errors, which will allow for more errors to be detected 21.26 + if (!speculative) { 21.27 + log.deferAll(); 21.28 + log.deferredDiagnostics = ListBuffer.lb(); 21.29 + } 21.30 + try { 21.31 + new AliveAnalyzer().analyzeTree(env, that, make); 21.32 + new FlowAnalyzer().analyzeTree(env, that, make); 21.33 + } finally { 21.34 + if (!speculative) { 21.35 + log.deferredDiagFilter = prevDeferDiagsFilter; 21.36 + log.deferredDiagnostics = prevDeferredDiagnostics; 21.37 + } 21.38 + } 21.39 + } 21.40 + 21.41 /** 21.42 * Definite assignment scan mode 21.43 */ 21.44 @@ -659,6 +682,27 @@ 21.45 } 21.46 } 21.47 21.48 + @Override 21.49 + public void visitLambda(JCLambda tree) { 21.50 + if (tree.type != null && 21.51 + tree.type.isErroneous()) { 21.52 + return; 21.53 + } 21.54 + 21.55 + ListBuffer<PendingExit> prevPending = pendingExits; 21.56 + boolean prevAlive = alive; 21.57 + try { 21.58 + pendingExits = ListBuffer.lb(); 21.59 + alive = true; 21.60 + scanStat(tree.body); 21.61 + tree.canCompleteNormally = alive; 21.62 + } 21.63 + finally { 21.64 + pendingExits = prevPending; 21.65 + alive = prevAlive; 21.66 + } 21.67 + } 21.68 + 21.69 public void visitTopLevel(JCCompilationUnit tree) { 21.70 // Do nothing for TopLevel since each class is visited individually 21.71 } 21.72 @@ -670,6 +714,9 @@ 21.73 /** Perform definite assignment/unassignment analysis on a tree. 21.74 */ 21.75 public void analyzeTree(Env<AttrContext> env, TreeMaker make) { 21.76 + analyzeTree(env, env.tree, make); 21.77 + } 21.78 + public void analyzeTree(Env<AttrContext> env, JCTree tree, TreeMaker make) { 21.79 try { 21.80 attrEnv = env; 21.81 Flow.this.make = make; 21.82 @@ -1185,6 +1232,29 @@ 21.83 } 21.84 } 21.85 21.86 + @Override 21.87 + public void visitLambda(JCLambda tree) { 21.88 + if (tree.type != null && 21.89 + tree.type.isErroneous()) { 21.90 + return; 21.91 + } 21.92 + List<Type> prevCaught = caught; 21.93 + List<Type> prevThrown = thrown; 21.94 + ListBuffer<FlowPendingExit> prevPending = pendingExits; 21.95 + try { 21.96 + pendingExits = ListBuffer.lb(); 21.97 + caught = List.of(syms.throwableType); //inhibit exception checking 21.98 + thrown = List.nil(); 21.99 + scan(tree.body); 21.100 + tree.inferredThrownTypes = thrown; 21.101 + } 21.102 + finally { 21.103 + pendingExits = prevPending; 21.104 + caught = prevCaught; 21.105 + thrown = prevThrown; 21.106 + } 21.107 + } 21.108 + 21.109 public void visitTopLevel(JCCompilationUnit tree) { 21.110 // Do nothing for TopLevel since each class is visited individually 21.111 } 21.112 @@ -1267,6 +1337,10 @@ 21.113 */ 21.114 int nextadr; 21.115 21.116 + /** The first variable sequence number in a block that can return. 21.117 + */ 21.118 + int returnadr; 21.119 + 21.120 /** The list of unreferenced automatic resources. 21.121 */ 21.122 Scope unrefdResources; 21.123 @@ -1296,8 +1370,8 @@ 21.124 21.125 @Override 21.126 void markDead() { 21.127 - inits.inclRange(firstadr, nextadr); 21.128 - uninits.inclRange(firstadr, nextadr); 21.129 + inits.inclRange(returnadr, nextadr); 21.130 + uninits.inclRange(returnadr, nextadr); 21.131 } 21.132 21.133 /*-------------- Processing variables ----------------------*/ 21.134 @@ -1318,11 +1392,7 @@ 21.135 * index into the vars array. 21.136 */ 21.137 void newVar(VarSymbol sym) { 21.138 - if (nextadr == vars.length) { 21.139 - VarSymbol[] newvars = new VarSymbol[nextadr * 2]; 21.140 - System.arraycopy(vars, 0, newvars, 0, nextadr); 21.141 - vars = newvars; 21.142 - } 21.143 + vars = ArrayUtils.ensureCapacity(vars, nextadr); 21.144 if ((sym.flags() & FINAL) == 0) { 21.145 sym.flags_field |= EFFECTIVELY_FINAL; 21.146 } 21.147 @@ -1556,6 +1626,7 @@ 21.148 Bits uninitsPrev = uninits.dup(); 21.149 int nextadrPrev = nextadr; 21.150 int firstadrPrev = firstadr; 21.151 + int returnadrPrev = returnadr; 21.152 Lint lintPrev = lint; 21.153 21.154 lint = lint.augment(tree.sym.annotations); 21.155 @@ -1600,6 +1671,7 @@ 21.156 uninits = uninitsPrev; 21.157 nextadr = nextadrPrev; 21.158 firstadr = firstadrPrev; 21.159 + returnadr = returnadrPrev; 21.160 lint = lintPrev; 21.161 } 21.162 } 21.163 @@ -1984,6 +2056,35 @@ 21.164 scan(tree.def); 21.165 } 21.166 21.167 + @Override 21.168 + public void visitLambda(JCLambda tree) { 21.169 + Bits prevUninits = uninits; 21.170 + Bits prevInits = inits; 21.171 + int returnadrPrev = returnadr; 21.172 + ListBuffer<AssignPendingExit> prevPending = pendingExits; 21.173 + try { 21.174 + returnadr = nextadr; 21.175 + pendingExits = new ListBuffer<AssignPendingExit>(); 21.176 + for (List<JCVariableDecl> l = tree.params; l.nonEmpty(); l = l.tail) { 21.177 + JCVariableDecl def = l.head; 21.178 + scan(def); 21.179 + inits.incl(def.sym.adr); 21.180 + uninits.excl(def.sym.adr); 21.181 + } 21.182 + if (tree.getBodyKind() == JCLambda.BodyKind.EXPRESSION) { 21.183 + scanExpr(tree.body); 21.184 + } else { 21.185 + scan(tree.body); 21.186 + } 21.187 + } 21.188 + finally { 21.189 + returnadr = returnadrPrev; 21.190 + uninits = prevUninits; 21.191 + inits = prevInits; 21.192 + pendingExits = prevPending; 21.193 + } 21.194 + } 21.195 + 21.196 public void visitNewArray(JCNewArray tree) { 21.197 scanExprs(tree.dims); 21.198 scanExprs(tree.elems);
22.1 --- a/src/share/classes/com/sun/tools/javac/comp/Infer.java Thu Oct 11 09:50:52 2012 -0700 22.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Infer.java Thu Oct 11 17:00:54 2012 -0700 22.3 @@ -25,18 +25,24 @@ 22.4 22.5 package com.sun.tools.javac.comp; 22.6 22.7 +import com.sun.tools.javac.code.*; 22.8 +import com.sun.tools.javac.code.Symbol.*; 22.9 +import com.sun.tools.javac.code.Type.*; 22.10 +import com.sun.tools.javac.code.Type.UndetVar.InferenceBound; 22.11 +import com.sun.tools.javac.comp.DeferredAttr.AttrMode; 22.12 +import com.sun.tools.javac.comp.Resolve.InapplicableMethodException; 22.13 +import com.sun.tools.javac.comp.Resolve.VerboseResolutionMode; 22.14 import com.sun.tools.javac.tree.JCTree; 22.15 import com.sun.tools.javac.tree.JCTree.JCTypeCast; 22.16 import com.sun.tools.javac.tree.TreeInfo; 22.17 import com.sun.tools.javac.util.*; 22.18 import com.sun.tools.javac.util.List; 22.19 -import com.sun.tools.javac.code.*; 22.20 -import com.sun.tools.javac.code.Type.*; 22.21 -import com.sun.tools.javac.code.Symbol.*; 22.22 -import com.sun.tools.javac.comp.Resolve.InapplicableMethodException; 22.23 -import com.sun.tools.javac.comp.Resolve.VerboseResolutionMode; 22.24 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; 22.25 22.26 +import java.util.HashMap; 22.27 +import java.util.Map; 22.28 +import java.util.Set; 22.29 + 22.30 import static com.sun.tools.javac.code.TypeTags.*; 22.31 22.32 /** Helper class for type parameter inference, used by the attribution phase. 22.33 @@ -57,6 +63,7 @@ 22.34 Types types; 22.35 Check chk; 22.36 Resolve rs; 22.37 + DeferredAttr deferredAttr; 22.38 Log log; 22.39 JCDiagnostic.Factory diags; 22.40 22.41 @@ -72,55 +79,54 @@ 22.42 syms = Symtab.instance(context); 22.43 types = Types.instance(context); 22.44 rs = Resolve.instance(context); 22.45 + deferredAttr = DeferredAttr.instance(context); 22.46 log = Log.instance(context); 22.47 chk = Check.instance(context); 22.48 diags = JCDiagnostic.Factory.instance(context); 22.49 inferenceException = new InferenceException(diags); 22.50 - 22.51 } 22.52 22.53 + /** 22.54 + * This exception class is design to store a list of diagnostics corresponding 22.55 + * to inference errors that can arise during a method applicability check. 22.56 + */ 22.57 public static class InferenceException extends InapplicableMethodException { 22.58 private static final long serialVersionUID = 0; 22.59 22.60 + List<JCDiagnostic> messages = List.nil(); 22.61 + 22.62 InferenceException(JCDiagnostic.Factory diags) { 22.63 super(diags); 22.64 } 22.65 + 22.66 + @Override 22.67 + InapplicableMethodException setMessage(JCDiagnostic diag) { 22.68 + messages = messages.append(diag); 22.69 + return this; 22.70 + } 22.71 + 22.72 + @Override 22.73 + public JCDiagnostic getDiagnostic() { 22.74 + return messages.head; 22.75 + } 22.76 + 22.77 + void clear() { 22.78 + messages = List.nil(); 22.79 + } 22.80 } 22.81 22.82 private final InferenceException inferenceException; 22.83 22.84 /*************************************************************************** 22.85 - * Auxiliary type values and classes 22.86 - ***************************************************************************/ 22.87 - 22.88 - /** A mapping that turns type variables into undetermined type variables. 22.89 - */ 22.90 - List<Type> makeUndetvars(List<Type> tvars) { 22.91 - List<Type> undetvars = Type.map(tvars, fromTypeVarFun); 22.92 - for (Type t : undetvars) { 22.93 - UndetVar uv = (UndetVar)t; 22.94 - uv.hibounds = types.getBounds((TypeVar)uv.qtype); 22.95 - } 22.96 - return undetvars; 22.97 - } 22.98 - //where 22.99 - Mapping fromTypeVarFun = new Mapping("fromTypeVarFun") { 22.100 - public Type apply(Type t) { 22.101 - if (t.tag == TYPEVAR) return new UndetVar(t); 22.102 - else return t.map(this); 22.103 - } 22.104 - }; 22.105 - 22.106 -/*************************************************************************** 22.107 * Mini/Maximization of UndetVars 22.108 ***************************************************************************/ 22.109 22.110 /** Instantiate undetermined type variable to its minimal upper bound. 22.111 * Throw a NoInstanceException if this not possible. 22.112 */ 22.113 - void maximizeInst(UndetVar that, Warner warn) throws InferenceException { 22.114 - List<Type> hibounds = Type.filter(that.hibounds, errorFilter); 22.115 - if (that.eq.isEmpty()) { 22.116 + void maximizeInst(UndetVar that, Warner warn) throws InferenceException { 22.117 + List<Type> hibounds = Type.filter(that.getBounds(InferenceBound.UPPER), boundFilter); 22.118 + if (that.getBounds(InferenceBound.EQ).isEmpty()) { 22.119 if (hibounds.isEmpty()) 22.120 that.inst = syms.objectType; 22.121 else if (hibounds.tail.isEmpty()) 22.122 @@ -128,7 +134,7 @@ 22.123 else 22.124 that.inst = types.glb(hibounds); 22.125 } else { 22.126 - that.inst = that.eq.head; 22.127 + that.inst = that.getBounds(InferenceBound.EQ).head; 22.128 } 22.129 if (that.inst == null || 22.130 that.inst.isErroneous()) 22.131 @@ -137,10 +143,10 @@ 22.132 that.qtype, hibounds); 22.133 } 22.134 22.135 - private Filter<Type> errorFilter = new Filter<Type>() { 22.136 + private Filter<Type> boundFilter = new Filter<Type>() { 22.137 @Override 22.138 public boolean accepts(Type t) { 22.139 - return !t.isErroneous(); 22.140 + return !t.isErroneous() && t.tag != BOT; 22.141 } 22.142 }; 22.143 22.144 @@ -148,11 +154,12 @@ 22.145 * Throw a NoInstanceException if this not possible. 22.146 */ 22.147 void minimizeInst(UndetVar that, Warner warn) throws InferenceException { 22.148 - List<Type> lobounds = Type.filter(that.lobounds, errorFilter); 22.149 - if (that.eq.isEmpty()) { 22.150 - if (lobounds.isEmpty()) 22.151 - that.inst = syms.botType; 22.152 - else if (lobounds.tail.isEmpty()) 22.153 + List<Type> lobounds = Type.filter(that.getBounds(InferenceBound.LOWER), boundFilter); 22.154 + if (that.getBounds(InferenceBound.EQ).isEmpty()) { 22.155 + if (lobounds.isEmpty()) { 22.156 + //do nothing - the inference variable is under-constrained 22.157 + return; 22.158 + } else if (lobounds.tail.isEmpty()) 22.159 that.inst = lobounds.head.isPrimitive() ? syms.errType : lobounds.head; 22.160 else { 22.161 that.inst = types.lub(lobounds); 22.162 @@ -162,120 +169,99 @@ 22.163 .setMessage("no.unique.minimal.instance.exists", 22.164 that.qtype, lobounds); 22.165 } else { 22.166 - that.inst = that.eq.head; 22.167 + that.inst = that.getBounds(InferenceBound.EQ).head; 22.168 } 22.169 } 22.170 22.171 - Type asUndetType(Type t, List<Type> undetvars) { 22.172 - return types.subst(t, inferenceVars(undetvars), undetvars); 22.173 - } 22.174 - 22.175 - List<Type> inferenceVars(List<Type> undetvars) { 22.176 - ListBuffer<Type> tvars = ListBuffer.lb(); 22.177 - for (Type uv : undetvars) { 22.178 - tvars.append(((UndetVar)uv).qtype); 22.179 - } 22.180 - return tvars.toList(); 22.181 - } 22.182 - 22.183 /*************************************************************************** 22.184 * Exported Methods 22.185 ***************************************************************************/ 22.186 22.187 - /** Try to instantiate expression type `that' to given type `to'. 22.188 - * If a maximal instantiation exists which makes this type 22.189 - * a subtype of type `to', return the instantiated type. 22.190 - * If no instantiation exists, or if several incomparable 22.191 - * best instantiations exist throw a NoInstanceException. 22.192 + /** 22.193 + * Instantiate uninferred inference variables (JLS 15.12.2.8). First 22.194 + * if the method return type is non-void, we derive constraints from the 22.195 + * expected type - then we use declared bound well-formedness to derive additional 22.196 + * constraints. If no instantiation exists, or if several incomparable 22.197 + * best instantiations exist throw a NoInstanceException. 22.198 */ 22.199 - public List<Type> instantiateUninferred(DiagnosticPosition pos, 22.200 - List<Type> undetvars, 22.201 - List<Type> tvars, 22.202 - MethodType mtype, 22.203 - Attr.ResultInfo resultInfo, 22.204 - Warner warn) throws InferenceException { 22.205 + public void instantiateUninferred(DiagnosticPosition pos, 22.206 + InferenceContext inferenceContext, 22.207 + MethodType mtype, 22.208 + Attr.ResultInfo resultInfo, 22.209 + Warner warn) throws InferenceException { 22.210 Type to = resultInfo.pt; 22.211 - if (to.tag == NONE) { 22.212 + if (to.tag == NONE || resultInfo.checkContext.inferenceContext().free(resultInfo.pt)) { 22.213 to = mtype.getReturnType().tag <= VOID ? 22.214 mtype.getReturnType() : syms.objectType; 22.215 } 22.216 - Type qtype1 = types.subst(mtype.getReturnType(), tvars, undetvars); 22.217 + Type qtype1 = inferenceContext.asFree(mtype.getReturnType(), types); 22.218 if (!types.isSubtype(qtype1, 22.219 qtype1.tag == UNDETVAR ? types.boxedTypeOrType(to) : to)) { 22.220 throw inferenceException 22.221 - .setMessage("infer.no.conforming.instance.exists", 22.222 - tvars, mtype.getReturnType(), to); 22.223 + .setMessage("infer.no.conforming.instance.exists", 22.224 + inferenceContext.restvars(), mtype.getReturnType(), to); 22.225 } 22.226 22.227 - List<Type> insttypes; 22.228 while (true) { 22.229 boolean stuck = true; 22.230 - insttypes = List.nil(); 22.231 - for (Type t : undetvars) { 22.232 + for (Type t : inferenceContext.undetvars) { 22.233 UndetVar uv = (UndetVar)t; 22.234 - if (uv.inst == null && (uv.eq.nonEmpty() || !Type.containsAny(uv.hibounds, tvars))) { 22.235 + if (uv.inst == null && (uv.getBounds(InferenceBound.EQ).nonEmpty() || 22.236 + !inferenceContext.free(uv.getBounds(InferenceBound.UPPER)))) { 22.237 maximizeInst((UndetVar)t, warn); 22.238 stuck = false; 22.239 } 22.240 - insttypes = insttypes.append(uv.inst == null ? uv.qtype : uv.inst); 22.241 } 22.242 - if (!Type.containsAny(insttypes, tvars)) { 22.243 + if (inferenceContext.restvars().isEmpty()) { 22.244 //all variables have been instantiated - exit 22.245 break; 22.246 } else if (stuck) { 22.247 //some variables could not be instantiated because of cycles in 22.248 //upper bounds - provide a (possibly recursive) default instantiation 22.249 - insttypes = types.subst(insttypes, 22.250 - tvars, 22.251 - instantiateAsUninferredVars(undetvars, tvars)); 22.252 + instantiateAsUninferredVars(inferenceContext); 22.253 break; 22.254 } else { 22.255 //some variables have been instantiated - replace newly instantiated 22.256 //variables in remaining upper bounds and continue 22.257 - for (Type t : undetvars) { 22.258 + for (Type t : inferenceContext.undetvars) { 22.259 UndetVar uv = (UndetVar)t; 22.260 - uv.hibounds = types.subst(uv.hibounds, tvars, insttypes); 22.261 + uv.substBounds(inferenceContext.inferenceVars(), inferenceContext.instTypes(), types); 22.262 } 22.263 } 22.264 } 22.265 - return insttypes; 22.266 } 22.267 22.268 /** 22.269 * Infer cyclic inference variables as described in 15.12.2.8. 22.270 */ 22.271 - private List<Type> instantiateAsUninferredVars(List<Type> undetvars, List<Type> tvars) { 22.272 - Assert.check(undetvars.length() == tvars.length()); 22.273 - ListBuffer<Type> insttypes = ListBuffer.lb(); 22.274 + private void instantiateAsUninferredVars(InferenceContext inferenceContext) { 22.275 ListBuffer<Type> todo = ListBuffer.lb(); 22.276 //step 1 - create fresh tvars 22.277 - for (Type t : undetvars) { 22.278 + for (Type t : inferenceContext.undetvars) { 22.279 UndetVar uv = (UndetVar)t; 22.280 if (uv.inst == null) { 22.281 TypeSymbol fresh_tvar = new TypeSymbol(Flags.SYNTHETIC, uv.qtype.tsym.name, null, uv.qtype.tsym.owner); 22.282 - fresh_tvar.type = new TypeVar(fresh_tvar, types.makeCompoundType(uv.hibounds), null); 22.283 + fresh_tvar.type = new TypeVar(fresh_tvar, types.makeCompoundType(uv.getBounds(InferenceBound.UPPER)), null); 22.284 todo.append(uv); 22.285 uv.inst = fresh_tvar.type; 22.286 } 22.287 - insttypes.append(uv.inst); 22.288 } 22.289 //step 2 - replace fresh tvars in their bounds 22.290 - List<Type> formals = tvars; 22.291 + List<Type> formals = inferenceContext.inferenceVars(); 22.292 for (Type t : todo) { 22.293 UndetVar uv = (UndetVar)t; 22.294 TypeVar ct = (TypeVar)uv.inst; 22.295 - ct.bound = types.glb(types.subst(types.getBounds(ct), tvars, insttypes.toList())); 22.296 + ct.bound = types.glb(inferenceContext.asInstTypes(types.getBounds(ct), types)); 22.297 if (ct.bound.isErroneous()) { 22.298 //report inference error if glb fails 22.299 reportBoundError(uv, BoundErrorKind.BAD_UPPER); 22.300 } 22.301 formals = formals.tail; 22.302 } 22.303 - return insttypes.toList(); 22.304 } 22.305 22.306 - /** Instantiate method type `mt' by finding instantiations of 22.307 - * `tvars' so that method can be applied to `argtypes'. 22.308 + /** Instantiate a generic method type by finding instantiations for all its 22.309 + * inference variables so that it can be applied to a given argument type list. 22.310 */ 22.311 public Type instantiateMethod(Env<AttrContext> env, 22.312 List<Type> tvars, 22.313 @@ -285,85 +271,65 @@ 22.314 List<Type> argtypes, 22.315 boolean allowBoxing, 22.316 boolean useVarargs, 22.317 + Resolve.MethodResolutionContext resolveContext, 22.318 Warner warn) throws InferenceException { 22.319 //-System.err.println("instantiateMethod(" + tvars + ", " + mt + ", " + argtypes + ")"); //DEBUG 22.320 - List<Type> undetvars = makeUndetvars(tvars); 22.321 + final InferenceContext inferenceContext = new InferenceContext(tvars, this, true); 22.322 + inferenceException.clear(); 22.323 22.324 - List<Type> capturedArgs = 22.325 - rs.checkRawArgumentsAcceptable(env, undetvars, argtypes, mt.getParameterTypes(), 22.326 - allowBoxing, useVarargs, warn, new InferenceCheckHandler(undetvars)); 22.327 + try { 22.328 + rs.checkRawArgumentsAcceptable(env, msym, resolveContext.attrMode(), inferenceContext, 22.329 + argtypes, mt.getParameterTypes(), allowBoxing, useVarargs, warn, 22.330 + new InferenceCheckHandler(inferenceContext)); 22.331 22.332 - // minimize as yet undetermined type variables 22.333 - for (Type t : undetvars) 22.334 - minimizeInst((UndetVar) t, warn); 22.335 + // minimize as yet undetermined type variables 22.336 + for (Type t : inferenceContext.undetvars) { 22.337 + minimizeInst((UndetVar)t, warn); 22.338 + } 22.339 22.340 - /** Type variables instantiated to bottom */ 22.341 - ListBuffer<Type> restvars = new ListBuffer<Type>(); 22.342 + checkWithinBounds(inferenceContext, warn); 22.343 22.344 - /** Undet vars instantiated to bottom */ 22.345 - final ListBuffer<Type> restundet = new ListBuffer<Type>(); 22.346 + mt = (MethodType)inferenceContext.asInstType(mt, types); 22.347 22.348 - /** Instantiated types or TypeVars if under-constrained */ 22.349 - ListBuffer<Type> insttypes = new ListBuffer<Type>(); 22.350 + List<Type> restvars = inferenceContext.restvars(); 22.351 22.352 - /** Instantiated types or UndetVars if under-constrained */ 22.353 - ListBuffer<Type> undettypes = new ListBuffer<Type>(); 22.354 + if (!restvars.isEmpty()) { 22.355 + if (resultInfo != null && !warn.hasNonSilentLint(Lint.LintCategory.UNCHECKED)) { 22.356 + instantiateUninferred(env.tree.pos(), inferenceContext, mt, resultInfo, warn); 22.357 + checkWithinBounds(inferenceContext, warn); 22.358 + mt = (MethodType)inferenceContext.asInstType(mt, types); 22.359 + if (rs.verboseResolutionMode.contains(VerboseResolutionMode.DEFERRED_INST)) { 22.360 + log.note(env.tree.pos, "deferred.method.inst", msym, mt, resultInfo.pt); 22.361 + } 22.362 + } 22.363 + } 22.364 22.365 - for (Type t : undetvars) { 22.366 - UndetVar uv = (UndetVar)t; 22.367 - if (uv.inst.tag == BOT) { 22.368 - restvars.append(uv.qtype); 22.369 - restundet.append(uv); 22.370 - insttypes.append(uv.qtype); 22.371 - undettypes.append(uv); 22.372 - uv.inst = null; 22.373 - } else { 22.374 - insttypes.append(uv.inst); 22.375 - undettypes.append(uv.inst); 22.376 - } 22.377 + // return instantiated version of method type 22.378 + return mt; 22.379 + } finally { 22.380 + inferenceContext.notifyChange(types); 22.381 } 22.382 - checkWithinBounds(tvars, undetvars, insttypes.toList(), warn); 22.383 - 22.384 - mt = (MethodType)types.subst(mt, tvars, insttypes.toList()); 22.385 - 22.386 - if (!restvars.isEmpty() && resultInfo != null) { 22.387 - List<Type> restInferred = 22.388 - instantiateUninferred(env.tree.pos(), restundet.toList(), restvars.toList(), mt, resultInfo, warn); 22.389 - checkWithinBounds(tvars, undetvars, 22.390 - types.subst(insttypes.toList(), restvars.toList(), restInferred), warn); 22.391 - mt = (MethodType)types.subst(mt, restvars.toList(), restInferred); 22.392 - if (rs.verboseResolutionMode.contains(VerboseResolutionMode.DEFERRED_INST)) { 22.393 - log.note(env.tree.pos, "deferred.method.inst", msym, mt, resultInfo.pt); 22.394 - } 22.395 - } 22.396 - 22.397 - if (restvars.isEmpty() || resultInfo != null) { 22.398 - // check that actuals conform to inferred formals 22.399 - checkArgumentsAcceptable(env, capturedArgs, mt.getParameterTypes(), allowBoxing, useVarargs, warn); 22.400 - } 22.401 - // return instantiated version of method type 22.402 - return mt; 22.403 } 22.404 //where 22.405 22.406 /** inference check handler **/ 22.407 class InferenceCheckHandler implements Resolve.MethodCheckHandler { 22.408 22.409 - List<Type> undetvars; 22.410 + InferenceContext inferenceContext; 22.411 22.412 - public InferenceCheckHandler(List<Type> undetvars) { 22.413 - this.undetvars = undetvars; 22.414 + public InferenceCheckHandler(InferenceContext inferenceContext) { 22.415 + this.inferenceContext = inferenceContext; 22.416 } 22.417 22.418 public InapplicableMethodException arityMismatch() { 22.419 - return inferenceException.setMessage("infer.arg.length.mismatch", inferenceVars(undetvars)); 22.420 + return inferenceException.setMessage("infer.arg.length.mismatch", inferenceContext.inferenceVars()); 22.421 } 22.422 public InapplicableMethodException argumentMismatch(boolean varargs, JCDiagnostic details) { 22.423 String key = varargs ? 22.424 "infer.varargs.argument.mismatch" : 22.425 "infer.no.conforming.assignment.exists"; 22.426 return inferenceException.setMessage(key, 22.427 - inferenceVars(undetvars), details); 22.428 + inferenceContext.inferenceVars(), details); 22.429 } 22.430 public InapplicableMethodException inaccessibleVarargs(Symbol location, Type expected) { 22.431 return inferenceException.setMessage("inaccessible.varargs.type", 22.432 @@ -371,51 +337,61 @@ 22.433 } 22.434 } 22.435 22.436 - private void checkArgumentsAcceptable(Env<AttrContext> env, List<Type> actuals, List<Type> formals, 22.437 - boolean allowBoxing, boolean useVarargs, Warner warn) { 22.438 - try { 22.439 - rs.checkRawArgumentsAcceptable(env, actuals, formals, 22.440 - allowBoxing, useVarargs, warn); 22.441 - } 22.442 - catch (InapplicableMethodException ex) { 22.443 - // inferred method is not applicable 22.444 - throw inferenceException.setMessage(ex.getDiagnostic()); 22.445 - } 22.446 - } 22.447 - 22.448 /** check that type parameters are within their bounds. 22.449 */ 22.450 - void checkWithinBounds(List<Type> tvars, 22.451 - List<Type> undetvars, 22.452 - List<Type> arguments, 22.453 - Warner warn) 22.454 - throws InferenceException { 22.455 - List<Type> args = arguments; 22.456 - for (Type t : undetvars) { 22.457 + void checkWithinBounds(InferenceContext inferenceContext, 22.458 + Warner warn) throws InferenceException { 22.459 + //step 1 - check compatibility of instantiated type w.r.t. initial bounds 22.460 + for (Type t : inferenceContext.undetvars) { 22.461 UndetVar uv = (UndetVar)t; 22.462 - uv.hibounds = types.subst(uv.hibounds, tvars, arguments); 22.463 - uv.lobounds = types.subst(uv.lobounds, tvars, arguments); 22.464 - uv.eq = types.subst(uv.eq, tvars, arguments); 22.465 - checkCompatibleUpperBounds(uv, tvars); 22.466 - if (args.head.tag != TYPEVAR || !args.head.containsAny(tvars)) { 22.467 - Type inst = args.head; 22.468 - for (Type u : uv.hibounds) { 22.469 - if (!types.isSubtypeUnchecked(inst, types.subst(u, tvars, undetvars), warn)) { 22.470 + uv.substBounds(inferenceContext.inferenceVars(), inferenceContext.instTypes(), types); 22.471 + checkCompatibleUpperBounds(uv, inferenceContext.inferenceVars()); 22.472 + if (!inferenceContext.restvars().contains(uv.qtype)) { 22.473 + Type inst = inferenceContext.asInstType(t, types); 22.474 + for (Type u : uv.getBounds(InferenceBound.UPPER)) { 22.475 + if (!types.isSubtypeUnchecked(inst, inferenceContext.asFree(u, types), warn)) { 22.476 reportBoundError(uv, BoundErrorKind.UPPER); 22.477 } 22.478 } 22.479 - for (Type l : uv.lobounds) { 22.480 - if (!types.isSubtypeUnchecked(types.subst(l, tvars, undetvars), inst, warn)) { 22.481 + for (Type l : uv.getBounds(InferenceBound.LOWER)) { 22.482 + Assert.check(!inferenceContext.free(l)); 22.483 + if (!types.isSubtypeUnchecked(l, inst, warn)) { 22.484 reportBoundError(uv, BoundErrorKind.LOWER); 22.485 } 22.486 } 22.487 - for (Type e : uv.eq) { 22.488 - if (!types.isSameType(inst, types.subst(e, tvars, undetvars))) { 22.489 + for (Type e : uv.getBounds(InferenceBound.EQ)) { 22.490 + Assert.check(!inferenceContext.free(e)); 22.491 + if (!types.isSameType(inst, e)) { 22.492 reportBoundError(uv, BoundErrorKind.EQ); 22.493 } 22.494 } 22.495 } 22.496 - args = args.tail; 22.497 + } 22.498 + 22.499 + //step 2 - check that eq bounds are consistent w.r.t. eq/lower bounds 22.500 + for (Type t : inferenceContext.undetvars) { 22.501 + UndetVar uv = (UndetVar)t; 22.502 + //check eq bounds consistency 22.503 + Type eq = null; 22.504 + for (Type e : uv.getBounds(InferenceBound.EQ)) { 22.505 + Assert.check(!inferenceContext.free(e)); 22.506 + if (eq != null && !types.isSameType(e, eq)) { 22.507 + reportBoundError(uv, BoundErrorKind.EQ); 22.508 + } 22.509 + eq = e; 22.510 + for (Type l : uv.getBounds(InferenceBound.LOWER)) { 22.511 + Assert.check(!inferenceContext.free(l)); 22.512 + if (!types.isSubtypeUnchecked(l, e, warn)) { 22.513 + reportBoundError(uv, BoundErrorKind.BAD_EQ_LOWER); 22.514 + } 22.515 + } 22.516 + for (Type u : uv.getBounds(InferenceBound.UPPER)) { 22.517 + if (inferenceContext.free(u)) continue; 22.518 + if (!types.isSubtypeUnchecked(e, u, warn)) { 22.519 + reportBoundError(uv, BoundErrorKind.BAD_EQ_UPPER); 22.520 + } 22.521 + } 22.522 + } 22.523 } 22.524 } 22.525 22.526 @@ -423,7 +399,7 @@ 22.527 // VGJ: sort of inlined maximizeInst() below. Adding 22.528 // bounds can cause lobounds that are above hibounds. 22.529 ListBuffer<Type> hiboundsNoVars = ListBuffer.lb(); 22.530 - for (Type t : Type.filter(uv.hibounds, errorFilter)) { 22.531 + for (Type t : Type.filter(uv.getBounds(InferenceBound.UPPER), boundFilter)) { 22.532 if (!t.containsAny(tvars)) { 22.533 hiboundsNoVars.append(t); 22.534 } 22.535 @@ -444,25 +420,43 @@ 22.536 BAD_UPPER() { 22.537 @Override 22.538 InapplicableMethodException setMessage(InferenceException ex, UndetVar uv) { 22.539 - return ex.setMessage("incompatible.upper.bounds", uv.qtype, uv.hibounds); 22.540 + return ex.setMessage("incompatible.upper.bounds", uv.qtype, 22.541 + uv.getBounds(InferenceBound.UPPER)); 22.542 + } 22.543 + }, 22.544 + BAD_EQ_UPPER() { 22.545 + @Override 22.546 + InapplicableMethodException setMessage(InferenceException ex, UndetVar uv) { 22.547 + return ex.setMessage("incompatible.eq.upper.bounds", uv.qtype, 22.548 + uv.getBounds(InferenceBound.EQ), uv.getBounds(InferenceBound.UPPER)); 22.549 + } 22.550 + }, 22.551 + BAD_EQ_LOWER() { 22.552 + @Override 22.553 + InapplicableMethodException setMessage(InferenceException ex, UndetVar uv) { 22.554 + return ex.setMessage("incompatible.eq.lower.bounds", uv.qtype, 22.555 + uv.getBounds(InferenceBound.EQ), uv.getBounds(InferenceBound.LOWER)); 22.556 } 22.557 }, 22.558 UPPER() { 22.559 @Override 22.560 InapplicableMethodException setMessage(InferenceException ex, UndetVar uv) { 22.561 - return ex.setMessage("inferred.do.not.conform.to.upper.bounds", uv.inst, uv.hibounds); 22.562 + return ex.setMessage("inferred.do.not.conform.to.upper.bounds", uv.inst, 22.563 + uv.getBounds(InferenceBound.UPPER)); 22.564 } 22.565 }, 22.566 LOWER() { 22.567 @Override 22.568 InapplicableMethodException setMessage(InferenceException ex, UndetVar uv) { 22.569 - return ex.setMessage("inferred.do.not.conform.to.lower.bounds", uv.inst, uv.lobounds); 22.570 + return ex.setMessage("inferred.do.not.conform.to.lower.bounds", uv.inst, 22.571 + uv.getBounds(InferenceBound.LOWER)); 22.572 } 22.573 }, 22.574 EQ() { 22.575 @Override 22.576 InapplicableMethodException setMessage(InferenceException ex, UndetVar uv) { 22.577 - return ex.setMessage("inferred.do.not.conform.to.eq.bounds", uv.inst, uv.eq); 22.578 + return ex.setMessage("inferred.do.not.conform.to.eq.bounds", uv.inst, 22.579 + uv.getBounds(InferenceBound.EQ)); 22.580 } 22.581 }; 22.582 22.583 @@ -473,6 +467,75 @@ 22.584 throw bk.setMessage(inferenceException, uv); 22.585 } 22.586 22.587 + // <editor-fold desc="functional interface instantiation"> 22.588 + /** 22.589 + * This method is used to infer a suitable target functional interface in case 22.590 + * the original parameterized interface contains wildcards. An inference process 22.591 + * is applied so that wildcard bounds, as well as explicit lambda/method ref parameters 22.592 + * (where applicable) are used to constraint the solution. 22.593 + */ 22.594 + public Type instantiateFunctionalInterface(DiagnosticPosition pos, Type funcInterface, 22.595 + List<Type> paramTypes, Check.CheckContext checkContext) { 22.596 + if (types.capture(funcInterface) == funcInterface) { 22.597 + //if capture doesn't change the type then return the target unchanged 22.598 + //(this means the target contains no wildcards!) 22.599 + return funcInterface; 22.600 + } else { 22.601 + Type formalInterface = funcInterface.tsym.type; 22.602 + InferenceContext funcInterfaceContext = 22.603 + new InferenceContext(funcInterface.tsym.type.getTypeArguments(), this, false); 22.604 + if (paramTypes != null) { 22.605 + //get constraints from explicit params (this is done by 22.606 + //checking that explicit param types are equal to the ones 22.607 + //in the functional interface descriptors) 22.608 + List<Type> descParameterTypes = types.findDescriptorType(formalInterface).getParameterTypes(); 22.609 + if (descParameterTypes.size() != paramTypes.size()) { 22.610 + checkContext.report(pos, diags.fragment("incompatible.arg.types.in.lambda")); 22.611 + return types.createErrorType(funcInterface); 22.612 + } 22.613 + for (Type p : descParameterTypes) { 22.614 + if (!types.isSameType(funcInterfaceContext.asFree(p, types), paramTypes.head)) { 22.615 + checkContext.report(pos, diags.fragment("no.suitable.functional.intf.inst", funcInterface)); 22.616 + return types.createErrorType(funcInterface); 22.617 + } 22.618 + paramTypes = paramTypes.tail; 22.619 + } 22.620 + for (Type t : funcInterfaceContext.undetvars) { 22.621 + UndetVar uv = (UndetVar)t; 22.622 + minimizeInst(uv, Warner.noWarnings); 22.623 + if (uv.inst == null && 22.624 + Type.filter(uv.getBounds(InferenceBound.UPPER), boundFilter).nonEmpty()) { 22.625 + maximizeInst(uv, Warner.noWarnings); 22.626 + } 22.627 + } 22.628 + 22.629 + formalInterface = funcInterfaceContext.asInstType(formalInterface, types); 22.630 + } 22.631 + ListBuffer<Type> typeargs = ListBuffer.lb(); 22.632 + List<Type> actualTypeargs = funcInterface.getTypeArguments(); 22.633 + //for remaining uninferred type-vars in the functional interface type, 22.634 + //simply replace the wildcards with its bound 22.635 + for (Type t : formalInterface.getTypeArguments()) { 22.636 + if (actualTypeargs.head.tag == WILDCARD) { 22.637 + WildcardType wt = (WildcardType)actualTypeargs.head; 22.638 + typeargs.append(wt.type); 22.639 + } else { 22.640 + typeargs.append(actualTypeargs.head); 22.641 + } 22.642 + actualTypeargs = actualTypeargs.tail; 22.643 + } 22.644 + Type owntype = types.subst(formalInterface, funcInterfaceContext.inferenceVars(), typeargs.toList()); 22.645 + if (!chk.checkValidGenericType(owntype)) { 22.646 + //if the inferred functional interface type is not well-formed, 22.647 + //or if it's not a subtype of the original target, issue an error 22.648 + checkContext.report(pos, diags.fragment("no.suitable.functional.intf.inst", funcInterface)); 22.649 + return types.createErrorType(funcInterface); 22.650 + } 22.651 + return owntype; 22.652 + } 22.653 + } 22.654 + // </editor-fold> 22.655 + 22.656 /** 22.657 * Compute a synthetic method type corresponding to the requested polymorphic 22.658 * method signature. The target return type is computed from the immediately 22.659 @@ -480,6 +543,7 @@ 22.660 */ 22.661 Type instantiatePolymorphicSignatureInstance(Env<AttrContext> env, 22.662 MethodSymbol spMethod, // sig. poly. method or null if none 22.663 + Resolve.MethodResolutionContext resolveContext, 22.664 List<Type> argtypes) { 22.665 final Type restype; 22.666 22.667 @@ -509,7 +573,7 @@ 22.668 restype = syms.objectType; 22.669 } 22.670 22.671 - List<Type> paramtypes = Type.map(argtypes, implicitArgType); 22.672 + List<Type> paramtypes = Type.map(argtypes, new ImplicitArgType(spMethod, resolveContext.step)); 22.673 List<Type> exType = spMethod != null ? 22.674 spMethod.getThrownTypes() : 22.675 List.of(syms.throwableType); // make it throw all exceptions 22.676 @@ -521,14 +585,234 @@ 22.677 return mtype; 22.678 } 22.679 //where 22.680 - Mapping implicitArgType = new Mapping ("implicitArgType") { 22.681 - public Type apply(Type t) { 22.682 - t = types.erasure(t); 22.683 - if (t.tag == BOT) 22.684 - // nulls type as the marker type Null (which has no instances) 22.685 - // infer as java.lang.Void for now 22.686 - t = types.boxedClass(syms.voidType).type; 22.687 - return t; 22.688 + class ImplicitArgType extends DeferredAttr.DeferredTypeMap { 22.689 + 22.690 + public ImplicitArgType(Symbol msym, Resolve.MethodResolutionPhase phase) { 22.691 + deferredAttr.super(AttrMode.SPECULATIVE, msym, phase); 22.692 + } 22.693 + 22.694 + public Type apply(Type t) { 22.695 + t = types.erasure(super.apply(t)); 22.696 + if (t.tag == BOT) 22.697 + // nulls type as the marker type Null (which has no instances) 22.698 + // infer as java.lang.Void for now 22.699 + t = types.boxedClass(syms.voidType).type; 22.700 + return t; 22.701 + } 22.702 + } 22.703 + 22.704 + /** 22.705 + * Mapping that turns inference variables into undet vars 22.706 + * (used by inference context) 22.707 + */ 22.708 + class FromTypeVarFun extends Mapping { 22.709 + 22.710 + boolean includeBounds; 22.711 + 22.712 + FromTypeVarFun(boolean includeBounds) { 22.713 + super("fromTypeVarFunWithBounds"); 22.714 + this.includeBounds = includeBounds; 22.715 + } 22.716 + 22.717 + public Type apply(Type t) { 22.718 + if (t.tag == TYPEVAR) return new UndetVar((TypeVar)t, types, includeBounds); 22.719 + else return t.map(this); 22.720 + } 22.721 + }; 22.722 + 22.723 + /** 22.724 + * An inference context keeps track of the set of variables that are free 22.725 + * in the current context. It provides utility methods for opening/closing 22.726 + * types to their corresponding free/closed forms. It also provide hooks for 22.727 + * attaching deferred post-inference action (see PendingCheck). Finally, 22.728 + * it can be used as an entry point for performing upper/lower bound inference 22.729 + * (see InferenceKind). 22.730 + */ 22.731 + static class InferenceContext { 22.732 + 22.733 + /** 22.734 + * Single-method-interface for defining inference callbacks. Certain actions 22.735 + * (i.e. subtyping checks) might need to be redone after all inference variables 22.736 + * have been fixed. 22.737 + */ 22.738 + interface FreeTypeListener { 22.739 + void typesInferred(InferenceContext inferenceContext); 22.740 + } 22.741 + 22.742 + /** list of inference vars as undet vars */ 22.743 + List<Type> undetvars; 22.744 + 22.745 + /** list of inference vars in this context */ 22.746 + List<Type> inferencevars; 22.747 + 22.748 + java.util.Map<FreeTypeListener, List<Type>> freeTypeListeners = 22.749 + new java.util.HashMap<FreeTypeListener, List<Type>>(); 22.750 + 22.751 + List<FreeTypeListener> freetypeListeners = List.nil(); 22.752 + 22.753 + public InferenceContext(List<Type> inferencevars, Infer infer, boolean includeBounds) { 22.754 + this.undetvars = Type.map(inferencevars, infer.new FromTypeVarFun(includeBounds)); 22.755 + this.inferencevars = inferencevars; 22.756 + } 22.757 + 22.758 + /** 22.759 + * returns the list of free variables (as type-variables) in this 22.760 + * inference context 22.761 + */ 22.762 + List<Type> inferenceVars() { 22.763 + return inferencevars; 22.764 + } 22.765 + 22.766 + /** 22.767 + * returns the list of uninstantiated variables (as type-variables) in this 22.768 + * inference context (usually called after instantiate()) 22.769 + */ 22.770 + List<Type> restvars() { 22.771 + List<Type> undetvars = this.undetvars; 22.772 + ListBuffer<Type> restvars = ListBuffer.lb(); 22.773 + for (Type t : instTypes()) { 22.774 + UndetVar uv = (UndetVar)undetvars.head; 22.775 + if (uv.qtype == t) { 22.776 + restvars.append(t); 22.777 } 22.778 - }; 22.779 + undetvars = undetvars.tail; 22.780 + } 22.781 + return restvars.toList(); 22.782 + } 22.783 + 22.784 + /** 22.785 + * is this type free? 22.786 + */ 22.787 + final boolean free(Type t) { 22.788 + return t.containsAny(inferencevars); 22.789 + } 22.790 + 22.791 + final boolean free(List<Type> ts) { 22.792 + for (Type t : ts) { 22.793 + if (free(t)) return true; 22.794 + } 22.795 + return false; 22.796 + } 22.797 + 22.798 + /** 22.799 + * Returns a list of free variables in a given type 22.800 + */ 22.801 + final List<Type> freeVarsIn(Type t) { 22.802 + ListBuffer<Type> buf = ListBuffer.lb(); 22.803 + for (Type iv : inferenceVars()) { 22.804 + if (t.contains(iv)) { 22.805 + buf.add(iv); 22.806 + } 22.807 + } 22.808 + return buf.toList(); 22.809 + } 22.810 + 22.811 + final List<Type> freeVarsIn(List<Type> ts) { 22.812 + ListBuffer<Type> buf = ListBuffer.lb(); 22.813 + for (Type t : ts) { 22.814 + buf.appendList(freeVarsIn(t)); 22.815 + } 22.816 + ListBuffer<Type> buf2 = ListBuffer.lb(); 22.817 + for (Type t : buf) { 22.818 + if (!buf2.contains(t)) { 22.819 + buf2.add(t); 22.820 + } 22.821 + } 22.822 + return buf2.toList(); 22.823 + } 22.824 + 22.825 + /** 22.826 + * Replace all free variables in a given type with corresponding 22.827 + * undet vars (used ahead of subtyping/compatibility checks to allow propagation 22.828 + * of inference constraints). 22.829 + */ 22.830 + final Type asFree(Type t, Types types) { 22.831 + return types.subst(t, inferencevars, undetvars); 22.832 + } 22.833 + 22.834 + final List<Type> asFree(List<Type> ts, Types types) { 22.835 + ListBuffer<Type> buf = ListBuffer.lb(); 22.836 + for (Type t : ts) { 22.837 + buf.append(asFree(t, types)); 22.838 + } 22.839 + return buf.toList(); 22.840 + } 22.841 + 22.842 + List<Type> instTypes() { 22.843 + ListBuffer<Type> buf = ListBuffer.lb(); 22.844 + for (Type t : undetvars) { 22.845 + UndetVar uv = (UndetVar)t; 22.846 + buf.append(uv.inst != null ? uv.inst : uv.qtype); 22.847 + } 22.848 + return buf.toList(); 22.849 + } 22.850 + 22.851 + /** 22.852 + * Replace all free variables in a given type with corresponding 22.853 + * instantiated types - if one or more free variable has not been 22.854 + * fully instantiated, it will still be available in the resulting type. 22.855 + */ 22.856 + Type asInstType(Type t, Types types) { 22.857 + return types.subst(t, inferencevars, instTypes()); 22.858 + } 22.859 + 22.860 + List<Type> asInstTypes(List<Type> ts, Types types) { 22.861 + ListBuffer<Type> buf = ListBuffer.lb(); 22.862 + for (Type t : ts) { 22.863 + buf.append(asInstType(t, types)); 22.864 + } 22.865 + return buf.toList(); 22.866 + } 22.867 + 22.868 + /** 22.869 + * Add custom hook for performing post-inference action 22.870 + */ 22.871 + void addFreeTypeListener(List<Type> types, FreeTypeListener ftl) { 22.872 + freeTypeListeners.put(ftl, freeVarsIn(types)); 22.873 + } 22.874 + 22.875 + /** 22.876 + * Mark the inference context as complete and trigger evaluation 22.877 + * of all deferred checks. 22.878 + */ 22.879 + void notifyChange(Types types) { 22.880 + InferenceException thrownEx = null; 22.881 + for (Map.Entry<FreeTypeListener, List<Type>> entry : 22.882 + new HashMap<FreeTypeListener, List<Type>>(freeTypeListeners).entrySet()) { 22.883 + if (!Type.containsAny(entry.getValue(), restvars())) { 22.884 + try { 22.885 + entry.getKey().typesInferred(this); 22.886 + freeTypeListeners.remove(entry.getKey()); 22.887 + } catch (InferenceException ex) { 22.888 + if (thrownEx == null) { 22.889 + thrownEx = ex; 22.890 + } 22.891 + } 22.892 + } 22.893 + } 22.894 + //inference exception multiplexing - present any inference exception 22.895 + //thrown when processing listeners as a single one 22.896 + if (thrownEx != null) { 22.897 + throw thrownEx; 22.898 + } 22.899 + } 22.900 + 22.901 + void solveAny(List<Type> varsToSolve, Types types, Infer infer) { 22.902 + boolean progress = false; 22.903 + for (Type t : varsToSolve) { 22.904 + UndetVar uv = (UndetVar)asFree(t, types); 22.905 + if (uv.inst == null) { 22.906 + infer.minimizeInst(uv, Warner.noWarnings); 22.907 + if (uv.inst != null) { 22.908 + progress = true; 22.909 + } 22.910 + } 22.911 + } 22.912 + if (!progress) { 22.913 + throw infer.inferenceException.setMessage("cyclic.inference", varsToSolve); 22.914 + } 22.915 + } 22.916 } 22.917 + 22.918 + final InferenceContext emptyContext = new InferenceContext(List.<Type>nil(), this, false); 22.919 +}
23.1 --- a/src/share/classes/com/sun/tools/javac/comp/Lower.java Thu Oct 11 09:50:52 2012 -0700 23.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Lower.java Thu Oct 11 17:00:54 2012 -0700 23.3 @@ -1998,7 +1998,7 @@ 23.4 // replace with <BoxedClass>.TYPE 23.5 ClassSymbol c = types.boxedClass(type); 23.6 Symbol typeSym = 23.7 - rs.access( 23.8 + rs.accessBase( 23.9 rs.findIdentInType(attrEnv, c.type, names.TYPE, VAR), 23.10 pos, c.type, names.TYPE, true); 23.11 if (typeSym.kind == VAR)
24.1 --- a/src/share/classes/com/sun/tools/javac/comp/MemberEnter.java Thu Oct 11 09:50:52 2012 -0700 24.2 +++ b/src/share/classes/com/sun/tools/javac/comp/MemberEnter.java Thu Oct 11 17:00:54 2012 -0700 24.3 @@ -604,6 +604,10 @@ 24.4 env.dup(tree, env.info.dup(env.info.scope.dupUnshared())); 24.5 localEnv.enclMethod = tree; 24.6 localEnv.info.scope.owner = tree.sym; 24.7 + if (tree.sym.type != null) { 24.8 + //when this is called in the enter stage, there's no type to be set 24.9 + localEnv.info.returnResult = attr.new ResultInfo(VAL, tree.sym.type.getReturnType()); 24.10 + } 24.11 if ((tree.mods.flags & STATIC) != 0) localEnv.info.staticLevel++; 24.12 return localEnv; 24.13 } 24.14 @@ -642,7 +646,9 @@ 24.15 tree.sym = v; 24.16 if (tree.init != null) { 24.17 v.flags_field |= HASINIT; 24.18 - if ((v.flags_field & FINAL) != 0 && !tree.init.hasTag(NEWCLASS)) { 24.19 + if ((v.flags_field & FINAL) != 0 && 24.20 + !tree.init.hasTag(NEWCLASS) && 24.21 + !tree.init.hasTag(LAMBDA)) { 24.22 Env<AttrContext> initEnv = getInitEnv(tree, env); 24.23 initEnv.info.enclVar = v; 24.24 v.setLazyConstValue(initEnv(tree, initEnv), attr, tree.init); 24.25 @@ -667,7 +673,7 @@ 24.26 Env<AttrContext> initEnv(JCVariableDecl tree, Env<AttrContext> env) { 24.27 Env<AttrContext> localEnv = env.dupto(new AttrContextEnv(tree, env.info.dup())); 24.28 if (tree.sym.owner.kind == TYP) { 24.29 - localEnv.info.scope = new Scope.DelegatedScope(env.info.scope); 24.30 + localEnv.info.scope = env.info.scope.dupUnshared(); 24.31 localEnv.info.scope.owner = tree.sym; 24.32 } 24.33 if ((tree.mods.flags & STATIC) != 0 || 24.34 @@ -970,9 +976,11 @@ 24.35 List<Type> thrown = List.nil(); 24.36 long ctorFlags = 0; 24.37 boolean based = false; 24.38 + boolean addConstructor = true; 24.39 if (c.name.isEmpty()) { 24.40 JCNewClass nc = (JCNewClass)env.next.tree; 24.41 if (nc.constructor != null) { 24.42 + addConstructor = nc.constructor.kind != ERR; 24.43 Type superConstrType = types.memberType(c.type, 24.44 nc.constructor); 24.45 argtypes = superConstrType.getParameterTypes(); 24.46 @@ -985,10 +993,12 @@ 24.47 thrown = superConstrType.getThrownTypes(); 24.48 } 24.49 } 24.50 - JCTree constrDef = DefaultConstructor(make.at(tree.pos), c, 24.51 - typarams, argtypes, thrown, 24.52 - ctorFlags, based); 24.53 - tree.defs = tree.defs.prepend(constrDef); 24.54 + if (addConstructor) { 24.55 + JCTree constrDef = DefaultConstructor(make.at(tree.pos), c, 24.56 + typarams, argtypes, thrown, 24.57 + ctorFlags, based); 24.58 + tree.defs = tree.defs.prepend(constrDef); 24.59 + } 24.60 } 24.61 24.62 // If this is a class, enter symbols for this and super into
25.1 --- a/src/share/classes/com/sun/tools/javac/comp/Resolve.java Thu Oct 11 09:50:52 2012 -0700 25.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Resolve.java Thu Oct 11 17:00:54 2012 -0700 25.3 @@ -27,14 +27,20 @@ 25.4 25.5 import com.sun.tools.javac.api.Formattable.LocalizedString; 25.6 import com.sun.tools.javac.code.*; 25.7 +import com.sun.tools.javac.code.Symbol.*; 25.8 import com.sun.tools.javac.code.Type.*; 25.9 -import com.sun.tools.javac.code.Symbol.*; 25.10 import com.sun.tools.javac.comp.Attr.ResultInfo; 25.11 import com.sun.tools.javac.comp.Check.CheckContext; 25.12 +import com.sun.tools.javac.comp.DeferredAttr.AttrMode; 25.13 +import com.sun.tools.javac.comp.DeferredAttr.DeferredAttrContext; 25.14 +import com.sun.tools.javac.comp.DeferredAttr.DeferredType; 25.15 +import com.sun.tools.javac.comp.Infer.InferenceContext; 25.16 +import com.sun.tools.javac.comp.Infer.InferenceContext.FreeTypeListener; 25.17 import com.sun.tools.javac.comp.Resolve.MethodResolutionContext.Candidate; 25.18 import com.sun.tools.javac.jvm.*; 25.19 import com.sun.tools.javac.tree.*; 25.20 import com.sun.tools.javac.tree.JCTree.*; 25.21 +import com.sun.tools.javac.tree.JCTree.JCMemberReference.ReferenceKind; 25.22 import com.sun.tools.javac.util.*; 25.23 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticFlag; 25.24 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; 25.25 @@ -44,9 +50,8 @@ 25.26 import java.util.Collection; 25.27 import java.util.EnumMap; 25.28 import java.util.EnumSet; 25.29 -import java.util.HashSet; 25.30 +import java.util.Iterator; 25.31 import java.util.Map; 25.32 -import java.util.Set; 25.33 25.34 import javax.lang.model.element.ElementVisitor; 25.35 25.36 @@ -73,6 +78,7 @@ 25.37 Log log; 25.38 Symtab syms; 25.39 Attr attr; 25.40 + DeferredAttr deferredAttr; 25.41 Check chk; 25.42 Infer infer; 25.43 ClassReader reader; 25.44 @@ -93,10 +99,6 @@ 25.45 25.46 varNotFound = new 25.47 SymbolNotFoundError(ABSENT_VAR); 25.48 - wrongMethod = new 25.49 - InapplicableSymbolError(); 25.50 - wrongMethods = new 25.51 - InapplicableSymbolsError(); 25.52 methodNotFound = new 25.53 SymbolNotFoundError(ABSENT_MTH); 25.54 typeNotFound = new 25.55 @@ -105,6 +107,7 @@ 25.56 names = Names.instance(context); 25.57 log = Log.instance(context); 25.58 attr = Attr.instance(context); 25.59 + deferredAttr = DeferredAttr.instance(context); 25.60 chk = Check.instance(context); 25.61 infer = Infer.instance(context); 25.62 reader = ClassReader.instance(context); 25.63 @@ -127,8 +130,6 @@ 25.64 /** error symbols, which are returned when resolution fails 25.65 */ 25.66 private final SymbolNotFoundError varNotFound; 25.67 - private final InapplicableSymbolError wrongMethod; 25.68 - private final InapplicableSymbolsError wrongMethods; 25.69 private final SymbolNotFoundError methodNotFound; 25.70 private final SymbolNotFoundError typeNotFound; 25.71 25.72 @@ -215,9 +216,12 @@ 25.73 } 25.74 } 25.75 String key = success ? "verbose.resolve.multi" : "verbose.resolve.multi.1"; 25.76 + List<Type> argtypes2 = Type.map(argtypes, 25.77 + deferredAttr.new RecoveryDeferredTypeMap(AttrMode.SPECULATIVE, bestSoFar, currentResolutionContext.step)); 25.78 JCDiagnostic main = diags.note(log.currentSource(), dpos, key, name, 25.79 site.tsym, mostSpecificPos, currentResolutionContext.step, 25.80 - methodArguments(argtypes), methodArguments(typeargtypes)); 25.81 + methodArguments(argtypes2), 25.82 + methodArguments(typeargtypes)); 25.83 JCDiagnostic d = new JCDiagnostic.MultilineDiagnostic(main, subDiags.toList()); 25.84 log.report(d); 25.85 } 25.86 @@ -247,7 +251,7 @@ 25.87 /** An environment is "static" if its static level is greater than 25.88 * the one of its outer environment 25.89 */ 25.90 - static boolean isStatic(Env<AttrContext> env) { 25.91 + protected static boolean isStatic(Env<AttrContext> env) { 25.92 return env.info.staticLevel > env.outer.info.staticLevel; 25.93 } 25.94 25.95 @@ -445,8 +449,18 @@ 25.96 boolean useVarargs, 25.97 Warner warn) 25.98 throws Infer.InferenceException { 25.99 - if (useVarargs && (m.flags() & VARARGS) == 0) 25.100 - throw inapplicableMethodException.setMessage(); 25.101 + if (useVarargs && (m.flags() & VARARGS) == 0) { 25.102 + //better error recovery - if we stumbled upon a non-varargs method 25.103 + //during varargs applicability phase, the method should be treated as 25.104 + //not applicable; the reason for inapplicability can be found in the 25.105 + //candidate for 'm' that was created during the BOX phase. 25.106 + Candidate prevCandidate = currentResolutionContext.getCandidate(m, BOX); 25.107 + JCDiagnostic details = null; 25.108 + if (prevCandidate != null && !prevCandidate.isApplicable()) { 25.109 + details = prevCandidate.details; 25.110 + } 25.111 + throw inapplicableMethodException.setMessage(details); 25.112 + } 25.113 Type mt = types.memberType(site, m); 25.114 25.115 // tvars is the list of formal type variables for which type arguments 25.116 @@ -497,13 +511,34 @@ 25.117 argtypes, 25.118 allowBoxing, 25.119 useVarargs, 25.120 + currentResolutionContext, 25.121 warn); 25.122 25.123 - checkRawArgumentsAcceptable(env, argtypes, mt.getParameterTypes(), 25.124 + checkRawArgumentsAcceptable(env, m, argtypes, mt.getParameterTypes(), 25.125 allowBoxing, useVarargs, warn); 25.126 return mt; 25.127 } 25.128 25.129 + Type checkMethod(Env<AttrContext> env, 25.130 + Type site, 25.131 + Symbol m, 25.132 + ResultInfo resultInfo, 25.133 + List<Type> argtypes, 25.134 + List<Type> typeargtypes, 25.135 + Warner warn) { 25.136 + MethodResolutionContext prevContext = currentResolutionContext; 25.137 + try { 25.138 + currentResolutionContext = new MethodResolutionContext(); 25.139 + currentResolutionContext.attrMode = DeferredAttr.AttrMode.CHECK; 25.140 + MethodResolutionPhase step = currentResolutionContext.step = env.info.pendingResolutionPhase; 25.141 + return rawInstantiate(env, site, m, resultInfo, argtypes, typeargtypes, 25.142 + step.isBoxingRequired(), step.isVarargsRequired(), warn); 25.143 + } 25.144 + finally { 25.145 + currentResolutionContext = prevContext; 25.146 + } 25.147 + } 25.148 + 25.149 /** Same but returns null instead throwing a NoInstanceException 25.150 */ 25.151 Type instantiate(Env<AttrContext> env, 25.152 @@ -526,13 +561,14 @@ 25.153 /** Check if a parameter list accepts a list of args. 25.154 */ 25.155 boolean argumentsAcceptable(Env<AttrContext> env, 25.156 + Symbol msym, 25.157 List<Type> argtypes, 25.158 List<Type> formals, 25.159 boolean allowBoxing, 25.160 boolean useVarargs, 25.161 Warner warn) { 25.162 try { 25.163 - checkRawArgumentsAcceptable(env, argtypes, formals, allowBoxing, useVarargs, warn); 25.164 + checkRawArgumentsAcceptable(env, msym, argtypes, formals, allowBoxing, useVarargs, warn); 25.165 return true; 25.166 } catch (InapplicableMethodException ex) { 25.167 return false; 25.168 @@ -579,12 +615,13 @@ 25.169 }; 25.170 25.171 void checkRawArgumentsAcceptable(Env<AttrContext> env, 25.172 + Symbol msym, 25.173 List<Type> argtypes, 25.174 List<Type> formals, 25.175 boolean allowBoxing, 25.176 boolean useVarargs, 25.177 Warner warn) { 25.178 - checkRawArgumentsAcceptable(env, List.<Type>nil(), argtypes, formals, 25.179 + checkRawArgumentsAcceptable(env, msym, currentResolutionContext.attrMode(), infer.emptyContext, argtypes, formals, 25.180 allowBoxing, useVarargs, warn, resolveHandler); 25.181 } 25.182 25.183 @@ -594,35 +631,41 @@ 25.184 * compatible (by method invocation conversion) with the types in F. 25.185 * 25.186 * Since this routine is shared between overload resolution and method 25.187 - * type-inference, it is crucial that actual types are converted to the 25.188 - * corresponding 'undet' form (i.e. where inference variables are replaced 25.189 - * with undetvars) so that constraints can be propagated and collected. 25.190 + * type-inference, a (possibly empty) inference context is used to convert 25.191 + * formal types to the corresponding 'undet' form ahead of a compatibility 25.192 + * check so that constraints can be propagated and collected. 25.193 * 25.194 - * Moreover, if one or more types in A is a poly type, this routine calls 25.195 - * Infer.instantiateArg in order to complete the poly type (this might involve 25.196 - * deferred attribution). 25.197 + * Moreover, if one or more types in A is a deferred type, this routine uses 25.198 + * DeferredAttr in order to perform deferred attribution. If one or more actual 25.199 + * deferred types are stuck, they are placed in a queue and revisited later 25.200 + * after the remainder of the arguments have been seen. If this is not sufficient 25.201 + * to 'unstuck' the argument, a cyclic inference error is called out. 25.202 * 25.203 * A method check handler (see above) is used in order to report errors. 25.204 */ 25.205 - List<Type> checkRawArgumentsAcceptable(Env<AttrContext> env, 25.206 - List<Type> undetvars, 25.207 + void checkRawArgumentsAcceptable(final Env<AttrContext> env, 25.208 + Symbol msym, 25.209 + DeferredAttr.AttrMode mode, 25.210 + final Infer.InferenceContext inferenceContext, 25.211 List<Type> argtypes, 25.212 List<Type> formals, 25.213 boolean allowBoxing, 25.214 boolean useVarargs, 25.215 Warner warn, 25.216 - MethodCheckHandler handler) { 25.217 + final MethodCheckHandler handler) { 25.218 Type varargsFormal = useVarargs ? formals.last() : null; 25.219 - ListBuffer<Type> checkedArgs = ListBuffer.lb(); 25.220 25.221 if (varargsFormal == null && 25.222 argtypes.size() != formals.size()) { 25.223 throw handler.arityMismatch(); // not enough args 25.224 } 25.225 25.226 + DeferredAttr.DeferredAttrContext deferredAttrContext = 25.227 + deferredAttr.new DeferredAttrContext(mode, msym, currentResolutionContext.step, inferenceContext); 25.228 + 25.229 while (argtypes.nonEmpty() && formals.head != varargsFormal) { 25.230 - ResultInfo resultInfo = methodCheckResult(formals.head, allowBoxing, false, undetvars, handler, warn); 25.231 - checkedArgs.append(resultInfo.check(env.tree.pos(), argtypes.head)); 25.232 + ResultInfo mresult = methodCheckResult(formals.head, allowBoxing, false, inferenceContext, deferredAttrContext, handler, warn); 25.233 + mresult.check(null, argtypes.head); 25.234 argtypes = argtypes.tail; 25.235 formals = formals.tail; 25.236 } 25.237 @@ -634,19 +677,33 @@ 25.238 if (useVarargs) { 25.239 //note: if applicability check is triggered by most specific test, 25.240 //the last argument of a varargs is _not_ an array type (see JLS 15.12.2.5) 25.241 - Type elt = types.elemtype(varargsFormal); 25.242 + final Type elt = types.elemtype(varargsFormal); 25.243 + ResultInfo mresult = methodCheckResult(elt, allowBoxing, true, inferenceContext, deferredAttrContext, handler, warn); 25.244 while (argtypes.nonEmpty()) { 25.245 - ResultInfo resultInfo = methodCheckResult(elt, allowBoxing, true, undetvars, handler, warn); 25.246 - checkedArgs.append(resultInfo.check(env.tree.pos(), argtypes.head)); 25.247 + mresult.check(null, argtypes.head); 25.248 argtypes = argtypes.tail; 25.249 } 25.250 //check varargs element type accessibility 25.251 - if (undetvars.isEmpty() && !isAccessible(env, elt)) { 25.252 + varargsAccessible(env, elt, handler, inferenceContext); 25.253 + } 25.254 + 25.255 + deferredAttrContext.complete(); 25.256 + } 25.257 + 25.258 + void varargsAccessible(final Env<AttrContext> env, final Type t, final Resolve.MethodCheckHandler handler, final InferenceContext inferenceContext) { 25.259 + if (inferenceContext.free(t)) { 25.260 + inferenceContext.addFreeTypeListener(List.of(t), new FreeTypeListener() { 25.261 + @Override 25.262 + public void typesInferred(InferenceContext inferenceContext) { 25.263 + varargsAccessible(env, inferenceContext.asInstType(t, types), handler, inferenceContext); 25.264 + } 25.265 + }); 25.266 + } else { 25.267 + if (!isAccessible(env, t)) { 25.268 Symbol location = env.enclClass.sym; 25.269 - throw handler.inaccessibleVarargs(location, elt); 25.270 + throw handler.inaccessibleVarargs(location, t); 25.271 } 25.272 } 25.273 - return checkedArgs.toList(); 25.274 } 25.275 25.276 /** 25.277 @@ -657,13 +714,16 @@ 25.278 25.279 MethodCheckHandler handler; 25.280 boolean useVarargs; 25.281 - List<Type> undetvars; 25.282 + Infer.InferenceContext inferenceContext; 25.283 + DeferredAttrContext deferredAttrContext; 25.284 Warner rsWarner; 25.285 25.286 - public MethodCheckContext(MethodCheckHandler handler, boolean useVarargs, List<Type> undetvars, Warner rsWarner) { 25.287 + public MethodCheckContext(MethodCheckHandler handler, boolean useVarargs, 25.288 + Infer.InferenceContext inferenceContext, DeferredAttrContext deferredAttrContext, Warner rsWarner) { 25.289 this.handler = handler; 25.290 this.useVarargs = useVarargs; 25.291 - this.undetvars = undetvars; 25.292 + this.inferenceContext = inferenceContext; 25.293 + this.deferredAttrContext = deferredAttrContext; 25.294 this.rsWarner = rsWarner; 25.295 } 25.296 25.297 @@ -674,6 +734,14 @@ 25.298 public Warner checkWarner(DiagnosticPosition pos, Type found, Type req) { 25.299 return rsWarner; 25.300 } 25.301 + 25.302 + public InferenceContext inferenceContext() { 25.303 + return inferenceContext; 25.304 + } 25.305 + 25.306 + public DeferredAttrContext deferredAttrContext() { 25.307 + return deferredAttrContext; 25.308 + } 25.309 } 25.310 25.311 /** 25.312 @@ -682,12 +750,17 @@ 25.313 */ 25.314 class StrictMethodContext extends MethodCheckContext { 25.315 25.316 - public StrictMethodContext(MethodCheckHandler handler, boolean useVarargs, List<Type> undetvars, Warner rsWarner) { 25.317 - super(handler, useVarargs, undetvars, rsWarner); 25.318 + public StrictMethodContext(MethodCheckHandler handler, boolean useVarargs, 25.319 + Infer.InferenceContext inferenceContext, DeferredAttrContext deferredAttrContext, Warner rsWarner) { 25.320 + super(handler, useVarargs, inferenceContext, deferredAttrContext, rsWarner); 25.321 } 25.322 25.323 public boolean compatible(Type found, Type req, Warner warn) { 25.324 - return types.isSubtypeUnchecked(found, infer.asUndetType(req, undetvars), warn); 25.325 + return types.isSubtypeUnchecked(found, inferenceContext.asFree(req, types), warn); 25.326 + } 25.327 + 25.328 + public boolean allowBoxing() { 25.329 + return false; 25.330 } 25.331 } 25.332 25.333 @@ -697,12 +770,17 @@ 25.334 */ 25.335 class LooseMethodContext extends MethodCheckContext { 25.336 25.337 - public LooseMethodContext(MethodCheckHandler handler, boolean useVarargs, List<Type> undetvars, Warner rsWarner) { 25.338 - super(handler, useVarargs, undetvars, rsWarner); 25.339 + public LooseMethodContext(MethodCheckHandler handler, boolean useVarargs, 25.340 + Infer.InferenceContext inferenceContext, DeferredAttrContext deferredAttrContext, Warner rsWarner) { 25.341 + super(handler, useVarargs, inferenceContext, deferredAttrContext, rsWarner); 25.342 } 25.343 25.344 public boolean compatible(Type found, Type req, Warner warn) { 25.345 - return types.isConvertible(found, infer.asUndetType(req, undetvars), warn); 25.346 + return types.isConvertible(found, inferenceContext.asFree(req, types), warn); 25.347 + } 25.348 + 25.349 + public boolean allowBoxing() { 25.350 + return true; 25.351 } 25.352 } 25.353 25.354 @@ -710,16 +788,37 @@ 25.355 * Create a method check context to be used during method applicability check 25.356 */ 25.357 ResultInfo methodCheckResult(Type to, boolean allowBoxing, boolean useVarargs, 25.358 - List<Type> undetvars, MethodCheckHandler methodHandler, Warner rsWarner) { 25.359 + Infer.InferenceContext inferenceContext, DeferredAttr.DeferredAttrContext deferredAttrContext, 25.360 + MethodCheckHandler methodHandler, Warner rsWarner) { 25.361 MethodCheckContext checkContext = allowBoxing ? 25.362 - new LooseMethodContext(methodHandler, useVarargs, undetvars, rsWarner) : 25.363 - new StrictMethodContext(methodHandler, useVarargs, undetvars, rsWarner); 25.364 - return attr.new ResultInfo(VAL, to, checkContext) { 25.365 - @Override 25.366 - protected Type check(DiagnosticPosition pos, Type found) { 25.367 - return super.check(pos, chk.checkNonVoid(pos, types.capture(types.upperBound(found)))); 25.368 + new LooseMethodContext(methodHandler, useVarargs, inferenceContext, deferredAttrContext, rsWarner) : 25.369 + new StrictMethodContext(methodHandler, useVarargs, inferenceContext, deferredAttrContext, rsWarner); 25.370 + return new MethodResultInfo(to, checkContext, deferredAttrContext); 25.371 + } 25.372 + 25.373 + class MethodResultInfo extends ResultInfo { 25.374 + 25.375 + DeferredAttr.DeferredAttrContext deferredAttrContext; 25.376 + 25.377 + public MethodResultInfo(Type pt, MethodCheckContext checkContext, DeferredAttr.DeferredAttrContext deferredAttrContext) { 25.378 + attr.super(VAL, pt, checkContext); 25.379 + this.deferredAttrContext = deferredAttrContext; 25.380 + } 25.381 + 25.382 + @Override 25.383 + protected Type check(DiagnosticPosition pos, Type found) { 25.384 + if (found.tag == DEFERRED) { 25.385 + DeferredType dt = (DeferredType)found; 25.386 + return dt.check(this); 25.387 + } else { 25.388 + return super.check(pos, chk.checkNonVoid(pos, types.capture(types.upperBound(found.baseType())))); 25.389 } 25.390 - }; 25.391 + } 25.392 + 25.393 + @Override 25.394 + protected MethodResultInfo dup(Type newPt) { 25.395 + return new MethodResultInfo(newPt, (MethodCheckContext)checkContext, deferredAttrContext); 25.396 + } 25.397 } 25.398 25.399 public static class InapplicableMethodException extends RuntimeException { 25.400 @@ -733,16 +832,13 @@ 25.401 this.diags = diags; 25.402 } 25.403 InapplicableMethodException setMessage() { 25.404 - this.diagnostic = null; 25.405 - return this; 25.406 + return setMessage((JCDiagnostic)null); 25.407 } 25.408 InapplicableMethodException setMessage(String key) { 25.409 - this.diagnostic = key != null ? diags.fragment(key) : null; 25.410 - return this; 25.411 + return setMessage(key != null ? diags.fragment(key) : null); 25.412 } 25.413 InapplicableMethodException setMessage(String key, Object... args) { 25.414 - this.diagnostic = key != null ? diags.fragment(key, args) : null; 25.415 - return this; 25.416 + return setMessage(key != null ? diags.fragment(key, args) : null); 25.417 } 25.418 InapplicableMethodException setMessage(JCDiagnostic diag) { 25.419 this.diagnostic = diag; 25.420 @@ -937,11 +1033,10 @@ 25.421 currentResolutionContext.addInapplicableCandidate(sym, ex.getDiagnostic()); 25.422 switch (bestSoFar.kind) { 25.423 case ABSENT_MTH: 25.424 - return wrongMethod; 25.425 + return new InapplicableSymbolError(currentResolutionContext); 25.426 case WRONG_MTH: 25.427 if (operator) return bestSoFar; 25.428 - case WRONG_MTHS: 25.429 - return wrongMethods; 25.430 + bestSoFar = new InapplicableSymbolsError(currentResolutionContext); 25.431 default: 25.432 return bestSoFar; 25.433 } 25.434 @@ -953,7 +1048,7 @@ 25.435 } 25.436 return (bestSoFar.kind > AMBIGUOUS) 25.437 ? sym 25.438 - : mostSpecific(sym, bestSoFar, env, site, 25.439 + : mostSpecific(argtypes, sym, bestSoFar, env, site, 25.440 allowBoxing && operator, useVarargs); 25.441 } 25.442 25.443 @@ -967,7 +1062,7 @@ 25.444 * @param allowBoxing Allow boxing conversions of arguments. 25.445 * @param useVarargs Box trailing arguments into an array for varargs. 25.446 */ 25.447 - Symbol mostSpecific(Symbol m1, 25.448 + Symbol mostSpecific(List<Type> argtypes, Symbol m1, 25.449 Symbol m2, 25.450 Env<AttrContext> env, 25.451 final Type site, 25.452 @@ -976,8 +1071,10 @@ 25.453 switch (m2.kind) { 25.454 case MTH: 25.455 if (m1 == m2) return m1; 25.456 - boolean m1SignatureMoreSpecific = signatureMoreSpecific(env, site, m1, m2, allowBoxing, useVarargs); 25.457 - boolean m2SignatureMoreSpecific = signatureMoreSpecific(env, site, m2, m1, allowBoxing, useVarargs); 25.458 + boolean m1SignatureMoreSpecific = 25.459 + signatureMoreSpecific(argtypes, env, site, m1, m2, allowBoxing, useVarargs); 25.460 + boolean m2SignatureMoreSpecific = 25.461 + signatureMoreSpecific(argtypes, env, site, m2, m1, allowBoxing, useVarargs); 25.462 if (m1SignatureMoreSpecific && m2SignatureMoreSpecific) { 25.463 Type mt1 = types.memberType(site, m1); 25.464 Type mt2 = types.memberType(site, m2); 25.465 @@ -1035,8 +1132,8 @@ 25.466 return this; 25.467 else 25.468 return super.implementation(origin, types, checkResult); 25.469 - } 25.470 - }; 25.471 + } 25.472 + }; 25.473 return result; 25.474 } 25.475 if (m1SignatureMoreSpecific) return m1; 25.476 @@ -1044,8 +1141,8 @@ 25.477 return ambiguityError(m1, m2); 25.478 case AMBIGUOUS: 25.479 AmbiguityError e = (AmbiguityError)m2; 25.480 - Symbol err1 = mostSpecific(m1, e.sym, env, site, allowBoxing, useVarargs); 25.481 - Symbol err2 = mostSpecific(m1, e.sym2, env, site, allowBoxing, useVarargs); 25.482 + Symbol err1 = mostSpecific(argtypes, m1, e.sym, env, site, allowBoxing, useVarargs); 25.483 + Symbol err2 = mostSpecific(argtypes, m1, e.sym2, env, site, allowBoxing, useVarargs); 25.484 if (err1 == err2) return err1; 25.485 if (err1 == e.sym && err2 == e.sym2) return m2; 25.486 if (err1 instanceof AmbiguityError && 25.487 @@ -1059,13 +1156,83 @@ 25.488 } 25.489 } 25.490 //where 25.491 - private boolean signatureMoreSpecific(Env<AttrContext> env, Type site, Symbol m1, Symbol m2, boolean allowBoxing, boolean useVarargs) { 25.492 + private boolean signatureMoreSpecific(List<Type> actuals, Env<AttrContext> env, Type site, Symbol m1, Symbol m2, boolean allowBoxing, boolean useVarargs) { 25.493 + Symbol m12 = adjustVarargs(m1, m2, useVarargs); 25.494 + Symbol m22 = adjustVarargs(m2, m1, useVarargs); 25.495 + Type mtype1 = types.memberType(site, m12); 25.496 + Type mtype2 = types.memberType(site, m22); 25.497 + 25.498 + //check if invocation is more specific 25.499 + if (invocationMoreSpecific(env, site, m22, mtype1.getParameterTypes(), allowBoxing, useVarargs)) { 25.500 + return true; 25.501 + } 25.502 + 25.503 + //perform structural check 25.504 + 25.505 + List<Type> formals1 = mtype1.getParameterTypes(); 25.506 + Type lastFormal1 = formals1.last(); 25.507 + List<Type> formals2 = mtype2.getParameterTypes(); 25.508 + Type lastFormal2 = formals2.last(); 25.509 + ListBuffer<Type> newFormals = ListBuffer.lb(); 25.510 + 25.511 + boolean hasStructuralPoly = false; 25.512 + for (Type actual : actuals) { 25.513 + //perform formal argument adaptation in case actuals > formals (varargs) 25.514 + Type f1 = formals1.isEmpty() ? 25.515 + lastFormal1 : formals1.head; 25.516 + Type f2 = formals2.isEmpty() ? 25.517 + lastFormal2 : formals2.head; 25.518 + 25.519 + //is this a structural actual argument? 25.520 + boolean isStructuralPoly = actual.tag == DEFERRED && 25.521 + (((DeferredType)actual).tree.hasTag(LAMBDA) || 25.522 + ((DeferredType)actual).tree.hasTag(REFERENCE)); 25.523 + 25.524 + Type newFormal = f1; 25.525 + 25.526 + if (isStructuralPoly) { 25.527 + //for structural arguments only - check that corresponding formals 25.528 + //are related - if so replace formal with <null> 25.529 + hasStructuralPoly = true; 25.530 + DeferredType dt = (DeferredType)actual; 25.531 + Type t1 = deferredAttr.new DeferredTypeMap(AttrMode.SPECULATIVE, m1, currentResolutionContext.step).apply(dt); 25.532 + Type t2 = deferredAttr.new DeferredTypeMap(AttrMode.SPECULATIVE, m2, currentResolutionContext.step).apply(dt); 25.533 + if (t1.isErroneous() || t2.isErroneous() || !isStructuralSubtype(t1, t2)) { 25.534 + //not structural subtypes - simply fail 25.535 + return false; 25.536 + } else { 25.537 + newFormal = syms.botType; 25.538 + } 25.539 + } 25.540 + 25.541 + newFormals.append(newFormal); 25.542 + if (newFormals.length() > mtype2.getParameterTypes().length()) { 25.543 + //expand m2's type so as to fit the new formal arity (varargs) 25.544 + m22.type = types.createMethodTypeWithParameters(m22.type, m22.type.getParameterTypes().append(f2)); 25.545 + } 25.546 + 25.547 + formals1 = formals1.isEmpty() ? formals1 : formals1.tail; 25.548 + formals2 = formals2.isEmpty() ? formals2 : formals2.tail; 25.549 + } 25.550 + 25.551 + if (!hasStructuralPoly) { 25.552 + //if no structural actual was found, we're done 25.553 + return false; 25.554 + } 25.555 + //perform additional adaptation if actuals < formals (varargs) 25.556 + for (Type t : formals1) { 25.557 + newFormals.append(t); 25.558 + } 25.559 + //check if invocation (with tweaked args) is more specific 25.560 + return invocationMoreSpecific(env, site, m22, newFormals.toList(), allowBoxing, useVarargs); 25.561 + } 25.562 + //where 25.563 + private boolean invocationMoreSpecific(Env<AttrContext> env, Type site, Symbol m2, List<Type> argtypes1, boolean allowBoxing, boolean useVarargs) { 25.564 noteWarner.clear(); 25.565 - Type mtype1 = types.memberType(site, adjustVarargs(m1, m2, useVarargs)); 25.566 - Type mtype2 = instantiate(env, site, adjustVarargs(m2, m1, useVarargs), null, 25.567 - types.lowerBoundArgtypes(mtype1), null, 25.568 + Type mst = instantiate(env, site, m2, null, 25.569 + types.lowerBounds(argtypes1), null, 25.570 allowBoxing, false, noteWarner); 25.571 - return mtype2 != null && 25.572 + return mst != null && 25.573 !noteWarner.hasLint(Lint.LintCategory.UNCHECKED); 25.574 } 25.575 //where 25.576 @@ -1104,6 +1271,32 @@ 25.577 } 25.578 } 25.579 //where 25.580 + boolean isStructuralSubtype(Type s, Type t) { 25.581 + 25.582 + Type ret_s = types.findDescriptorType(s).getReturnType(); 25.583 + Type ret_t = types.findDescriptorType(t).getReturnType(); 25.584 + 25.585 + //covariant most specific check for function descriptor return type 25.586 + if (!types.isSubtype(ret_s, ret_t)) { 25.587 + return false; 25.588 + } 25.589 + 25.590 + List<Type> args_s = types.findDescriptorType(s).getParameterTypes(); 25.591 + List<Type> args_t = types.findDescriptorType(t).getParameterTypes(); 25.592 + 25.593 + //arity must be identical 25.594 + if (args_s.length() != args_t.length()) { 25.595 + return false; 25.596 + } 25.597 + 25.598 + //invariant most specific check for function descriptor parameter types 25.599 + if (!types.isSameTypes(args_t, args_s)) { 25.600 + return false; 25.601 + } 25.602 + 25.603 + return true; 25.604 + } 25.605 + //where 25.606 Type mostSpecificReturnType(Type mt1, Type mt2) { 25.607 Type rt1 = mt1.getReturnType(); 25.608 Type rt2 = mt2.getReturnType(); 25.609 @@ -1160,12 +1353,10 @@ 25.610 argtypes, 25.611 typeargtypes, 25.612 site.tsym.type, 25.613 - true, 25.614 bestSoFar, 25.615 allowBoxing, 25.616 useVarargs, 25.617 - operator, 25.618 - new HashSet<TypeSymbol>()); 25.619 + operator); 25.620 reportVerboseResolutionDiagnostic(env.tree.pos(), name, site, argtypes, typeargtypes, bestSoFar); 25.621 return bestSoFar; 25.622 } 25.623 @@ -1176,56 +1367,134 @@ 25.624 List<Type> argtypes, 25.625 List<Type> typeargtypes, 25.626 Type intype, 25.627 - boolean abstractok, 25.628 Symbol bestSoFar, 25.629 boolean allowBoxing, 25.630 boolean useVarargs, 25.631 - boolean operator, 25.632 - Set<TypeSymbol> seen) { 25.633 - for (Type ct = intype; ct.tag == CLASS || ct.tag == TYPEVAR; ct = types.supertype(ct)) { 25.634 - while (ct.tag == TYPEVAR) 25.635 - ct = ct.getUpperBound(); 25.636 - ClassSymbol c = (ClassSymbol)ct.tsym; 25.637 - if (!seen.add(c)) return bestSoFar; 25.638 - if ((c.flags() & (ABSTRACT | INTERFACE | ENUM)) == 0) 25.639 - abstractok = false; 25.640 - for (Scope.Entry e = c.members().lookup(name); 25.641 - e.scope != null; 25.642 - e = e.next()) { 25.643 - //- System.out.println(" e " + e.sym); 25.644 - if (e.sym.kind == MTH && 25.645 - (e.sym.flags_field & SYNTHETIC) == 0) { 25.646 - bestSoFar = selectBest(env, site, argtypes, typeargtypes, 25.647 - e.sym, bestSoFar, 25.648 - allowBoxing, 25.649 - useVarargs, 25.650 - operator); 25.651 + boolean operator) { 25.652 + boolean abstractOk = true; 25.653 + List<Type> itypes = List.nil(); 25.654 + for (TypeSymbol s : superclasses(intype)) { 25.655 + bestSoFar = lookupMethod(env, site, name, argtypes, typeargtypes, 25.656 + s.members(), bestSoFar, allowBoxing, useVarargs, operator, true); 25.657 + //We should not look for abstract methods if receiver is a concrete class 25.658 + //(as concrete classes are expected to implement all abstracts coming 25.659 + //from superinterfaces) 25.660 + abstractOk &= (s.flags() & (ABSTRACT | INTERFACE | ENUM)) != 0; 25.661 + if (abstractOk) { 25.662 + for (Type itype : types.interfaces(s.type)) { 25.663 + itypes = types.union(types.closure(itype), itypes); 25.664 } 25.665 } 25.666 - if (name == names.init) 25.667 - break; 25.668 - //- System.out.println(" - " + bestSoFar); 25.669 - if (abstractok) { 25.670 - Symbol concrete = methodNotFound; 25.671 - if ((bestSoFar.flags() & ABSTRACT) == 0) 25.672 - concrete = bestSoFar; 25.673 - for (List<Type> l = types.interfaces(c.type); 25.674 - l.nonEmpty(); 25.675 - l = l.tail) { 25.676 - bestSoFar = findMethod(env, site, name, argtypes, 25.677 - typeargtypes, 25.678 - l.head, abstractok, bestSoFar, 25.679 - allowBoxing, useVarargs, operator, seen); 25.680 - } 25.681 - if (concrete != bestSoFar && 25.682 - concrete.kind < ERR && bestSoFar.kind < ERR && 25.683 - types.isSubSignature(concrete.type, bestSoFar.type)) 25.684 - bestSoFar = concrete; 25.685 + if (name == names.init) break; 25.686 + } 25.687 + 25.688 + Symbol concrete = bestSoFar.kind < ERR && 25.689 + (bestSoFar.flags() & ABSTRACT) == 0 ? 25.690 + bestSoFar : methodNotFound; 25.691 + 25.692 + if (name != names.init) { 25.693 + //keep searching for abstract methods 25.694 + for (Type itype : itypes) { 25.695 + if (!itype.isInterface()) continue; //skip j.l.Object (included by Types.closure()) 25.696 + bestSoFar = lookupMethod(env, site, name, argtypes, typeargtypes, 25.697 + itype.tsym.members(), bestSoFar, allowBoxing, useVarargs, operator, true); 25.698 + if (concrete != bestSoFar && 25.699 + concrete.kind < ERR && bestSoFar.kind < ERR && 25.700 + types.isSubSignature(concrete.type, bestSoFar.type)) { 25.701 + //this is an hack - as javac does not do full membership checks 25.702 + //most specific ends up comparing abstract methods that might have 25.703 + //been implemented by some concrete method in a subclass and, 25.704 + //because of raw override, it is possible for an abstract method 25.705 + //to be more specific than the concrete method - so we need 25.706 + //to explicitly call that out (see CR 6178365) 25.707 + bestSoFar = concrete; 25.708 + } 25.709 } 25.710 } 25.711 return bestSoFar; 25.712 } 25.713 25.714 + /** 25.715 + * Return an Iterable object to scan the superclasses of a given type. 25.716 + * It's crucial that the scan is done lazily, as we don't want to accidentally 25.717 + * access more supertypes than strictly needed (as this could trigger completion 25.718 + * errors if some of the not-needed supertypes are missing/ill-formed). 25.719 + */ 25.720 + Iterable<TypeSymbol> superclasses(final Type intype) { 25.721 + return new Iterable<TypeSymbol>() { 25.722 + public Iterator<TypeSymbol> iterator() { 25.723 + return new Iterator<TypeSymbol>() { 25.724 + 25.725 + List<TypeSymbol> seen = List.nil(); 25.726 + TypeSymbol currentSym = symbolFor(intype); 25.727 + TypeSymbol prevSym = null; 25.728 + 25.729 + public boolean hasNext() { 25.730 + if (currentSym == syms.noSymbol) { 25.731 + currentSym = symbolFor(types.supertype(prevSym.type)); 25.732 + } 25.733 + return currentSym != null; 25.734 + } 25.735 + 25.736 + public TypeSymbol next() { 25.737 + prevSym = currentSym; 25.738 + currentSym = syms.noSymbol; 25.739 + Assert.check(prevSym != null || prevSym != syms.noSymbol); 25.740 + return prevSym; 25.741 + } 25.742 + 25.743 + public void remove() { 25.744 + throw new UnsupportedOperationException(); 25.745 + } 25.746 + 25.747 + TypeSymbol symbolFor(Type t) { 25.748 + if (t.tag != CLASS && 25.749 + t.tag != TYPEVAR) { 25.750 + return null; 25.751 + } 25.752 + while (t.tag == TYPEVAR) 25.753 + t = t.getUpperBound(); 25.754 + if (seen.contains(t.tsym)) { 25.755 + //degenerate case in which we have a circular 25.756 + //class hierarchy - because of ill-formed classfiles 25.757 + return null; 25.758 + } 25.759 + seen = seen.prepend(t.tsym); 25.760 + return t.tsym; 25.761 + } 25.762 + }; 25.763 + } 25.764 + }; 25.765 + } 25.766 + 25.767 + /** 25.768 + * Lookup a method with given name and argument types in a given scope 25.769 + */ 25.770 + Symbol lookupMethod(Env<AttrContext> env, 25.771 + Type site, 25.772 + Name name, 25.773 + List<Type> argtypes, 25.774 + List<Type> typeargtypes, 25.775 + Scope sc, 25.776 + Symbol bestSoFar, 25.777 + boolean allowBoxing, 25.778 + boolean useVarargs, 25.779 + boolean operator, 25.780 + boolean abstractok) { 25.781 + for (Symbol s : sc.getElementsByName(name, lookupFilter)) { 25.782 + bestSoFar = selectBest(env, site, argtypes, typeargtypes, s, 25.783 + bestSoFar, allowBoxing, useVarargs, operator); 25.784 + } 25.785 + return bestSoFar; 25.786 + } 25.787 + //where 25.788 + Filter<Symbol> lookupFilter = new Filter<Symbol>() { 25.789 + public boolean accepts(Symbol s) { 25.790 + return s.kind == MTH && 25.791 + (s.flags() & SYNTHETIC) == 0; 25.792 + } 25.793 + }; 25.794 + 25.795 /** Find unqualified method matching given name, type and value arguments. 25.796 * @param env The current environment. 25.797 * @param name The method's name. 25.798 @@ -1521,14 +1790,41 @@ 25.799 * 25.800 * @param sym The symbol that was found, or a ResolveError. 25.801 * @param pos The position to use for error reporting. 25.802 + * @param location The symbol the served as a context for this lookup 25.803 * @param site The original type from where the selection took place. 25.804 * @param name The symbol's name. 25.805 + * @param qualified Did we get here through a qualified expression resolution? 25.806 * @param argtypes The invocation's value arguments, 25.807 * if we looked for a method. 25.808 * @param typeargtypes The invocation's type arguments, 25.809 * if we looked for a method. 25.810 + * @param logResolveHelper helper class used to log resolve errors 25.811 */ 25.812 - Symbol access(Symbol sym, 25.813 + Symbol accessInternal(Symbol sym, 25.814 + DiagnosticPosition pos, 25.815 + Symbol location, 25.816 + Type site, 25.817 + Name name, 25.818 + boolean qualified, 25.819 + List<Type> argtypes, 25.820 + List<Type> typeargtypes, 25.821 + LogResolveHelper logResolveHelper) { 25.822 + if (sym.kind >= AMBIGUOUS) { 25.823 + ResolveError errSym = (ResolveError)sym; 25.824 + sym = errSym.access(name, qualified ? site.tsym : syms.noSymbol); 25.825 + argtypes = logResolveHelper.getArgumentTypes(errSym, sym, name, argtypes); 25.826 + if (logResolveHelper.resolveDiagnosticNeeded(site, argtypes, typeargtypes)) { 25.827 + logResolveError(errSym, pos, location, site, name, argtypes, typeargtypes); 25.828 + } 25.829 + } 25.830 + return sym; 25.831 + } 25.832 + 25.833 + /** 25.834 + * Variant of the generalized access routine, to be used for generating method 25.835 + * resolution diagnostics 25.836 + */ 25.837 + Symbol accessMethod(Symbol sym, 25.838 DiagnosticPosition pos, 25.839 Symbol location, 25.840 Type site, 25.841 @@ -1536,53 +1832,91 @@ 25.842 boolean qualified, 25.843 List<Type> argtypes, 25.844 List<Type> typeargtypes) { 25.845 - if (sym.kind >= AMBIGUOUS) { 25.846 - ResolveError errSym = (ResolveError)sym; 25.847 - if (!site.isErroneous() && 25.848 - !Type.isErroneous(argtypes) && 25.849 - (typeargtypes==null || !Type.isErroneous(typeargtypes))) 25.850 - logResolveError(errSym, pos, location, site, name, argtypes, typeargtypes); 25.851 - sym = errSym.access(name, qualified ? site.tsym : syms.noSymbol); 25.852 - } 25.853 - return sym; 25.854 + return accessInternal(sym, pos, location, site, name, qualified, argtypes, typeargtypes, methodLogResolveHelper); 25.855 } 25.856 25.857 - /** Same as original access(), but without location. 25.858 + /** Same as original accessMethod(), but without location. 25.859 */ 25.860 - Symbol access(Symbol sym, 25.861 + Symbol accessMethod(Symbol sym, 25.862 DiagnosticPosition pos, 25.863 Type site, 25.864 Name name, 25.865 boolean qualified, 25.866 List<Type> argtypes, 25.867 List<Type> typeargtypes) { 25.868 - return access(sym, pos, site.tsym, site, name, qualified, argtypes, typeargtypes); 25.869 + return accessMethod(sym, pos, site.tsym, site, name, qualified, argtypes, typeargtypes); 25.870 } 25.871 25.872 - /** Same as original access(), but without type arguments and arguments. 25.873 + /** 25.874 + * Variant of the generalized access routine, to be used for generating variable, 25.875 + * type resolution diagnostics 25.876 */ 25.877 - Symbol access(Symbol sym, 25.878 + Symbol accessBase(Symbol sym, 25.879 DiagnosticPosition pos, 25.880 Symbol location, 25.881 Type site, 25.882 Name name, 25.883 boolean qualified) { 25.884 - if (sym.kind >= AMBIGUOUS) 25.885 - return access(sym, pos, location, site, name, qualified, List.<Type>nil(), null); 25.886 - else 25.887 - return sym; 25.888 + return accessInternal(sym, pos, location, site, name, qualified, List.<Type>nil(), null, basicLogResolveHelper); 25.889 } 25.890 25.891 - /** Same as original access(), but without location, type arguments and arguments. 25.892 + /** Same as original accessBase(), but without location. 25.893 */ 25.894 - Symbol access(Symbol sym, 25.895 + Symbol accessBase(Symbol sym, 25.896 DiagnosticPosition pos, 25.897 Type site, 25.898 Name name, 25.899 boolean qualified) { 25.900 - return access(sym, pos, site.tsym, site, name, qualified); 25.901 + return accessBase(sym, pos, site.tsym, site, name, qualified); 25.902 } 25.903 25.904 + interface LogResolveHelper { 25.905 + boolean resolveDiagnosticNeeded(Type site, List<Type> argtypes, List<Type> typeargtypes); 25.906 + List<Type> getArgumentTypes(ResolveError errSym, Symbol accessedSym, Name name, List<Type> argtypes); 25.907 + } 25.908 + 25.909 + LogResolveHelper basicLogResolveHelper = new LogResolveHelper() { 25.910 + public boolean resolveDiagnosticNeeded(Type site, List<Type> argtypes, List<Type> typeargtypes) { 25.911 + return !site.isErroneous(); 25.912 + } 25.913 + public List<Type> getArgumentTypes(ResolveError errSym, Symbol accessedSym, Name name, List<Type> argtypes) { 25.914 + return argtypes; 25.915 + } 25.916 + }; 25.917 + 25.918 + LogResolveHelper methodLogResolveHelper = new LogResolveHelper() { 25.919 + public boolean resolveDiagnosticNeeded(Type site, List<Type> argtypes, List<Type> typeargtypes) { 25.920 + return !site.isErroneous() && 25.921 + !Type.isErroneous(argtypes) && 25.922 + (typeargtypes == null || !Type.isErroneous(typeargtypes)); 25.923 + } 25.924 + public List<Type> getArgumentTypes(ResolveError errSym, Symbol accessedSym, Name name, List<Type> argtypes) { 25.925 + if (syms.operatorNames.contains(name)) { 25.926 + return argtypes; 25.927 + } else { 25.928 + Symbol msym = errSym.kind == WRONG_MTH ? 25.929 + ((InapplicableSymbolError)errSym).errCandidate().sym : accessedSym; 25.930 + 25.931 + List<Type> argtypes2 = Type.map(argtypes, 25.932 + deferredAttr.new RecoveryDeferredTypeMap(AttrMode.SPECULATIVE, msym, currentResolutionContext.firstErroneousResolutionPhase())); 25.933 + 25.934 + if (msym != accessedSym) { 25.935 + //fixup deferred type caches - this 'hack' is required because the symbol 25.936 + //returned by InapplicableSymbolError.access() will hide the candidate 25.937 + //method symbol that can be used for lookups in the speculative cache, 25.938 + //causing problems in Attr.checkId() 25.939 + for (Type t : argtypes) { 25.940 + if (t.tag == DEFERRED) { 25.941 + DeferredType dt = (DeferredType)t; 25.942 + dt.speculativeCache.dupAllTo(msym, accessedSym); 25.943 + } 25.944 + } 25.945 + } 25.946 + return argtypes2; 25.947 + } 25.948 + } 25.949 + }; 25.950 + 25.951 /** Check that sym is not an abstract method. 25.952 */ 25.953 void checkNonAbstract(DiagnosticPosition pos, Symbol sym) { 25.954 @@ -1641,7 +1975,7 @@ 25.955 */ 25.956 Symbol resolveIdent(DiagnosticPosition pos, Env<AttrContext> env, 25.957 Name name, int kind) { 25.958 - return access( 25.959 + return accessBase( 25.960 findIdent(env, name, kind), 25.961 pos, env.enclClass.sym.type, name, false); 25.962 } 25.963 @@ -1666,19 +2000,19 @@ 25.964 while (steps.nonEmpty() && 25.965 steps.head.isApplicable(boxingEnabled, varargsEnabled) && 25.966 sym.kind >= ERRONEOUS) { 25.967 - currentResolutionContext.step = steps.head; 25.968 + currentResolutionContext.step = env.info.pendingResolutionPhase = steps.head; 25.969 sym = findFun(env, name, argtypes, typeargtypes, 25.970 steps.head.isBoxingRequired, 25.971 - env.info.varArgs = steps.head.isVarargsRequired); 25.972 + steps.head.isVarargsRequired); 25.973 currentResolutionContext.resolutionCache.put(steps.head, sym); 25.974 steps = steps.tail; 25.975 } 25.976 if (sym.kind >= AMBIGUOUS) {//if nothing is found return the 'first' error 25.977 MethodResolutionPhase errPhase = 25.978 currentResolutionContext.firstErroneousResolutionPhase(); 25.979 - sym = access(currentResolutionContext.resolutionCache.get(errPhase), 25.980 + sym = accessMethod(currentResolutionContext.resolutionCache.get(errPhase), 25.981 pos, env.enclClass.sym.type, name, false, argtypes, typeargtypes); 25.982 - env.info.varArgs = errPhase.isVarargsRequired; 25.983 + env.info.pendingResolutionPhase = errPhase; 25.984 } 25.985 return sym; 25.986 } 25.987 @@ -1718,10 +2052,10 @@ 25.988 while (steps.nonEmpty() && 25.989 steps.head.isApplicable(boxingEnabled, varargsEnabled) && 25.990 sym.kind >= ERRONEOUS) { 25.991 - currentResolutionContext.step = steps.head; 25.992 + currentResolutionContext.step = env.info.pendingResolutionPhase = steps.head; 25.993 sym = findMethod(env, site, name, argtypes, typeargtypes, 25.994 steps.head.isBoxingRequired(), 25.995 - env.info.varArgs = steps.head.isVarargsRequired(), false); 25.996 + steps.head.isVarargsRequired(), false); 25.997 currentResolutionContext.resolutionCache.put(steps.head, sym); 25.998 steps = steps.tail; 25.999 } 25.1000 @@ -1729,13 +2063,13 @@ 25.1001 //if nothing is found return the 'first' error 25.1002 MethodResolutionPhase errPhase = 25.1003 currentResolutionContext.firstErroneousResolutionPhase(); 25.1004 - sym = access(currentResolutionContext.resolutionCache.get(errPhase), 25.1005 + sym = accessMethod(currentResolutionContext.resolutionCache.get(errPhase), 25.1006 pos, location, site, name, true, argtypes, typeargtypes); 25.1007 - env.info.varArgs = errPhase.isVarargsRequired; 25.1008 + env.info.pendingResolutionPhase = errPhase; 25.1009 } else if (allowMethodHandles) { 25.1010 MethodSymbol msym = (MethodSymbol)sym; 25.1011 if (msym.isSignaturePolymorphic(types)) { 25.1012 - env.info.varArgs = false; 25.1013 + env.info.pendingResolutionPhase = BASIC; 25.1014 return findPolymorphicSignatureInstance(env, sym, argtypes); 25.1015 } 25.1016 } 25.1017 @@ -1757,7 +2091,7 @@ 25.1018 Symbol spMethod, 25.1019 List<Type> argtypes) { 25.1020 Type mtype = infer.instantiatePolymorphicSignatureInstance(env, 25.1021 - (MethodSymbol)spMethod, argtypes); 25.1022 + (MethodSymbol)spMethod, currentResolutionContext, argtypes); 25.1023 for (Symbol sym : polymorphicSignatureScope.getElementsByName(spMethod.name)) { 25.1024 if (types.isSameType(mtype, sym.type)) { 25.1025 return sym; 25.1026 @@ -1825,18 +2159,18 @@ 25.1027 while (steps.nonEmpty() && 25.1028 steps.head.isApplicable(boxingEnabled, varargsEnabled) && 25.1029 sym.kind >= ERRONEOUS) { 25.1030 - currentResolutionContext.step = steps.head; 25.1031 + currentResolutionContext.step = env.info.pendingResolutionPhase = steps.head; 25.1032 sym = findConstructor(pos, env, site, argtypes, typeargtypes, 25.1033 steps.head.isBoxingRequired(), 25.1034 - env.info.varArgs = steps.head.isVarargsRequired()); 25.1035 + steps.head.isVarargsRequired()); 25.1036 currentResolutionContext.resolutionCache.put(steps.head, sym); 25.1037 steps = steps.tail; 25.1038 } 25.1039 if (sym.kind >= AMBIGUOUS) {//if nothing is found return the 'first' error 25.1040 MethodResolutionPhase errPhase = currentResolutionContext.firstErroneousResolutionPhase(); 25.1041 - sym = access(currentResolutionContext.resolutionCache.get(errPhase), 25.1042 + sym = accessMethod(currentResolutionContext.resolutionCache.get(errPhase), 25.1043 pos, site, names.init, true, argtypes, typeargtypes); 25.1044 - env.info.varArgs = errPhase.isVarargsRequired(); 25.1045 + env.info.pendingResolutionPhase = errPhase; 25.1046 } 25.1047 return sym; 25.1048 } 25.1049 @@ -1868,18 +2202,20 @@ 25.1050 while (steps.nonEmpty() && 25.1051 steps.head.isApplicable(boxingEnabled, varargsEnabled) && 25.1052 sym.kind >= ERRONEOUS) { 25.1053 - currentResolutionContext.step = steps.head; 25.1054 + currentResolutionContext.step = env.info.pendingResolutionPhase = steps.head; 25.1055 sym = findDiamond(env, site, argtypes, typeargtypes, 25.1056 steps.head.isBoxingRequired(), 25.1057 - env.info.varArgs = steps.head.isVarargsRequired()); 25.1058 + steps.head.isVarargsRequired()); 25.1059 currentResolutionContext.resolutionCache.put(steps.head, sym); 25.1060 steps = steps.tail; 25.1061 } 25.1062 if (sym.kind >= AMBIGUOUS) { 25.1063 - final JCDiagnostic details = sym.kind == WRONG_MTH ? 25.1064 - currentResolutionContext.candidates.head.details : 25.1065 + Symbol errSym = 25.1066 + currentResolutionContext.resolutionCache.get(currentResolutionContext.firstErroneousResolutionPhase()); 25.1067 + final JCDiagnostic details = errSym.kind == WRONG_MTH ? 25.1068 + ((InapplicableSymbolError)errSym).errCandidate().details : 25.1069 null; 25.1070 - Symbol errSym = new ResolveError(WRONG_MTH, "diamond error") { 25.1071 + errSym = new InapplicableSymbolError(errSym.kind, "diamondError", currentResolutionContext) { 25.1072 @Override 25.1073 JCDiagnostic getDiagnostic(DiagnosticType dkind, DiagnosticPosition pos, 25.1074 Symbol location, Type site, Name name, List<Type> argtypes, List<Type> typeargtypes) { 25.1075 @@ -1891,8 +2227,8 @@ 25.1076 } 25.1077 }; 25.1078 MethodResolutionPhase errPhase = currentResolutionContext.firstErroneousResolutionPhase(); 25.1079 - sym = access(errSym, pos, site, names.init, true, argtypes, typeargtypes); 25.1080 - env.info.varArgs = errPhase.isVarargsRequired(); 25.1081 + sym = accessMethod(errSym, pos, site, names.init, true, argtypes, typeargtypes); 25.1082 + env.info.pendingResolutionPhase = errPhase; 25.1083 } 25.1084 return sym; 25.1085 } 25.1086 @@ -1919,16 +2255,23 @@ 25.1087 for (Scope.Entry e = site.tsym.members().lookup(names.init); 25.1088 e.scope != null; 25.1089 e = e.next()) { 25.1090 + final Symbol sym = e.sym; 25.1091 //- System.out.println(" e " + e.sym); 25.1092 - if (e.sym.kind == MTH && 25.1093 - (e.sym.flags_field & SYNTHETIC) == 0) { 25.1094 + if (sym.kind == MTH && 25.1095 + (sym.flags_field & SYNTHETIC) == 0) { 25.1096 List<Type> oldParams = e.sym.type.tag == FORALL ? 25.1097 - ((ForAll)e.sym.type).tvars : 25.1098 + ((ForAll)sym.type).tvars : 25.1099 List.<Type>nil(); 25.1100 Type constrType = new ForAll(site.tsym.type.getTypeArguments().appendList(oldParams), 25.1101 - types.createMethodTypeWithReturn(e.sym.type.asMethodType(), site)); 25.1102 + types.createMethodTypeWithReturn(sym.type.asMethodType(), site)); 25.1103 + MethodSymbol newConstr = new MethodSymbol(sym.flags(), names.init, constrType, site.tsym) { 25.1104 + @Override 25.1105 + public Symbol baseSymbol() { 25.1106 + return sym; 25.1107 + } 25.1108 + }; 25.1109 bestSoFar = selectBest(env, site, argtypes, typeargtypes, 25.1110 - new MethodSymbol(e.sym.flags(), names.init, constrType, site.tsym), 25.1111 + newConstr, 25.1112 bestSoFar, 25.1113 allowBoxing, 25.1114 useVarargs, 25.1115 @@ -1938,6 +2281,335 @@ 25.1116 return bestSoFar; 25.1117 } 25.1118 25.1119 + /** 25.1120 + * Resolution of member references is typically done as a single 25.1121 + * overload resolution step, where the argument types A are inferred from 25.1122 + * the target functional descriptor. 25.1123 + * 25.1124 + * If the member reference is a method reference with a type qualifier, 25.1125 + * a two-step lookup process is performed. The first step uses the 25.1126 + * expected argument list A, while the second step discards the first 25.1127 + * type from A (which is treated as a receiver type). 25.1128 + * 25.1129 + * There are two cases in which inference is performed: (i) if the member 25.1130 + * reference is a constructor reference and the qualifier type is raw - in 25.1131 + * which case diamond inference is used to infer a parameterization for the 25.1132 + * type qualifier; (ii) if the member reference is an unbound reference 25.1133 + * where the type qualifier is raw - in that case, during the unbound lookup 25.1134 + * the receiver argument type is used to infer an instantiation for the raw 25.1135 + * qualifier type. 25.1136 + * 25.1137 + * When a multi-step resolution process is exploited, it is an error 25.1138 + * if two candidates are found (ambiguity). 25.1139 + * 25.1140 + * This routine returns a pair (T,S), where S is the member reference symbol, 25.1141 + * and T is the type of the class in which S is defined. This is necessary as 25.1142 + * the type T might be dynamically inferred (i.e. if constructor reference 25.1143 + * has a raw qualifier). 25.1144 + */ 25.1145 + Pair<Symbol, ReferenceLookupHelper> resolveMemberReference(DiagnosticPosition pos, 25.1146 + Env<AttrContext> env, 25.1147 + JCMemberReference referenceTree, 25.1148 + Type site, 25.1149 + Name name, List<Type> argtypes, 25.1150 + List<Type> typeargtypes, 25.1151 + boolean boxingAllowed) { 25.1152 + //step 1 - bound lookup 25.1153 + ReferenceLookupHelper boundLookupHelper = name.equals(names.init) ? 25.1154 + new ConstructorReferenceLookupHelper(referenceTree, site, argtypes, typeargtypes, boxingAllowed) : 25.1155 + new MethodReferenceLookupHelper(referenceTree, name, site, argtypes, typeargtypes, boxingAllowed); 25.1156 + Env<AttrContext> boundEnv = env.dup(env.tree, env.info.dup()); 25.1157 + Symbol boundSym = findMemberReference(boundEnv, boundLookupHelper); 25.1158 + 25.1159 + //step 2 - unbound lookup 25.1160 + ReferenceLookupHelper unboundLookupHelper = boundLookupHelper.unboundLookup(); 25.1161 + Env<AttrContext> unboundEnv = env.dup(env.tree, env.info.dup()); 25.1162 + Symbol unboundSym = findMemberReference(unboundEnv, unboundLookupHelper); 25.1163 + 25.1164 + //merge results 25.1165 + Pair<Symbol, ReferenceLookupHelper> res; 25.1166 + if (unboundSym.kind != MTH) { 25.1167 + res = new Pair<Symbol, ReferenceLookupHelper>(boundSym, boundLookupHelper); 25.1168 + env.info.pendingResolutionPhase = boundEnv.info.pendingResolutionPhase; 25.1169 + } else if (boundSym.kind == MTH) { 25.1170 + res = new Pair<Symbol, ReferenceLookupHelper>(ambiguityError(boundSym, unboundSym), boundLookupHelper); 25.1171 + env.info.pendingResolutionPhase = boundEnv.info.pendingResolutionPhase; 25.1172 + } else { 25.1173 + res = new Pair<Symbol, ReferenceLookupHelper>(unboundSym, unboundLookupHelper); 25.1174 + env.info.pendingResolutionPhase = unboundEnv.info.pendingResolutionPhase; 25.1175 + } 25.1176 + 25.1177 + return res; 25.1178 + } 25.1179 + 25.1180 + /** 25.1181 + * Helper for defining custom method-like lookup logic; a lookup helper 25.1182 + * provides hooks for (i) the actual lookup logic and (ii) accessing the 25.1183 + * lookup result (this step might result in compiler diagnostics to be generated) 25.1184 + */ 25.1185 + abstract class LookupHelper { 25.1186 + 25.1187 + /** name of the symbol to lookup */ 25.1188 + Name name; 25.1189 + 25.1190 + /** location in which the lookup takes place */ 25.1191 + Type site; 25.1192 + 25.1193 + /** actual types used during the lookup */ 25.1194 + List<Type> argtypes; 25.1195 + 25.1196 + /** type arguments used during the lookup */ 25.1197 + List<Type> typeargtypes; 25.1198 + 25.1199 + LookupHelper(Name name, Type site, List<Type> argtypes, List<Type> typeargtypes) { 25.1200 + this.name = name; 25.1201 + this.site = site; 25.1202 + this.argtypes = argtypes; 25.1203 + this.typeargtypes = typeargtypes; 25.1204 + } 25.1205 + 25.1206 + /** 25.1207 + * Search for a symbol under a given overload resolution phase - this method 25.1208 + * is usually called several times, once per each overload resolution phase 25.1209 + */ 25.1210 + abstract Symbol lookup(Env<AttrContext> env, MethodResolutionPhase phase); 25.1211 + 25.1212 + /** 25.1213 + * Validate the result of the lookup 25.1214 + */ 25.1215 + abstract Symbol access(Env<AttrContext> env, Symbol symbol); 25.1216 + } 25.1217 + 25.1218 + /** 25.1219 + * Helper class for member reference lookup. A reference lookup helper 25.1220 + * defines the basic logic for member reference lookup; a method gives 25.1221 + * access to an 'unbound' helper used to perform an unbound member 25.1222 + * reference lookup. 25.1223 + */ 25.1224 + abstract class ReferenceLookupHelper extends LookupHelper { 25.1225 + 25.1226 + /** The member reference tree */ 25.1227 + JCMemberReference referenceTree; 25.1228 + 25.1229 + /** Max overload resolution phase handled by this helper */ 25.1230 + MethodResolutionPhase maxPhase; 25.1231 + 25.1232 + ReferenceLookupHelper(JCMemberReference referenceTree, Name name, Type site, 25.1233 + List<Type> argtypes, List<Type> typeargtypes, boolean boxingAllowed) { 25.1234 + super(name, site, argtypes, typeargtypes); 25.1235 + this.referenceTree = referenceTree; 25.1236 + this.maxPhase = boxingAllowed ? VARARITY : BASIC; 25.1237 + } 25.1238 + 25.1239 + /** 25.1240 + * Returns an unbound version of this lookup helper. By default, this 25.1241 + * method returns an dummy lookup helper. 25.1242 + */ 25.1243 + ReferenceLookupHelper unboundLookup() { 25.1244 + //dummy loopkup helper that always return 'methodNotFound' 25.1245 + return new ReferenceLookupHelper(referenceTree, name, site, argtypes, typeargtypes, maxPhase.isBoxingRequired()) { 25.1246 + @Override 25.1247 + ReferenceLookupHelper unboundLookup() { 25.1248 + return this; 25.1249 + } 25.1250 + @Override 25.1251 + Symbol lookupReference(Env<AttrContext> env, MethodResolutionPhase phase) { 25.1252 + return methodNotFound; 25.1253 + } 25.1254 + @Override 25.1255 + ReferenceKind referenceKind(Symbol sym) { 25.1256 + Assert.error(); 25.1257 + return null; 25.1258 + } 25.1259 + }; 25.1260 + } 25.1261 + 25.1262 + /** 25.1263 + * Get the kind of the member reference 25.1264 + */ 25.1265 + abstract JCMemberReference.ReferenceKind referenceKind(Symbol sym); 25.1266 + 25.1267 + @Override 25.1268 + Symbol lookup(Env<AttrContext> env, MethodResolutionPhase phase) { 25.1269 + return (env.info.pendingResolutionPhase.ordinal() > maxPhase.ordinal()) ? 25.1270 + methodNotFound : lookupReference(env, phase); 25.1271 + } 25.1272 + 25.1273 + abstract Symbol lookupReference(Env<AttrContext> env, MethodResolutionPhase phase); 25.1274 + 25.1275 + Symbol access(Env<AttrContext> env, Symbol sym) { 25.1276 + if (sym.kind >= AMBIGUOUS) { 25.1277 + MethodResolutionPhase errPhase = currentResolutionContext.firstErroneousResolutionPhase(); 25.1278 + if (errPhase.ordinal() > maxPhase.ordinal()) { 25.1279 + errPhase = maxPhase; 25.1280 + } 25.1281 + env.info.pendingResolutionPhase = errPhase; 25.1282 + sym = currentResolutionContext.resolutionCache.get(errPhase); 25.1283 + } 25.1284 + return sym; 25.1285 + } 25.1286 + } 25.1287 + 25.1288 + /** 25.1289 + * Helper class for method reference lookup. The lookup logic is based 25.1290 + * upon Resolve.findMethod; in certain cases, this helper class has a 25.1291 + * corresponding unbound helper class (see UnboundMethodReferenceLookupHelper). 25.1292 + * In such cases, non-static lookup results are thrown away. 25.1293 + */ 25.1294 + class MethodReferenceLookupHelper extends ReferenceLookupHelper { 25.1295 + 25.1296 + MethodReferenceLookupHelper(JCMemberReference referenceTree, Name name, Type site, 25.1297 + List<Type> argtypes, List<Type> typeargtypes, boolean boxingAllowed) { 25.1298 + super(referenceTree, name, site, argtypes, typeargtypes, boxingAllowed); 25.1299 + } 25.1300 + 25.1301 + protected Symbol lookupReferenceInternal(Env<AttrContext> env, MethodResolutionPhase phase) { 25.1302 + return findMethod(env, site, name, argtypes, typeargtypes, 25.1303 + phase.isBoxingRequired(), phase.isVarargsRequired(), syms.operatorNames.contains(name)); 25.1304 + } 25.1305 + 25.1306 + protected Symbol adjustLookupResult(Env<AttrContext> env, Symbol sym) { 25.1307 + return !TreeInfo.isStaticSelector(referenceTree.expr, names) || 25.1308 + sym.kind != MTH || 25.1309 + sym.isStatic() ? sym : new StaticError(sym); 25.1310 + } 25.1311 + 25.1312 + @Override 25.1313 + final Symbol lookupReference(Env<AttrContext> env, MethodResolutionPhase phase) { 25.1314 + return adjustLookupResult(env, lookupReferenceInternal(env, phase)); 25.1315 + } 25.1316 + 25.1317 + @Override 25.1318 + ReferenceLookupHelper unboundLookup() { 25.1319 + if (TreeInfo.isStaticSelector(referenceTree.expr, names) && 25.1320 + argtypes.nonEmpty() && 25.1321 + types.isSubtypeUnchecked(argtypes.head, site)) { 25.1322 + return new UnboundMethodReferenceLookupHelper(referenceTree, name, 25.1323 + site, argtypes, typeargtypes, maxPhase.isBoxingRequired()); 25.1324 + } else { 25.1325 + return super.unboundLookup(); 25.1326 + } 25.1327 + } 25.1328 + 25.1329 + @Override 25.1330 + ReferenceKind referenceKind(Symbol sym) { 25.1331 + if (sym.isStatic()) { 25.1332 + return TreeInfo.isStaticSelector(referenceTree.expr, names) ? 25.1333 + ReferenceKind.STATIC : ReferenceKind.STATIC_EVAL; 25.1334 + } else { 25.1335 + Name selName = TreeInfo.name(referenceTree.getQualifierExpression()); 25.1336 + return selName != null && selName == names._super ? 25.1337 + ReferenceKind.SUPER : 25.1338 + ReferenceKind.BOUND; 25.1339 + } 25.1340 + } 25.1341 + } 25.1342 + 25.1343 + /** 25.1344 + * Helper class for unbound method reference lookup. Essentially the same 25.1345 + * as the basic method reference lookup helper; main difference is that static 25.1346 + * lookup results are thrown away. If qualifier type is raw, an attempt to 25.1347 + * infer a parameterized type is made using the first actual argument (that 25.1348 + * would otherwise be ignored during the lookup). 25.1349 + */ 25.1350 + class UnboundMethodReferenceLookupHelper extends MethodReferenceLookupHelper { 25.1351 + 25.1352 + UnboundMethodReferenceLookupHelper(JCMemberReference referenceTree, Name name, Type site, 25.1353 + List<Type> argtypes, List<Type> typeargtypes, boolean boxingAllowed) { 25.1354 + super(referenceTree, name, 25.1355 + site.isRaw() ? types.asSuper(argtypes.head, site.tsym) : site, 25.1356 + argtypes.tail, typeargtypes, boxingAllowed); 25.1357 + } 25.1358 + 25.1359 + @Override 25.1360 + protected Symbol adjustLookupResult(Env<AttrContext> env, Symbol sym) { 25.1361 + return sym.kind != MTH || !sym.isStatic() ? sym : new StaticError(sym); 25.1362 + } 25.1363 + 25.1364 + @Override 25.1365 + ReferenceLookupHelper unboundLookup() { 25.1366 + return this; 25.1367 + } 25.1368 + 25.1369 + @Override 25.1370 + ReferenceKind referenceKind(Symbol sym) { 25.1371 + return ReferenceKind.UNBOUND; 25.1372 + } 25.1373 + } 25.1374 + 25.1375 + /** 25.1376 + * Helper class for constructor reference lookup. The lookup logic is based 25.1377 + * upon either Resolve.findMethod or Resolve.findDiamond - depending on 25.1378 + * whether the constructor reference needs diamond inference (this is the case 25.1379 + * if the qualifier type is raw). A special erroneous symbol is returned 25.1380 + * if the lookup returns the constructor of an inner class and there's no 25.1381 + * enclosing instance in scope. 25.1382 + */ 25.1383 + class ConstructorReferenceLookupHelper extends ReferenceLookupHelper { 25.1384 + 25.1385 + boolean needsInference; 25.1386 + 25.1387 + ConstructorReferenceLookupHelper(JCMemberReference referenceTree, Type site, List<Type> argtypes, 25.1388 + List<Type> typeargtypes, boolean boxingAllowed) { 25.1389 + super(referenceTree, names.init, site, argtypes, typeargtypes, boxingAllowed); 25.1390 + if (site.isRaw()) { 25.1391 + this.site = new ClassType(site.getEnclosingType(), site.tsym.type.getTypeArguments(), site.tsym); 25.1392 + needsInference = true; 25.1393 + } 25.1394 + } 25.1395 + 25.1396 + @Override 25.1397 + protected Symbol lookupReference(Env<AttrContext> env, MethodResolutionPhase phase) { 25.1398 + Symbol sym = needsInference ? 25.1399 + findDiamond(env, site, argtypes, typeargtypes, phase.isBoxingRequired(), phase.isVarargsRequired()) : 25.1400 + findMethod(env, site, name, argtypes, typeargtypes, 25.1401 + phase.isBoxingRequired(), phase.isVarargsRequired(), syms.operatorNames.contains(name)); 25.1402 + return sym.kind != MTH || 25.1403 + site.getEnclosingType().tag == NONE || 25.1404 + hasEnclosingInstance(env, site) ? 25.1405 + sym : new InvalidSymbolError(Kinds.MISSING_ENCL, sym, null) { 25.1406 + @Override 25.1407 + JCDiagnostic getDiagnostic(DiagnosticType dkind, DiagnosticPosition pos, Symbol location, Type site, Name name, List<Type> argtypes, List<Type> typeargtypes) { 25.1408 + return diags.create(dkind, log.currentSource(), pos, 25.1409 + "cant.access.inner.cls.constr", site.tsym.name, argtypes, site.getEnclosingType()); 25.1410 + } 25.1411 + }; 25.1412 + } 25.1413 + 25.1414 + @Override 25.1415 + ReferenceKind referenceKind(Symbol sym) { 25.1416 + return site.getEnclosingType().tag == NONE ? 25.1417 + ReferenceKind.TOPLEVEL : ReferenceKind.IMPLICIT_INNER; 25.1418 + } 25.1419 + } 25.1420 + 25.1421 + /** 25.1422 + * Resolution step for member reference. This generalizes a standard 25.1423 + * method/constructor lookup - on each overload resolution step, a 25.1424 + * lookup helper class is used to perform the reference lookup; at the end 25.1425 + * of the lookup, the helper is used to validate the results. 25.1426 + */ 25.1427 + Symbol findMemberReference(Env<AttrContext> env, LookupHelper lookupHelper) { 25.1428 + MethodResolutionContext prevResolutionContext = currentResolutionContext; 25.1429 + try { 25.1430 + currentResolutionContext = new MethodResolutionContext(); 25.1431 + Symbol sym = methodNotFound; 25.1432 + List<MethodResolutionPhase> steps = methodResolutionSteps; 25.1433 + while (steps.nonEmpty() && 25.1434 + steps.head.isApplicable(boxingEnabled, varargsEnabled) && 25.1435 + sym.kind >= ERRONEOUS) { 25.1436 + currentResolutionContext.step = env.info.pendingResolutionPhase = steps.head; 25.1437 + sym = lookupHelper.lookup(env, steps.head); 25.1438 + currentResolutionContext.resolutionCache.put(steps.head, sym); 25.1439 + steps = steps.tail; 25.1440 + } 25.1441 + return lookupHelper.access(env, sym); 25.1442 + } 25.1443 + finally { 25.1444 + currentResolutionContext = prevResolutionContext; 25.1445 + } 25.1446 + } 25.1447 + 25.1448 /** Resolve constructor. 25.1449 * @param pos The position to use for error reporting. 25.1450 * @param env The environment current at the constructor invocation. 25.1451 @@ -2013,7 +2685,7 @@ 25.1452 if (boxingEnabled && sym.kind >= WRONG_MTHS) 25.1453 sym = findMethod(env, syms.predefClass.type, name, argtypes, 25.1454 null, true, false, true); 25.1455 - return access(sym, pos, env.enclClass.sym.type, name, 25.1456 + return accessMethod(sym, pos, env.enclClass.sym.type, name, 25.1457 false, argtypes, null); 25.1458 } 25.1459 finally { 25.1460 @@ -2065,7 +2737,7 @@ 25.1461 Symbol sym = env1.info.scope.lookup(name).sym; 25.1462 if (sym != null) { 25.1463 if (staticOnly) sym = new StaticError(sym); 25.1464 - return access(sym, pos, env.enclClass.sym.type, 25.1465 + return accessBase(sym, pos, env.enclClass.sym.type, 25.1466 name, true); 25.1467 } 25.1468 } 25.1469 @@ -2087,6 +2759,23 @@ 25.1470 Env<AttrContext> env, 25.1471 Symbol member, 25.1472 boolean isSuperCall) { 25.1473 + Symbol sym = resolveSelfContainingInternal(env, member, isSuperCall); 25.1474 + if (sym == null) { 25.1475 + log.error(pos, "encl.class.required", member); 25.1476 + return syms.errSymbol; 25.1477 + } else { 25.1478 + return accessBase(sym, pos, env.enclClass.sym.type, sym.name, true); 25.1479 + } 25.1480 + } 25.1481 + 25.1482 + boolean hasEnclosingInstance(Env<AttrContext> env, Type type) { 25.1483 + Symbol encl = resolveSelfContainingInternal(env, type.tsym, false); 25.1484 + return encl != null && encl.kind < ERRONEOUS; 25.1485 + } 25.1486 + 25.1487 + private Symbol resolveSelfContainingInternal(Env<AttrContext> env, 25.1488 + Symbol member, 25.1489 + boolean isSuperCall) { 25.1490 Name name = names._this; 25.1491 Env<AttrContext> env1 = isSuperCall ? env.outer : env; 25.1492 boolean staticOnly = false; 25.1493 @@ -2097,8 +2786,7 @@ 25.1494 Symbol sym = env1.info.scope.lookup(name).sym; 25.1495 if (sym != null) { 25.1496 if (staticOnly) sym = new StaticError(sym); 25.1497 - return access(sym, pos, env.enclClass.sym.type, 25.1498 - name, true); 25.1499 + return sym; 25.1500 } 25.1501 } 25.1502 if ((env1.enclClass.sym.flags() & STATIC) != 0) 25.1503 @@ -2106,8 +2794,7 @@ 25.1504 env1 = env1.outer; 25.1505 } 25.1506 } 25.1507 - log.error(pos, "encl.class.required", member); 25.1508 - return syms.errSymbol; 25.1509 + return null; 25.1510 } 25.1511 25.1512 /** 25.1513 @@ -2155,7 +2842,19 @@ 25.1514 private final LocalizedString noArgs = new LocalizedString("compiler.misc.no.args"); 25.1515 25.1516 public Object methodArguments(List<Type> argtypes) { 25.1517 - return argtypes == null || argtypes.isEmpty() ? noArgs : argtypes; 25.1518 + if (argtypes == null || argtypes.isEmpty()) { 25.1519 + return noArgs; 25.1520 + } else { 25.1521 + ListBuffer<Object> diagArgs = ListBuffer.lb(); 25.1522 + for (Type t : argtypes) { 25.1523 + if (t.tag == DEFERRED) { 25.1524 + diagArgs.append(((DeferredAttr.DeferredType)t).tree); 25.1525 + } else { 25.1526 + diagArgs.append(t); 25.1527 + } 25.1528 + } 25.1529 + return diagArgs; 25.1530 + } 25.1531 } 25.1532 25.1533 /** 25.1534 @@ -2163,7 +2862,7 @@ 25.1535 * represent a different kinds of resolution error - as such they must 25.1536 * specify how they map into concrete compiler diagnostics. 25.1537 */ 25.1538 - private abstract class ResolveError extends Symbol { 25.1539 + abstract class ResolveError extends Symbol { 25.1540 25.1541 /** The name of the kind of error, for debugging only. */ 25.1542 final String debugName; 25.1543 @@ -2220,17 +2919,6 @@ 25.1544 Name name, 25.1545 List<Type> argtypes, 25.1546 List<Type> typeargtypes); 25.1547 - 25.1548 - /** 25.1549 - * A name designates an operator if it consists 25.1550 - * of a non-empty sequence of operator symbols {@literal +-~!/*%&|^<>= } 25.1551 - */ 25.1552 - boolean isOperator(Name name) { 25.1553 - int i = 0; 25.1554 - while (i < name.getByteLength() && 25.1555 - "+-~!*/%&|^<>=".indexOf(name.getByteAt(i)) >= 0) i++; 25.1556 - return i > 0 && i == name.getByteLength(); 25.1557 - } 25.1558 } 25.1559 25.1560 /** 25.1561 @@ -2291,7 +2979,7 @@ 25.1562 if (name == names.error) 25.1563 return null; 25.1564 25.1565 - if (isOperator(name)) { 25.1566 + if (syms.operatorNames.contains(name)) { 25.1567 boolean isUnaryOp = argtypes.size() == 1; 25.1568 String key = argtypes.size() == 1 ? 25.1569 "operator.cant.be.applied" : 25.1570 @@ -2313,8 +3001,7 @@ 25.1571 hasLocation = !location.name.equals(names._this) && 25.1572 !location.name.equals(names._super); 25.1573 } 25.1574 - boolean isConstructor = kind == ABSENT_MTH && 25.1575 - name == names.table.names.init; 25.1576 + boolean isConstructor = kind == ABSENT_MTH && name == names.init; 25.1577 KindName kindname = isConstructor ? KindName.CONSTRUCTOR : absentKind(kind); 25.1578 Name idname = isConstructor ? site.tsym.name : name; 25.1579 String errKey = getErrorKey(kindname, typeargtypes.nonEmpty(), hasLocation); 25.1580 @@ -2365,12 +3052,15 @@ 25.1581 */ 25.1582 class InapplicableSymbolError extends ResolveError { 25.1583 25.1584 - InapplicableSymbolError() { 25.1585 - super(WRONG_MTH, "inapplicable symbol error"); 25.1586 + protected MethodResolutionContext resolveContext; 25.1587 + 25.1588 + InapplicableSymbolError(MethodResolutionContext context) { 25.1589 + this(WRONG_MTH, "inapplicable symbol error", context); 25.1590 } 25.1591 25.1592 - protected InapplicableSymbolError(int kind, String debugName) { 25.1593 + protected InapplicableSymbolError(int kind, String debugName, MethodResolutionContext context) { 25.1594 super(kind, debugName); 25.1595 + this.resolveContext = context; 25.1596 } 25.1597 25.1598 @Override 25.1599 @@ -2394,7 +3084,7 @@ 25.1600 if (name == names.error) 25.1601 return null; 25.1602 25.1603 - if (isOperator(name)) { 25.1604 + if (syms.operatorNames.contains(name)) { 25.1605 boolean isUnaryOp = argtypes.size() == 1; 25.1606 String key = argtypes.size() == 1 ? 25.1607 "operator.cant.be.applied" : 25.1608 @@ -2408,7 +3098,7 @@ 25.1609 Candidate c = errCandidate(); 25.1610 Symbol ws = c.sym.asMemberOf(site, types); 25.1611 return diags.create(dkind, log.currentSource(), pos, 25.1612 - "cant.apply.symbol" + (c.details != null ? ".1" : ""), 25.1613 + "cant.apply.symbol", 25.1614 kindName(ws), 25.1615 ws.name == names.init ? ws.owner.name : ws.name, 25.1616 methodArguments(ws.type.getParameterTypes()), 25.1617 @@ -2425,13 +3115,13 @@ 25.1618 } 25.1619 25.1620 protected boolean shouldReport(Candidate c) { 25.1621 + MethodResolutionPhase errPhase = resolveContext.firstErroneousResolutionPhase(); 25.1622 return !c.isApplicable() && 25.1623 - (((c.sym.flags() & VARARGS) != 0 && c.step == VARARITY) || 25.1624 - (c.sym.flags() & VARARGS) == 0 && c.step == (boxingEnabled ? BOX : BASIC)); 25.1625 + c.step == errPhase; 25.1626 } 25.1627 25.1628 private Candidate errCandidate() { 25.1629 - for (Candidate c : currentResolutionContext.candidates) { 25.1630 + for (Candidate c : resolveContext.candidates) { 25.1631 if (shouldReport(c)) { 25.1632 return c; 25.1633 } 25.1634 @@ -2448,8 +3138,8 @@ 25.1635 */ 25.1636 class InapplicableSymbolsError extends InapplicableSymbolError { 25.1637 25.1638 - InapplicableSymbolsError() { 25.1639 - super(WRONG_MTHS, "inapplicable symbols"); 25.1640 + InapplicableSymbolsError(MethodResolutionContext context) { 25.1641 + super(WRONG_MTHS, "inapplicable symbols", context); 25.1642 } 25.1643 25.1644 @Override 25.1645 @@ -2460,7 +3150,7 @@ 25.1646 Name name, 25.1647 List<Type> argtypes, 25.1648 List<Type> typeargtypes) { 25.1649 - if (currentResolutionContext.candidates.nonEmpty()) { 25.1650 + if (!resolveContext.candidates.isEmpty()) { 25.1651 JCDiagnostic err = diags.create(dkind, 25.1652 log.currentSource(), 25.1653 pos, 25.1654 @@ -2478,7 +3168,7 @@ 25.1655 //where 25.1656 List<JCDiagnostic> candidateDetails(Type site) { 25.1657 List<JCDiagnostic> details = List.nil(); 25.1658 - for (Candidate c : currentResolutionContext.candidates) { 25.1659 + for (Candidate c : resolveContext.candidates) { 25.1660 if (!shouldReport(c)) continue; 25.1661 JCDiagnostic detailDiag = diags.fragment("inapplicable.method", 25.1662 Kinds.kindName(c.sym), 25.1663 @@ -2491,7 +3181,7 @@ 25.1664 } 25.1665 25.1666 private Name getName() { 25.1667 - Symbol sym = currentResolutionContext.candidates.head.sym; 25.1668 + Symbol sym = resolveContext.candidates.head.sym; 25.1669 return sym.name == names.init ? 25.1670 sym.owner.name : 25.1671 sym.name; 25.1672 @@ -2672,9 +3362,10 @@ 25.1673 private Map<MethodResolutionPhase, Symbol> resolutionCache = 25.1674 new EnumMap<MethodResolutionPhase, Symbol>(MethodResolutionPhase.class); 25.1675 25.1676 - private MethodResolutionPhase step = null; 25.1677 + MethodResolutionPhase step = null; 25.1678 25.1679 private boolean internalResolution = false; 25.1680 + private DeferredAttr.AttrMode attrMode = DeferredAttr.AttrMode.SPECULATIVE; 25.1681 25.1682 private MethodResolutionPhase firstErroneousResolutionPhase() { 25.1683 MethodResolutionPhase bestSoFar = BASIC; 25.1684 @@ -2684,6 +3375,7 @@ 25.1685 steps.head.isApplicable(boxingEnabled, varargsEnabled) && 25.1686 sym.kind >= WRONG_MTHS) { 25.1687 sym = resolutionCache.get(steps.head); 25.1688 + if (sym.kind == ABSENT_MTH) break; //ignore spurious empty entries 25.1689 bestSoFar = steps.head; 25.1690 steps = steps.tail; 25.1691 } 25.1692 @@ -2692,8 +3384,7 @@ 25.1693 25.1694 void addInapplicableCandidate(Symbol sym, JCDiagnostic details) { 25.1695 Candidate c = new Candidate(currentResolutionContext.step, sym, details, null); 25.1696 - if (!candidates.contains(c)) 25.1697 - candidates = candidates.append(c); 25.1698 + candidates = candidates.append(c); 25.1699 } 25.1700 25.1701 void addApplicableCandidate(Symbol sym, Type mtype) { 25.1702 @@ -2701,6 +3392,16 @@ 25.1703 candidates = candidates.append(c); 25.1704 } 25.1705 25.1706 + Candidate getCandidate(Symbol sym, MethodResolutionPhase phase) { 25.1707 + for (Candidate c : currentResolutionContext.candidates) { 25.1708 + if (c.step == phase && 25.1709 + c.sym.baseSymbol() == sym.baseSymbol()) { 25.1710 + return c; 25.1711 + } 25.1712 + } 25.1713 + return null; 25.1714 + } 25.1715 + 25.1716 /** 25.1717 * This class represents an overload resolution candidate. There are two 25.1718 * kinds of candidates: applicable methods and inapplicable methods; 25.1719 @@ -2728,9 +3429,9 @@ 25.1720 Symbol s1 = this.sym; 25.1721 Symbol s2 = ((Candidate)o).sym; 25.1722 if ((s1 != s2 && 25.1723 - (s1.overrides(s2, s1.owner.type.tsym, types, false) || 25.1724 - (s2.overrides(s1, s2.owner.type.tsym, types, false)))) || 25.1725 - ((s1.isConstructor() || s2.isConstructor()) && s1.owner != s2.owner)) 25.1726 + (s1.overrides(s2, s1.owner.type.tsym, types, false) || 25.1727 + (s2.overrides(s1, s2.owner.type.tsym, types, false)))) || 25.1728 + ((s1.isConstructor() || s2.isConstructor()) && s1.owner != s2.owner)) 25.1729 return true; 25.1730 } 25.1731 return false; 25.1732 @@ -2740,6 +3441,14 @@ 25.1733 return mtype != null; 25.1734 } 25.1735 } 25.1736 + 25.1737 + DeferredAttr.AttrMode attrMode() { 25.1738 + return attrMode; 25.1739 + } 25.1740 + 25.1741 + boolean internal() { 25.1742 + return internalResolution; 25.1743 + } 25.1744 } 25.1745 25.1746 MethodResolutionContext currentResolutionContext = null;
26.1 --- a/src/share/classes/com/sun/tools/javac/comp/TransTypes.java Thu Oct 11 09:50:52 2012 -0700 26.2 +++ b/src/share/classes/com/sun/tools/javac/comp/TransTypes.java Thu Oct 11 17:00:54 2012 -0700 26.3 @@ -627,6 +627,16 @@ 26.4 result = tree; 26.5 } 26.6 26.7 + @Override 26.8 + public void visitLambda(JCLambda tree) { 26.9 + Assert.error("Translation of lambda expression not supported yet"); 26.10 + } 26.11 + 26.12 + @Override 26.13 + public void visitReference(JCMemberReference tree) { 26.14 + Assert.error("Translation of method reference not supported yet"); 26.15 + } 26.16 + 26.17 public void visitParens(JCParens tree) { 26.18 tree.expr = translate(tree.expr, pt); 26.19 tree.type = erasure(tree.type);
27.1 --- a/src/share/classes/com/sun/tools/javac/file/Locations.java Thu Oct 11 09:50:52 2012 -0700 27.2 +++ b/src/share/classes/com/sun/tools/javac/file/Locations.java Thu Oct 11 17:00:54 2012 -0700 27.3 @@ -733,11 +733,7 @@ 27.4 urls[count++] = url; 27.5 } 27.6 } 27.7 - if (urls.length != count) { 27.8 - URL[] tmp = new URL[count]; 27.9 - System.arraycopy(urls, 0, tmp, 0, count); 27.10 - urls = tmp; 27.11 - } 27.12 + urls = Arrays.copyOf(urls, count); 27.13 return urls; 27.14 } 27.15
28.1 --- a/src/share/classes/com/sun/tools/javac/jvm/ClassFile.java Thu Oct 11 09:50:52 2012 -0700 28.2 +++ b/src/share/classes/com/sun/tools/javac/jvm/ClassFile.java Thu Oct 11 17:00:54 2012 -0700 28.3 @@ -84,6 +84,16 @@ 28.4 public final static int CONSTANT_MethodType = 16; 28.5 public final static int CONSTANT_InvokeDynamic = 18; 28.6 28.7 + public final static int REF_getField = 1; 28.8 + public final static int REF_getStatic = 2; 28.9 + public final static int REF_putField = 3; 28.10 + public final static int REF_putStatic = 4; 28.11 + public final static int REF_invokeVirtual = 5; 28.12 + public final static int REF_invokeStatic = 6; 28.13 + public final static int REF_invokeSpecial = 7; 28.14 + public final static int REF_newInvokeSpecial = 8; 28.15 + public final static int REF_invokeInterface = 9; 28.16 + 28.17 public final static int MAX_PARAMETERS = 0xff; 28.18 public final static int MAX_DIMENSIONS = 0xff; 28.19 public final static int MAX_CODE = 0xffff;
29.1 --- a/src/share/classes/com/sun/tools/javac/jvm/ClassWriter.java Thu Oct 11 09:50:52 2012 -0700 29.2 +++ b/src/share/classes/com/sun/tools/javac/jvm/ClassWriter.java Thu Oct 11 17:00:54 2012 -0700 29.3 @@ -26,6 +26,8 @@ 29.4 package com.sun.tools.javac.jvm; 29.5 29.6 import java.io.*; 29.7 +import java.util.LinkedHashMap; 29.8 +import java.util.Map; 29.9 import java.util.Set; 29.10 import java.util.HashSet; 29.11 29.12 @@ -137,6 +139,11 @@ 29.13 */ 29.14 ListBuffer<ClassSymbol> innerClassesQueue; 29.15 29.16 + /** The bootstrap methods to be written in the corresponding class attribute 29.17 + * (one for each invokedynamic) 29.18 + */ 29.19 + Map<MethodSymbol, Pool.MethodHandle> bootstrapMethods; 29.20 + 29.21 /** The log to use for verbose output. 29.22 */ 29.23 private final Log log; 29.24 @@ -477,11 +484,27 @@ 29.25 29.26 if (value instanceof MethodSymbol) { 29.27 MethodSymbol m = (MethodSymbol)value; 29.28 - poolbuf.appendByte((m.owner.flags() & INTERFACE) != 0 29.29 - ? CONSTANT_InterfaceMethodref 29.30 - : CONSTANT_Methodref); 29.31 - poolbuf.appendChar(pool.put(m.owner)); 29.32 - poolbuf.appendChar(pool.put(nameType(m))); 29.33 + if (!m.isDynamic()) { 29.34 + poolbuf.appendByte((m.owner.flags() & INTERFACE) != 0 29.35 + ? CONSTANT_InterfaceMethodref 29.36 + : CONSTANT_Methodref); 29.37 + poolbuf.appendChar(pool.put(m.owner)); 29.38 + poolbuf.appendChar(pool.put(nameType(m))); 29.39 + } else { 29.40 + //invokedynamic 29.41 + DynamicMethodSymbol dynSym = (DynamicMethodSymbol)m; 29.42 + Pool.MethodHandle handle = new Pool.MethodHandle(dynSym.bsmKind, dynSym.bsm); 29.43 + bootstrapMethods.put(dynSym, handle); 29.44 + //init cp entries 29.45 + pool.put(names.BootstrapMethods); 29.46 + pool.put(handle); 29.47 + for (Object staticArg : dynSym.staticArgs) { 29.48 + pool.put(staticArg); 29.49 + } 29.50 + poolbuf.appendByte(CONSTANT_InvokeDynamic); 29.51 + poolbuf.appendChar(bootstrapMethods.size() - 1); 29.52 + poolbuf.appendChar(pool.put(nameType(dynSym))); 29.53 + } 29.54 } else if (value instanceof VarSymbol) { 29.55 VarSymbol v = (VarSymbol)value; 29.56 poolbuf.appendByte(CONSTANT_Fieldref); 29.57 @@ -526,11 +549,20 @@ 29.58 } else if (value instanceof String) { 29.59 poolbuf.appendByte(CONSTANT_String); 29.60 poolbuf.appendChar(pool.put(names.fromString((String)value))); 29.61 + } else if (value instanceof MethodType) { 29.62 + MethodType mtype = (MethodType)value; 29.63 + poolbuf.appendByte(CONSTANT_MethodType); 29.64 + poolbuf.appendChar(pool.put(typeSig(mtype))); 29.65 } else if (value instanceof Type) { 29.66 Type type = (Type)value; 29.67 if (type.tag == CLASS) enterInner((ClassSymbol)type.tsym); 29.68 poolbuf.appendByte(CONSTANT_Class); 29.69 poolbuf.appendChar(pool.put(xClassName(type))); 29.70 + } else if (value instanceof Pool.MethodHandle) { 29.71 + Pool.MethodHandle ref = (Pool.MethodHandle)value; 29.72 + poolbuf.appendByte(CONSTANT_MethodHandle); 29.73 + poolbuf.appendByte(ref.refKind); 29.74 + poolbuf.appendChar(pool.put(ref.refSym)); 29.75 } else { 29.76 Assert.error("writePool " + value); 29.77 } 29.78 @@ -914,6 +946,25 @@ 29.79 endAttr(alenIdx); 29.80 } 29.81 29.82 + /** Write "bootstrapMethods" attribute. 29.83 + */ 29.84 + void writeBootstrapMethods() { 29.85 + int alenIdx = writeAttr(names.BootstrapMethods); 29.86 + databuf.appendChar(bootstrapMethods.size()); 29.87 + for (Map.Entry<MethodSymbol, Pool.MethodHandle> entry : bootstrapMethods.entrySet()) { 29.88 + DynamicMethodSymbol dsym = (DynamicMethodSymbol)entry.getKey(); 29.89 + //write BSM handle 29.90 + databuf.appendChar(pool.get(entry.getValue())); 29.91 + //write static args length 29.92 + databuf.appendChar(dsym.staticArgs.length); 29.93 + //write static args array 29.94 + for (Object o : dsym.staticArgs) { 29.95 + databuf.appendChar(pool.get(o)); 29.96 + } 29.97 + } 29.98 + endAttr(alenIdx); 29.99 + } 29.100 + 29.101 /** Write field symbol, entering all references into constant pool. 29.102 */ 29.103 void writeField(VarSymbol v) { 29.104 @@ -1483,6 +1534,7 @@ 29.105 pool = c.pool; 29.106 innerClasses = null; 29.107 innerClassesQueue = null; 29.108 + bootstrapMethods = new LinkedHashMap<MethodSymbol, Pool.MethodHandle>(); 29.109 29.110 Type supertype = types.supertype(c.type); 29.111 List<Type> interfaces = types.interfaces(c.type); 29.112 @@ -1589,6 +1641,12 @@ 29.113 writeInnerClasses(); 29.114 acount++; 29.115 } 29.116 + 29.117 + if (!bootstrapMethods.isEmpty()) { 29.118 + writeBootstrapMethods(); 29.119 + acount++; 29.120 + } 29.121 + 29.122 endAttrs(acountIdx, acount); 29.123 29.124 poolbuf.appendBytes(databuf.elems, 0, databuf.length);
30.1 --- a/src/share/classes/com/sun/tools/javac/jvm/Code.java Thu Oct 11 09:50:52 2012 -0700 30.2 +++ b/src/share/classes/com/sun/tools/javac/jvm/Code.java Thu Oct 11 17:00:54 2012 -0700 30.3 @@ -314,11 +314,7 @@ 30.4 */ 30.5 private void emit1(int od) { 30.6 if (!alive) return; 30.7 - if (cp == code.length) { 30.8 - byte[] newcode = new byte[cp * 2]; 30.9 - System.arraycopy(code, 0, newcode, 0, cp); 30.10 - code = newcode; 30.11 - } 30.12 + code = ArrayUtils.ensureCapacity(code, cp); 30.13 code[cp++] = (byte)od; 30.14 } 30.15 30.16 @@ -903,6 +899,8 @@ 30.17 if (o instanceof Double) return syms.doubleType; 30.18 if (o instanceof ClassSymbol) return syms.classType; 30.19 if (o instanceof Type.ArrayType) return syms.classType; 30.20 + if (o instanceof Type.MethodType) return syms.methodTypeType; 30.21 + if (o instanceof Pool.MethodHandle) return syms.methodHandleType; 30.22 throw new AssertionError(o); 30.23 } 30.24 30.25 @@ -1245,12 +1243,8 @@ 30.26 30.27 if (stackMapBuffer == null) { 30.28 stackMapBuffer = new StackMapFrame[20]; 30.29 - } else if (stackMapBuffer.length == stackMapBufferSize) { 30.30 - StackMapFrame[] newStackMapBuffer = 30.31 - new StackMapFrame[stackMapBufferSize << 1]; 30.32 - System.arraycopy(stackMapBuffer, 0, newStackMapBuffer, 30.33 - 0, stackMapBufferSize); 30.34 - stackMapBuffer = newStackMapBuffer; 30.35 + } else { 30.36 + stackMapBuffer = ArrayUtils.ensureCapacity(stackMapBuffer, stackMapBufferSize); 30.37 } 30.38 StackMapFrame frame = 30.39 stackMapBuffer[stackMapBufferSize++] = new StackMapFrame(); 30.40 @@ -1318,12 +1312,10 @@ 30.41 30.42 if (stackMapTableBuffer == null) { 30.43 stackMapTableBuffer = new StackMapTableFrame[20]; 30.44 - } else if (stackMapTableBuffer.length == stackMapBufferSize) { 30.45 - StackMapTableFrame[] newStackMapTableBuffer = 30.46 - new StackMapTableFrame[stackMapBufferSize << 1]; 30.47 - System.arraycopy(stackMapTableBuffer, 0, newStackMapTableBuffer, 30.48 - 0, stackMapBufferSize); 30.49 - stackMapTableBuffer = newStackMapTableBuffer; 30.50 + } else { 30.51 + stackMapTableBuffer = ArrayUtils.ensureCapacity( 30.52 + stackMapTableBuffer, 30.53 + stackMapBufferSize); 30.54 } 30.55 stackMapTableBuffer[stackMapBufferSize++] = 30.56 StackMapTableFrame.getInstance(frame, lastFrame.pc, lastFrame.locals, types); 30.57 @@ -1649,10 +1641,8 @@ 30.58 void lock(int register) { 30.59 if (locks == null) { 30.60 locks = new int[20]; 30.61 - } else if (locks.length == nlocks) { 30.62 - int[] newLocks = new int[locks.length << 1]; 30.63 - System.arraycopy(locks, 0, newLocks, 0, locks.length); 30.64 - locks = newLocks; 30.65 + } else { 30.66 + locks = ArrayUtils.ensureCapacity(locks, nlocks); 30.67 } 30.68 locks[nlocks] = register; 30.69 nlocks++; 30.70 @@ -1678,11 +1668,7 @@ 30.71 default: 30.72 break; 30.73 } 30.74 - if (stacksize+2 >= stack.length) { 30.75 - Type[] newstack = new Type[2*stack.length]; 30.76 - System.arraycopy(stack, 0, newstack, 0, stack.length); 30.77 - stack = newstack; 30.78 - } 30.79 + stack = ArrayUtils.ensureCapacity(stack, stacksize+2); 30.80 stack[stacksize++] = t; 30.81 switch (width(t)) { 30.82 case 1: 30.83 @@ -1869,13 +1855,7 @@ 30.84 /** Add a new local variable. */ 30.85 private void addLocalVar(VarSymbol v) { 30.86 int adr = v.adr; 30.87 - if (adr+1 >= lvar.length) { 30.88 - int newlength = lvar.length << 1; 30.89 - if (newlength <= adr) newlength = adr + 10; 30.90 - LocalVar[] new_lvar = new LocalVar[newlength]; 30.91 - System.arraycopy(lvar, 0, new_lvar, 0, lvar.length); 30.92 - lvar = new_lvar; 30.93 - } 30.94 + lvar = ArrayUtils.ensureCapacity(lvar, adr+1); 30.95 Assert.checkNull(lvar[adr]); 30.96 if (pendingJumps != null) resolvePending(); 30.97 lvar[adr] = new LocalVar(v); 30.98 @@ -1955,11 +1935,8 @@ 30.99 if ((var.sym.flags() & Flags.SYNTHETIC) != 0) return; 30.100 if (varBuffer == null) 30.101 varBuffer = new LocalVar[20]; 30.102 - else if (varBufferSize >= varBuffer.length) { 30.103 - LocalVar[] newVarBuffer = new LocalVar[varBufferSize*2]; 30.104 - System.arraycopy(varBuffer, 0, newVarBuffer, 0, varBuffer.length); 30.105 - varBuffer = newVarBuffer; 30.106 - } 30.107 + else 30.108 + varBuffer = ArrayUtils.ensureCapacity(varBuffer, varBufferSize); 30.109 varBuffer[varBufferSize++] = var; 30.110 } 30.111
31.1 --- a/src/share/classes/com/sun/tools/javac/jvm/Gen.java Thu Oct 11 09:50:52 2012 -0700 31.2 +++ b/src/share/classes/com/sun/tools/javac/jvm/Gen.java Thu Oct 11 17:00:54 2012 -0700 31.3 @@ -2103,6 +2103,8 @@ 31.4 result = res; 31.5 } else if (sym.kind == VAR && sym.owner.kind == MTH) { 31.6 result = items.makeLocalItem((VarSymbol)sym); 31.7 + } else if (isInvokeDynamic(sym)) { 31.8 + result = items.makeDynamicItem(sym); 31.9 } else if ((sym.flags() & STATIC) != 0) { 31.10 if (!isAccessSuper(env.enclMethod)) 31.11 sym = binaryQualifier(sym, env.enclClass.type); 31.12 @@ -2152,8 +2154,12 @@ 31.13 result = items. 31.14 makeImmediateItem(sym.type, ((VarSymbol) sym).getConstValue()); 31.15 } else { 31.16 - if (!accessSuper) 31.17 + if (isInvokeDynamic(sym)) { 31.18 + result = items.makeDynamicItem(sym); 31.19 + return; 31.20 + } else if (!accessSuper) { 31.21 sym = binaryQualifier(sym, tree.selected.type); 31.22 + } 31.23 if ((sym.flags() & STATIC) != 0) { 31.24 if (!selectSuper && (ssym == null || ssym.kind != TYP)) 31.25 base = base.load(); 31.26 @@ -2174,6 +2180,10 @@ 31.27 } 31.28 } 31.29 31.30 + public boolean isInvokeDynamic(Symbol sym) { 31.31 + return sym.kind == MTH && ((MethodSymbol)sym).isDynamic(); 31.32 + } 31.33 + 31.34 public void visitLiteral(JCLiteral tree) { 31.35 if (tree.type.tag == TypeTags.BOT) { 31.36 code.emitop0(aconst_null);
32.1 --- a/src/share/classes/com/sun/tools/javac/jvm/Items.java Thu Oct 11 09:50:52 2012 -0700 32.2 +++ b/src/share/classes/com/sun/tools/javac/jvm/Items.java Thu Oct 11 17:00:54 2012 -0700 32.3 @@ -1,5 +1,5 @@ 32.4 /* 32.5 - * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved. 32.6 + * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved. 32.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 32.8 * 32.9 * This code is free software; you can redistribute it and/or modify it 32.10 @@ -110,6 +110,13 @@ 32.11 return stackItem[Code.typecode(type)]; 32.12 } 32.13 32.14 + /** Make an item representing a dynamically invoked method. 32.15 + * @param member The represented symbol. 32.16 + */ 32.17 + Item makeDynamicItem(Symbol member) { 32.18 + return new DynamicItem(member); 32.19 + } 32.20 + 32.21 /** Make an item representing an indexed expression. 32.22 * @param type The expression's type. 32.23 */ 32.24 @@ -457,6 +464,35 @@ 32.25 } 32.26 } 32.27 32.28 + /** An item representing a dynamic call site. 32.29 + */ 32.30 + class DynamicItem extends StaticItem { 32.31 + DynamicItem(Symbol member) { 32.32 + super(member); 32.33 + } 32.34 + 32.35 + Item load() { 32.36 + assert false; 32.37 + return null; 32.38 + } 32.39 + 32.40 + void store() { 32.41 + assert false; 32.42 + } 32.43 + 32.44 + Item invoke() { 32.45 + // assert target.hasNativeInvokeDynamic(); 32.46 + MethodType mtype = (MethodType)member.erasure(types); 32.47 + int rescode = Code.typecode(mtype.restype); 32.48 + code.emitInvokedynamic(pool.put(member), mtype); 32.49 + return stackItem[rescode]; 32.50 + } 32.51 + 32.52 + public String toString() { 32.53 + return "dynamic(" + member + ")"; 32.54 + } 32.55 + } 32.56 + 32.57 /** An item representing an instance variable or method. 32.58 */ 32.59 class MemberItem extends Item {
33.1 --- a/src/share/classes/com/sun/tools/javac/jvm/Pool.java Thu Oct 11 09:50:52 2012 -0700 33.2 +++ b/src/share/classes/com/sun/tools/javac/jvm/Pool.java Thu Oct 11 17:00:54 2012 -0700 33.3 @@ -1,5 +1,5 @@ 33.4 /* 33.5 - * Copyright (c) 1999, 2008, Oracle and/or its affiliates. All rights reserved. 33.6 + * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved. 33.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 33.8 * 33.9 * This code is free software; you can redistribute it and/or modify it 33.10 @@ -25,10 +25,17 @@ 33.11 33.12 package com.sun.tools.javac.jvm; 33.13 33.14 +import com.sun.tools.javac.code.Kinds; 33.15 +import com.sun.tools.javac.code.Symbol; 33.16 +import com.sun.tools.javac.code.Symbol.*; 33.17 + 33.18 +import com.sun.tools.javac.util.ArrayUtils; 33.19 +import com.sun.tools.javac.util.Assert; 33.20 +import com.sun.tools.javac.util.Filter; 33.21 +import com.sun.tools.javac.util.Name; 33.22 + 33.23 import java.util.*; 33.24 33.25 -import com.sun.tools.javac.code.Symbol.*; 33.26 - 33.27 /** An internal structure that corresponds to the constant pool of a classfile. 33.28 * 33.29 * <p><b>This is NOT part of any supported API. 33.30 @@ -83,14 +90,6 @@ 33.31 indices.clear(); 33.32 } 33.33 33.34 - /** Double pool buffer in size. 33.35 - */ 33.36 - private void doublePool() { 33.37 - Object[] newpool = new Object[pool.length * 2]; 33.38 - System.arraycopy(pool, 0, newpool, 0, pool.length); 33.39 - pool = newpool; 33.40 - } 33.41 - 33.42 /** Place an object in the pool, unless it is already there. 33.43 * If object is a symbol also enter its owner unless the owner is a 33.44 * package. Return the object's index in the pool. 33.45 @@ -106,10 +105,10 @@ 33.46 // System.err.println("put " + value + " " + value.getClass());//DEBUG 33.47 index = pp; 33.48 indices.put(value, index); 33.49 - if (pp == pool.length) doublePool(); 33.50 + pool = ArrayUtils.ensureCapacity(pool, pp); 33.51 pool[pp++] = value; 33.52 if (value instanceof Long || value instanceof Double) { 33.53 - if (pp == pool.length) doublePool(); 33.54 + pool = ArrayUtils.ensureCapacity(pool, pp); 33.55 pool[pp++] = null; 33.56 } 33.57 } 33.58 @@ -167,4 +166,86 @@ 33.59 v.type.hashCode(); 33.60 } 33.61 } 33.62 + 33.63 + public static class MethodHandle { 33.64 + 33.65 + /** Reference kind - see ClassFile */ 33.66 + int refKind; 33.67 + 33.68 + /** Reference symbol */ 33.69 + Symbol refSym; 33.70 + 33.71 + public MethodHandle(int refKind, Symbol refSym) { 33.72 + this.refKind = refKind; 33.73 + this.refSym = refSym; 33.74 + checkConsistent(); 33.75 + } 33.76 + public boolean equals(Object other) { 33.77 + if (!(other instanceof MethodHandle)) return false; 33.78 + MethodHandle mr = (MethodHandle) other; 33.79 + if (mr.refKind != refKind) return false; 33.80 + Symbol o = mr.refSym; 33.81 + return 33.82 + o.name == refSym.name && 33.83 + o.owner == refSym.owner && 33.84 + o.type.equals(refSym.type); 33.85 + } 33.86 + public int hashCode() { 33.87 + return 33.88 + refKind * 65 + 33.89 + refSym.name.hashCode() * 33 + 33.90 + refSym.owner.hashCode() * 9 + 33.91 + refSym.type.hashCode(); 33.92 + } 33.93 + 33.94 + /** 33.95 + * Check consistency of reference kind and symbol (see JVMS 4.4.8) 33.96 + */ 33.97 + @SuppressWarnings("fallthrough") 33.98 + private void checkConsistent() { 33.99 + boolean staticOk = false; 33.100 + int expectedKind = -1; 33.101 + Filter<Name> nameFilter = nonInitFilter; 33.102 + boolean interfaceOwner = false; 33.103 + switch (refKind) { 33.104 + case ClassFile.REF_getStatic: 33.105 + case ClassFile.REF_putStatic: 33.106 + staticOk = true; 33.107 + case ClassFile.REF_getField: 33.108 + case ClassFile.REF_putField: 33.109 + expectedKind = Kinds.VAR; 33.110 + break; 33.111 + case ClassFile.REF_newInvokeSpecial: 33.112 + nameFilter = initFilter; 33.113 + expectedKind = Kinds.MTH; 33.114 + break; 33.115 + case ClassFile.REF_invokeInterface: 33.116 + interfaceOwner = true; 33.117 + expectedKind = Kinds.MTH; 33.118 + break; 33.119 + case ClassFile.REF_invokeStatic: 33.120 + staticOk = true; 33.121 + case ClassFile.REF_invokeVirtual: 33.122 + case ClassFile.REF_invokeSpecial: 33.123 + expectedKind = Kinds.MTH; 33.124 + break; 33.125 + } 33.126 + Assert.check(!refSym.isStatic() || staticOk); 33.127 + Assert.check(refSym.kind == expectedKind); 33.128 + Assert.check(nameFilter.accepts(refSym.name)); 33.129 + Assert.check(!refSym.owner.isInterface() || interfaceOwner); 33.130 + } 33.131 + //where 33.132 + Filter<Name> nonInitFilter = new Filter<Name>() { 33.133 + public boolean accepts(Name n) { 33.134 + return n != n.table.names.init && n != n.table.names.clinit; 33.135 + } 33.136 + }; 33.137 + 33.138 + Filter<Name> initFilter = new Filter<Name>() { 33.139 + public boolean accepts(Name n) { 33.140 + return n == n.table.names.init; 33.141 + } 33.142 + }; 33.143 + } 33.144 }
34.1 --- a/src/share/classes/com/sun/tools/javac/main/JavaCompiler.java Thu Oct 11 09:50:52 2012 -0700 34.2 +++ b/src/share/classes/com/sun/tools/javac/main/JavaCompiler.java Thu Oct 11 17:00:54 2012 -0700 34.3 @@ -406,10 +406,17 @@ 34.4 ? names.fromString(options.get("failcomplete")) 34.5 : null; 34.6 34.7 - shouldStopPolicy = 34.8 - options.isSet("shouldStopPolicy") 34.9 + shouldStopPolicyIfError = 34.10 + options.isSet("shouldStopPolicy") // backwards compatible 34.11 ? CompileState.valueOf(options.get("shouldStopPolicy")) 34.12 - : null; 34.13 + : options.isSet("shouldStopPolicyIfError") 34.14 + ? CompileState.valueOf(options.get("shouldStopPolicyIfError")) 34.15 + : CompileState.INIT; 34.16 + shouldStopPolicyIfNoError = 34.17 + options.isSet("shouldStopPolicyIfNoError") 34.18 + ? CompileState.valueOf(options.get("shouldStopPolicyIfNoError")) 34.19 + : CompileState.GENERATE; 34.20 + 34.21 if (options.isUnset("oldDiags")) 34.22 log.setDiagnosticFormatter(RichDiagnosticFormatter.instance(context)); 34.23 } 34.24 @@ -486,12 +493,20 @@ 34.25 public boolean verboseCompilePolicy; 34.26 34.27 /** 34.28 - * Policy of how far to continue processing. null means until first 34.29 - * error. 34.30 + * Policy of how far to continue compilation after errors have occurred. 34.31 + * Set this to minimum CompileState (INIT) to stop as soon as possible 34.32 + * after errors. 34.33 */ 34.34 - public CompileState shouldStopPolicy; 34.35 + public CompileState shouldStopPolicyIfError; 34.36 34.37 - /** A queue of all as yet unattributed classes. 34.38 + /** 34.39 + * Policy of how far to continue compilation when no errors have occurred. 34.40 + * Set this to maximum CompileState (GENERATE) to perform full compilation. 34.41 + * Set this lower to perform partial compilation, such as -proc:only. 34.42 + */ 34.43 + public CompileState shouldStopPolicyIfNoError; 34.44 + 34.45 + /** A queue of all as yet unattributed classes.oLo 34.46 */ 34.47 public Todo todo; 34.48 34.49 @@ -501,6 +516,7 @@ 34.50 34.51 /** Ordered list of compiler phases for each compilation unit. */ 34.52 public enum CompileState { 34.53 + INIT(0), 34.54 PARSE(1), 34.55 ENTER(2), 34.56 PROCESS(3), 34.57 @@ -512,8 +528,11 @@ 34.58 CompileState(int value) { 34.59 this.value = value; 34.60 } 34.61 - boolean isDone(CompileState other) { 34.62 - return value >= other.value; 34.63 + boolean isAfter(CompileState other) { 34.64 + return value > other.value; 34.65 + } 34.66 + public static CompileState max(CompileState a, CompileState b) { 34.67 + return a.value > b.value ? a : b; 34.68 } 34.69 private int value; 34.70 }; 34.71 @@ -524,7 +543,7 @@ 34.72 private static final long serialVersionUID = 1812267524140424433L; 34.73 boolean isDone(Env<AttrContext> env, CompileState cs) { 34.74 CompileState ecs = get(env); 34.75 - return ecs != null && ecs.isDone(cs); 34.76 + return (ecs != null) && !cs.isAfter(ecs); 34.77 } 34.78 } 34.79 private CompileStates compileStates = new CompileStates(); 34.80 @@ -536,10 +555,10 @@ 34.81 protected Set<JavaFileObject> inputFiles = new HashSet<JavaFileObject>(); 34.82 34.83 protected boolean shouldStop(CompileState cs) { 34.84 - if (shouldStopPolicy == null) 34.85 - return (errorCount() > 0 || unrecoverableError()); 34.86 - else 34.87 - return cs.ordinal() > shouldStopPolicy.ordinal(); 34.88 + CompileState shouldStopPolicy = (errorCount() > 0 || unrecoverableError()) 34.89 + ? shouldStopPolicyIfError 34.90 + : shouldStopPolicyIfNoError; 34.91 + return cs.isAfter(shouldStopPolicy); 34.92 } 34.93 34.94 /** The number of errors reported so far. 34.95 @@ -924,6 +943,18 @@ 34.96 } 34.97 34.98 /** 34.99 + * Enter the symbols found in a list of parse trees if the compilation 34.100 + * is expected to proceed beyond anno processing into attr. 34.101 + * As a side-effect, this puts elements on the "todo" list. 34.102 + * Also stores a list of all top level classes in rootClasses. 34.103 + */ 34.104 + public List<JCCompilationUnit> enterTreesIfNeeded(List<JCCompilationUnit> roots) { 34.105 + if (shouldStop(CompileState.ATTR)) 34.106 + return List.nil(); 34.107 + return enterTrees(roots); 34.108 + } 34.109 + 34.110 + /** 34.111 * Enter the symbols found in a list of parse trees. 34.112 * As a side-effect, this puts elements on the "todo" list. 34.113 * Also stores a list of all top level classes in rootClasses. 34.114 @@ -1010,7 +1041,7 @@ 34.115 genEndPos = true; 34.116 if (!taskListener.isEmpty()) 34.117 taskListener.started(new TaskEvent(TaskEvent.Kind.ANNOTATION_PROCESSING)); 34.118 - log.deferDiagnostics = true; 34.119 + log.deferAll(); 34.120 } else { // free resources 34.121 procEnvImpl.close(); 34.122 } 34.123 @@ -1120,7 +1151,7 @@ 34.124 if (c != this) 34.125 annotationProcessingOccurred = c.annotationProcessingOccurred = true; 34.126 // doProcessing will have handled deferred diagnostics 34.127 - Assert.check(c.log.deferDiagnostics == false 34.128 + Assert.check(c.log.deferredDiagFilter == null 34.129 && c.log.deferredDiagnostics.size() == 0); 34.130 return c; 34.131 } finally { 34.132 @@ -1196,7 +1227,7 @@ 34.133 if (errorCount() > 0 && !shouldStop(CompileState.ATTR)) { 34.134 //if in fail-over mode, ensure that AST expression nodes 34.135 //are correctly initialized (e.g. they have a type/symbol) 34.136 - attr.postAttr(env); 34.137 + attr.postAttr(env.tree); 34.138 } 34.139 compileStates.put(env, CompileState.ATTR); 34.140 } 34.141 @@ -1648,6 +1679,8 @@ 34.142 hasBeenUsed = true; 34.143 closeables = prev.closeables; 34.144 prev.closeables = List.nil(); 34.145 + shouldStopPolicyIfError = prev.shouldStopPolicyIfError; 34.146 + shouldStopPolicyIfNoError = prev.shouldStopPolicyIfNoError; 34.147 } 34.148 34.149 public static void enableLogging() {
35.1 --- a/src/share/classes/com/sun/tools/javac/parser/JavaTokenizer.java Thu Oct 11 09:50:52 2012 -0700 35.2 +++ b/src/share/classes/com/sun/tools/javac/parser/JavaTokenizer.java Thu Oct 11 17:00:54 2012 -0700 35.3 @@ -638,10 +638,6 @@ 35.4 lexError(pos, "unclosed.str.lit"); 35.5 } 35.6 break loop; 35.7 - case '#': 35.8 - reader.scanChar(); 35.9 - tk = TokenKind.HASH; 35.10 - break loop; 35.11 default: 35.12 if (isSpecial(reader.ch)) { 35.13 scanOperator();
36.1 --- a/src/share/classes/com/sun/tools/javac/parser/JavacParser.java Thu Oct 11 09:50:52 2012 -0700 36.2 +++ b/src/share/classes/com/sun/tools/javac/parser/JavacParser.java Thu Oct 11 17:00:54 2012 -0700 36.3 @@ -950,12 +950,13 @@ 36.4 break; 36.5 case LPAREN: 36.6 if (typeArgs == null && (mode & EXPR) != 0) { 36.7 - if (peekToken(FINAL) || 36.8 + if (peekToken(MONKEYS_AT) || 36.9 + peekToken(FINAL) || 36.10 peekToken(RPAREN) || 36.11 peekToken(IDENTIFIER, COMMA) || 36.12 peekToken(IDENTIFIER, RPAREN, ARROW)) { 36.13 //implicit n-ary lambda 36.14 - t = lambdaExpressionOrStatement(true, peekToken(FINAL), pos); 36.15 + t = lambdaExpressionOrStatement(true, peekToken(MONKEYS_AT) || peekToken(FINAL), pos); 36.16 break; 36.17 } else { 36.18 nextToken(); 36.19 @@ -1159,7 +1160,7 @@ 36.20 case LT: 36.21 if ((mode & TYPE) == 0 && isUnboundMemberRef()) { 36.22 //this is an unbound method reference whose qualifier 36.23 - //is a generic type i.e. A<S>#m 36.24 + //is a generic type i.e. A<S>::m 36.25 int pos1 = token.pos; 36.26 accept(LT); 36.27 ListBuffer<JCExpression> args = new ListBuffer<JCExpression>(); 36.28 @@ -1177,7 +1178,8 @@ 36.29 t = toP(F.at(token.pos).Select(t, ident())); 36.30 t = typeArgumentsOpt(t); 36.31 } 36.32 - if (token.kind != HASH) { 36.33 + t = bracketsOpt(t); 36.34 + if (token.kind != COLCOL) { 36.35 //method reference expected here 36.36 t = illegal(); 36.37 } 36.38 @@ -1237,6 +1239,10 @@ 36.39 nextToken(); 36.40 t = bracketsOpt(t); 36.41 t = toP(F.at(pos1).TypeArray(t)); 36.42 + if (token.kind == COLCOL) { 36.43 + mode = EXPR; 36.44 + continue; 36.45 + } 36.46 return t; 36.47 } 36.48 mode = oldmode; 36.49 @@ -1269,10 +1275,10 @@ 36.50 t = argumentsOpt(typeArgs, typeArgumentsOpt(t)); 36.51 typeArgs = null; 36.52 } 36.53 - } else if ((mode & EXPR) != 0 && token.kind == HASH) { 36.54 + } else if ((mode & EXPR) != 0 && token.kind == COLCOL) { 36.55 mode = EXPR; 36.56 if (typeArgs != null) return illegal(); 36.57 - accept(HASH); 36.58 + accept(COLCOL); 36.59 t = memberReferenceSuffix(pos1, t); 36.60 } else { 36.61 break; 36.62 @@ -1311,9 +1317,11 @@ 36.63 case GT: 36.64 depth--; 36.65 if (depth == 0) { 36.66 + TokenKind nextKind = S.token(pos + 1).kind; 36.67 return 36.68 - S.token(pos + 1).kind == TokenKind.DOT || 36.69 - S.token(pos + 1).kind == TokenKind.HASH; 36.70 + nextKind == TokenKind.DOT || 36.71 + nextKind == TokenKind.LBRACKET || 36.72 + nextKind == TokenKind.COLCOL; 36.73 } 36.74 break; 36.75 default: 36.76 @@ -1343,11 +1351,6 @@ 36.77 } 36.78 36.79 JCExpression lambdaExpressionOrStatementRest(List<JCVariableDecl> args, int pos) { 36.80 - if (token.kind != ARROW) { 36.81 - //better error recovery 36.82 - return F.at(pos).Erroneous(args); 36.83 - } 36.84 - 36.85 checkLambda(); 36.86 accept(ARROW); 36.87 36.88 @@ -1372,7 +1375,7 @@ 36.89 nextToken(); 36.90 if (token.kind == LPAREN || typeArgs != null) { 36.91 t = arguments(typeArgs, t); 36.92 - } else if (token.kind == HASH) { 36.93 + } else if (token.kind == COLCOL) { 36.94 if (typeArgs != null) return illegal(); 36.95 t = memberReferenceSuffix(t); 36.96 } else { 36.97 @@ -1583,20 +1586,22 @@ 36.98 t = toP(F.at(pos).Select(t, names._class)); 36.99 } 36.100 } else if ((mode & TYPE) != 0) { 36.101 - mode = TYPE; 36.102 - } else { 36.103 + if (token.kind != COLCOL) { 36.104 + mode = TYPE; 36.105 + } 36.106 + } else if (token.kind != COLCOL) { 36.107 syntaxError(token.pos, "dot.class.expected"); 36.108 } 36.109 return t; 36.110 } 36.111 36.112 /** 36.113 - * MemberReferenceSuffix = "#" [TypeArguments] Ident 36.114 - * | "#" [TypeArguments] "new" 36.115 + * MemberReferenceSuffix = "::" [TypeArguments] Ident 36.116 + * | "::" [TypeArguments] "new" 36.117 */ 36.118 JCExpression memberReferenceSuffix(JCExpression t) { 36.119 int pos1 = token.pos; 36.120 - accept(HASH); 36.121 + accept(COLCOL); 36.122 return memberReferenceSuffix(pos1, t); 36.123 } 36.124 36.125 @@ -2165,27 +2170,10 @@ 36.126 while (true) { 36.127 int pos = token.pos; 36.128 switch (token.kind) { 36.129 - case CASE: { 36.130 - nextToken(); 36.131 - JCExpression pat = parseExpression(); 36.132 - accept(COLON); 36.133 - List<JCStatement> stats = blockStatements(); 36.134 - JCCase c = F.at(pos).Case(pat, stats); 36.135 - if (stats.isEmpty()) 36.136 - storeEnd(c, S.prevToken().endPos); 36.137 - cases.append(c); 36.138 + case CASE: 36.139 + case DEFAULT: 36.140 + cases.append(switchBlockStatementGroup()); 36.141 break; 36.142 - } 36.143 - case DEFAULT: { 36.144 - nextToken(); 36.145 - accept(COLON); 36.146 - List<JCStatement> stats = blockStatements(); 36.147 - JCCase c = F.at(pos).Case(null, stats); 36.148 - if (stats.isEmpty()) 36.149 - storeEnd(c, S.prevToken().endPos); 36.150 - cases.append(c); 36.151 - break; 36.152 - } 36.153 case RBRACE: case EOF: 36.154 return cases.toList(); 36.155 default: 36.156 @@ -2196,6 +2184,32 @@ 36.157 } 36.158 } 36.159 36.160 + protected JCCase switchBlockStatementGroup() { 36.161 + int pos = token.pos; 36.162 + List<JCStatement> stats; 36.163 + JCCase c; 36.164 + switch (token.kind) { 36.165 + case CASE: 36.166 + nextToken(); 36.167 + JCExpression pat = parseExpression(); 36.168 + accept(COLON); 36.169 + stats = blockStatements(); 36.170 + c = F.at(pos).Case(pat, stats); 36.171 + if (stats.isEmpty()) 36.172 + storeEnd(c, S.prevToken().endPos); 36.173 + return c; 36.174 + case DEFAULT: 36.175 + nextToken(); 36.176 + accept(COLON); 36.177 + stats = blockStatements(); 36.178 + c = F.at(pos).Case(null, stats); 36.179 + if (stats.isEmpty()) 36.180 + storeEnd(c, S.prevToken().endPos); 36.181 + return c; 36.182 + } 36.183 + throw new AssertionError("should not reach here"); 36.184 + } 36.185 + 36.186 /** MoreStatementExpressions = { COMMA StatementExpression } 36.187 */ 36.188 <T extends ListBuffer<? super JCExpressionStatement>> T moreStatementExpressions(int pos,
37.1 --- a/src/share/classes/com/sun/tools/javac/parser/Tokens.java Thu Oct 11 09:50:52 2012 -0700 37.2 +++ b/src/share/classes/com/sun/tools/javac/parser/Tokens.java Thu Oct 11 17:00:54 2012 -0700 37.3 @@ -177,7 +177,7 @@ 37.4 FALSE("false", Tag.NAMED), 37.5 NULL("null", Tag.NAMED), 37.6 ARROW("->"), 37.7 - HASH("#"), 37.8 + COLCOL("::"), 37.9 LPAREN("("), 37.10 RPAREN(")"), 37.11 LBRACE("{"),
38.1 --- a/src/share/classes/com/sun/tools/javac/parser/UnicodeReader.java Thu Oct 11 09:50:52 2012 -0700 38.2 +++ b/src/share/classes/com/sun/tools/javac/parser/UnicodeReader.java Thu Oct 11 17:00:54 2012 -0700 38.3 @@ -1,5 +1,5 @@ 38.4 /* 38.5 - * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. 38.6 + * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. 38.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 38.8 * 38.9 * This code is free software; you can redistribute it and/or modify it 38.10 @@ -25,13 +25,15 @@ 38.11 38.12 package com.sun.tools.javac.parser; 38.13 38.14 +import java.nio.CharBuffer; 38.15 +import java.util.Arrays; 38.16 + 38.17 import com.sun.tools.javac.file.JavacFileManager; 38.18 +import com.sun.tools.javac.util.ArrayUtils; 38.19 import com.sun.tools.javac.util.Log; 38.20 import com.sun.tools.javac.util.Name; 38.21 import com.sun.tools.javac.util.Names; 38.22 38.23 -import java.nio.CharBuffer; 38.24 - 38.25 import static com.sun.tools.javac.util.LayoutCharacters.*; 38.26 38.27 /** The char reader used by the javac lexer/tokenizer. Returns the sequence of 38.28 @@ -91,9 +93,7 @@ 38.29 if (input.length > 0 && Character.isWhitespace(input[input.length - 1])) { 38.30 inputLength--; 38.31 } else { 38.32 - char[] newInput = new char[inputLength + 1]; 38.33 - System.arraycopy(input, 0, newInput, 0, input.length); 38.34 - input = newInput; 38.35 + input = Arrays.copyOf(input, inputLength + 1); 38.36 } 38.37 } 38.38 buf = input; 38.39 @@ -130,11 +130,7 @@ 38.40 /** Append a character to sbuf. 38.41 */ 38.42 protected void putChar(char ch, boolean scan) { 38.43 - if (sp == sbuf.length) { 38.44 - char[] newsbuf = new char[sbuf.length * 2]; 38.45 - System.arraycopy(sbuf, 0, newsbuf, 0, sbuf.length); 38.46 - sbuf = newsbuf; 38.47 - } 38.48 + sbuf = ArrayUtils.ensureCapacity(sbuf, sp); 38.49 sbuf[sp++] = ch; 38.50 if (scan) 38.51 scanChar();
39.1 --- a/src/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java Thu Oct 11 09:50:52 2012 -0700 39.2 +++ b/src/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java Thu Oct 11 17:00:54 2012 -0700 39.3 @@ -49,7 +49,7 @@ 39.4 39.5 import com.sun.source.util.JavacTask; 39.6 import com.sun.source.util.TaskEvent; 39.7 -import com.sun.tools.javac.api.JavacTaskImpl; 39.8 +import com.sun.tools.javac.api.BasicJavacTask; 39.9 import com.sun.tools.javac.api.JavacTrees; 39.10 import com.sun.tools.javac.api.MultiTaskListener; 39.11 import com.sun.tools.javac.code.*; 39.12 @@ -97,11 +97,9 @@ 39.13 private final boolean printRounds; 39.14 private final boolean verbose; 39.15 private final boolean lint; 39.16 - private final boolean procOnly; 39.17 private final boolean fatalErrors; 39.18 private final boolean werror; 39.19 private final boolean showResolveErrors; 39.20 - private boolean foundTypeProcessors; 39.21 39.22 private final JavacFiler filer; 39.23 private final JavacMessager messager; 39.24 @@ -167,12 +165,14 @@ 39.25 printRounds = options.isSet(XPRINTROUNDS); 39.26 verbose = options.isSet(VERBOSE); 39.27 lint = Lint.instance(context).isEnabled(PROCESSING); 39.28 - procOnly = options.isSet(PROC, "only") || options.isSet(XPRINT); 39.29 + if (options.isSet(PROC, "only") || options.isSet(XPRINT)) { 39.30 + JavaCompiler compiler = JavaCompiler.instance(context); 39.31 + compiler.shouldStopPolicyIfNoError = CompileState.PROCESS; 39.32 + } 39.33 fatalErrors = options.isSet("fatalEnterError"); 39.34 showResolveErrors = options.isSet("showResolveErrors"); 39.35 werror = options.isSet(WERROR); 39.36 platformAnnotations = initPlatformAnnotations(); 39.37 - foundTypeProcessors = false; 39.38 39.39 // Initialize services before any processors are initialized 39.40 // in case processors use them. 39.41 @@ -462,7 +462,7 @@ 39.42 * State about how a processor has been used by the tool. If a 39.43 * processor has been used on a prior round, its process method is 39.44 * called on all subsequent rounds, perhaps with an empty set of 39.45 - * annotations to process. The {@code annotatedSupported} method 39.46 + * annotations to process. The {@code annotationSupported} method 39.47 * caches the supported annotation information from the first (and 39.48 * only) getSupportedAnnotationTypes call to the processor. 39.49 */ 39.50 @@ -806,7 +806,7 @@ 39.51 log = Log.instance(context); 39.52 log.nerrors = priorErrors; 39.53 log.nwarnings += priorWarnings; 39.54 - log.deferDiagnostics = true; 39.55 + log.deferAll(); 39.56 39.57 // the following is for the benefit of JavacProcessingEnvironment.getContext() 39.58 JavacProcessingEnvironment.this.context = context; 39.59 @@ -882,7 +882,9 @@ 39.60 /** Create the compiler to be used for the final compilation. */ 39.61 JavaCompiler finalCompiler(boolean errorStatus) { 39.62 try { 39.63 - JavaCompiler c = JavaCompiler.instance(nextContext()); 39.64 + Context nextCtx = nextContext(); 39.65 + JavacProcessingEnvironment.this.context = nextCtx; 39.66 + JavaCompiler c = JavaCompiler.instance(nextCtx); 39.67 c.log.nwarnings += compiler.log.nwarnings; 39.68 if (errorStatus) { 39.69 c.log.nerrors += compiler.log.nerrors; 39.70 @@ -1021,7 +1023,7 @@ 39.71 } 39.72 39.73 /** Get the context for the next round of processing. 39.74 - * Important values are propogated from round to round; 39.75 + * Important values are propagated from round to round; 39.76 * other values are implicitly reset. 39.77 */ 39.78 private Context nextContext() { 39.79 @@ -1086,10 +1088,11 @@ 39.80 elementUtils.setContext(next); 39.81 typeUtils.setContext(next); 39.82 39.83 - JavacTaskImpl task = (JavacTaskImpl) context.get(JavacTask.class); 39.84 + JavacTask task = context.get(JavacTask.class); 39.85 if (task != null) { 39.86 next.put(JavacTask.class, task); 39.87 - task.updateContext(next); 39.88 + if (task instanceof BasicJavacTask) 39.89 + ((BasicJavacTask) task).updateContext(next); 39.90 } 39.91 39.92 JavacTrees trees = context.get(JavacTrees.class); 39.93 @@ -1189,14 +1192,7 @@ 39.94 return compiler; 39.95 } 39.96 39.97 - if (procOnly && !foundTypeProcessors) { 39.98 - compiler.todo.clear(); 39.99 - } else { 39.100 - if (procOnly && foundTypeProcessors) 39.101 - compiler.shouldStopPolicy = CompileState.FLOW; 39.102 - 39.103 - compiler.enterTrees(roots); 39.104 - } 39.105 + compiler.enterTreesIfNeeded(roots); 39.106 39.107 return compiler; 39.108 }
40.1 --- a/src/share/classes/com/sun/tools/javac/resources/compiler.properties Thu Oct 11 09:50:52 2012 -0700 40.2 +++ b/src/share/classes/com/sun/tools/javac/resources/compiler.properties Thu Oct 11 17:00:54 2012 -0700 40.3 @@ -148,13 +148,8 @@ 40.4 compiler.err.call.must.be.first.stmt.in.ctor=\ 40.5 call to {0} must be first statement in constructor 40.6 40.7 +# 0: symbol kind, 1: name, 2: list of type or message segment, 3: list of type or message segment, 4: symbol kind, 5: type, 6: message segment 40.8 compiler.err.cant.apply.symbol=\ 40.9 - {0} {1} in {4} {5} cannot be applied to given types\n\ 40.10 - required: {2}\n\ 40.11 - found: {3} 40.12 - 40.13 -# 0: symbol kind, 1: name, 2: list of type or message segment, 3: list of type or message segment, 4: symbol kind, 5: type, 6: message segment 40.14 -compiler.err.cant.apply.symbol.1=\ 40.15 {0} {1} in {4} {5} cannot be applied to given types;\n\ 40.16 required: {2}\n\ 40.17 found: {3}\n\ 40.18 @@ -164,6 +159,74 @@ 40.19 compiler.err.cant.apply.symbols=\ 40.20 no suitable {0} found for {1}({2}) 40.21 40.22 +# 0: symbol kind, 1: name, 2: list of type or message segment, 3: list of type or message segment, 4: symbol kind, 5: type, 6: message segment 40.23 +compiler.misc.cant.apply.symbol=\ 40.24 + {0} {1} in {4} {5} cannot be applied to given types\n\ 40.25 + required: {2}\n\ 40.26 + found: {3}\n\ 40.27 + reason: {6} 40.28 + 40.29 +# 0: symbol kind, 1: name, 2: list of type 40.30 +compiler.misc.cant.apply.symbols=\ 40.31 + no suitable {0} found for {1}({2}) 40.32 + 40.33 + 40.34 +# 0: type 40.35 +compiler.err.cant.access.arg.type.in.functional.desc=\ 40.36 + cannot access parameter type {0} in target functional descriptor 40.37 + 40.38 +# 0: type 40.39 +compiler.err.cant.access.return.in.functional.desc=\ 40.40 + cannot access return type {0} in target functional descriptor 40.41 + 40.42 +# 0: type 40.43 +compiler.err.cant.access.thrown.in.functional.desc=\ 40.44 + cannot access thrown type {0} in target functional descriptor 40.45 + 40.46 +# 0: symbol kind, 1: symbol 40.47 +compiler.misc.no.abstracts=\ 40.48 + no abstract method found in {0} {1} 40.49 + 40.50 +# 0: symbol kind, 1: symbol 40.51 +compiler.misc.incompatible.abstracts=\ 40.52 + multiple non-overriding abstract methods found in {0} {1} 40.53 + 40.54 +compiler.misc.not.a.functional.intf=\ 40.55 + the target type must be a functional interface 40.56 + 40.57 +# 0: message segment 40.58 +compiler.misc.not.a.functional.intf.1=\ 40.59 + the target type must be a functional interface\n\ 40.60 + {0} 40.61 + 40.62 +# 0: symbol, 1: symbol kind, 2: symbol 40.63 +compiler.misc.invalid.generic.desc.in.functional.intf=\ 40.64 + invalid functional descriptor: method {0} in {1} {2} is generic 40.65 + 40.66 +# 0: symbol kind, 1: symbol 40.67 +compiler.misc.incompatible.descs.in.functional.intf=\ 40.68 + incompatible function descriptors found in {0} {1} 40.69 + 40.70 +# 0: name, 1: list of type, 2: type, 3: list of type 40.71 +compiler.misc.descriptor=\ 40.72 + descriptor: {2} {0}({1}) 40.73 + 40.74 +# 0: name, 1: list of type, 2: type, 3: list of type 40.75 +compiler.misc.descriptor.throws=\ 40.76 + descriptor: {2} {0}({1}) throws {3} 40.77 + 40.78 +# 0: type 40.79 +compiler.misc.no.suitable.functional.intf.inst=\ 40.80 + cannot infer functional interface descriptor for {0} 40.81 + 40.82 +# 0: symbol kind, 1: message segment 40.83 +compiler.err.invalid.mref=\ 40.84 + invalid {0} reference; {1} 40.85 + 40.86 +# 0: symbol kind, 1: message segment 40.87 +compiler.misc.invalid.mref=\ 40.88 + invalid {0} reference; {1} 40.89 + 40.90 # 0: symbol 40.91 compiler.err.cant.assign.val.to.final.var=\ 40.92 cannot assign a value to final variable {0} 40.93 @@ -173,6 +236,9 @@ 40.94 local variables referenced from {1} must be final or effectively final 40.95 40.96 40.97 +compiler.misc.lambda=\ 40.98 + a lambda expression 40.99 + 40.100 compiler.misc.inner.cls=\ 40.101 an inner class 40.102 40.103 @@ -292,7 +358,7 @@ 40.104 40.105 # 0: type, 1: symbol 40.106 compiler.err.invalid.containedby.annotation.elem.nondefault=\ 40.107 - duplicate annotation, element {1} in containing annotation {0} does not have a default value 40.108 + containing annotation {0} does not have a default value for element {1} 40.109 40.110 # 0: symbol, 1: type, 2: symbol, 3: type 40.111 compiler.err.invalid.containedby.annotation.retention=\ 40.112 @@ -592,6 +658,9 @@ 40.113 compiler.err.missing.ret.stmt=\ 40.114 missing return statement 40.115 40.116 +compiler.misc.missing.ret.val=\ 40.117 + missing return value 40.118 + 40.119 compiler.err.missing.ret.val=\ 40.120 missing return value 40.121 40.122 @@ -635,6 +704,31 @@ 40.123 second operand: {0}\n\ 40.124 third operand : {1} 40.125 40.126 +# 0: message segment 40.127 +compiler.misc.incompatible.type.in.conditional=\ 40.128 + bad type in conditional expression; {0} 40.129 + 40.130 +# 0: type 40.131 +compiler.misc.incompatible.ret.type.in.lambda=\ 40.132 + bad return type in lambda expression\n\ 40.133 + {0} 40.134 + 40.135 +# 0: type 40.136 +compiler.misc.incompatible.ret.type.in.mref=\ 40.137 + bad return type in method reference\n\ 40.138 + {0} 40.139 + 40.140 +# 0: list of type 40.141 +compiler.err.incompatible.thrown.types.in.lambda=\ 40.142 + incompatible thrown types {0} in lambda expression 40.143 + 40.144 +# 0: list of type 40.145 +compiler.err.incompatible.thrown.types.in.mref=\ 40.146 + incompatible thrown types {0} in method reference 40.147 + 40.148 +compiler.misc.incompatible.arg.types.in.lambda=\ 40.149 + incompatible parameter types in lambda expression 40.150 + 40.151 compiler.err.new.not.allowed.in.annotation=\ 40.152 ''new'' not allowed in an annotation 40.153 40.154 @@ -658,6 +752,15 @@ 40.155 {0} in {1} is defined in an inaccessible class or interface 40.156 40.157 # 0: symbol, 1: symbol 40.158 +compiler.misc.not.def.access.class.intf.cant.access=\ 40.159 + {0} in {1} is defined in an inaccessible class or interface 40.160 + 40.161 +# 0: symbol, 1: list of type, 2: type 40.162 +compiler.misc.cant.access.inner.cls.constr=\ 40.163 + cannot access constructor {0}({1})\n\ 40.164 + an enclosing instance of type {2} is not in scope 40.165 + 40.166 +# 0: symbol, 1: symbol 40.167 compiler.err.not.def.public.cant.access=\ 40.168 {0} is not public in {1}; cannot be accessed from outside package 40.169 40.170 @@ -755,7 +858,13 @@ 40.171 40.172 # 0: name, 1: symbol kind, 2: symbol, 3: symbol, 4: symbol kind, 5: symbol, 6: symbol 40.173 compiler.err.ref.ambiguous=\ 40.174 - reference to {0} is ambiguous, both {1} {2} in {3} and {4} {5} in {6} match 40.175 + reference to {0} is ambiguous\n\ 40.176 + both {1} {2} in {3} and {4} {5} in {6} match 40.177 + 40.178 +# 0: name, 1: symbol kind, 2: symbol, 3: symbol, 4: symbol kind, 5: symbol, 6: symbol 40.179 +compiler.misc.ref.ambiguous=\ 40.180 + reference to {0} is ambiguous\n\ 40.181 + both {1} {2} in {3} and {4} {5} in {6} match 40.182 40.183 compiler.err.repeated.annotation.target=\ 40.184 repeated annotation target 40.185 @@ -991,6 +1100,10 @@ 40.186 40.187 ## The following string will appear before all messages keyed as: 40.188 ## "compiler.note". 40.189 + 40.190 +compiler.note.potential.lambda.found=\ 40.191 + This anonymous inner class creation can be turned into a lambda expression. 40.192 + 40.193 compiler.note.note=\ 40.194 Note:\u0020 40.195 40.196 @@ -1652,6 +1765,18 @@ 40.197 compiler.misc.incompatible.upper.bounds=\ 40.198 inference variable {0} has incompatible upper bounds {1} 40.199 40.200 +# 0: type, 1: list of type, 2: list of type 40.201 +compiler.misc.incompatible.eq.upper.bounds=\ 40.202 + inference variable {0} has incompatible bounds\n\ 40.203 + equality constraints: {1}\n\ 40.204 + upper bounds: {2} 40.205 + 40.206 +# 0: type, 1: list of type, 2: list of type 40.207 +compiler.misc.incompatible.eq.lower.bounds=\ 40.208 + inference variable {0} has incompatible bounds\n\ 40.209 + equality constraints: {1}\n\ 40.210 + lower bounds: {2} 40.211 + 40.212 # 0: list of type, 1: type, 2: type 40.213 compiler.misc.infer.no.conforming.instance.exists=\ 40.214 no instance(s) of type variable(s) {0} exist so that {1} conforms to {2} 40.215 @@ -1689,6 +1814,10 @@ 40.216 inferred: {0}\n\ 40.217 equality constraints(s): {1} 40.218 40.219 +# 0: list of type 40.220 +compiler.misc.cyclic.inference=\ 40.221 + Cannot instantiate inference variables {0} because of an inference loop 40.222 + 40.223 # 0: symbol 40.224 compiler.misc.diamond=\ 40.225 {0}<> 40.226 @@ -1728,6 +1857,10 @@ 40.227 compiler.err.non-static.cant.be.ref=\ 40.228 non-static {0} {1} cannot be referenced from a static context 40.229 40.230 +# 0: symbol kind, 1: symbol 40.231 +compiler.misc.non-static.cant.be.ref=\ 40.232 + non-static {0} {1} cannot be referenced from a static context 40.233 + 40.234 ## Both arguments ({0}, {1}) are "kindname"s. {0} is a comma-separated list 40.235 ## of kindnames (the list should be identical to that provided in source. 40.236 compiler.err.unexpected.type=\ 40.237 @@ -1735,6 +1868,12 @@ 40.238 required: {0}\n\ 40.239 found: {1} 40.240 40.241 +compiler.err.unexpected.lambda=\ 40.242 + lambda expression not expected here 40.243 + 40.244 +compiler.err.unexpected.mref=\ 40.245 + method reference not expected here 40.246 + 40.247 ## The first argument {0} is a "kindname" (e.g. 'constructor', 'field', etc.) 40.248 ## The second argument {1} is the non-resolved symbol 40.249 ## The third argument {2} is a list of type parameters (non-empty if {1} is a method) 40.250 @@ -1774,6 +1913,20 @@ 40.251 symbol: {0} <{2}>{1}({3})\n\ 40.252 location: {4} 40.253 40.254 +### Following are replicated/used for method reference diagnostics 40.255 + 40.256 +# 0: symbol kind, 1: name, 2: unused, 3: list of type, 4: message segment 40.257 +compiler.misc.cant.resolve.location.args=\ 40.258 + cannot find symbol\n\ 40.259 + symbol: {0} {1}({3})\n\ 40.260 + location: {4} 40.261 + 40.262 +# 0: symbol kind, 1: name, 2: list of type, 3: list, 4: message segment 40.263 +compiler.misc.cant.resolve.location.args.params=\ 40.264 + cannot find symbol\n\ 40.265 + symbol: {0} <{2}>{1}({3})\n\ 40.266 + location: {4} 40.267 + 40.268 ##a location subdiagnostic is composed as follows: 40.269 ## The first argument {0} is the location "kindname" (e.g. 'constructor', 'field', etc.) 40.270 ## The second argument {1} is the location name
41.1 --- a/src/share/classes/com/sun/tools/javac/tree/JCTree.java Thu Oct 11 09:50:52 2012 -0700 41.2 +++ b/src/share/classes/com/sun/tools/javac/tree/JCTree.java Thu Oct 11 17:00:54 2012 -0700 41.3 @@ -1810,11 +1810,46 @@ 41.4 */ 41.5 public static class JCMemberReference extends JCExpression implements MemberReferenceTree { 41.6 public ReferenceMode mode; 41.7 + public ReferenceKind kind; 41.8 public Name name; 41.9 public JCExpression expr; 41.10 public List<JCExpression> typeargs; 41.11 public Type targetType; 41.12 public Symbol sym; 41.13 + public Type varargsElement; 41.14 + 41.15 + /** 41.16 + * Javac-dependent classification for member references, based 41.17 + * on relevant properties w.r.t. code-generation 41.18 + */ 41.19 + public enum ReferenceKind { 41.20 + /** super # instMethod */ 41.21 + SUPER(ReferenceMode.INVOKE, false), 41.22 + /** Type # instMethod */ 41.23 + UNBOUND(ReferenceMode.INVOKE, true), 41.24 + /** Type # staticMethod */ 41.25 + STATIC(ReferenceMode.INVOKE, false), 41.26 + /** Expr # instMethod */ 41.27 + BOUND(ReferenceMode.INVOKE, false), 41.28 + /** Expr # staticMethod */ 41.29 + STATIC_EVAL(ReferenceMode.INVOKE, false), 41.30 + /** Inner # new */ 41.31 + IMPLICIT_INNER(ReferenceMode.NEW, false), 41.32 + /** Toplevel # new */ 41.33 + TOPLEVEL(ReferenceMode.NEW, false); 41.34 + 41.35 + ReferenceMode mode; 41.36 + boolean unbound; 41.37 + 41.38 + private ReferenceKind(ReferenceMode mode, boolean unbound) { 41.39 + this.mode = mode; 41.40 + this.unbound = unbound; 41.41 + } 41.42 + 41.43 + public boolean isUnbound() { 41.44 + return unbound; 41.45 + } 41.46 + } 41.47 41.48 protected JCMemberReference(ReferenceMode mode, Name name, JCExpression expr, List<JCExpression> typeargs) { 41.49 this.mode = mode; 41.50 @@ -1843,6 +1878,9 @@ 41.51 public Tag getTag() { 41.52 return REFERENCE; 41.53 } 41.54 + public boolean hasKind(ReferenceKind kind) { 41.55 + return this.kind == kind; 41.56 + } 41.57 } 41.58 41.59 /**
42.1 --- a/src/share/classes/com/sun/tools/javac/tree/Pretty.java Thu Oct 11 09:50:52 2012 -0700 42.2 +++ b/src/share/classes/com/sun/tools/javac/tree/Pretty.java Thu Oct 11 17:00:54 2012 -0700 42.3 @@ -81,6 +81,17 @@ 42.4 */ 42.5 DocCommentTable docComments = null; 42.6 42.7 + /** 42.8 + * A string sequence to be used when Pretty output should be constrained 42.9 + * to fit into a given size 42.10 + */ 42.11 + private final static String trimSequence = "[...]"; 42.12 + 42.13 + /** 42.14 + * Max number of chars to be generated when output should fit into a single line 42.15 + */ 42.16 + private final static int PREFERRED_LENGTH = 20; 42.17 + 42.18 /** Align code to be indented to left margin. 42.19 */ 42.20 void align() throws IOException { 42.21 @@ -129,6 +140,31 @@ 42.22 out.write(lineSep); 42.23 } 42.24 42.25 + public static String toSimpleString(JCTree tree) { 42.26 + return toSimpleString(tree, PREFERRED_LENGTH); 42.27 + } 42.28 + 42.29 + public static String toSimpleString(JCTree tree, int maxLength) { 42.30 + StringWriter s = new StringWriter(); 42.31 + try { 42.32 + new Pretty(s, false).printExpr(tree); 42.33 + } 42.34 + catch (IOException e) { 42.35 + // should never happen, because StringWriter is defined 42.36 + // never to throw any IOExceptions 42.37 + throw new AssertionError(e); 42.38 + } 42.39 + //we need to (i) replace all line terminators with a space and (ii) remove 42.40 + //occurrences of 'missing' in the Pretty output (generated when types are missing) 42.41 + String res = s.toString().replaceAll("\\s+", " ").replaceAll("/\\*missing\\*/", ""); 42.42 + if (res.length() < maxLength) { 42.43 + return res; 42.44 + } else { 42.45 + int split = (maxLength - trimSequence.length()) * 2 / 3; 42.46 + return res.substring(0, split) + trimSequence + res.substring(split); 42.47 + } 42.48 + } 42.49 + 42.50 String lineSep = System.getProperty("line.separator"); 42.51 42.52 /************************************************************************** 42.53 @@ -911,7 +947,16 @@ 42.54 public void visitLambda(JCLambda tree) { 42.55 try { 42.56 print("("); 42.57 - printExprs(tree.params); 42.58 + if (TreeInfo.isExplicitLambda(tree)) { 42.59 + printExprs(tree.params); 42.60 + } else { 42.61 + String sep = ""; 42.62 + for (JCVariableDecl param : tree.params) { 42.63 + print(sep); 42.64 + print(param.name); 42.65 + sep = ","; 42.66 + } 42.67 + } 42.68 print(")->"); 42.69 printExpr(tree.body); 42.70 } catch (IOException e) {
43.1 --- a/src/share/classes/com/sun/tools/javac/tree/TreeInfo.java Thu Oct 11 09:50:52 2012 -0700 43.2 +++ b/src/share/classes/com/sun/tools/javac/tree/TreeInfo.java Thu Oct 11 17:00:54 2012 -0700 43.3 @@ -245,6 +245,27 @@ 43.4 } 43.5 } 43.6 43.7 + /** Return true if a a tree corresponds to a poly expression. */ 43.8 + public static boolean isPoly(JCTree tree, JCTree origin) { 43.9 + switch (tree.getTag()) { 43.10 + case APPLY: 43.11 + case NEWCLASS: 43.12 + case CONDEXPR: 43.13 + return !origin.hasTag(TYPECAST); 43.14 + case LAMBDA: 43.15 + case REFERENCE: 43.16 + return true; 43.17 + case PARENS: 43.18 + return isPoly(((JCParens)tree).expr, origin); 43.19 + default: 43.20 + return false; 43.21 + } 43.22 + } 43.23 + 43.24 + public static boolean isExplicitLambda(JCLambda lambda) { 43.25 + return lambda.params.isEmpty() || 43.26 + lambda.params.head.vartype != null; 43.27 + } 43.28 /** 43.29 * Return true if the AST corresponds to a static select of the kind A.B 43.30 */ 43.31 @@ -261,6 +282,7 @@ 43.32 return isStaticSym(base) && 43.33 isStaticSelector(((JCFieldAccess)base).selected, names); 43.34 case TYPEAPPLY: 43.35 + case TYPEARRAY: 43.36 return true; 43.37 default: 43.38 return false; 43.39 @@ -383,6 +405,10 @@ 43.40 JCVariableDecl node = (JCVariableDecl)tree; 43.41 if (node.mods.pos != Position.NOPOS) { 43.42 return node.mods.pos; 43.43 + } else if (node.vartype == null) { 43.44 + //if there's no type (partially typed lambda parameter) 43.45 + //simply return node position 43.46 + return node.pos; 43.47 } else { 43.48 return getStartPos(node.vartype); 43.49 }
44.1 --- a/src/share/classes/com/sun/tools/javac/util/AbstractDiagnosticFormatter.java Thu Oct 11 09:50:52 2012 -0700 44.2 +++ b/src/share/classes/com/sun/tools/javac/util/AbstractDiagnosticFormatter.java Thu Oct 11 17:00:54 2012 -0700 44.3 @@ -43,8 +43,10 @@ 44.4 import com.sun.tools.javac.code.Symbol; 44.5 import com.sun.tools.javac.code.Type; 44.6 import com.sun.tools.javac.code.Type.CapturedType; 44.7 +import com.sun.tools.javac.tree.JCTree.*; 44.8 44.9 import com.sun.tools.javac.file.BaseFileObject; 44.10 +import com.sun.tools.javac.tree.Pretty; 44.11 import static com.sun.tools.javac.util.JCDiagnostic.DiagnosticType.*; 44.12 44.13 /** 44.14 @@ -180,6 +182,9 @@ 44.15 } 44.16 return s; 44.17 } 44.18 + else if (arg instanceof JCExpression) { 44.19 + return expr2String((JCExpression)arg); 44.20 + } 44.21 else if (arg instanceof Iterable<?>) { 44.22 return formatIterable(d, (Iterable<?>)arg, l); 44.23 } 44.24 @@ -199,6 +204,20 @@ 44.25 return String.valueOf(arg); 44.26 } 44.27 } 44.28 + //where 44.29 + private String expr2String(JCExpression tree) { 44.30 + switch(tree.getTag()) { 44.31 + case PARENS: 44.32 + return expr2String(((JCParens)tree).expr); 44.33 + case LAMBDA: 44.34 + case REFERENCE: 44.35 + case CONDEXPR: 44.36 + return Pretty.toSimpleString(tree); 44.37 + default: 44.38 + Assert.error("unexpected tree kind " + tree.getKind()); 44.39 + return null; 44.40 + } 44.41 + } 44.42 44.43 /** 44.44 * Format an iterable argument of a given diagnostic. 44.45 @@ -490,6 +509,7 @@ 44.46 * lead to infinite loops. 44.47 */ 44.48 protected Printer printer = new Printer() { 44.49 + 44.50 @Override 44.51 protected String localize(Locale locale, String key, Object... args) { 44.52 return AbstractDiagnosticFormatter.this.localize(locale, key, args);
45.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 45.2 +++ b/src/share/classes/com/sun/tools/javac/util/ArrayUtils.java Thu Oct 11 17:00:54 2012 -0700 45.3 @@ -0,0 +1,87 @@ 45.4 +/* 45.5 + * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved. 45.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 45.7 + * 45.8 + * This code is free software; you can redistribute it and/or modify it 45.9 + * under the terms of the GNU General Public License version 2 only, as 45.10 + * published by the Free Software Foundation. Oracle designates this 45.11 + * particular file as subject to the "Classpath" exception as provided 45.12 + * by Oracle in the LICENSE file that accompanied this code. 45.13 + * 45.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 45.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 45.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 45.17 + * version 2 for more details (a copy is included in the LICENSE file that 45.18 + * accompanied this code). 45.19 + * 45.20 + * You should have received a copy of the GNU General Public License version 45.21 + * 2 along with this work; if not, write to the Free Software Foundation, 45.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 45.23 + * 45.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 45.25 + * or visit www.oracle.com if you need additional information or have any 45.26 + * questions. 45.27 + */ 45.28 + 45.29 +package com.sun.tools.javac.util; 45.30 + 45.31 +import java.lang.reflect.Array; 45.32 + 45.33 +/** <p><b>This is NOT part of any supported API. 45.34 + * If you write code that depends on this, you do so at your own risk. 45.35 + * This code and its internal interfaces are subject to change or 45.36 + * deletion without notice.</b> 45.37 + */ 45.38 +public class ArrayUtils { 45.39 + 45.40 + private static int calculateNewLength(int currentLength, int maxIndex) { 45.41 + while (currentLength < maxIndex + 1) 45.42 + currentLength = currentLength * 2; 45.43 + return currentLength; 45.44 + } 45.45 + 45.46 + public static <T> T[] ensureCapacity(T[] array, int maxIndex) { 45.47 + if (maxIndex < array.length) { 45.48 + return array; 45.49 + } else { 45.50 + int newLength = calculateNewLength(array.length, maxIndex); 45.51 + @SuppressWarnings("unchecked") 45.52 + T[] result = (T[]) Array.newInstance(array.getClass().getComponentType(), newLength); 45.53 + System.arraycopy(array, 0, result, 0, array.length); 45.54 + return result; 45.55 + } 45.56 + } 45.57 + 45.58 + public static byte[] ensureCapacity(byte[] array, int maxIndex) { 45.59 + if (maxIndex < array.length) { 45.60 + return array; 45.61 + } else { 45.62 + int newLength = calculateNewLength(array.length, maxIndex); 45.63 + byte[] result = new byte[newLength]; 45.64 + System.arraycopy(array, 0, result, 0, array.length); 45.65 + return result; 45.66 + } 45.67 + } 45.68 + 45.69 + public static char[] ensureCapacity(char[] array, int maxIndex) { 45.70 + if (maxIndex < array.length) { 45.71 + return array; 45.72 + } else { 45.73 + int newLength = calculateNewLength(array.length, maxIndex); 45.74 + char[] result = new char[newLength]; 45.75 + System.arraycopy(array, 0, result, 0, array.length); 45.76 + return result; 45.77 + } 45.78 + } 45.79 + 45.80 + public static int[] ensureCapacity(int[] array, int maxIndex) { 45.81 + if (maxIndex < array.length) { 45.82 + return array; 45.83 + } else { 45.84 + int newLength = calculateNewLength(array.length, maxIndex); 45.85 + int[] result = new int[newLength]; 45.86 + System.arraycopy(array, 0, result, 0, array.length); 45.87 + return result; 45.88 + } 45.89 + } 45.90 +}
46.1 --- a/src/share/classes/com/sun/tools/javac/util/Bits.java Thu Oct 11 09:50:52 2012 -0700 46.2 +++ b/src/share/classes/com/sun/tools/javac/util/Bits.java Thu Oct 11 17:00:54 2012 -0700 46.3 @@ -25,6 +25,8 @@ 46.4 46.5 package com.sun.tools.javac.util; 46.6 46.7 +import java.util.Arrays; 46.8 + 46.9 /** A class for extensible, mutable bit sets. 46.10 * 46.11 * <p><b>This is NOT part of any supported API. 46.12 @@ -62,9 +64,7 @@ 46.13 46.14 private void sizeTo(int len) { 46.15 if (bits.length < len) { 46.16 - int[] newbits = new int[len]; 46.17 - System.arraycopy(bits, 0, newbits, 0, bits.length); 46.18 - bits = newbits; 46.19 + bits = Arrays.copyOf(bits, len); 46.20 } 46.21 } 46.22
47.1 --- a/src/share/classes/com/sun/tools/javac/util/ByteBuffer.java Thu Oct 11 09:50:52 2012 -0700 47.2 +++ b/src/share/classes/com/sun/tools/javac/util/ByteBuffer.java Thu Oct 11 17:00:54 2012 -0700 47.3 @@ -1,5 +1,5 @@ 47.4 /* 47.5 - * Copyright (c) 1999, 2008, Oracle and/or its affiliates. All rights reserved. 47.6 + * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved. 47.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 47.8 * 47.9 * This code is free software; you can redistribute it and/or modify it 47.10 @@ -60,16 +60,10 @@ 47.11 length = 0; 47.12 } 47.13 47.14 - private void copy(int size) { 47.15 - byte[] newelems = new byte[size]; 47.16 - System.arraycopy(elems, 0, newelems, 0, elems.length); 47.17 - elems = newelems; 47.18 - } 47.19 - 47.20 /** Append byte to this buffer. 47.21 */ 47.22 public void appendByte(int b) { 47.23 - if (length >= elems.length) copy(elems.length * 2); 47.24 + elems = ArrayUtils.ensureCapacity(elems, length); 47.25 elems[length++] = (byte)b; 47.26 } 47.27 47.28 @@ -77,7 +71,7 @@ 47.29 * starting at given `start' offset. 47.30 */ 47.31 public void appendBytes(byte[] bs, int start, int len) { 47.32 - while (length + len > elems.length) copy(elems.length * 2); 47.33 + elems = ArrayUtils.ensureCapacity(elems, length + len); 47.34 System.arraycopy(bs, start, elems, length, len); 47.35 length += len; 47.36 } 47.37 @@ -91,7 +85,7 @@ 47.38 /** Append a character as a two byte number. 47.39 */ 47.40 public void appendChar(int x) { 47.41 - while (length + 1 >= elems.length) copy(elems.length * 2); 47.42 + elems = ArrayUtils.ensureCapacity(elems, length + 1); 47.43 elems[length ] = (byte)((x >> 8) & 0xFF); 47.44 elems[length+1] = (byte)((x ) & 0xFF); 47.45 length = length + 2; 47.46 @@ -100,7 +94,7 @@ 47.47 /** Append an integer as a four byte number. 47.48 */ 47.49 public void appendInt(int x) { 47.50 - while (length + 3 >= elems.length) copy(elems.length * 2); 47.51 + elems = ArrayUtils.ensureCapacity(elems, length + 3); 47.52 elems[length ] = (byte)((x >> 24) & 0xFF); 47.53 elems[length+1] = (byte)((x >> 16) & 0xFF); 47.54 elems[length+2] = (byte)((x >> 8) & 0xFF);
48.1 --- a/src/share/classes/com/sun/tools/javac/util/List.java Thu Oct 11 09:50:52 2012 -0700 48.2 +++ b/src/share/classes/com/sun/tools/javac/util/List.java Thu Oct 11 17:00:54 2012 -0700 48.3 @@ -83,6 +83,19 @@ 48.4 } 48.5 }; 48.6 48.7 + /** Returns the list obtained from 'l' after removing all elements 'elem' 48.8 + */ 48.9 + public static <A> List<A> filter(List<A> l, A elem) { 48.10 + Assert.checkNonNull(elem); 48.11 + List<A> res = List.nil(); 48.12 + for (A a : l) { 48.13 + if (a != null && !a.equals(elem)) { 48.14 + res = res.prepend(a); 48.15 + } 48.16 + } 48.17 + return res.reverse(); 48.18 + } 48.19 + 48.20 /** Construct a list consisting of given element. 48.21 */ 48.22 public static <A> List<A> of(A x1) { 48.23 @@ -120,6 +133,14 @@ 48.24 return xs; 48.25 } 48.26 48.27 + public static <A> List<A> from(Iterable<? extends A> coll) { 48.28 + List<A> xs = nil(); 48.29 + for (A a : coll) { 48.30 + xs = new List<A>(a, xs); 48.31 + } 48.32 + return xs; 48.33 + } 48.34 + 48.35 /** Construct a list consisting of a given number of identical elements. 48.36 * @param len The number of elements in the list. 48.37 * @param init The value of each element.
49.1 --- a/src/share/classes/com/sun/tools/javac/util/Log.java Thu Oct 11 09:50:52 2012 -0700 49.2 +++ b/src/share/classes/com/sun/tools/javac/util/Log.java Thu Oct 11 17:00:54 2012 -0700 49.3 @@ -130,7 +130,7 @@ 49.4 /** 49.5 * Deferred diagnostics 49.6 */ 49.7 - public boolean deferDiagnostics; 49.8 + public Filter<JCDiagnostic> deferredDiagFilter; 49.9 public Queue<JCDiagnostic> deferredDiagnostics = new ListBuffer<JCDiagnostic>(); 49.10 49.11 /** Construct a log with given I/O redirections. 49.12 @@ -450,7 +450,7 @@ 49.13 49.14 /** Report selected deferred diagnostics, and clear the deferDiagnostics flag. */ 49.15 public void reportDeferredDiagnostics(Set<JCDiagnostic.Kind> kinds) { 49.16 - deferDiagnostics = false; 49.17 + deferredDiagFilter = null; 49.18 JCDiagnostic d; 49.19 while ((d = deferredDiagnostics.poll()) != null) { 49.20 if (kinds.contains(d.getKind())) 49.21 @@ -464,7 +464,7 @@ 49.22 * reported so far, the diagnostic may be handed off to writeDiagnostic. 49.23 */ 49.24 public void report(JCDiagnostic diagnostic) { 49.25 - if (deferDiagnostics) { 49.26 + if (deferredDiagFilter != null && deferredDiagFilter.accepts(diagnostic)) { 49.27 deferredDiagnostics.add(diagnostic); 49.28 return; 49.29 } 49.30 @@ -551,6 +551,18 @@ 49.31 } 49.32 } 49.33 49.34 + public void deferAll() { 49.35 + deferredDiagFilter = new Filter<JCDiagnostic>() { 49.36 + public boolean accepts(JCDiagnostic t) { 49.37 + return true; 49.38 + } 49.39 + }; 49.40 + } 49.41 + 49.42 + public void deferNone() { 49.43 + deferredDiagFilter = null; 49.44 + } 49.45 + 49.46 /** Find a localized string in the resource bundle. 49.47 * Because this method is static, it ignores the locale. 49.48 * Use localize(key, args) when possible.
50.1 --- a/src/share/classes/com/sun/tools/javac/util/Names.java Thu Oct 11 09:50:52 2012 -0700 50.2 +++ b/src/share/classes/com/sun/tools/javac/util/Names.java Thu Oct 11 17:00:54 2012 -0700 50.3 @@ -118,6 +118,7 @@ 50.4 // attribute names 50.5 public final Name Annotation; 50.6 public final Name AnnotationDefault; 50.7 + public final Name BootstrapMethods; 50.8 public final Name Bridge; 50.9 public final Name CharacterRangeTable; 50.10 public final Name Code; 50.11 @@ -246,6 +247,7 @@ 50.12 // attribute names 50.13 Annotation = fromString("Annotation"); 50.14 AnnotationDefault = fromString("AnnotationDefault"); 50.15 + BootstrapMethods = fromString("BootstrapMethods"); 50.16 Bridge = fromString("Bridge"); 50.17 CharacterRangeTable = fromString("CharacterRangeTable"); 50.18 Code = fromString("Code");
51.1 --- a/src/share/classes/com/sun/tools/javac/util/RawDiagnosticFormatter.java Thu Oct 11 09:50:52 2012 -0700 51.2 +++ b/src/share/classes/com/sun/tools/javac/util/RawDiagnosticFormatter.java Thu Oct 11 17:00:54 2012 -0700 51.3 @@ -32,6 +32,7 @@ 51.4 import com.sun.tools.javac.api.DiagnosticFormatter.Configuration.*; 51.5 import com.sun.tools.javac.api.Formattable; 51.6 import com.sun.tools.javac.file.BaseFileObject; 51.7 +import com.sun.tools.javac.tree.JCTree.*; 51.8 import com.sun.tools.javac.util.AbstractDiagnosticFormatter.SimpleConfiguration; 51.9 51.10 import static com.sun.tools.javac.api.DiagnosticFormatter.PositionKind.*; 51.11 @@ -117,16 +118,17 @@ 51.12 @Override 51.13 protected String formatArgument(JCDiagnostic diag, Object arg, Locale l) { 51.14 String s; 51.15 - if (arg instanceof Formattable) 51.16 + if (arg instanceof Formattable) { 51.17 s = arg.toString(); 51.18 - else if (arg instanceof BaseFileObject) 51.19 + } else if (arg instanceof JCExpression) { 51.20 + JCExpression tree = (JCExpression)arg; 51.21 + s = "@" + tree.getStartPosition(); 51.22 + } else if (arg instanceof BaseFileObject) { 51.23 s = ((BaseFileObject) arg).getShortName(); 51.24 - else 51.25 + } else { 51.26 s = super.formatArgument(diag, arg, null); 51.27 - if (arg instanceof JCDiagnostic) 51.28 - return "(" + s + ")"; 51.29 - else 51.30 - return s; 51.31 + } 51.32 + return (arg instanceof JCDiagnostic) ? "(" + s + ")" : s; 51.33 } 51.34 51.35 @Override
52.1 --- a/src/share/classes/com/sun/tools/javac/util/RichDiagnosticFormatter.java Thu Oct 11 09:50:52 2012 -0700 52.2 +++ b/src/share/classes/com/sun/tools/javac/util/RichDiagnosticFormatter.java Thu Oct 11 17:00:54 2012 -0700 52.3 @@ -393,11 +393,6 @@ 52.4 } 52.5 52.6 @Override 52.7 - protected String printMethodArgs(List<Type> args, boolean varArgs, Locale locale) { 52.8 - return super.printMethodArgs(args, varArgs, locale); 52.9 - } 52.10 - 52.11 - @Override 52.12 public String visitClassSymbol(ClassSymbol s, Locale locale) { 52.13 String name = nameSimplifier.simplify(s); 52.14 if (name.length() == 0 ||
53.1 --- a/src/share/classes/com/sun/tools/javac/util/SharedNameTable.java Thu Oct 11 09:50:52 2012 -0700 53.2 +++ b/src/share/classes/com/sun/tools/javac/util/SharedNameTable.java Thu Oct 11 17:00:54 2012 -0700 53.3 @@ -1,5 +1,5 @@ 53.4 /* 53.5 - * Copyright (c) 1999, 2008, Oracle and/or its affiliates. All rights reserved. 53.6 + * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved. 53.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 53.8 * 53.9 * This code is free software; you can redistribute it and/or modify it 53.10 @@ -93,13 +93,7 @@ 53.11 @Override 53.12 public Name fromChars(char[] cs, int start, int len) { 53.13 int nc = this.nc; 53.14 - byte[] bytes = this.bytes; 53.15 - while (nc + len * 3 >= bytes.length) { 53.16 - // System.err.println("doubling name buffer of length " + names.length + " to fit " + len + " chars");//DEBUG 53.17 - byte[] newnames = new byte[bytes.length * 2]; 53.18 - System.arraycopy(bytes, 0, newnames, 0, bytes.length); 53.19 - bytes = this.bytes = newnames; 53.20 - } 53.21 + byte[] bytes = this.bytes = ArrayUtils.ensureCapacity(this.bytes, nc + len * 3); 53.22 int nbytes = Convert.chars2utf(cs, start, bytes, nc, len) - nc; 53.23 int h = hashValue(bytes, nc, nbytes) & hashMask; 53.24 NameImpl n = hashes[h]; 53.25 @@ -133,12 +127,7 @@ 53.26 } 53.27 if (n == null) { 53.28 int nc = this.nc; 53.29 - while (nc + len > names.length) { 53.30 - // System.err.println("doubling name buffer of length + " + names.length + " to fit " + len + " bytes");//DEBUG 53.31 - byte[] newnames = new byte[names.length * 2]; 53.32 - System.arraycopy(names, 0, newnames, 0, names.length); 53.33 - names = this.bytes = newnames; 53.34 - } 53.35 + names = this.bytes = ArrayUtils.ensureCapacity(names, nc + len); 53.36 System.arraycopy(cs, start, names, nc, len); 53.37 n = new NameImpl(this); 53.38 n.index = nc;
54.1 --- a/src/share/classes/com/sun/tools/javap/CodeWriter.java Thu Oct 11 09:50:52 2012 -0700 54.2 +++ b/src/share/classes/com/sun/tools/javap/CodeWriter.java Thu Oct 11 17:00:54 2012 -0700 54.3 @@ -1,5 +1,5 @@ 54.4 /* 54.5 - * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved. 54.6 + * Copyright (c) 2007, 2012, Oracle and/or its affiliates. All rights reserved. 54.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 54.8 * 54.9 * This code is free software; you can redistribute it and/or modify it 54.10 @@ -45,8 +45,8 @@ 54.11 * This code and its internal interfaces are subject to change or 54.12 * deletion without notice.</b> 54.13 */ 54.14 -class CodeWriter extends BasicWriter { 54.15 - static CodeWriter instance(Context context) { 54.16 +public class CodeWriter extends BasicWriter { 54.17 + public static CodeWriter instance(Context context) { 54.18 CodeWriter instance = context.get(CodeWriter.class); 54.19 if (instance == null) 54.20 instance = new CodeWriter(context);
55.1 --- a/src/share/classes/com/sun/tools/javap/StackMapWriter.java Thu Oct 11 09:50:52 2012 -0700 55.2 +++ b/src/share/classes/com/sun/tools/javap/StackMapWriter.java Thu Oct 11 17:00:54 2012 -0700 55.3 @@ -1,5 +1,5 @@ 55.4 /* 55.5 - * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved. 55.6 + * Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved. 55.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 55.8 * 55.9 * This code is free software; you can redistribute it and/or modify it 55.10 @@ -25,10 +25,11 @@ 55.11 55.12 package com.sun.tools.javap; 55.13 55.14 -import com.sun.tools.classfile.AccessFlags; 55.15 +import java.util.Arrays; 55.16 import java.util.HashMap; 55.17 import java.util.Map; 55.18 55.19 +import com.sun.tools.classfile.AccessFlags; 55.20 import com.sun.tools.classfile.Attribute; 55.21 import com.sun.tools.classfile.Code_attribute; 55.22 import com.sun.tools.classfile.ConstantPool; 55.23 @@ -233,8 +234,7 @@ 55.24 StackMap prev = map.get(pc); 55.25 assert (prev != null); 55.26 int k = 251 - frame.frame_type; 55.27 - verification_type_info[] new_locals = new verification_type_info[prev.locals.length - k]; 55.28 - System.arraycopy(prev.locals, 0, new_locals, 0, new_locals.length); 55.29 + verification_type_info[] new_locals = Arrays.copyOf(prev.locals, prev.locals.length - k); 55.30 StackMap m = new StackMap(new_locals, empty); 55.31 map.put(new_pc, m); 55.32 return new_pc;
56.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 56.2 +++ b/test/com/sun/javadoc/testHelpFile/TestHelpFile.java Thu Oct 11 17:00:54 2012 -0700 56.3 @@ -0,0 +1,76 @@ 56.4 +/* 56.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 56.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 56.7 + * 56.8 + * This code is free software; you can redistribute it and/or modify it 56.9 + * under the terms of the GNU General Public License version 2 only, as 56.10 + * published by the Free Software Foundation. 56.11 + * 56.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 56.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 56.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 56.15 + * version 2 for more details (a copy is included in the LICENSE file that 56.16 + * accompanied this code). 56.17 + * 56.18 + * You should have received a copy of the GNU General Public License version 56.19 + * 2 along with this work; if not, write to the Free Software Foundation, 56.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 56.21 + * 56.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 56.23 + * or visit www.oracle.com if you need additional information or have any 56.24 + * questions. 56.25 + */ 56.26 + 56.27 +/* 56.28 + * @test 56.29 + * @bug 7132631 56.30 + * @summary Make sure that the help file is generated correctly. 56.31 + * @author Bhavesh Patel 56.32 + * @library ../lib/ 56.33 + * @build JavadocTester TestHelpFile 56.34 + * @run main TestHelpFile 56.35 + */ 56.36 + 56.37 +public class TestHelpFile extends JavadocTester { 56.38 + 56.39 + //Test information. 56.40 + private static final String BUG_ID = "7132631"; 56.41 + 56.42 + //Javadoc arguments. 56.43 + private static final String[] ARGS = new String[] { 56.44 + "-d", BUG_ID, "-sourcepath", SRC_DIR, 56.45 + SRC_DIR + FS + "TestHelpFile.java" 56.46 + }; 56.47 + 56.48 + private static final String[][] NEGATED_TEST = NO_TEST; 56.49 + 56.50 + private static final String[][] TEST = { 56.51 + {BUG_ID + FS + "help-doc.html", 56.52 + "<a href=\"constant-values.html\">Constant Field Values</a>" 56.53 + }, 56.54 + }; 56.55 + 56.56 + /** 56.57 + * The entry point of the test. 56.58 + * @param args the array of command line arguments. 56.59 + */ 56.60 + public static void main(String[] args) { 56.61 + TestHelpFile tester = new TestHelpFile(); 56.62 + run(tester, ARGS, TEST, NEGATED_TEST); 56.63 + tester.printSummary(); 56.64 + } 56.65 + 56.66 + /** 56.67 + * {@inheritDoc} 56.68 + */ 56.69 + public String getBugId() { 56.70 + return BUG_ID; 56.71 + } 56.72 + 56.73 + /** 56.74 + * {@inheritDoc} 56.75 + */ 56.76 + public String getBugName() { 56.77 + return getClass().getName(); 56.78 + } 56.79 +}
57.1 --- a/test/com/sun/javadoc/testUseOption/TestUseOption.java Thu Oct 11 09:50:52 2012 -0700 57.2 +++ b/test/com/sun/javadoc/testUseOption/TestUseOption.java Thu Oct 11 17:00:54 2012 -0700 57.3 @@ -1,5 +1,5 @@ 57.4 /* 57.5 - * Copyright (c) 2002, 2011, Oracle and/or its affiliates. All rights reserved. 57.6 + * Copyright (c) 2002, 2012, Oracle and/or its affiliates. All rights reserved. 57.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 57.8 * 57.9 * This code is free software; you can redistribute it and/or modify it 57.10 @@ -23,7 +23,7 @@ 57.11 57.12 /* 57.13 * @test 57.14 - * @bug 4496290 4985072 7006178 57.15 + * @bug 4496290 4985072 7006178 7068595 57.16 * @summary A simple test to determine if -use works. 57.17 * @author jamieh 57.18 * @library ../lib/ 57.19 @@ -34,7 +34,7 @@ 57.20 57.21 public class TestUseOption extends JavadocTester { 57.22 57.23 - private static final String BUG_ID = "4496290-4985072-7006178"; 57.24 + private static final String BUG_ID = "4496290-4985072-7006178-7068595"; 57.25 57.26 //Input for string search tests. 57.27 private static final String[] TEST2 = { 57.28 @@ -64,6 +64,13 @@ 57.29 } 57.30 }; 57.31 57.32 + private static final String[][] TEST4 = { 57.33 + {BUG_ID + "-4" + FS + "pkg2" + FS + "class-use" + FS + "C3.html", "<a href=" + 57.34 + "\"../../index.html?pkg2/class-use/C3.html\" target=\"_top\">" + 57.35 + "Frames</a></li>" 57.36 + } 57.37 + }; 57.38 + 57.39 private static final String[] ARGS = new String[] { 57.40 "-d", BUG_ID, "-sourcepath", SRC_DIR, "-use", "pkg1", "pkg2" 57.41 }; 57.42 @@ -76,6 +83,10 @@ 57.43 "-d", BUG_ID + "-3", "-sourcepath", SRC_DIR, "-use", SRC_DIR + FS + "C.java", SRC_DIR + FS + "UsedInC.java" 57.44 }; 57.45 57.46 + private static final String[] ARGS4 = new String[] { 57.47 + "-d", BUG_ID + "-4", "-sourcepath", SRC_DIR, "-use", "pkg1", "pkg2" 57.48 + }; 57.49 + 57.50 /** 57.51 * The entry point of the test. 57.52 * @param args the array of command line arguments. 57.53 @@ -108,6 +119,7 @@ 57.54 } 57.55 tester.printSummary(); 57.56 run(tester, ARGS3, TEST3, NO_TEST); 57.57 + run(tester, ARGS4, TEST4, NO_TEST); 57.58 tester.printSummary(); 57.59 } 57.60
58.1 --- a/test/tools/javac/6402516/TestLocalElements.java Thu Oct 11 09:50:52 2012 -0700 58.2 +++ b/test/tools/javac/6402516/TestLocalElements.java Thu Oct 11 17:00:54 2012 -0700 58.3 @@ -43,9 +43,9 @@ 58.4 58.5 boolean b = new Object() { 58.6 public boolean equals(Object other) { 58.7 - String p = "p, other, super, this; super, this; List, Test2, Test; java.io.*, java.lang.*"; 58.8 - String q = "q, p, other, super, this; super, this; List, Test2, Test; java.io.*, java.lang.*"; 58.9 - String r = "r, q, p, other, super, this; super, this; List, Test2, Test; java.io.*, java.lang.*"; 58.10 + String p = "p, other, super, this; -, super, this; List, Test2, Test; java.io.*, java.lang.*"; 58.11 + String q = "q, p, other, super, this; -, super, this; List, Test2, Test; java.io.*, java.lang.*"; 58.12 + String r = "r, q, p, other, super, this; -, super, this; List, Test2, Test; java.io.*, java.lang.*"; 58.13 return (this == other); 58.14 } 58.15
59.1 --- a/test/tools/javac/6758789/T6758789a.out Thu Oct 11 09:50:52 2012 -0700 59.2 +++ b/test/tools/javac/6758789/T6758789a.out Thu Oct 11 17:00:54 2012 -0700 59.3 @@ -1,3 +1,3 @@ 59.4 -T6758789a.java:14:9: compiler.err.cant.apply.symbol.1: kindname.method, m1, compiler.misc.no.args, int, kindname.class, T6758789a, (compiler.misc.arg.length.mismatch) 59.5 -T6758789a.java:15:9: compiler.err.cant.apply.symbol.1: kindname.method, m2, int, compiler.misc.no.args, kindname.class, T6758789a, (compiler.misc.arg.length.mismatch) 59.6 +T6758789a.java:14:9: compiler.err.cant.apply.symbol: kindname.method, m1, compiler.misc.no.args, int, kindname.class, T6758789a, (compiler.misc.arg.length.mismatch) 59.7 +T6758789a.java:15:9: compiler.err.cant.apply.symbol: kindname.method, m2, int, compiler.misc.no.args, kindname.class, T6758789a, (compiler.misc.arg.length.mismatch) 59.8 2 errors
60.1 --- a/test/tools/javac/6758789/T6758789b.out Thu Oct 11 09:50:52 2012 -0700 60.2 +++ b/test/tools/javac/6758789/T6758789b.out Thu Oct 11 17:00:54 2012 -0700 60.3 @@ -1,4 +1,4 @@ 60.4 -T6758789b.java:16:11: compiler.warn.prob.found.req: (compiler.misc.unchecked.assign), T6758789a.Foo, T6758789a.Foo<java.lang.Object> 60.5 +T6758789b.java:16:11: compiler.warn.prob.found.req: (compiler.misc.unchecked.assign), T6758789a.Foo, T6758789a.Foo<X> 60.6 T6758789b.java:16:10: compiler.warn.unchecked.meth.invocation.applied: kindname.method, m, T6758789a.Foo<X>, T6758789a.Foo, kindname.class, T6758789a 60.7 - compiler.err.warnings.and.werror 60.8 1 error
61.1 --- a/test/tools/javac/6840059/T6840059.out Thu Oct 11 09:50:52 2012 -0700 61.2 +++ b/test/tools/javac/6840059/T6840059.out Thu Oct 11 17:00:54 2012 -0700 61.3 @@ -1,3 +1,2 @@ 61.4 -T6840059.java:15:9: compiler.err.cant.apply.symbol.1: kindname.constructor, T6840059, java.lang.Integer, java.lang.String, kindname.class, T6840059, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.inconvertible.types: java.lang.String, java.lang.Integer)) 61.5 -T6840059.java:15:25: compiler.err.cant.apply.symbol.1: kindname.constructor, T6840059, java.lang.Integer, compiler.misc.no.args, kindname.class, T6840059, (compiler.misc.arg.length.mismatch) 61.6 -2 errors 61.7 +T6840059.java:15:9: compiler.err.cant.apply.symbol: kindname.constructor, T6840059, java.lang.Integer, java.lang.String, kindname.class, T6840059, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.inconvertible.types: java.lang.String, java.lang.Integer)) 61.8 +1 error
62.1 --- a/test/tools/javac/6857948/T6857948.out Thu Oct 11 09:50:52 2012 -0700 62.2 +++ b/test/tools/javac/6857948/T6857948.out Thu Oct 11 17:00:54 2012 -0700 62.3 @@ -1,3 +1,2 @@ 62.4 T6857948.java:16:32: compiler.err.cant.resolve.location.args: kindname.method, nosuchfunction, , , (compiler.misc.location: kindname.class, Test, null) 62.5 -T6857948.java:16:50: compiler.err.cant.apply.symbol.1: kindname.constructor, Foo, java.lang.String, compiler.misc.no.args, kindname.class, Foo, (compiler.misc.arg.length.mismatch) 62.6 -2 errors 62.7 +1 error
63.1 --- a/test/tools/javac/7132880/T7132880.out Thu Oct 11 09:50:52 2012 -0700 63.2 +++ b/test/tools/javac/7132880/T7132880.out Thu Oct 11 17:00:54 2012 -0700 63.3 @@ -1,4 +1,4 @@ 63.4 -T7132880.java:23:12: compiler.err.cant.apply.symbol.1: kindname.method, m1, java.lang.Integer, java.lang.String, kindname.class, Outer.Inner1, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.inconvertible.types: java.lang.String, java.lang.Integer)) 63.5 +T7132880.java:23:12: compiler.err.cant.apply.symbol: kindname.method, m1, java.lang.Integer, java.lang.String, kindname.class, Outer.Inner1, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.inconvertible.types: java.lang.String, java.lang.Integer)) 63.6 T7132880.java:33:12: compiler.err.cant.apply.symbols: kindname.method, m1, java.lang.String,{(compiler.misc.inapplicable.method: kindname.method, Outer.Inner2, m1(java.lang.Double), (compiler.misc.no.conforming.assignment.exists: (compiler.misc.inconvertible.types: java.lang.String, java.lang.Double))),(compiler.misc.inapplicable.method: kindname.method, Outer.Inner2, m1(java.lang.Integer), (compiler.misc.no.conforming.assignment.exists: (compiler.misc.inconvertible.types: java.lang.String, java.lang.Integer)))} 63.7 T7132880.java:43:12: compiler.err.ref.ambiguous: m2, kindname.method, m2(java.lang.Object,int), Outer.Inner3, kindname.method, m2(int,java.lang.Object), Outer.Inner3 63.8 3 errors
64.1 --- a/test/tools/javac/Diagnostics/6722234/T6722234a_1.out Thu Oct 11 09:50:52 2012 -0700 64.2 +++ b/test/tools/javac/Diagnostics/6722234/T6722234a_1.out Thu Oct 11 17:00:54 2012 -0700 64.3 @@ -1,2 +1,2 @@ 64.4 -T6722234a.java:12:9: compiler.err.cant.apply.symbol.1: kindname.method, m, compiler.misc.type.var: T, 1, compiler.misc.type.var: T, 2, kindname.class, T6722234a<compiler.misc.type.var: T, 1>, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.inconvertible.types: compiler.misc.type.var: T, 2, compiler.misc.type.var: T, 1)) 64.5 +T6722234a.java:12:9: compiler.err.cant.apply.symbol: kindname.method, m, compiler.misc.type.var: T, 1, compiler.misc.type.var: T, 2, kindname.class, T6722234a<compiler.misc.type.var: T, 1>, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.inconvertible.types: compiler.misc.type.var: T, 2, compiler.misc.type.var: T, 1)) 64.6 1 error
65.1 --- a/test/tools/javac/Diagnostics/6722234/T6722234a_2.out Thu Oct 11 09:50:52 2012 -0700 65.2 +++ b/test/tools/javac/Diagnostics/6722234/T6722234a_2.out Thu Oct 11 17:00:54 2012 -0700 65.3 @@ -1,3 +1,3 @@ 65.4 -T6722234a.java:12:9: compiler.err.cant.apply.symbol.1: kindname.method, m, compiler.misc.type.var: T, 1, compiler.misc.type.var: T, 2, kindname.class, T6722234a<compiler.misc.type.var: T, 1>, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.inconvertible.types: compiler.misc.type.var: T, 2, compiler.misc.type.var: T, 1)) 65.5 +T6722234a.java:12:9: compiler.err.cant.apply.symbol: kindname.method, m, compiler.misc.type.var: T, 1, compiler.misc.type.var: T, 2, kindname.class, T6722234a<compiler.misc.type.var: T, 1>, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.inconvertible.types: compiler.misc.type.var: T, 2, compiler.misc.type.var: T, 1)) 65.6 - compiler.misc.where.description.typevar.1: compiler.misc.type.var: T, 1,compiler.misc.type.var: T, 2,{(compiler.misc.where.typevar: compiler.misc.type.var: T, 1, java.lang.String, kindname.class, T6722234a),(compiler.misc.where.typevar: compiler.misc.type.var: T, 2, java.lang.Integer, kindname.method, <compiler.misc.type.var: T, 2>test(compiler.misc.type.var: T, 2))} 65.7 1 error
66.1 --- a/test/tools/javac/Diagnostics/6722234/T6722234b_1.out Thu Oct 11 09:50:52 2012 -0700 66.2 +++ b/test/tools/javac/Diagnostics/6722234/T6722234b_1.out Thu Oct 11 17:00:54 2012 -0700 66.3 @@ -1,2 +1,2 @@ 66.4 -T6722234b.java:16:9: compiler.err.cant.apply.symbol.1: kindname.method, m, List<T>,List<T>, List<compiler.misc.type.captureof: 1, ? extends T6722234b>,List<compiler.misc.type.captureof: 2, ? extends T6722234b>, kindname.class, T6722234b, (compiler.misc.inferred.do.not.conform.to.eq.bounds: compiler.misc.type.captureof: 2, ? extends T6722234b, compiler.misc.type.captureof: 2, ? extends T6722234b,compiler.misc.type.captureof: 1, ? extends T6722234b) 66.5 +T6722234b.java:16:9: compiler.err.cant.apply.symbol: kindname.method, m, List<T>,List<T>, List<compiler.misc.type.captureof: 1, ? extends T6722234b>,List<compiler.misc.type.captureof: 2, ? extends T6722234b>, kindname.class, T6722234b, (compiler.misc.inferred.do.not.conform.to.eq.bounds: compiler.misc.type.captureof: 2, ? extends T6722234b, compiler.misc.type.captureof: 2, ? extends T6722234b,compiler.misc.type.captureof: 1, ? extends T6722234b) 66.6 1 error
67.1 --- a/test/tools/javac/Diagnostics/6722234/T6722234b_2.out Thu Oct 11 09:50:52 2012 -0700 67.2 +++ b/test/tools/javac/Diagnostics/6722234/T6722234b_2.out Thu Oct 11 17:00:54 2012 -0700 67.3 @@ -1,4 +1,4 @@ 67.4 -T6722234b.java:16:9: compiler.err.cant.apply.symbol.1: kindname.method, m, List<T>,List<T>, List<compiler.misc.captured.type: 1>,List<compiler.misc.captured.type: 2>, kindname.class, T6722234b, (compiler.misc.inferred.do.not.conform.to.eq.bounds: compiler.misc.captured.type: 2, compiler.misc.captured.type: 2,compiler.misc.captured.type: 1) 67.5 +T6722234b.java:16:9: compiler.err.cant.apply.symbol: kindname.method, m, List<T>,List<T>, List<compiler.misc.captured.type: 1>,List<compiler.misc.captured.type: 2>, kindname.class, T6722234b, (compiler.misc.inferred.do.not.conform.to.eq.bounds: compiler.misc.captured.type: 2, compiler.misc.captured.type: 2,compiler.misc.captured.type: 1) 67.6 - compiler.misc.where.description.typevar: T,{(compiler.misc.where.typevar: T, Object, kindname.method, <T>m(List<T>,List<T>))} 67.7 - compiler.misc.where.description.captured.1: compiler.misc.captured.type: 1,compiler.misc.captured.type: 2,{(compiler.misc.where.captured.1: compiler.misc.captured.type: 1, T6722234b, compiler.misc.type.null, ? extends T6722234b),(compiler.misc.where.captured.1: compiler.misc.captured.type: 2, T6722234b, compiler.misc.type.null, ? extends T6722234b)} 67.8 1 error
68.1 --- a/test/tools/javac/Diagnostics/6722234/T6722234c.out Thu Oct 11 09:50:52 2012 -0700 68.2 +++ b/test/tools/javac/Diagnostics/6722234/T6722234c.out Thu Oct 11 17:00:54 2012 -0700 68.3 @@ -1,2 +1,2 @@ 68.4 -T6722234c.java:14:9: compiler.err.cant.apply.symbol.1: kindname.method, m, T6722234c.String, java.lang.String, kindname.class, T6722234c, (compiler.misc.infer.no.conforming.assignment.exists: T, (compiler.misc.inconvertible.types: java.lang.String, T6722234c.String)) 68.5 +T6722234c.java:14:9: compiler.err.cant.apply.symbol: kindname.method, m, T6722234c.String, java.lang.String, kindname.class, T6722234c, (compiler.misc.infer.no.conforming.assignment.exists: T, (compiler.misc.inconvertible.types: java.lang.String, T6722234c.String)) 68.6 1 error
69.1 --- a/test/tools/javac/Diagnostics/6862608/T6862608a.out Thu Oct 11 09:50:52 2012 -0700 69.2 +++ b/test/tools/javac/Diagnostics/6862608/T6862608a.out Thu Oct 11 17:00:54 2012 -0700 69.3 @@ -1,3 +1,3 @@ 69.4 -T6862608a.java:19:33: compiler.err.cant.apply.symbol.1: kindname.method, compound, java.lang.Iterable<? extends java.util.Comparator<? super T>>, java.util.List<java.util.Comparator<?>>, kindname.class, T6862608a, (compiler.misc.infer.no.conforming.assignment.exists: T, (compiler.misc.inconvertible.types: java.util.List<java.util.Comparator<?>>, java.lang.Iterable<? extends java.util.Comparator<? super T>>)) 69.5 +T6862608a.java:19:33: compiler.err.cant.apply.symbol: kindname.method, compound, java.lang.Iterable<? extends java.util.Comparator<? super T>>, java.util.List<java.util.Comparator<?>>, kindname.class, T6862608a, (compiler.misc.infer.no.conforming.assignment.exists: T, (compiler.misc.inconvertible.types: java.util.List<java.util.Comparator<?>>, java.lang.Iterable<? extends java.util.Comparator<? super T>>)) 69.6 - compiler.misc.where.description.typevar: T,{(compiler.misc.where.typevar: T, java.lang.Object, kindname.method, <T>compound(java.lang.Iterable<? extends java.util.Comparator<? super T>>))} 69.7 1 error
70.1 --- a/test/tools/javac/Diagnostics/6862608/T6862608b.out Thu Oct 11 09:50:52 2012 -0700 70.2 +++ b/test/tools/javac/Diagnostics/6862608/T6862608b.out Thu Oct 11 17:00:54 2012 -0700 70.3 @@ -1,3 +1,3 @@ 70.4 -T6862608b.java:11:7: compiler.err.cant.apply.symbol.1: kindname.method, test, compiler.misc.type.var: T, 1, compiler.misc.type.var: T, 2, kindname.class, T66862608b<compiler.misc.type.var: T, 1,compiler.misc.type.var: S, 2>, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.inconvertible.types: compiler.misc.type.var: T, 2, compiler.misc.type.var: T, 1)) 70.5 +T6862608b.java:11:7: compiler.err.cant.apply.symbol: kindname.method, test, compiler.misc.type.var: T, 1, compiler.misc.type.var: T, 2, kindname.class, T66862608b<compiler.misc.type.var: T, 1,compiler.misc.type.var: S, 2>, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.inconvertible.types: compiler.misc.type.var: T, 2, compiler.misc.type.var: T, 1)) 70.6 - compiler.misc.where.description.typevar.1: compiler.misc.type.var: T, 1,compiler.misc.type.var: T, 2,compiler.misc.type.var: S, 1,compiler.misc.type.var: S, 2,{(compiler.misc.where.typevar: compiler.misc.type.var: T, 1, java.lang.String, kindname.class, T66862608b),(compiler.misc.where.typevar: compiler.misc.type.var: T, 2, compiler.misc.type.var: S, 1, kindname.method, <compiler.misc.type.var: S, 1,compiler.misc.type.var: T, 2>foo(compiler.misc.type.var: T, 2)),(compiler.misc.where.typevar: compiler.misc.type.var: S, 1, java.lang.Object, kindname.method, <compiler.misc.type.var: S, 1,compiler.misc.type.var: T, 2>foo(compiler.misc.type.var: T, 2)),(compiler.misc.where.typevar: compiler.misc.type.var: S, 2, java.lang.Object, kindname.class, T66862608b)} 70.7 1 error
71.1 --- a/test/tools/javac/T6326754.out Thu Oct 11 09:50:52 2012 -0700 71.2 +++ b/test/tools/javac/T6326754.out Thu Oct 11 17:00:54 2012 -0700 71.3 @@ -1,7 +1,7 @@ 71.4 T6326754.java:44:12: compiler.err.name.clash.same.erasure: TestConstructor(T), TestConstructor(K) 71.5 T6326754.java:52:17: compiler.err.name.clash.same.erasure: setT(K), setT(T) 71.6 T6326754.java:64:18: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: T, T) 71.7 -T6326754.java:70:11: compiler.err.cant.apply.symbol.1: kindname.method, setT, java.lang.Object, compiler.misc.no.args, kindname.class, TestC<T>, (compiler.misc.arg.length.mismatch) 71.8 +T6326754.java:70:11: compiler.err.cant.apply.symbol: kindname.method, setT, java.lang.Object, compiler.misc.no.args, kindname.class, TestC<T>, (compiler.misc.arg.length.mismatch) 71.9 - compiler.note.unchecked.filename: T6326754.java 71.10 - compiler.note.unchecked.recompile 71.11 4 errors
72.1 --- a/test/tools/javac/conditional/Conditional.java Thu Oct 11 09:50:52 2012 -0700 72.2 +++ b/test/tools/javac/conditional/Conditional.java Thu Oct 11 17:00:54 2012 -0700 72.3 @@ -27,6 +27,7 @@ 72.4 * @summary Conditional operator applies assignment conversion 72.5 * @author Tim Hanson, BEA 72.6 * 72.7 + * @compile -XDallowPoly Conditional.java 72.8 * @compile/fail Conditional.java 72.9 */ 72.10
73.1 --- a/test/tools/javac/diags/CheckResourceKeys.java Thu Oct 11 09:50:52 2012 -0700 73.2 +++ b/test/tools/javac/diags/CheckResourceKeys.java Thu Oct 11 17:00:54 2012 -0700 73.3 @@ -185,6 +185,8 @@ 73.4 "compiler.err.cant.resolve.args.params", 73.5 "compiler.err.cant.resolve.location.args", 73.6 "compiler.err.cant.resolve.location.args.params", 73.7 + "compiler.misc.cant.resolve.location.args", 73.8 + "compiler.misc.cant.resolve.location.args.params", 73.9 // JavaCompiler, reports #errors and #warnings 73.10 "compiler.misc.count.error", 73.11 "compiler.misc.count.error.plural",
74.1 --- a/test/tools/javac/diags/examples.not-yet.txt Thu Oct 11 09:50:52 2012 -0700 74.2 +++ b/test/tools/javac/diags/examples.not-yet.txt Thu Oct 11 17:00:54 2012 -0700 74.3 @@ -1,7 +1,6 @@ 74.4 compiler.err.already.annotated # internal compiler error? 74.5 compiler.err.already.defined.this.unit # seems to be masked by compiler.err.duplicate.class 74.6 compiler.err.annotation.value.not.allowable.type # cannot happen: precluded by complete type-specific tests 74.7 -compiler.err.cant.apply.symbol 74.8 compiler.err.cant.read.file # (apt.JavaCompiler?) 74.9 compiler.err.cant.select.static.class.from.param.type 74.10 compiler.err.illegal.char.for.encoding 74.11 @@ -65,6 +64,7 @@ 74.12 compiler.misc.kindname.type.variable 74.13 compiler.misc.kindname.type.variable.bound 74.14 compiler.misc.kindname.value 74.15 +compiler.misc.incompatible.eq.lower.bounds # cannot happen? 74.16 compiler.misc.no.unique.minimal.instance.exists 74.17 compiler.misc.resume.abort # prompt for a response 74.18 compiler.misc.source.unavailable # DiagnosticSource
75.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 75.2 +++ b/test/tools/javac/diags/examples/CantAccessArgTypeInFunctionalDesc.java Thu Oct 11 17:00:54 2012 -0700 75.3 @@ -0,0 +1,35 @@ 75.4 +/* 75.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 75.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 75.7 + * 75.8 + * This code is free software; you can redistribute it and/or modify it 75.9 + * under the terms of the GNU General Public License version 2 only, as 75.10 + * published by the Free Software Foundation. 75.11 + * 75.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 75.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 75.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 75.15 + * version 2 for more details (a copy is included in the LICENSE file that 75.16 + * accompanied this code). 75.17 + * 75.18 + * You should have received a copy of the GNU General Public License version 75.19 + * 2 along with this work; if not, write to the Free Software Foundation, 75.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 75.21 + * 75.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 75.23 + * or visit www.oracle.com if you need additional information or have any 75.24 + * questions. 75.25 + */ 75.26 + 75.27 +// key: compiler.err.cant.access.arg.type.in.functional.desc 75.28 +// key: compiler.err.report.access 75.29 +// options: -XDallowLambda 75.30 + 75.31 +interface SAM_InaccessibleArg { 75.32 + void m(Foo.Bar bar); 75.33 + static class Foo { private class Bar { } } 75.34 +} 75.35 + 75.36 +class CantAccessArgTypeInFunctionalDesc { 75.37 + SAM_InaccessibleArg s = x-> { }; 75.38 +}
76.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 76.2 +++ b/test/tools/javac/diags/examples/CantAccessInnerClsConstr.java Thu Oct 11 17:00:54 2012 -0700 76.3 @@ -0,0 +1,40 @@ 76.4 +/* 76.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 76.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 76.7 + * 76.8 + * This code is free software; you can redistribute it and/or modify it 76.9 + * under the terms of the GNU General Public License version 2 only, as 76.10 + * published by the Free Software Foundation. 76.11 + * 76.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 76.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 76.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 76.15 + * version 2 for more details (a copy is included in the LICENSE file that 76.16 + * accompanied this code). 76.17 + * 76.18 + * You should have received a copy of the GNU General Public License version 76.19 + * 2 along with this work; if not, write to the Free Software Foundation, 76.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 76.21 + * 76.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 76.23 + * or visit www.oracle.com if you need additional information or have any 76.24 + * questions. 76.25 + */ 76.26 + 76.27 +// key: compiler.err.prob.found.req 76.28 +// key: compiler.misc.cant.access.inner.cls.constr 76.29 +// key: compiler.misc.invalid.mref 76.30 +// options: -XDallowMethodReferences 76.31 + 76.32 +class CantAccessInnerClsConstructor { 76.33 + 76.34 + interface SAM { 76.35 + Outer m(); 76.36 + } 76.37 + 76.38 + class Outer { } 76.39 + 76.40 + static void test() { 76.41 + SAM s = Outer::new; 76.42 + } 76.43 +}
77.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 77.2 +++ b/test/tools/javac/diags/examples/CantAccessReturnTypeInFunctionalDesc.java Thu Oct 11 17:00:54 2012 -0700 77.3 @@ -0,0 +1,34 @@ 77.4 +/* 77.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 77.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 77.7 + * 77.8 + * This code is free software; you can redistribute it and/or modify it 77.9 + * under the terms of the GNU General Public License version 2 only, as 77.10 + * published by the Free Software Foundation. 77.11 + * 77.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 77.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 77.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 77.15 + * version 2 for more details (a copy is included in the LICENSE file that 77.16 + * accompanied this code). 77.17 + * 77.18 + * You should have received a copy of the GNU General Public License version 77.19 + * 2 along with this work; if not, write to the Free Software Foundation, 77.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 77.21 + * 77.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 77.23 + * or visit www.oracle.com if you need additional information or have any 77.24 + * questions. 77.25 + */ 77.26 + 77.27 +// key: compiler.err.cant.access.return.in.functional.desc 77.28 +// options: -XDallowLambda 77.29 + 77.30 +interface SAM_InaccessibleRet { 77.31 + Foo.Bar m(); 77.32 + static class Foo { private class Bar { } } 77.33 +} 77.34 + 77.35 +class CantAccessReturnTypeInFunctionalDesc { 77.36 + SAM_InaccessibleRet s = ()->null; 77.37 +}
78.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 78.2 +++ b/test/tools/javac/diags/examples/CantAccessThrownTypesInFunctionalDesc.java Thu Oct 11 17:00:54 2012 -0700 78.3 @@ -0,0 +1,34 @@ 78.4 +/* 78.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 78.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 78.7 + * 78.8 + * This code is free software; you can redistribute it and/or modify it 78.9 + * under the terms of the GNU General Public License version 2 only, as 78.10 + * published by the Free Software Foundation. 78.11 + * 78.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 78.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 78.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 78.15 + * version 2 for more details (a copy is included in the LICENSE file that 78.16 + * accompanied this code). 78.17 + * 78.18 + * You should have received a copy of the GNU General Public License version 78.19 + * 2 along with this work; if not, write to the Free Software Foundation, 78.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 78.21 + * 78.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 78.23 + * or visit www.oracle.com if you need additional information or have any 78.24 + * questions. 78.25 + */ 78.26 + 78.27 +// key: compiler.err.cant.access.thrown.in.functional.desc 78.28 +// options: -XDallowLambda 78.29 + 78.30 +interface SAM_InaccessibleThrown { 78.31 + void m() throws Foo.Bar; 78.32 + static class Foo { private class Bar extends Exception { } } 78.33 +} 78.34 + 78.35 +class CantAccessThrownTypesInFunctionalDesc { 78.36 + SAM_InaccessibleThrown s = ()-> { }; 78.37 +}
79.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 79.2 +++ b/test/tools/javac/diags/examples/CantApplySymbolFragment.java Thu Oct 11 17:00:54 2012 -0700 79.3 @@ -0,0 +1,42 @@ 79.4 +/* 79.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 79.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 79.7 + * 79.8 + * This code is free software; you can redistribute it and/or modify it 79.9 + * under the terms of the GNU General Public License version 2 only, as 79.10 + * published by the Free Software Foundation. 79.11 + * 79.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 79.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 79.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 79.15 + * version 2 for more details (a copy is included in the LICENSE file that 79.16 + * accompanied this code). 79.17 + * 79.18 + * You should have received a copy of the GNU General Public License version 79.19 + * 2 along with this work; if not, write to the Free Software Foundation, 79.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 79.21 + * 79.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 79.23 + * or visit www.oracle.com if you need additional information or have any 79.24 + * questions. 79.25 + */ 79.26 + 79.27 +// key: compiler.err.prob.found.req 79.28 +// key: compiler.misc.inconvertible.types 79.29 +// key: compiler.misc.no.conforming.assignment.exists 79.30 +// key: compiler.misc.cant.apply.symbol 79.31 +// key: compiler.misc.invalid.mref 79.32 +// options: -XDallowMethodReferences 79.33 + 79.34 +class CantApplySymbolFragment { 79.35 + 79.36 + interface SAM { 79.37 + void m(Integer u); 79.38 + } 79.39 + 79.40 + static void f(String s) { } 79.41 + 79.42 + void test() { 79.43 + SAM s = CantApplySymbolFragment::f; 79.44 + } 79.45 +}
80.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 80.2 +++ b/test/tools/javac/diags/examples/CantApplySymbolsFragment.java Thu Oct 11 17:00:54 2012 -0700 80.3 @@ -0,0 +1,46 @@ 80.4 +/* 80.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 80.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 80.7 + * 80.8 + * This code is free software; you can redistribute it and/or modify it 80.9 + * under the terms of the GNU General Public License version 2 only, as 80.10 + * published by the Free Software Foundation. 80.11 + * 80.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 80.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 80.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 80.15 + * version 2 for more details (a copy is included in the LICENSE file that 80.16 + * accompanied this code). 80.17 + * 80.18 + * You should have received a copy of the GNU General Public License version 80.19 + * 2 along with this work; if not, write to the Free Software Foundation, 80.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 80.21 + * 80.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 80.23 + * or visit www.oracle.com if you need additional information or have any 80.24 + * questions. 80.25 + */ 80.26 + 80.27 +// key: compiler.err.prob.found.req 80.28 +// key: compiler.misc.inconvertible.types 80.29 +// key: compiler.misc.no.conforming.assignment.exists 80.30 +// key: compiler.misc.arg.length.mismatch 80.31 +// key: compiler.misc.inapplicable.method 80.32 +// key: compiler.misc.cant.apply.symbols 80.33 +// key: compiler.misc.invalid.mref 80.34 +// options: -XDallowMethodReferences 80.35 + 80.36 +class CantApplySymbolsFragment { 80.37 + 80.38 + interface SAM { 80.39 + void m(Integer u); 80.40 + } 80.41 + 80.42 + static void f() { } 80.43 + 80.44 + static void f(String s) { } 80.45 + 80.46 + void test() { 80.47 + SAM s = CantApplySymbolsFragment::f; 80.48 + } 80.49 +}
81.1 --- a/test/tools/javac/diags/examples/CantRefNonEffectivelyFinalVar.java Thu Oct 11 09:50:52 2012 -0700 81.2 +++ b/test/tools/javac/diags/examples/CantRefNonEffectivelyFinalVar.java Thu Oct 11 17:00:54 2012 -0700 81.3 @@ -23,7 +23,8 @@ 81.4 81.5 // key: compiler.err.cant.ref.non.effectively.final.var 81.6 // key: compiler.misc.inner.cls 81.7 -// options: -XDallowEffectivelyFinalInInnerClasses 81.8 +// key: compiler.misc.lambda 81.9 +// options: -XDallowLambda -XDallowEffectivelyFinalInInnerClasses 81.10 81.11 class CantRefNonEffectivelyFinalVar { 81.12 void test() { 81.13 @@ -31,4 +32,14 @@ 81.14 new Object() { int j = i; }; 81.15 i = 2; 81.16 } 81.17 + 81.18 + interface SAM { 81.19 + void m(); 81.20 + } 81.21 + 81.22 + void test2() { 81.23 + int i = 0; 81.24 + SAM s = ()-> { int j = i; }; 81.25 + i++; 81.26 + } 81.27 }
82.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 82.2 +++ b/test/tools/javac/diags/examples/CantResolveLocationArgsFragment.java Thu Oct 11 17:00:54 2012 -0700 82.3 @@ -0,0 +1,38 @@ 82.4 +/* 82.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 82.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 82.7 + * 82.8 + * This code is free software; you can redistribute it and/or modify it 82.9 + * under the terms of the GNU General Public License version 2 only, as 82.10 + * published by the Free Software Foundation. 82.11 + * 82.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 82.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 82.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 82.15 + * version 2 for more details (a copy is included in the LICENSE file that 82.16 + * accompanied this code). 82.17 + * 82.18 + * You should have received a copy of the GNU General Public License version 82.19 + * 2 along with this work; if not, write to the Free Software Foundation, 82.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 82.21 + * 82.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 82.23 + * or visit www.oracle.com if you need additional information or have any 82.24 + * questions. 82.25 + */ 82.26 + 82.27 +// key: compiler.misc.cant.resolve.location.args 82.28 +// key: compiler.misc.location 82.29 +// key: compiler.err.invalid.mref 82.30 +// options: -XDallowMethodReferences 82.31 + 82.32 +class CantResolveLocationArgsFragment { 82.33 + 82.34 + interface SAM { 82.35 + void m(Integer u); 82.36 + } 82.37 + 82.38 + void test() { 82.39 + SAM s = CantResolveLocationArgsFragment::f; 82.40 + } 82.41 +}
83.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 83.2 +++ b/test/tools/javac/diags/examples/CantResolveLocationArgsParamsFragment.java Thu Oct 11 17:00:54 2012 -0700 83.3 @@ -0,0 +1,38 @@ 83.4 +/* 83.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 83.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 83.7 + * 83.8 + * This code is free software; you can redistribute it and/or modify it 83.9 + * under the terms of the GNU General Public License version 2 only, as 83.10 + * published by the Free Software Foundation. 83.11 + * 83.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 83.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 83.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 83.15 + * version 2 for more details (a copy is included in the LICENSE file that 83.16 + * accompanied this code). 83.17 + * 83.18 + * You should have received a copy of the GNU General Public License version 83.19 + * 2 along with this work; if not, write to the Free Software Foundation, 83.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 83.21 + * 83.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 83.23 + * or visit www.oracle.com if you need additional information or have any 83.24 + * questions. 83.25 + */ 83.26 + 83.27 +// key: compiler.misc.cant.resolve.location.args.params 83.28 +// key: compiler.misc.location 83.29 +// key: compiler.err.invalid.mref 83.30 +// options: -XDallowMethodReferences 83.31 + 83.32 +class CantResolveLocationArgsParamsFragment { 83.33 + 83.34 + interface SAM { 83.35 + void m(Integer u); 83.36 + } 83.37 + 83.38 + void test() { 83.39 + SAM s = CantResolveLocationArgsParamsFragment::<String>f; 83.40 + } 83.41 +}
84.1 --- a/test/tools/javac/diags/examples/CatchWithoutTry.java Thu Oct 11 09:50:52 2012 -0700 84.2 +++ b/test/tools/javac/diags/examples/CatchWithoutTry.java Thu Oct 11 17:00:54 2012 -0700 84.3 @@ -1,5 +1,5 @@ 84.4 /* 84.5 - * Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved. 84.6 + * Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved. 84.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 84.8 * 84.9 * This code is free software; you can redistribute it and/or modify it 84.10 @@ -23,6 +23,8 @@ 84.11 84.12 // key: compiler.err.catch.without.try 84.13 // key: compiler.err.expected 84.14 +// key: compiler.err.not.stmt 84.15 +// key: compiler.err.lambda.not.supported.in.source 84.16 84.17 class CatchWithoutTry { 84.18 void m() {
85.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 85.2 +++ b/test/tools/javac/diags/examples/CyclicInference.java Thu Oct 11 17:00:54 2012 -0700 85.3 @@ -0,0 +1,38 @@ 85.4 +/* 85.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 85.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 85.7 + * 85.8 + * This code is free software; you can redistribute it and/or modify it 85.9 + * under the terms of the GNU General Public License version 2 only, as 85.10 + * published by the Free Software Foundation. 85.11 + * 85.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 85.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 85.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 85.15 + * version 2 for more details (a copy is included in the LICENSE file that 85.16 + * accompanied this code). 85.17 + * 85.18 + * You should have received a copy of the GNU General Public License version 85.19 + * 2 along with this work; if not, write to the Free Software Foundation, 85.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 85.21 + * 85.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 85.23 + * or visit www.oracle.com if you need additional information or have any 85.24 + * questions. 85.25 + */ 85.26 + 85.27 +// key: compiler.err.cant.apply.symbol 85.28 +// key: compiler.misc.cyclic.inference 85.29 +// options: -XDallowLambda -XDallowPoly 85.30 + 85.31 +class CyclicInference { 85.32 + interface SAM<X> { 85.33 + void m(X x); 85.34 + } 85.35 + 85.36 + <Z> void g(SAM<Z> sz) { } 85.37 + 85.38 + void test() { 85.39 + g(x-> {}); 85.40 + } 85.41 +}
86.1 --- a/test/tools/javac/diags/examples/ExplicitParamsDoNotConformToBounds.java Thu Oct 11 09:50:52 2012 -0700 86.2 +++ b/test/tools/javac/diags/examples/ExplicitParamsDoNotConformToBounds.java Thu Oct 11 17:00:54 2012 -0700 86.3 @@ -21,7 +21,7 @@ 86.4 * questions. 86.5 */ 86.6 86.7 -// key: compiler.err.cant.apply.symbol.1 86.8 +// key: compiler.err.cant.apply.symbol 86.9 // key: compiler.misc.explicit.param.do.not.conform.to.bounds 86.10 86.11 class ExplicitParamsDoNotConformToBounds {
87.1 --- a/test/tools/javac/diags/examples/InaccessibleVarargsType/InaccessibleVarargsType.java Thu Oct 11 09:50:52 2012 -0700 87.2 +++ b/test/tools/javac/diags/examples/InaccessibleVarargsType/InaccessibleVarargsType.java Thu Oct 11 17:00:54 2012 -0700 87.3 @@ -22,7 +22,7 @@ 87.4 */ 87.5 87.6 // key: compiler.misc.inaccessible.varargs.type 87.7 -// key: compiler.err.cant.apply.symbol.1 87.8 +// key: compiler.err.cant.apply.symbol 87.9 87.10 import p1.B; 87.11
88.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 88.2 +++ b/test/tools/javac/diags/examples/IncompatibleAbstracts.java Thu Oct 11 17:00:54 2012 -0700 88.3 @@ -0,0 +1,37 @@ 88.4 +/* 88.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 88.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 88.7 + * 88.8 + * This code is free software; you can redistribute it and/or modify it 88.9 + * under the terms of the GNU General Public License version 2 only, as 88.10 + * published by the Free Software Foundation. 88.11 + * 88.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 88.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 88.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 88.15 + * version 2 for more details (a copy is included in the LICENSE file that 88.16 + * accompanied this code). 88.17 + * 88.18 + * You should have received a copy of the GNU General Public License version 88.19 + * 2 along with this work; if not, write to the Free Software Foundation, 88.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 88.21 + * 88.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 88.23 + * or visit www.oracle.com if you need additional information or have any 88.24 + * questions. 88.25 + */ 88.26 + 88.27 +// key: compiler.err.prob.found.req 88.28 +// key: compiler.misc.not.a.functional.intf.1 88.29 +// key: compiler.misc.incompatible.abstracts 88.30 +// options: -XDallowLambda 88.31 + 88.32 +class IncompatibleAbstracts { 88.33 + 88.34 + interface SAM { 88.35 + void m(String s); 88.36 + void m(Integer i); 88.37 + } 88.38 + 88.39 + SAM s = x-> { }; 88.40 +}
89.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 89.2 +++ b/test/tools/javac/diags/examples/IncompatibleArgTypesInLambda.java Thu Oct 11 17:00:54 2012 -0700 89.3 @@ -0,0 +1,34 @@ 89.4 +/* 89.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 89.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 89.7 + * 89.8 + * This code is free software; you can redistribute it and/or modify it 89.9 + * under the terms of the GNU General Public License version 2 only, as 89.10 + * published by the Free Software Foundation. 89.11 + * 89.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 89.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 89.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 89.15 + * version 2 for more details (a copy is included in the LICENSE file that 89.16 + * accompanied this code). 89.17 + * 89.18 + * You should have received a copy of the GNU General Public License version 89.19 + * 2 along with this work; if not, write to the Free Software Foundation, 89.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 89.21 + * 89.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 89.23 + * or visit www.oracle.com if you need additional information or have any 89.24 + * questions. 89.25 + */ 89.26 + 89.27 +// key: compiler.err.prob.found.req 89.28 +// key: compiler.misc.incompatible.arg.types.in.lambda 89.29 +// options: -XDallowLambda -XDallowPoly 89.30 + 89.31 +class IncompatibleArgTypesInLambda { 89.32 + interface SAM { 89.33 + void m(Integer x); 89.34 + } 89.35 + 89.36 + SAM s = (String x)-> {}; 89.37 +}
90.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 90.2 +++ b/test/tools/javac/diags/examples/IncompatibleDescsInFunctionalIntf.java Thu Oct 11 17:00:54 2012 -0700 90.3 @@ -0,0 +1,43 @@ 90.4 +/* 90.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 90.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 90.7 + * 90.8 + * This code is free software; you can redistribute it and/or modify it 90.9 + * under the terms of the GNU General Public License version 2 only, as 90.10 + * published by the Free Software Foundation. 90.11 + * 90.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 90.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 90.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 90.15 + * version 2 for more details (a copy is included in the LICENSE file that 90.16 + * accompanied this code). 90.17 + * 90.18 + * You should have received a copy of the GNU General Public License version 90.19 + * 2 along with this work; if not, write to the Free Software Foundation, 90.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 90.21 + * 90.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 90.23 + * or visit www.oracle.com if you need additional information or have any 90.24 + * questions. 90.25 + */ 90.26 + 90.27 +// key: compiler.err.types.incompatible.diff.ret 90.28 +// key: compiler.err.prob.found.req 90.29 +// key: compiler.misc.incompatible.descs.in.functional.intf 90.30 +// key: compiler.misc.descriptor 90.31 +// key: compiler.misc.descriptor.throws 90.32 +// options: -XDallowLambda 90.33 + 90.34 +class IncompatibleDescsInFunctionalIntf { 90.35 + interface A { 90.36 + Integer m(String i) throws Exception; 90.37 + } 90.38 + 90.39 + interface B { 90.40 + String m(String i); 90.41 + } 90.42 + 90.43 + interface SAM extends A,B { } 90.44 + 90.45 + SAM s = x-> { }; 90.46 +}
91.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 91.2 +++ b/test/tools/javac/diags/examples/IncompatibleEqUpperBounds.java Thu Oct 11 17:00:54 2012 -0700 91.3 @@ -0,0 +1,35 @@ 91.4 +/* 91.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 91.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 91.7 + * 91.8 + * This code is free software; you can redistribute it and/or modify it 91.9 + * under the terms of the GNU General Public License version 2 only, as 91.10 + * published by the Free Software Foundation. 91.11 + * 91.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 91.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 91.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 91.15 + * version 2 for more details (a copy is included in the LICENSE file that 91.16 + * accompanied this code). 91.17 + * 91.18 + * You should have received a copy of the GNU General Public License version 91.19 + * 2 along with this work; if not, write to the Free Software Foundation, 91.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 91.21 + * 91.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 91.23 + * or visit www.oracle.com if you need additional information or have any 91.24 + * questions. 91.25 + */ 91.26 + 91.27 +//key: compiler.err.cant.apply.symbol 91.28 +//key: compiler.misc.incompatible.eq.upper.bounds 91.29 + 91.30 +import java.util.List; 91.31 + 91.32 +class IncompatibleEqUpperBounds { 91.33 + <S, T extends List<S>> void m(List<? super S> s1, T s2) { } 91.34 + 91.35 + void test(List<Integer> li, List<String> ls) { 91.36 + m(li, ls); 91.37 + } 91.38 +}
92.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 92.2 +++ b/test/tools/javac/diags/examples/IncompatibleRetTypeInLambda.java Thu Oct 11 17:00:54 2012 -0700 92.3 @@ -0,0 +1,35 @@ 92.4 +/* 92.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 92.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 92.7 + * 92.8 + * This code is free software; you can redistribute it and/or modify it 92.9 + * under the terms of the GNU General Public License version 2 only, as 92.10 + * published by the Free Software Foundation. 92.11 + * 92.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 92.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 92.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 92.15 + * version 2 for more details (a copy is included in the LICENSE file that 92.16 + * accompanied this code). 92.17 + * 92.18 + * You should have received a copy of the GNU General Public License version 92.19 + * 2 along with this work; if not, write to the Free Software Foundation, 92.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 92.21 + * 92.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 92.23 + * or visit www.oracle.com if you need additional information or have any 92.24 + * questions. 92.25 + */ 92.26 + 92.27 +// key: compiler.err.prob.found.req 92.28 +// key: compiler.misc.inconvertible.types 92.29 +// key: compiler.misc.incompatible.ret.type.in.lambda 92.30 +// options: -XDallowLambda -XDallowPoly 92.31 + 92.32 +class IncompatibleRetTypeInLambda { 92.33 + interface SAM { 92.34 + Integer m(); 92.35 + } 92.36 + 92.37 + SAM s = ()-> ""; 92.38 +}
93.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 93.2 +++ b/test/tools/javac/diags/examples/IncompatibleRetTypeInMref.java Thu Oct 11 17:00:54 2012 -0700 93.3 @@ -0,0 +1,37 @@ 93.4 +/* 93.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 93.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 93.7 + * 93.8 + * This code is free software; you can redistribute it and/or modify it 93.9 + * under the terms of the GNU General Public License version 2 only, as 93.10 + * published by the Free Software Foundation. 93.11 + * 93.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 93.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 93.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 93.15 + * version 2 for more details (a copy is included in the LICENSE file that 93.16 + * accompanied this code). 93.17 + * 93.18 + * You should have received a copy of the GNU General Public License version 93.19 + * 2 along with this work; if not, write to the Free Software Foundation, 93.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 93.21 + * 93.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 93.23 + * or visit www.oracle.com if you need additional information or have any 93.24 + * questions. 93.25 + */ 93.26 + 93.27 +// key: compiler.err.prob.found.req 93.28 +// key: compiler.misc.inconvertible.types 93.29 +// key: compiler.misc.incompatible.ret.type.in.mref 93.30 +// options: -XDallowMethodReferences -XDallowPoly 93.31 + 93.32 +class IncompatibleRetTypeInMref { 93.33 + interface SAM { 93.34 + Integer m(); 93.35 + } 93.36 + 93.37 + static String f() { } 93.38 + 93.39 + SAM s = IncompatibleRetTypeInMref::f; 93.40 +}
94.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 94.2 +++ b/test/tools/javac/diags/examples/IncompatibleThrownTypesInLambda.java Thu Oct 11 17:00:54 2012 -0700 94.3 @@ -0,0 +1,33 @@ 94.4 +/* 94.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 94.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 94.7 + * 94.8 + * This code is free software; you can redistribute it and/or modify it 94.9 + * under the terms of the GNU General Public License version 2 only, as 94.10 + * published by the Free Software Foundation. 94.11 + * 94.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 94.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 94.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 94.15 + * version 2 for more details (a copy is included in the LICENSE file that 94.16 + * accompanied this code). 94.17 + * 94.18 + * You should have received a copy of the GNU General Public License version 94.19 + * 2 along with this work; if not, write to the Free Software Foundation, 94.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 94.21 + * 94.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 94.23 + * or visit www.oracle.com if you need additional information or have any 94.24 + * questions. 94.25 + */ 94.26 + 94.27 +// key: compiler.err.incompatible.thrown.types.in.lambda 94.28 +// options: -XDallowLambda 94.29 + 94.30 +class IncompatibleThrownTypesInLambda { 94.31 + interface SAM { 94.32 + void m(); 94.33 + } 94.34 + 94.35 + SAM s = ()-> { throw new Exception(); }; 94.36 +}
95.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 95.2 +++ b/test/tools/javac/diags/examples/IncompatibleThrownTypesInMref.java Thu Oct 11 17:00:54 2012 -0700 95.3 @@ -0,0 +1,35 @@ 95.4 +/* 95.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 95.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 95.7 + * 95.8 + * This code is free software; you can redistribute it and/or modify it 95.9 + * under the terms of the GNU General Public License version 2 only, as 95.10 + * published by the Free Software Foundation. 95.11 + * 95.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 95.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 95.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 95.15 + * version 2 for more details (a copy is included in the LICENSE file that 95.16 + * accompanied this code). 95.17 + * 95.18 + * You should have received a copy of the GNU General Public License version 95.19 + * 2 along with this work; if not, write to the Free Software Foundation, 95.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 95.21 + * 95.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 95.23 + * or visit www.oracle.com if you need additional information or have any 95.24 + * questions. 95.25 + */ 95.26 + 95.27 +// key: compiler.err.incompatible.thrown.types.in.mref 95.28 +// options: -XDallowMethodReferences 95.29 + 95.30 +class IncompatibleThrownTypesInMref { 95.31 + interface SAM { 95.32 + void m(); 95.33 + } 95.34 + 95.35 + static void f() throws Exception { } 95.36 + 95.37 + SAM s = IncompatibleThrownTypesInMref::f; 95.38 +}
96.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 96.2 +++ b/test/tools/javac/diags/examples/IncompatibleTypesInConditional.java Thu Oct 11 17:00:54 2012 -0700 96.3 @@ -0,0 +1,35 @@ 96.4 +/* 96.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 96.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 96.7 + * 96.8 + * This code is free software; you can redistribute it and/or modify it 96.9 + * under the terms of the GNU General Public License version 2 only, as 96.10 + * published by the Free Software Foundation. 96.11 + * 96.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 96.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 96.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 96.15 + * version 2 for more details (a copy is included in the LICENSE file that 96.16 + * accompanied this code). 96.17 + * 96.18 + * You should have received a copy of the GNU General Public License version 96.19 + * 2 along with this work; if not, write to the Free Software Foundation, 96.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 96.21 + * 96.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 96.23 + * or visit www.oracle.com if you need additional information or have any 96.24 + * questions. 96.25 + */ 96.26 + 96.27 +// key: compiler.err.prob.found.req 96.28 +// key: compiler.misc.incompatible.type.in.conditional 96.29 +// key: compiler.misc.inconvertible.types 96.30 +// options: -XDallowPoly 96.31 + 96.32 +class IncompatibleTypesInConditional { 96.33 + 96.34 + interface A { } 96.35 + interface B { } 96.36 + 96.37 + B b = true ? (A)null : (B)null; 96.38 +}
97.1 --- a/test/tools/javac/diags/examples/InferArgsLengthMismatch.java Thu Oct 11 09:50:52 2012 -0700 97.2 +++ b/test/tools/javac/diags/examples/InferArgsLengthMismatch.java Thu Oct 11 17:00:54 2012 -0700 97.3 @@ -21,7 +21,7 @@ 97.4 * questions. 97.5 */ 97.6 97.7 -// key: compiler.err.cant.apply.symbol.1 97.8 +// key: compiler.err.cant.apply.symbol 97.9 // key: compiler.misc.infer.arg.length.mismatch 97.10 97.11 class InferArgsLengthMismatch {
98.1 --- a/test/tools/javac/diags/examples/InferNoConformingAssignment.java Thu Oct 11 09:50:52 2012 -0700 98.2 +++ b/test/tools/javac/diags/examples/InferNoConformingAssignment.java Thu Oct 11 17:00:54 2012 -0700 98.3 @@ -21,7 +21,7 @@ 98.4 * questions. 98.5 */ 98.6 98.7 -// key: compiler.err.cant.apply.symbol.1 98.8 +// key: compiler.err.cant.apply.symbol 98.9 // key: compiler.misc.inconvertible.types 98.10 // key: compiler.misc.infer.no.conforming.assignment.exists 98.11
99.1 --- a/test/tools/javac/diags/examples/InferVarargsArgumentMismatch.java Thu Oct 11 09:50:52 2012 -0700 99.2 +++ b/test/tools/javac/diags/examples/InferVarargsArgumentMismatch.java Thu Oct 11 17:00:54 2012 -0700 99.3 @@ -21,7 +21,7 @@ 99.4 * questions. 99.5 */ 99.6 99.7 -// key: compiler.err.cant.apply.symbol.1 99.8 +// key: compiler.err.cant.apply.symbol 99.9 // key: compiler.misc.infer.varargs.argument.mismatch 99.10 // key: compiler.misc.inconvertible.types 99.11
100.1 --- a/test/tools/javac/diags/examples/InferredDoNotConformToEq.java Thu Oct 11 09:50:52 2012 -0700 100.2 +++ b/test/tools/javac/diags/examples/InferredDoNotConformToEq.java Thu Oct 11 17:00:54 2012 -0700 100.3 @@ -21,7 +21,7 @@ 100.4 * questions. 100.5 */ 100.6 100.7 -// key: compiler.err.cant.apply.symbol.1 100.8 +// key: compiler.err.cant.apply.symbol 100.9 // key: compiler.misc.inferred.do.not.conform.to.eq.bounds 100.10 100.11 import java.util.*;
101.1 --- a/test/tools/javac/diags/examples/InferredDoNotConformToUpper.java Thu Oct 11 09:50:52 2012 -0700 101.2 +++ b/test/tools/javac/diags/examples/InferredDoNotConformToUpper.java Thu Oct 11 17:00:54 2012 -0700 101.3 @@ -21,7 +21,7 @@ 101.4 * questions. 101.5 */ 101.6 101.7 -// key: compiler.err.cant.apply.symbol.1 101.8 +// key: compiler.err.cant.apply.symbol 101.9 // key: compiler.misc.inferred.do.not.conform.to.upper.bounds 101.10 101.11 import java.util.*;
102.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 102.2 +++ b/test/tools/javac/diags/examples/InvalidGenericDescInFunctionalInterface.java Thu Oct 11 17:00:54 2012 -0700 102.3 @@ -0,0 +1,35 @@ 102.4 +/* 102.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 102.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 102.7 + * 102.8 + * This code is free software; you can redistribute it and/or modify it 102.9 + * under the terms of the GNU General Public License version 2 only, as 102.10 + * published by the Free Software Foundation. 102.11 + * 102.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 102.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 102.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 102.15 + * version 2 for more details (a copy is included in the LICENSE file that 102.16 + * accompanied this code). 102.17 + * 102.18 + * You should have received a copy of the GNU General Public License version 102.19 + * 2 along with this work; if not, write to the Free Software Foundation, 102.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 102.21 + * 102.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 102.23 + * or visit www.oracle.com if you need additional information or have any 102.24 + * questions. 102.25 + */ 102.26 + 102.27 +// key: compiler.err.prob.found.req 102.28 +// key: compiler.misc.invalid.generic.desc.in.functional.intf 102.29 +// options: -XDallowLambda 102.30 + 102.31 +class InvalidGenericDescInFunctionalIntf { 102.32 + 102.33 + interface SAM { 102.34 + <Z> void m(); 102.35 + } 102.36 + 102.37 + SAM s = x-> { }; 102.38 +}
103.1 --- a/test/tools/javac/diags/examples/KindnameConstructor.java Thu Oct 11 09:50:52 2012 -0700 103.2 +++ b/test/tools/javac/diags/examples/KindnameConstructor.java Thu Oct 11 17:00:54 2012 -0700 103.3 @@ -23,12 +23,10 @@ 103.4 103.5 // key: compiler.misc.kindname.constructor 103.6 // key: compiler.misc.kindname.class 103.7 -// key: compiler.misc.no.args 103.8 -// key: compiler.err.cant.apply.symbol.1 103.9 -// key: compiler.misc.arg.length.mismatch 103.10 +// key: compiler.err.cant.apply.symbol 103.11 // key: compiler.misc.no.conforming.assignment.exists 103.12 // key: compiler.misc.inconvertible.types 103.13 -// key: compiler.misc.count.error.plural 103.14 +// key: compiler.misc.count.error 103.15 // key: compiler.err.error 103.16 // run: backdoor 103.17
104.1 --- a/test/tools/javac/diags/examples/MethodReferencesNotSupported.java Thu Oct 11 09:50:52 2012 -0700 104.2 +++ b/test/tools/javac/diags/examples/MethodReferencesNotSupported.java Thu Oct 11 17:00:54 2012 -0700 104.3 @@ -25,5 +25,5 @@ 104.4 // options: -source 7 -Xlint:-options 104.5 104.6 class MethodReferencesNotSupported { 104.7 - S s = A#foo; 104.8 + S s = A::foo; 104.9 }
105.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 105.2 +++ b/test/tools/javac/diags/examples/MissingReturnValueFragment.java Thu Oct 11 17:00:54 2012 -0700 105.3 @@ -0,0 +1,37 @@ 105.4 +/* 105.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 105.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 105.7 + * 105.8 + * This code is free software; you can redistribute it and/or modify it 105.9 + * under the terms of the GNU General Public License version 2 only, as 105.10 + * published by the Free Software Foundation. 105.11 + * 105.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 105.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 105.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 105.15 + * version 2 for more details (a copy is included in the LICENSE file that 105.16 + * accompanied this code). 105.17 + * 105.18 + * You should have received a copy of the GNU General Public License version 105.19 + * 2 along with this work; if not, write to the Free Software Foundation, 105.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 105.21 + * 105.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 105.23 + * or visit www.oracle.com if you need additional information or have any 105.24 + * questions. 105.25 + */ 105.26 + 105.27 +// key: compiler.err.prob.found.req 105.28 +// key: compiler.misc.incompatible.ret.type.in.lambda 105.29 +// key: compiler.misc.missing.ret.val 105.30 +// options: -XDallowLambda 105.31 + 105.32 +class MissingReturnValueFragment { 105.33 + interface SAM { 105.34 + String m(); 105.35 + } 105.36 + 105.37 + void test() { 105.38 + SAM s = ()->{}; 105.39 + } 105.40 +}
106.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 106.2 +++ b/test/tools/javac/diags/examples/NoAbstracts.java Thu Oct 11 17:00:54 2012 -0700 106.3 @@ -0,0 +1,34 @@ 106.4 +/* 106.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 106.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 106.7 + * 106.8 + * This code is free software; you can redistribute it and/or modify it 106.9 + * under the terms of the GNU General Public License version 2 only, as 106.10 + * published by the Free Software Foundation. 106.11 + * 106.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 106.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 106.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 106.15 + * version 2 for more details (a copy is included in the LICENSE file that 106.16 + * accompanied this code). 106.17 + * 106.18 + * You should have received a copy of the GNU General Public License version 106.19 + * 2 along with this work; if not, write to the Free Software Foundation, 106.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 106.21 + * 106.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 106.23 + * or visit www.oracle.com if you need additional information or have any 106.24 + * questions. 106.25 + */ 106.26 + 106.27 +// key: compiler.err.prob.found.req 106.28 +// key: compiler.misc.not.a.functional.intf.1 106.29 +// key: compiler.misc.no.abstracts 106.30 +// options: -XDallowLambda 106.31 + 106.32 +class NoAbstracts { 106.33 + 106.34 + interface SAM { } 106.35 + 106.36 + SAM s = x-> { }; 106.37 +}
107.1 --- a/test/tools/javac/diags/examples/NoArgs.java Thu Oct 11 09:50:52 2012 -0700 107.2 +++ b/test/tools/javac/diags/examples/NoArgs.java Thu Oct 11 17:00:54 2012 -0700 107.3 @@ -22,7 +22,7 @@ 107.4 */ 107.5 107.6 // key: compiler.misc.no.args 107.7 -// key: compiler.err.cant.apply.symbol.1 107.8 +// key: compiler.err.cant.apply.symbol 107.9 // key: compiler.misc.arg.length.mismatch 107.10 // run: simple 107.11
108.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 108.2 +++ b/test/tools/javac/diags/examples/NoSuitableFunctionalIntfInst.java Thu Oct 11 17:00:54 2012 -0700 108.3 @@ -0,0 +1,35 @@ 108.4 +/* 108.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 108.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 108.7 + * 108.8 + * This code is free software; you can redistribute it and/or modify it 108.9 + * under the terms of the GNU General Public License version 2 only, as 108.10 + * published by the Free Software Foundation. 108.11 + * 108.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 108.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 108.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 108.15 + * version 2 for more details (a copy is included in the LICENSE file that 108.16 + * accompanied this code). 108.17 + * 108.18 + * You should have received a copy of the GNU General Public License version 108.19 + * 2 along with this work; if not, write to the Free Software Foundation, 108.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 108.21 + * 108.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 108.23 + * or visit www.oracle.com if you need additional information or have any 108.24 + * questions. 108.25 + */ 108.26 + 108.27 +// key: compiler.err.prob.found.req 108.28 +// key: compiler.misc.no.suitable.functional.intf.inst 108.29 +// options: -XDallowLambda 108.30 + 108.31 +class NoSuitableFunctionalIntfInst { 108.32 + 108.33 + interface SAM<X extends Number> { 108.34 + void m(X x); 108.35 + } 108.36 + 108.37 + SAM<?> ss = (String s)-> { }; 108.38 +}
109.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 109.2 +++ b/test/tools/javac/diags/examples/NonStaticCantBeRefFragment.java Thu Oct 11 17:00:54 2012 -0700 109.3 @@ -0,0 +1,40 @@ 109.4 +/* 109.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 109.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 109.7 + * 109.8 + * This code is free software; you can redistribute it and/or modify it 109.9 + * under the terms of the GNU General Public License version 2 only, as 109.10 + * published by the Free Software Foundation. 109.11 + * 109.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 109.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 109.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 109.15 + * version 2 for more details (a copy is included in the LICENSE file that 109.16 + * accompanied this code). 109.17 + * 109.18 + * You should have received a copy of the GNU General Public License version 109.19 + * 2 along with this work; if not, write to the Free Software Foundation, 109.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 109.21 + * 109.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 109.23 + * or visit www.oracle.com if you need additional information or have any 109.24 + * questions. 109.25 + */ 109.26 + 109.27 +// key: compiler.err.prob.found.req 109.28 +// key: compiler.misc.non-static.cant.be.ref 109.29 +// key: compiler.misc.invalid.mref 109.30 +// options: -XDallowMethodReferences 109.31 + 109.32 +class NonStaticCantBeRefFragment { 109.33 + 109.34 + interface SAM { 109.35 + void m(Integer u); 109.36 + } 109.37 + 109.38 + void f(Integer i) { } 109.39 + 109.40 + static void test() { 109.41 + SAM s = NonStaticCantBeRefFragment::f; 109.42 + } 109.43 +}
110.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 110.2 +++ b/test/tools/javac/diags/examples/NotAFunctionalIntf.java Thu Oct 11 17:00:54 2012 -0700 110.3 @@ -0,0 +1,35 @@ 110.4 +/* 110.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 110.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 110.7 + * 110.8 + * This code is free software; you can redistribute it and/or modify it 110.9 + * under the terms of the GNU General Public License version 2 only, as 110.10 + * published by the Free Software Foundation. 110.11 + * 110.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 110.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 110.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 110.15 + * version 2 for more details (a copy is included in the LICENSE file that 110.16 + * accompanied this code). 110.17 + * 110.18 + * You should have received a copy of the GNU General Public License version 110.19 + * 2 along with this work; if not, write to the Free Software Foundation, 110.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 110.21 + * 110.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 110.23 + * or visit www.oracle.com if you need additional information or have any 110.24 + * questions. 110.25 + */ 110.26 + 110.27 +// key: compiler.err.prob.found.req 110.28 +// key: compiler.misc.not.a.functional.intf 110.29 +// options: -XDallowLambda 110.30 + 110.31 +class NotAFunctionalIntf { 110.32 + 110.33 + abstract class SAM { 110.34 + abstract <Z> void m(); 110.35 + } 110.36 + 110.37 + SAM s = x-> { }; 110.38 +}
111.1 --- a/test/tools/javac/diags/examples/NotApplicableMethodFound.java Thu Oct 11 09:50:52 2012 -0700 111.2 +++ b/test/tools/javac/diags/examples/NotApplicableMethodFound.java Thu Oct 11 17:00:54 2012 -0700 111.3 @@ -23,7 +23,7 @@ 111.4 111.5 // key: compiler.misc.not.applicable.method.found 111.6 // key: compiler.note.verbose.resolve.multi.1 111.7 -// key: compiler.err.cant.apply.symbol.1 111.8 +// key: compiler.err.cant.apply.symbol 111.9 // key: compiler.misc.no.conforming.assignment.exists 111.10 // key: compiler.misc.inconvertible.types 111.11 // options: -XDverboseResolution=inapplicable,failure
112.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 112.2 +++ b/test/tools/javac/diags/examples/NotDefAccessClassIntfCantAccessFragment.java Thu Oct 11 17:00:54 2012 -0700 112.3 @@ -0,0 +1,47 @@ 112.4 +/* 112.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 112.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 112.7 + * 112.8 + * This code is free software; you can redistribute it and/or modify it 112.9 + * under the terms of the GNU General Public License version 2 only, as 112.10 + * published by the Free Software Foundation. 112.11 + * 112.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 112.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 112.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 112.15 + * version 2 for more details (a copy is included in the LICENSE file that 112.16 + * accompanied this code). 112.17 + * 112.18 + * You should have received a copy of the GNU General Public License version 112.19 + * 2 along with this work; if not, write to the Free Software Foundation, 112.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 112.21 + * 112.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 112.23 + * or visit www.oracle.com if you need additional information or have any 112.24 + * questions. 112.25 + */ 112.26 + 112.27 +// key: compiler.err.prob.found.req 112.28 +// key: compiler.misc.not.def.access.class.intf.cant.access 112.29 +// key: compiler.misc.invalid.mref 112.30 +// options: -XDallowMethodReferences 112.31 + 112.32 +class NotDefAccessClassIntfCantAccessFragment { 112.33 + 112.34 + private class Private { 112.35 + void m() { } 112.36 + } 112.37 + 112.38 + Private getPrivate() { return new Private(); } 112.39 +} 112.40 + 112.41 +class NotDefAccessClassIntfCantAccessFragmentTest { 112.42 + 112.43 + interface SAM { 112.44 + void m(); 112.45 + } 112.46 + 112.47 + static void test() { 112.48 + SAM s = new NotDefAccessClassIntfCantAccessFragment().getPrivate()::m; 112.49 + } 112.50 +}
113.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 113.2 +++ b/test/tools/javac/diags/examples/PotentialLambdaFound.java Thu Oct 11 17:00:54 2012 -0700 113.3 @@ -0,0 +1,34 @@ 113.4 +/* 113.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 113.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 113.7 + * 113.8 + * This code is free software; you can redistribute it and/or modify it 113.9 + * under the terms of the GNU General Public License version 2 only, as 113.10 + * published by the Free Software Foundation. 113.11 + * 113.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 113.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 113.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 113.15 + * version 2 for more details (a copy is included in the LICENSE file that 113.16 + * accompanied this code). 113.17 + * 113.18 + * You should have received a copy of the GNU General Public License version 113.19 + * 2 along with this work; if not, write to the Free Software Foundation, 113.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 113.21 + * 113.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 113.23 + * or visit www.oracle.com if you need additional information or have any 113.24 + * questions. 113.25 + */ 113.26 + 113.27 +// key: compiler.note.potential.lambda.found 113.28 +// options: -XDallowLambda -XDidentifyLambdaCandidate=true 113.29 + 113.30 +class PotentialLambdaFound { 113.31 + 113.32 + interface SAM { 113.33 + void m(); 113.34 + } 113.35 + 113.36 + SAM s = new SAM() { public void m() { } }; 113.37 +}
114.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 114.2 +++ b/test/tools/javac/diags/examples/RefAmbiguousFragment.java Thu Oct 11 17:00:54 2012 -0700 114.3 @@ -0,0 +1,41 @@ 114.4 +/* 114.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 114.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 114.7 + * 114.8 + * This code is free software; you can redistribute it and/or modify it 114.9 + * under the terms of the GNU General Public License version 2 only, as 114.10 + * published by the Free Software Foundation. 114.11 + * 114.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 114.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 114.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 114.15 + * version 2 for more details (a copy is included in the LICENSE file that 114.16 + * accompanied this code). 114.17 + * 114.18 + * You should have received a copy of the GNU General Public License version 114.19 + * 2 along with this work; if not, write to the Free Software Foundation, 114.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 114.21 + * 114.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 114.23 + * or visit www.oracle.com if you need additional information or have any 114.24 + * questions. 114.25 + */ 114.26 + 114.27 +// key: compiler.err.prob.found.req 114.28 +// key: compiler.misc.ref.ambiguous 114.29 +// key: compiler.misc.invalid.mref 114.30 +// options: -XDallowMethodReferences 114.31 + 114.32 +class RefAmbiguousFragment { 114.33 + 114.34 + interface SAM { 114.35 + void m(Integer i1, Integer i2); 114.36 + } 114.37 + 114.38 + void f(Number n, Integer i) { } 114.39 + void f(Integer i, Number n) { } 114.40 + 114.41 + void test() { 114.42 + SAM s = RefAmbiguousFragment::f; 114.43 + } 114.44 +}
115.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 115.2 +++ b/test/tools/javac/diags/examples/UnexpectedLambda.java Thu Oct 11 17:00:54 2012 -0700 115.3 @@ -0,0 +1,29 @@ 115.4 +/* 115.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 115.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 115.7 + * 115.8 + * This code is free software; you can redistribute it and/or modify it 115.9 + * under the terms of the GNU General Public License version 2 only, as 115.10 + * published by the Free Software Foundation. 115.11 + * 115.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 115.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 115.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 115.15 + * version 2 for more details (a copy is included in the LICENSE file that 115.16 + * accompanied this code). 115.17 + * 115.18 + * You should have received a copy of the GNU General Public License version 115.19 + * 2 along with this work; if not, write to the Free Software Foundation, 115.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 115.21 + * 115.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 115.23 + * or visit www.oracle.com if you need additional information or have any 115.24 + * questions. 115.25 + */ 115.26 + 115.27 +// key: compiler.err.unexpected.lambda 115.28 +// options: -XDallowLambda 115.29 + 115.30 +class UnexpectedLambda { 115.31 + { (()-> { })++; } 115.32 +}
116.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 116.2 +++ b/test/tools/javac/diags/examples/UnexpectedMref.java Thu Oct 11 17:00:54 2012 -0700 116.3 @@ -0,0 +1,29 @@ 116.4 +/* 116.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 116.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 116.7 + * 116.8 + * This code is free software; you can redistribute it and/or modify it 116.9 + * under the terms of the GNU General Public License version 2 only, as 116.10 + * published by the Free Software Foundation. 116.11 + * 116.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 116.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 116.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 116.15 + * version 2 for more details (a copy is included in the LICENSE file that 116.16 + * accompanied this code). 116.17 + * 116.18 + * You should have received a copy of the GNU General Public License version 116.19 + * 2 along with this work; if not, write to the Free Software Foundation, 116.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 116.21 + * 116.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 116.23 + * or visit www.oracle.com if you need additional information or have any 116.24 + * questions. 116.25 + */ 116.26 + 116.27 +// key: compiler.err.unexpected.mref 116.28 +// options: -XDallowMethodReferences 116.29 + 116.30 +class UnexpectedLambda { 116.31 + { (Foo::bar)++; } 116.32 +}
117.1 --- a/test/tools/javac/diags/examples/VarargsArgumentMismatch.java Thu Oct 11 09:50:52 2012 -0700 117.2 +++ b/test/tools/javac/diags/examples/VarargsArgumentMismatch.java Thu Oct 11 17:00:54 2012 -0700 117.3 @@ -21,7 +21,7 @@ 117.4 * questions. 117.5 */ 117.6 117.7 -// key: compiler.err.cant.apply.symbol.1 117.8 +// key: compiler.err.cant.apply.symbol 117.9 // key: compiler.misc.varargs.argument.mismatch 117.10 // key: compiler.misc.inconvertible.types 117.11
118.1 --- a/test/tools/javac/diags/examples/VerboseResolveMulti1.java Thu Oct 11 09:50:52 2012 -0700 118.2 +++ b/test/tools/javac/diags/examples/VerboseResolveMulti1.java Thu Oct 11 17:00:54 2012 -0700 118.3 @@ -23,7 +23,7 @@ 118.4 118.5 // key: compiler.misc.not.applicable.method.found 118.6 // key: compiler.note.verbose.resolve.multi.1 118.7 -// key: compiler.err.cant.apply.symbol.1 118.8 +// key: compiler.err.cant.apply.symbol 118.9 // key: compiler.misc.no.conforming.assignment.exists 118.10 // key: compiler.misc.inconvertible.types 118.11 // options: -XDverboseResolution=inapplicable,failure
119.1 --- a/test/tools/javac/diags/examples/WhereCaptured.java Thu Oct 11 09:50:52 2012 -0700 119.2 +++ b/test/tools/javac/diags/examples/WhereCaptured.java Thu Oct 11 17:00:54 2012 -0700 119.3 @@ -25,7 +25,7 @@ 119.4 // key: compiler.misc.where.description.captured.1 119.5 // key: compiler.misc.where.description.typevar 119.6 // key: compiler.misc.where.typevar 119.7 -// key: compiler.err.cant.apply.symbol.1 119.8 +// key: compiler.err.cant.apply.symbol 119.9 // key: compiler.misc.inferred.do.not.conform.to.eq.bounds 119.10 // key: compiler.misc.captured.type 119.11 // options: -XDdiags=where,simpleNames
120.1 --- a/test/tools/javac/diags/examples/WhereCaptured1.java Thu Oct 11 09:50:52 2012 -0700 120.2 +++ b/test/tools/javac/diags/examples/WhereCaptured1.java Thu Oct 11 17:00:54 2012 -0700 120.3 @@ -25,7 +25,7 @@ 120.4 // key: compiler.misc.where.description.captured.1 120.5 // key: compiler.misc.where.description.typevar 120.6 // key: compiler.misc.where.typevar 120.7 -// key: compiler.err.cant.apply.symbol.1 120.8 +// key: compiler.err.cant.apply.symbol 120.9 // key: compiler.misc.inferred.do.not.conform.to.eq.bounds 120.10 // key: compiler.misc.captured.type 120.11 // key: compiler.misc.type.null
121.1 --- a/test/tools/javac/diags/examples/WhereTypeVar.java Thu Oct 11 09:50:52 2012 -0700 121.2 +++ b/test/tools/javac/diags/examples/WhereTypeVar.java Thu Oct 11 17:00:54 2012 -0700 121.3 @@ -24,7 +24,7 @@ 121.4 // key: compiler.misc.where.typevar 121.5 // key: compiler.misc.where.description.typevar.1 121.6 // key: compiler.misc.type.var 121.7 -// key: compiler.err.cant.apply.symbol.1 121.8 +// key: compiler.err.cant.apply.symbol 121.9 // key: compiler.misc.no.conforming.assignment.exists 121.10 // key: compiler.misc.inconvertible.types 121.11 // options: -XDdiags=where,disambiguateTvars
122.1 --- a/test/tools/javac/failover/CheckAttributedTree.java Thu Oct 11 09:50:52 2012 -0700 122.2 +++ b/test/tools/javac/failover/CheckAttributedTree.java Thu Oct 11 17:00:54 2012 -0700 122.3 @@ -376,7 +376,7 @@ 122.4 that.hasTag(CLASSDEF); 122.5 } 122.6 122.7 - private final List<String> excludedFields = Arrays.asList("varargsElement"); 122.8 + private final List<String> excludedFields = Arrays.asList("varargsElement", "targetType"); 122.9 122.10 void check(boolean ok, String label, Info self) { 122.11 if (!ok) {
123.1 --- a/test/tools/javac/generics/7015430/T7015430.out Thu Oct 11 09:50:52 2012 -0700 123.2 +++ b/test/tools/javac/generics/7015430/T7015430.out Thu Oct 11 17:00:54 2012 -0700 123.3 @@ -1,14 +1,14 @@ 123.4 -T7015430.java:41:15: compiler.warn.prob.found.req: (compiler.misc.unchecked.assign), java.lang.Iterable, java.lang.Iterable<java.lang.Exception> 123.5 +T7015430.java:41:15: compiler.warn.prob.found.req: (compiler.misc.unchecked.assign), java.lang.Iterable, java.lang.Iterable<E> 123.6 T7015430.java:41:14: compiler.warn.unchecked.meth.invocation.applied: kindname.method, empty, java.lang.Iterable<E>, java.lang.Iterable, kindname.class, T7015430 123.7 T7015430.java:50:42: compiler.warn.prob.found.req: (compiler.misc.unchecked.assign), java.lang.Iterable, java.lang.Iterable<java.lang.RuntimeException> 123.8 T7015430.java:50:41: compiler.warn.unchecked.meth.invocation.applied: kindname.method, empty, java.lang.Iterable<E>, java.lang.Iterable, kindname.class, T7015430 123.9 -T7015430.java:68:22: compiler.warn.prob.found.req: (compiler.misc.unchecked.assign), java.lang.Iterable, java.lang.Iterable<java.lang.Exception> 123.10 +T7015430.java:68:22: compiler.warn.prob.found.req: (compiler.misc.unchecked.assign), java.lang.Iterable, java.lang.Iterable<E> 123.11 T7015430.java:68:9: compiler.warn.unchecked.meth.invocation.applied: kindname.constructor, <init>, java.lang.Iterable<E>, java.lang.Iterable, kindname.class, T7015430 123.12 T7015430.java:77:40: compiler.warn.prob.found.req: (compiler.misc.unchecked.assign), java.lang.Iterable, java.lang.Iterable<java.lang.RuntimeException> 123.13 T7015430.java:77:9: compiler.warn.unchecked.meth.invocation.applied: kindname.constructor, <init>, java.lang.Iterable<E>, java.lang.Iterable, kindname.class, T7015430 123.14 T7015430.java:104:41: compiler.warn.prob.found.req: (compiler.misc.unchecked.assign), java.lang.Iterable, java.lang.Iterable<java.lang.RuntimeException> 123.15 T7015430.java:104:9: compiler.warn.unchecked.meth.invocation.applied: kindname.constructor, <init>, java.lang.Iterable<E>, java.lang.Iterable, kindname.class, T7015430 123.16 -T7015430.java:113:22: compiler.warn.prob.found.req: (compiler.misc.unchecked.assign), java.lang.Iterable, java.lang.Iterable<java.lang.Exception> 123.17 +T7015430.java:113:22: compiler.warn.prob.found.req: (compiler.misc.unchecked.assign), java.lang.Iterable, java.lang.Iterable<E> 123.18 T7015430.java:113:9: compiler.warn.unchecked.meth.invocation.applied: kindname.constructor, <init>, java.lang.Iterable<E>, java.lang.Iterable, kindname.class, T7015430 123.19 T7015430.java:41:14: compiler.err.unreported.exception.need.to.catch.or.throw: java.lang.Exception 123.20 T7015430.java:68:9: compiler.err.unreported.exception.need.to.catch.or.throw: java.lang.Exception
124.1 --- a/test/tools/javac/generics/7034511/T7034511a.out Thu Oct 11 09:50:52 2012 -0700 124.2 +++ b/test/tools/javac/generics/7034511/T7034511a.out Thu Oct 11 17:00:54 2012 -0700 124.3 @@ -1,2 +1,2 @@ 124.4 -T7034511a.java:18:14: compiler.err.cant.apply.symbol.1: kindname.method, foo, compiler.misc.type.captureof: 1, ?[], java.lang.String[], kindname.interface, T7034511a.A<T>, (compiler.misc.no.conforming.assignment.exists: java.lang.String[], compiler.misc.type.captureof: 1, ?[]) 124.5 +T7034511a.java:18:14: compiler.err.cant.apply.symbol: kindname.method, foo, compiler.misc.type.captureof: 1, ?[], java.lang.String[], kindname.interface, T7034511a.A<T>, (compiler.misc.no.conforming.assignment.exists: java.lang.String[], compiler.misc.type.captureof: 1, ?[]) 124.6 1 error
125.1 --- a/test/tools/javac/generics/7034511/T7034511b.out Thu Oct 11 09:50:52 2012 -0700 125.2 +++ b/test/tools/javac/generics/7034511/T7034511b.out Thu Oct 11 17:00:54 2012 -0700 125.3 @@ -1,2 +1,2 @@ 125.4 -T7034511b.java:14:11: compiler.err.cant.apply.symbol.1: kindname.method, toArray, compiler.misc.type.captureof: 1, ?[], java.lang.Object[], kindname.class, T7034511b.MyList<E>, (compiler.misc.no.conforming.assignment.exists: java.lang.Object[], compiler.misc.type.captureof: 1, ?[]) 125.5 +T7034511b.java:14:11: compiler.err.cant.apply.symbol: kindname.method, toArray, compiler.misc.type.captureof: 1, ?[], java.lang.Object[], kindname.class, T7034511b.MyList<E>, (compiler.misc.no.conforming.assignment.exists: java.lang.Object[], compiler.misc.type.captureof: 1, ?[]) 125.6 1 error
126.1 --- a/test/tools/javac/generics/7151802/T7151802.out Thu Oct 11 09:50:52 2012 -0700 126.2 +++ b/test/tools/javac/generics/7151802/T7151802.out Thu Oct 11 17:00:54 2012 -0700 126.3 @@ -1,5 +1,5 @@ 126.4 T7151802.java:14:31: compiler.warn.unchecked.meth.invocation.applied: kindname.method, get1, Z, T7151802.Foo, kindname.class, T7151802 126.5 -T7151802.java:22:31: compiler.warn.prob.found.req: (compiler.misc.unchecked.assign), T7151802.Foo, T7151802.Foo<java.lang.Object> 126.6 +T7151802.java:22:31: compiler.warn.prob.found.req: (compiler.misc.unchecked.assign), T7151802.Foo, T7151802.Foo<Z> 126.7 T7151802.java:22:30: compiler.warn.unchecked.meth.invocation.applied: kindname.method, get3, T7151802.Foo<Z>, T7151802.Foo, kindname.class, T7151802 126.8 T7151802.java:30:36: compiler.warn.unchecked.meth.invocation.applied: kindname.method, get5, compiler.misc.no.args, compiler.misc.no.args, kindname.class, T7151802 126.9 T7151802.java:38:32: compiler.warn.prob.found.req: (compiler.misc.unchecked.assign), T7151802.Foo, T7151802.Foo<java.lang.String>
127.1 --- a/test/tools/javac/generics/diamond/7002837/T7002837.java Thu Oct 11 09:50:52 2012 -0700 127.2 +++ b/test/tools/javac/generics/diamond/7002837/T7002837.java Thu Oct 11 17:00:54 2012 -0700 127.3 @@ -4,7 +4,7 @@ 127.4 * 127.5 * @summary Diamond: javac generates diamond inference errors when in 'finder' mode 127.6 * @author mcimadamore 127.7 - * @compile -Werror -XDfindDiamond T7002837.java 127.8 + * @compile/fail/ref=T7002837.out -Werror -XDrawDiagnostics -XDfindDiamond T7002837.java 127.9 * 127.10 */ 127.11
128.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 128.2 +++ b/test/tools/javac/generics/diamond/7002837/T7002837.out Thu Oct 11 17:00:54 2012 -0700 128.3 @@ -0,0 +1,4 @@ 128.4 +T7002837.java:13:19: compiler.warn.diamond.redundant.args.1: T7002837<java.lang.Integer>, T7002837<java.lang.Object&java.io.Serializable&java.lang.Comparable<?>> 128.5 +- compiler.err.warnings.and.werror 128.6 +1 error 128.7 +1 warning
129.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 129.2 +++ b/test/tools/javac/generics/diamond/7188968/T7188968.java Thu Oct 11 17:00:54 2012 -0700 129.3 @@ -0,0 +1,25 @@ 129.4 +/* 129.5 + * @test /nodynamiccopyright/ 129.6 + * @bug 7188968 129.7 + * 129.8 + * @summary Diamond: javac generates diamond inference errors when in 'finder' mode 129.9 + * @author mcimadamore 129.10 + * @compile/fail/ref=T7188968.out -Xlint:unchecked -XDrawDiagnostics T7188968.java 129.11 + * 129.12 + */ 129.13 +import java.util.List; 129.14 + 129.15 +class T7188968 { 129.16 + 129.17 + static class Foo<X> { 129.18 + Foo(List<X> ls, Object o) { } 129.19 + static <Z> Foo<Z> makeFoo(List<Z> lz, Object o) { return null; } 129.20 + } 129.21 + 129.22 + void test(List l) { 129.23 + new Foo(l, unknown); 129.24 + new Foo(l, unknown) { }; 129.25 + new Foo<>(l, unknown); 129.26 + Foo.makeFoo(l, unknown); 129.27 + } 129.28 +}
130.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 130.2 +++ b/test/tools/javac/generics/diamond/7188968/T7188968.out Thu Oct 11 17:00:54 2012 -0700 130.3 @@ -0,0 +1,7 @@ 130.4 +T7188968.java:20:20: compiler.err.cant.resolve.location: kindname.variable, unknown, , , (compiler.misc.location: kindname.class, T7188968, null) 130.5 +T7188968.java:21:20: compiler.err.cant.resolve.location: kindname.variable, unknown, , , (compiler.misc.location: kindname.class, T7188968, null) 130.6 +T7188968.java:21:29: compiler.warn.unchecked.call.mbr.of.raw.type: T7188968.Foo(java.util.List<X>,java.lang.Object), T7188968.Foo 130.7 +T7188968.java:22:22: compiler.err.cant.resolve.location: kindname.variable, unknown, , , (compiler.misc.location: kindname.class, T7188968, null) 130.8 +T7188968.java:23:24: compiler.err.cant.resolve.location: kindname.variable, unknown, , , (compiler.misc.location: kindname.class, T7188968, null) 130.9 +4 errors 130.10 +1 warning
131.1 --- a/test/tools/javac/generics/inference/6611449/T6611449.out Thu Oct 11 09:50:52 2012 -0700 131.2 +++ b/test/tools/javac/generics/inference/6611449/T6611449.out Thu Oct 11 17:00:54 2012 -0700 131.3 @@ -1,5 +1,5 @@ 131.4 T6611449.java:18:9: compiler.err.cant.apply.symbols: kindname.constructor, T6611449, int,{(compiler.misc.inapplicable.method: kindname.constructor, T6611449, <T>T6611449(T,T), (compiler.misc.infer.arg.length.mismatch: T)),(compiler.misc.inapplicable.method: kindname.constructor, T6611449, <T>T6611449(T), (compiler.misc.inferred.do.not.conform.to.upper.bounds: java.lang.Integer, S))} 131.5 T6611449.java:19:9: compiler.err.cant.apply.symbols: kindname.constructor, T6611449, int,int,{(compiler.misc.inapplicable.method: kindname.constructor, T6611449, <T>T6611449(T,T), (compiler.misc.inferred.do.not.conform.to.upper.bounds: java.lang.Integer, S)),(compiler.misc.inapplicable.method: kindname.constructor, T6611449, <T>T6611449(T), (compiler.misc.infer.arg.length.mismatch: T))} 131.6 -T6611449.java:20:9: compiler.err.cant.apply.symbol.1: kindname.method, m1, T, int, kindname.class, T6611449<S>, (compiler.misc.inferred.do.not.conform.to.upper.bounds: java.lang.Integer, S) 131.7 -T6611449.java:21:9: compiler.err.cant.apply.symbol.1: kindname.method, m2, T,T, int,int, kindname.class, T6611449<S>, (compiler.misc.inferred.do.not.conform.to.upper.bounds: java.lang.Integer, S) 131.8 +T6611449.java:20:9: compiler.err.cant.apply.symbol: kindname.method, m1, T, int, kindname.class, T6611449<S>, (compiler.misc.inferred.do.not.conform.to.upper.bounds: java.lang.Integer, S) 131.9 +T6611449.java:21:9: compiler.err.cant.apply.symbol: kindname.method, m2, T,T, int,int, kindname.class, T6611449<S>, (compiler.misc.inferred.do.not.conform.to.upper.bounds: java.lang.Integer, S) 131.10 4 errors
132.1 --- a/test/tools/javac/generics/inference/6638712/T6638712a.out Thu Oct 11 09:50:52 2012 -0700 132.2 +++ b/test/tools/javac/generics/inference/6638712/T6638712a.out Thu Oct 11 17:00:54 2012 -0700 132.3 @@ -1,2 +1,2 @@ 132.4 -T6638712a.java:16:33: compiler.err.cant.apply.symbol.1: kindname.method, compound, java.lang.Iterable<? extends java.util.Comparator<? super T>>, java.util.List<java.util.Comparator<?>>, kindname.class, T6638712a, (compiler.misc.infer.no.conforming.assignment.exists: T, (compiler.misc.inconvertible.types: java.util.List<java.util.Comparator<?>>, java.lang.Iterable<? extends java.util.Comparator<? super T>>)) 132.5 +T6638712a.java:16:33: compiler.err.cant.apply.symbol: kindname.method, compound, java.lang.Iterable<? extends java.util.Comparator<? super T>>, java.util.List<java.util.Comparator<?>>, kindname.class, T6638712a, (compiler.misc.infer.no.conforming.assignment.exists: T, (compiler.misc.inconvertible.types: java.util.List<java.util.Comparator<?>>, java.lang.Iterable<? extends java.util.Comparator<? super T>>)) 132.6 1 error
133.1 --- a/test/tools/javac/generics/inference/6638712/T6638712c.out Thu Oct 11 09:50:52 2012 -0700 133.2 +++ b/test/tools/javac/generics/inference/6638712/T6638712c.out Thu Oct 11 17:00:54 2012 -0700 133.3 @@ -1,2 +1,2 @@ 133.4 -T6638712c.java:16:9: compiler.err.cant.apply.symbol.1: kindname.method, sort, T[],java.util.Comparator<? super T>, java.lang.Enum[],java.util.Comparator<java.lang.Enum<?>>, kindname.class, T6638712c, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.inconvertible.types: java.util.Comparator<java.lang.Enum<?>>, java.util.Comparator<? super java.lang.Enum>)) 133.5 +T6638712c.java:16:9: compiler.err.cant.apply.symbol: kindname.method, sort, T[],java.util.Comparator<? super T>, java.lang.Enum[],java.util.Comparator<java.lang.Enum<?>>, kindname.class, T6638712c, (compiler.misc.infer.no.conforming.assignment.exists: T, (compiler.misc.inconvertible.types: java.util.Comparator<java.lang.Enum<?>>, java.util.Comparator<? super java.lang.Enum>)) 133.6 1 error
134.1 --- a/test/tools/javac/generics/inference/6638712/T6638712d.out Thu Oct 11 09:50:52 2012 -0700 134.2 +++ b/test/tools/javac/generics/inference/6638712/T6638712d.out Thu Oct 11 17:00:54 2012 -0700 134.3 @@ -1,2 +1,2 @@ 134.4 -T6638712d.java:16:9: compiler.err.cant.apply.symbol.1: kindname.method, m, U,java.util.List<java.util.List<U>>, int,java.util.List<java.util.List<java.lang.String>>, kindname.class, T6638712d, (compiler.misc.inferred.do.not.conform.to.lower.bounds: java.lang.String, java.lang.Integer) 134.5 +T6638712d.java:16:9: compiler.err.cant.apply.symbol: kindname.method, m, U,java.util.List<java.util.List<U>>, int,java.util.List<java.util.List<java.lang.String>>, kindname.class, T6638712d, (compiler.misc.inferred.do.not.conform.to.lower.bounds: java.lang.String, java.lang.Integer) 134.6 1 error
135.1 --- a/test/tools/javac/generics/inference/6838943/T6838943.out Thu Oct 11 09:50:52 2012 -0700 135.2 +++ b/test/tools/javac/generics/inference/6838943/T6838943.out Thu Oct 11 17:00:54 2012 -0700 135.3 @@ -1,2 +1,2 @@ 135.4 -T6838943.java:13:14: compiler.err.cant.apply.symbol.1: kindname.method, m, T6838943.A<Z>,Z, T6838943.A<T6838943.B>,T6838943.B, kindname.class, T6838943.C<X>, (compiler.misc.infer.no.conforming.assignment.exists: Z, (compiler.misc.inconvertible.types: T6838943.A<T6838943.B>, T6838943.A<Z>)) 135.5 +T6838943.java:13:14: compiler.err.cant.apply.symbol: kindname.method, m, T6838943.A<Z>,Z, T6838943.A<T6838943.B>,T6838943.B, kindname.class, T6838943.C<X>, (compiler.misc.infer.no.conforming.assignment.exists: Z, (compiler.misc.inconvertible.types: T6838943.A<T6838943.B>, T6838943.A<Z>)) 135.6 1 error
136.1 --- a/test/tools/javac/generics/inference/7086586/T7086586.out Thu Oct 11 09:50:52 2012 -0700 136.2 +++ b/test/tools/javac/generics/inference/7086586/T7086586.out Thu Oct 11 17:00:54 2012 -0700 136.3 @@ -1,5 +1,5 @@ 136.4 -T7086586.java:14:20: compiler.err.cant.apply.symbol.1: kindname.method, m, java.util.List<? super T>, java.util.List<compiler.misc.type.captureof: 1, ?>, kindname.class, T7086586, (compiler.misc.infer.no.conforming.assignment.exists: T, (compiler.misc.inconvertible.types: java.util.List<compiler.misc.type.captureof: 1, ?>, java.util.List<? super T>)) 136.5 -T7086586.java:15:20: compiler.err.cant.apply.symbol.1: kindname.method, m, java.util.List<? super T>, java.util.List<compiler.misc.type.captureof: 1, ?>, kindname.class, T7086586, (compiler.misc.infer.no.conforming.assignment.exists: T, (compiler.misc.inconvertible.types: java.util.List<compiler.misc.type.captureof: 1, ?>, java.util.List<? super T>)) 136.6 -T7086586.java:16:23: compiler.err.cant.apply.symbol.1: kindname.method, m, java.util.List<? super T>, java.util.List<compiler.misc.type.captureof: 1, ?>, kindname.class, T7086586, (compiler.misc.infer.no.conforming.assignment.exists: T, (compiler.misc.inconvertible.types: java.util.List<compiler.misc.type.captureof: 1, ?>, java.util.List<? super T>)) 136.7 -T7086586.java:17:9: compiler.err.cant.apply.symbol.1: kindname.method, m, java.util.List<? super T>, java.util.List<compiler.misc.type.captureof: 1, ?>, kindname.class, T7086586, (compiler.misc.infer.no.conforming.assignment.exists: T, (compiler.misc.inconvertible.types: java.util.List<compiler.misc.type.captureof: 1, ?>, java.util.List<? super T>)) 136.8 +T7086586.java:14:20: compiler.err.cant.apply.symbol: kindname.method, m, java.util.List<? super T>, java.util.List<compiler.misc.type.captureof: 1, ?>, kindname.class, T7086586, (compiler.misc.infer.no.conforming.assignment.exists: T, (compiler.misc.inconvertible.types: java.util.List<compiler.misc.type.captureof: 1, ?>, java.util.List<? super T>)) 136.9 +T7086586.java:15:20: compiler.err.cant.apply.symbol: kindname.method, m, java.util.List<? super T>, java.util.List<compiler.misc.type.captureof: 1, ?>, kindname.class, T7086586, (compiler.misc.infer.no.conforming.assignment.exists: T, (compiler.misc.inconvertible.types: java.util.List<compiler.misc.type.captureof: 1, ?>, java.util.List<? super T>)) 136.10 +T7086586.java:16:23: compiler.err.cant.apply.symbol: kindname.method, m, java.util.List<? super T>, java.util.List<compiler.misc.type.captureof: 1, ?>, kindname.class, T7086586, (compiler.misc.infer.no.conforming.assignment.exists: T, (compiler.misc.inconvertible.types: java.util.List<compiler.misc.type.captureof: 1, ?>, java.util.List<? super T>)) 136.11 +T7086586.java:17:9: compiler.err.cant.apply.symbol: kindname.method, m, java.util.List<? super T>, java.util.List<compiler.misc.type.captureof: 1, ?>, kindname.class, T7086586, (compiler.misc.infer.no.conforming.assignment.exists: T, (compiler.misc.inconvertible.types: java.util.List<compiler.misc.type.captureof: 1, ?>, java.util.List<? super T>)) 136.12 4 errors
137.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 137.2 +++ b/test/tools/javac/generics/inference/7177306/T7177306a.java Thu Oct 11 17:00:54 2012 -0700 137.3 @@ -0,0 +1,19 @@ 137.4 +/** 137.5 + * @test /nodynamiccopyright/ 137.6 + * @bug 7177306 137.7 + * @summary Regression: unchecked method call does not erase return type 137.8 + * @compile/fail/ref=T7177306a.out -Werror -Xlint:unchecked -XDrawDiagnostics T7177306a.java 137.9 + */ 137.10 + 137.11 +import java.util.List; 137.12 + 137.13 +class T7177306a<A> { 137.14 + 137.15 + public static void test(List l) { 137.16 + T7177306a<Object> to = m(l); 137.17 + } 137.18 + 137.19 + public static <E> T7177306a<String> m(List<E> le) { 137.20 + return null; 137.21 + } 137.22 +}
138.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 138.2 +++ b/test/tools/javac/generics/inference/7177306/T7177306a.out Thu Oct 11 17:00:54 2012 -0700 138.3 @@ -0,0 +1,6 @@ 138.4 +T7177306a.java:13:34: compiler.warn.prob.found.req: (compiler.misc.unchecked.assign), java.util.List, java.util.List<E> 138.5 +T7177306a.java:13:33: compiler.warn.unchecked.meth.invocation.applied: kindname.method, m, java.util.List<E>, java.util.List, kindname.class, T7177306a 138.6 +T7177306a.java:13:33: compiler.warn.prob.found.req: (compiler.misc.unchecked.assign), T7177306a, T7177306a<java.lang.Object> 138.7 +- compiler.err.warnings.and.werror 138.8 +1 error 138.9 +3 warnings
139.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 139.2 +++ b/test/tools/javac/generics/inference/7177306/T7177306b.java Thu Oct 11 17:00:54 2012 -0700 139.3 @@ -0,0 +1,18 @@ 139.4 +/** 139.5 + * @test /nodynamiccopyright/ 139.6 + * @bug 7177306 139.7 + * @summary Regression: unchecked method call does not erase return type 139.8 + * @compile/fail/ref=T7177306b.out -Werror -Xlint:unchecked -XDrawDiagnostics T7177306b.java 139.9 + */ 139.10 + 139.11 +import java.util.List; 139.12 + 139.13 +class T7177306b { 139.14 + 139.15 + <T, S extends List<T>> List<T> m(List<? super T> arg1, S arg2, Class<Object> arg3) { return arg2; } 139.16 + 139.17 + void test(List<Integer> li, List<String> ls, Class c) { 139.18 + m(li, ls, c); 139.19 + // should fail, because of bounds T <: Integer, S :> List<String> 139.20 + } 139.21 +}
140.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 140.2 +++ b/test/tools/javac/generics/inference/7177306/T7177306b.out Thu Oct 11 17:00:54 2012 -0700 140.3 @@ -0,0 +1,2 @@ 140.4 +T7177306b.java:15:9: compiler.err.cant.apply.symbol: kindname.method, m, java.util.List<? super T>,S,java.lang.Class<java.lang.Object>, java.util.List<java.lang.Integer>,java.util.List<java.lang.String>,java.lang.Class, kindname.class, T7177306b, (compiler.misc.incompatible.eq.upper.bounds: T, java.lang.String, java.lang.Integer,java.lang.Object) 140.5 +1 error
141.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 141.2 +++ b/test/tools/javac/generics/inference/7177306/T7177306c.java Thu Oct 11 17:00:54 2012 -0700 141.3 @@ -0,0 +1,38 @@ 141.4 +/* 141.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 141.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 141.7 + * 141.8 + * This code is free software; you can redistribute it and/or modify it 141.9 + * under the terms of the GNU General Public License version 2 only, as 141.10 + * published by the Free Software Foundation. 141.11 + * 141.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 141.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 141.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 141.15 + * version 2 for more details (a copy is included in the LICENSE file that 141.16 + * accompanied this code). 141.17 + * 141.18 + * You should have received a copy of the GNU General Public License version 141.19 + * 2 along with this work; if not, write to the Free Software Foundation, 141.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 141.21 + * 141.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 141.23 + * or visit www.oracle.com if you need additional information or have any 141.24 + * questions. 141.25 + */ 141.26 + 141.27 +/* 141.28 + * @test 141.29 + * @bug 7177306 141.30 + * @summary Regression: unchecked method call does not erase return type 141.31 + */ 141.32 +public class T7177306c { 141.33 + 141.34 + static <T> T m(T t) { return (T)"Null"; } 141.35 + 141.36 + public static void main(String[] args) { 141.37 + if (m("NonNullConst") != "Null") { 141.38 + throw new AssertionError("should not get there!"); 141.39 + } 141.40 + } 141.41 +}
142.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 142.2 +++ b/test/tools/javac/generics/inference/7177306/T7177306d.java Thu Oct 11 17:00:54 2012 -0700 142.3 @@ -0,0 +1,53 @@ 142.4 +/* 142.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 142.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 142.7 + * 142.8 + * This code is free software; you can redistribute it and/or modify it 142.9 + * under the terms of the GNU General Public License version 2 only, as 142.10 + * published by the Free Software Foundation. 142.11 + * 142.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 142.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 142.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 142.15 + * version 2 for more details (a copy is included in the LICENSE file that 142.16 + * accompanied this code). 142.17 + * 142.18 + * You should have received a copy of the GNU General Public License version 142.19 + * 2 along with this work; if not, write to the Free Software Foundation, 142.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 142.21 + * 142.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 142.23 + * or visit www.oracle.com if you need additional information or have any 142.24 + * questions. 142.25 + */ 142.26 + 142.27 +/* 142.28 + * @test 142.29 + * @bug 7177306 142.30 + * @summary Regression: unchecked method call does not erase return type 142.31 + */ 142.32 +import java.util.List; 142.33 + 142.34 +public class T7177306d { 142.35 + 142.36 + static int assertionCount = 0; 142.37 + 142.38 + static void assertTrue(boolean cond) { 142.39 + if (!cond) { 142.40 + throw new AssertionError(); 142.41 + } 142.42 + assertionCount++; 142.43 + } 142.44 + 142.45 + static <T, S extends List<T>> void m(List<? super T> arg1, S arg2, Class<Object> arg3) { assertTrue(false); } 142.46 + static void m(Object o1, Object o2, Object o3) { assertTrue(true); } 142.47 + 142.48 + static void test(List<Integer> li, List<String> ls, Class c) { 142.49 + m(li, ls, c); 142.50 + } 142.51 + 142.52 + public static void main(String[] args) { 142.53 + test(null, null, null); 142.54 + assertTrue(assertionCount == 1); 142.55 + } 142.56 +}
143.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 143.2 +++ b/test/tools/javac/generics/inference/7177306/T7177306e.java Thu Oct 11 17:00:54 2012 -0700 143.3 @@ -0,0 +1,17 @@ 143.4 +/** 143.5 + * @test /nodynamiccopyright/ 143.6 + * @bug 7177306 143.7 + * @summary Regression: unchecked method call does not erase return type 143.8 + * @compile/fail/ref=T7177306e.out -XDrawDiagnostics T7177306e.java 143.9 + */ 143.10 + 143.11 +import java.util.List; 143.12 + 143.13 +class T7177306e { 143.14 + 143.15 + <Z, U extends List<Z>> void m(List<U> lu) { } 143.16 + 143.17 + void test(List<List<?>> llw) { 143.18 + m(llw); 143.19 + } 143.20 +}
144.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 144.2 +++ b/test/tools/javac/generics/inference/7177306/T7177306e.out Thu Oct 11 17:00:54 2012 -0700 144.3 @@ -0,0 +1,2 @@ 144.4 +T7177306e.java:15:9: compiler.err.prob.found.req: (compiler.misc.inferred.do.not.conform.to.upper.bounds: java.util.List<?>, java.util.List<compiler.misc.type.captureof: 1, ?>) 144.5 +1 error
145.1 --- a/test/tools/javac/lambda/MethodReferenceParserTest.java Thu Oct 11 09:50:52 2012 -0700 145.2 +++ b/test/tools/javac/lambda/MethodReferenceParserTest.java Thu Oct 11 17:00:54 2012 -0700 145.3 @@ -1,5 +1,5 @@ 145.4 /* 145.5 - * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. 145.6 + * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. 145.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 145.8 * 145.9 * This code is free software; you can redistribute it and/or modify it 145.10 @@ -42,14 +42,14 @@ 145.11 static int checkCount = 0; 145.12 145.13 enum ReferenceKind { 145.14 - METHOD_REF("#Q##Gm"), 145.15 - CONSTRUCTOR_REF("#Q##Gnew"), 145.16 + METHOD_REF("#Q::#Gm"), 145.17 + CONSTRUCTOR_REF("#Q::#Gnew"), 145.18 FALSE_REF("min < max"), 145.19 - ERR_SUPER("#Q##Gsuper"), 145.20 - ERR_METH0("#Q##Gm()"), 145.21 - ERR_METH1("#Q##Gm(X)"), 145.22 - ERR_CONSTR0("#Q##Gnew()"), 145.23 - ERR_CONSTR1("#Q##Gnew(X)"); 145.24 + ERR_SUPER("#Q::#Gsuper"), 145.25 + ERR_METH0("#Q::#Gm()"), 145.26 + ERR_METH1("#Q::#Gm(X)"), 145.27 + ERR_CONSTR0("#Q::#Gnew()"), 145.28 + ERR_CONSTR1("#Q::#Gnew(X)"); 145.29 145.30 String referenceTemplate; 145.31 145.32 @@ -110,6 +110,8 @@ 145.33 METHOD("m()"), 145.34 FIELD("a.f"), 145.35 UBOUND_SIMPLE("A"), 145.36 + UNBOUND_ARRAY1("int[]"), 145.37 + UNBOUND_ARRAY2("A<G>[][]"), 145.38 UNBOUND_GENERIC1("A<X>"), 145.39 UNBOUND_GENERIC2("A<X, Y>"), 145.40 UNBOUND_GENERIC3("A<? extends X, ? super Y>"), 145.41 @@ -125,7 +127,7 @@ 145.42 } 145.43 145.44 enum ExprKind { 145.45 - NONE("#R#S"), 145.46 + NONE("#R::S"), 145.47 SINGLE_PAREN1("(#R#S)"), 145.48 SINGLE_PAREN2("(#R)#S"), 145.49 DOUBLE_PAREN1("((#R#S))"),
146.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 146.2 +++ b/test/tools/javac/lambda/TestInvokeDynamic.java Thu Oct 11 17:00:54 2012 -0700 146.3 @@ -0,0 +1,442 @@ 146.4 +/* 146.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 146.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 146.7 + * 146.8 + * This code is free software; you can redistribute it and/or modify it 146.9 + * under the terms of the GNU General Public License version 2 only, as 146.10 + * published by the Free Software Foundation. 146.11 + * 146.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 146.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 146.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 146.15 + * version 2 for more details (a copy is included in the LICENSE file that 146.16 + * accompanied this code). 146.17 + * 146.18 + * You should have received a copy of the GNU General Public License version 146.19 + * 2 along with this work; if not, write to the Free Software Foundation, 146.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 146.21 + * 146.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 146.23 + * or visit www.oracle.com if you need additional information or have any 146.24 + * questions. 146.25 + */ 146.26 + 146.27 +/* 146.28 + * @test 146.29 + * @bug 7194586 146.30 + * 146.31 + * @summary Add back-end support for invokedynamic 146.32 + * 146.33 + */ 146.34 + 146.35 +import com.sun.source.tree.MethodInvocationTree; 146.36 +import com.sun.source.tree.MethodTree; 146.37 +import com.sun.source.util.TaskEvent; 146.38 +import com.sun.source.util.TaskListener; 146.39 +import com.sun.source.util.TreeScanner; 146.40 + 146.41 +import com.sun.tools.classfile.Attribute; 146.42 +import com.sun.tools.classfile.BootstrapMethods_attribute; 146.43 +import com.sun.tools.classfile.ClassFile; 146.44 +import com.sun.tools.classfile.Code_attribute; 146.45 +import com.sun.tools.classfile.ConstantPool.*; 146.46 +import com.sun.tools.classfile.Instruction; 146.47 +import com.sun.tools.classfile.Method; 146.48 + 146.49 +import com.sun.tools.javac.api.JavacTaskImpl; 146.50 +import com.sun.tools.javac.api.JavacTool; 146.51 +import com.sun.tools.javac.code.Symbol; 146.52 +import com.sun.tools.javac.code.Symbol.MethodSymbol; 146.53 +import com.sun.tools.javac.code.Symtab; 146.54 +import com.sun.tools.javac.jvm.Pool; 146.55 +import com.sun.tools.javac.tree.JCTree.JCMethodInvocation; 146.56 +import com.sun.tools.javac.tree.JCTree.JCMethodDecl; 146.57 +import com.sun.tools.javac.tree.JCTree.JCIdent; 146.58 +import com.sun.tools.javac.util.Context; 146.59 +import com.sun.tools.javac.util.Names; 146.60 + 146.61 +import java.io.File; 146.62 +import java.net.URI; 146.63 +import java.util.ArrayList; 146.64 +import java.util.Arrays; 146.65 +import java.util.Locale; 146.66 + 146.67 +import javax.tools.Diagnostic; 146.68 +import javax.tools.JavaCompiler; 146.69 +import javax.tools.JavaFileManager; 146.70 +import javax.tools.JavaFileObject; 146.71 +import javax.tools.SimpleJavaFileObject; 146.72 +import javax.tools.StandardJavaFileManager; 146.73 +import javax.tools.ToolProvider; 146.74 + 146.75 +import static com.sun.tools.javac.jvm.ClassFile.*; 146.76 + 146.77 +public class TestInvokeDynamic { 146.78 + 146.79 + static int checkCount = 0; 146.80 + 146.81 + enum StaticArgumentKind { 146.82 + STRING("Hello!", "String", "Ljava/lang/String;") { 146.83 + @Override 146.84 + boolean check(CPInfo cpInfo) throws Exception { 146.85 + return (cpInfo instanceof CONSTANT_String_info) && 146.86 + ((CONSTANT_String_info)cpInfo).getString().equals(value); 146.87 + } 146.88 + }, 146.89 + CLASS(null, "Class<?>", "Ljava/lang/Class;") { 146.90 + @Override 146.91 + boolean check(CPInfo cpInfo) throws Exception { 146.92 + return (cpInfo instanceof CONSTANT_Class_info) && 146.93 + ((CONSTANT_Class_info)cpInfo).getName().equals("java/lang/String"); 146.94 + } 146.95 + }, 146.96 + INTEGER(1, "int", "I") { 146.97 + @Override 146.98 + boolean check(CPInfo cpInfo) throws Exception { 146.99 + return (cpInfo instanceof CONSTANT_Integer_info) && 146.100 + ((CONSTANT_Integer_info)cpInfo).value == ((Integer)value).intValue(); 146.101 + } 146.102 + }, 146.103 + LONG(1L, "long", "J") { 146.104 + @Override 146.105 + boolean check(CPInfo cpInfo) throws Exception { 146.106 + return (cpInfo instanceof CONSTANT_Long_info) && 146.107 + ((CONSTANT_Long_info)cpInfo).value == ((Long)value).longValue(); 146.108 + } 146.109 + }, 146.110 + FLOAT(1.0f, "float", "F") { 146.111 + @Override 146.112 + boolean check(CPInfo cpInfo) throws Exception { 146.113 + return (cpInfo instanceof CONSTANT_Float_info) && 146.114 + ((CONSTANT_Float_info)cpInfo).value == ((Float)value).floatValue(); 146.115 + } 146.116 + }, 146.117 + DOUBLE(1.0, "double","D") { 146.118 + @Override 146.119 + boolean check(CPInfo cpInfo) throws Exception { 146.120 + return (cpInfo instanceof CONSTANT_Double_info) && 146.121 + ((CONSTANT_Double_info)cpInfo).value == ((Double)value).doubleValue(); 146.122 + } 146.123 + }, 146.124 + METHOD_HANDLE(null, "MethodHandle", "Ljava/lang/invoke/MethodHandle;") { 146.125 + @Override 146.126 + boolean check(CPInfo cpInfo) throws Exception { 146.127 + if (!(cpInfo instanceof CONSTANT_MethodHandle_info)) return false; 146.128 + CONSTANT_MethodHandle_info handleInfo = (CONSTANT_MethodHandle_info)cpInfo; 146.129 + return handleInfo.getCPRefInfo().getClassName().equals("Array") && 146.130 + handleInfo.reference_kind == RefKind.REF_invokeVirtual && 146.131 + handleInfo.getCPRefInfo().getNameAndTypeInfo().getName().equals("clone") && 146.132 + handleInfo.getCPRefInfo().getNameAndTypeInfo().getType().equals("()Ljava/lang/Object;"); 146.133 + } 146.134 + }, 146.135 + METHOD_TYPE(null, "MethodType", "Ljava/lang/invoke/MethodType;") { 146.136 + @Override 146.137 + boolean check(CPInfo cpInfo) throws Exception { 146.138 + return (cpInfo instanceof CONSTANT_MethodType_info) && 146.139 + ((CONSTANT_MethodType_info)cpInfo).getType().equals("()Ljava/lang/Object;"); 146.140 + } 146.141 + }; 146.142 + 146.143 + Object value; 146.144 + String sourceTypeStr; 146.145 + String bytecodeTypeStr; 146.146 + 146.147 + StaticArgumentKind(Object value, String sourceTypeStr, String bytecodeTypeStr) { 146.148 + this.value = value; 146.149 + this.sourceTypeStr = sourceTypeStr; 146.150 + this.bytecodeTypeStr = bytecodeTypeStr; 146.151 + } 146.152 + 146.153 + abstract boolean check(CPInfo cpInfo) throws Exception; 146.154 + 146.155 + Object getValue(Symtab syms, Names names) { 146.156 + switch (this) { 146.157 + case STRING: 146.158 + case INTEGER: 146.159 + case LONG: 146.160 + case FLOAT: 146.161 + case DOUBLE: 146.162 + return value; 146.163 + case CLASS: 146.164 + return syms.stringType.tsym; 146.165 + case METHOD_HANDLE: 146.166 + return new Pool.MethodHandle(REF_invokeVirtual, syms.arrayCloneMethod); 146.167 + case METHOD_TYPE: 146.168 + return syms.arrayCloneMethod.type; 146.169 + default: 146.170 + throw new AssertionError(); 146.171 + } 146.172 + } 146.173 + } 146.174 + 146.175 + enum StaticArgumentsArity { 146.176 + ZERO(0), 146.177 + ONE(1), 146.178 + TWO(2), 146.179 + THREE(3); 146.180 + 146.181 + int arity; 146.182 + 146.183 + StaticArgumentsArity(int arity) { 146.184 + this.arity = arity; 146.185 + } 146.186 + } 146.187 + 146.188 + public static void main(String... args) throws Exception { 146.189 + // Create a single file manager and compiler and reuse it for each compile to save time. 146.190 + StandardJavaFileManager fm = JavacTool.create().getStandardFileManager(null, null, null); 146.191 + final JavaCompiler tool = ToolProvider.getSystemJavaCompiler(); 146.192 + for (StaticArgumentsArity arity : StaticArgumentsArity.values()) { 146.193 + if (arity.arity == 0) { 146.194 + new TestInvokeDynamic(arity).compileAndCheck(fm, tool); 146.195 + } else { 146.196 + for (StaticArgumentKind sak1 : StaticArgumentKind.values()) { 146.197 + if (arity.arity == 1) { 146.198 + new TestInvokeDynamic(arity, sak1).compileAndCheck(fm, tool); 146.199 + } else { 146.200 + for (StaticArgumentKind sak2 : StaticArgumentKind.values()) { 146.201 + if (arity.arity == 2) { 146.202 + new TestInvokeDynamic(arity, sak1, sak2).compileAndCheck(fm, tool); 146.203 + } else { 146.204 + for (StaticArgumentKind sak3 : StaticArgumentKind.values()) { 146.205 + new TestInvokeDynamic(arity, sak1, sak2, sak3).compileAndCheck(fm, tool); 146.206 + } 146.207 + } 146.208 + } 146.209 + } 146.210 + } 146.211 + } 146.212 + } 146.213 + 146.214 + System.out.println("Total checks made: " + checkCount); 146.215 + } 146.216 + 146.217 + StaticArgumentsArity arity; 146.218 + StaticArgumentKind[] saks; 146.219 + JavaSource source; 146.220 + DiagChecker dc; 146.221 + 146.222 + TestInvokeDynamic(StaticArgumentsArity arity, StaticArgumentKind... saks) { 146.223 + this.arity = arity; 146.224 + this.saks = saks; 146.225 + source = new JavaSource(); 146.226 + dc = new DiagChecker(); 146.227 + } 146.228 + 146.229 + void compileAndCheck(JavaFileManager fm, JavaCompiler tool) throws Exception { 146.230 + JavacTaskImpl ct = (JavacTaskImpl)tool.getTask(null, fm, dc, 146.231 + null, null, Arrays.asList(source)); 146.232 + Context context = ct.getContext(); 146.233 + Symtab syms = Symtab.instance(context); 146.234 + Names names = Names.instance(context); 146.235 + ct.addTaskListener(new Indifier(syms, names)); 146.236 + try { 146.237 + ct.generate(); 146.238 + } catch (Throwable t) { 146.239 + t.printStackTrace(); 146.240 + throw new AssertionError(String.format("Error thrown when compiling following code\n%s", source.source)); 146.241 + } 146.242 + if (dc.diagFound) { 146.243 + throw new AssertionError(String.format("Diags found when compiling following code\n%s\n\n%s", source.source, dc.printDiags())); 146.244 + } 146.245 + verifyBytecode(); 146.246 + } 146.247 + 146.248 + void verifyBytecode() { 146.249 + File compiledTest = new File("Test.class"); 146.250 + try { 146.251 + ClassFile cf = ClassFile.read(compiledTest); 146.252 + Method testMethod = null; 146.253 + for (Method m : cf.methods) { 146.254 + if (m.getName(cf.constant_pool).equals("test")) { 146.255 + testMethod = m; 146.256 + break; 146.257 + } 146.258 + } 146.259 + if (testMethod == null) { 146.260 + throw new Error("Test method not found"); 146.261 + } 146.262 + Code_attribute ea = (Code_attribute)testMethod.attributes.get(Attribute.Code); 146.263 + if (testMethod == null) { 146.264 + throw new Error("Code attribute for test() method not found"); 146.265 + } 146.266 + 146.267 + int bsmIdx = -1; 146.268 + 146.269 + for (Instruction i : ea.getInstructions()) { 146.270 + if (i.getMnemonic().equals("invokedynamic")) { 146.271 + CONSTANT_InvokeDynamic_info indyInfo = 146.272 + (CONSTANT_InvokeDynamic_info)cf.constant_pool.get(i.getShort(1)); 146.273 + bsmIdx = indyInfo.bootstrap_method_attr_index; 146.274 + if (!indyInfo.getNameAndTypeInfo().getType().equals("()V")) { 146.275 + throw new AssertionError("type mismatch for CONSTANT_InvokeDynamic_info"); 146.276 + } 146.277 + } 146.278 + } 146.279 + if (bsmIdx == -1) { 146.280 + throw new Error("Missing invokedynamic in generated code"); 146.281 + } 146.282 + 146.283 + BootstrapMethods_attribute bsm_attr = (BootstrapMethods_attribute)cf.getAttribute(Attribute.BootstrapMethods); 146.284 + if (bsm_attr.bootstrap_method_specifiers.length != 1) { 146.285 + throw new Error("Bad number of method specifiers in BootstrapMethods attribute"); 146.286 + } 146.287 + BootstrapMethods_attribute.BootstrapMethodSpecifier bsm_spec = 146.288 + bsm_attr.bootstrap_method_specifiers[0]; 146.289 + 146.290 + if (bsm_spec.bootstrap_arguments.length != arity.arity) { 146.291 + throw new Error("Bad number of static invokedynamic args in BootstrapMethod attribute"); 146.292 + } 146.293 + 146.294 + int count = 0; 146.295 + for (StaticArgumentKind sak : saks) { 146.296 + if (!sak.check(cf.constant_pool.get(bsm_spec.bootstrap_arguments[count]))) { 146.297 + throw new Error("Bad static argument value " + sak); 146.298 + } 146.299 + count++; 146.300 + } 146.301 + 146.302 + CONSTANT_MethodHandle_info bsm_handle = 146.303 + (CONSTANT_MethodHandle_info)cf.constant_pool.get(bsm_spec.bootstrap_method_ref); 146.304 + 146.305 + if (bsm_handle.reference_kind != RefKind.REF_invokeStatic) { 146.306 + throw new Error("Bad kind on boostrap method handle"); 146.307 + } 146.308 + 146.309 + CONSTANT_Methodref_info bsm_ref = 146.310 + (CONSTANT_Methodref_info)cf.constant_pool.get(bsm_handle.reference_index); 146.311 + 146.312 + if (!bsm_ref.getClassInfo().getName().equals("Bootstrap")) { 146.313 + throw new Error("Bad owner of boostrap method"); 146.314 + } 146.315 + 146.316 + if (!bsm_ref.getNameAndTypeInfo().getName().equals("bsm")) { 146.317 + throw new Error("Bad boostrap method name"); 146.318 + } 146.319 + 146.320 + if (!bsm_ref.getNameAndTypeInfo().getType().equals(asBSMSignatureString())) { 146.321 + throw new Error("Bad boostrap method type" + bsm_ref.getNameAndTypeInfo().getType() + " " + asBSMSignatureString()); 146.322 + } 146.323 + } catch (Exception e) { 146.324 + e.printStackTrace(); 146.325 + throw new Error("error reading " + compiledTest +": " + e); 146.326 + } 146.327 + } 146.328 + 146.329 + String asBSMSignatureString() { 146.330 + StringBuilder buf = new StringBuilder(); 146.331 + buf.append("(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;"); 146.332 + for (StaticArgumentKind sak : saks) { 146.333 + buf.append(sak.bytecodeTypeStr); 146.334 + } 146.335 + buf.append(")Ljava/lang/invoke/CallSite;"); 146.336 + return buf.toString(); 146.337 + } 146.338 + 146.339 + class JavaSource extends SimpleJavaFileObject { 146.340 + 146.341 + static final String source_template = "import java.lang.invoke.*;\n" + 146.342 + "class Bootstrap {\n" + 146.343 + " public static CallSite bsm(MethodHandles.Lookup lookup, String name, MethodType methodType #SARGS) {\n" + 146.344 + " return null;\n" + 146.345 + " }\n" + 146.346 + "}\n" + 146.347 + "class Test {\n" + 146.348 + " void m() { }\n" + 146.349 + " void test() { m(); }\n" + 146.350 + "}"; 146.351 + 146.352 + String source; 146.353 + 146.354 + JavaSource() { 146.355 + super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE); 146.356 + source = source_template.replace("#SARGS", asSignatureString()); 146.357 + } 146.358 + 146.359 + @Override 146.360 + public CharSequence getCharContent(boolean ignoreEncodingErrors) { 146.361 + return source; 146.362 + } 146.363 + 146.364 + String asSignatureString() { 146.365 + int count = 0; 146.366 + StringBuilder buf = new StringBuilder(); 146.367 + for (StaticArgumentKind sak : saks) { 146.368 + buf.append(","); 146.369 + buf.append(sak.sourceTypeStr); 146.370 + buf.append(' '); 146.371 + buf.append(String.format("x%d", count++)); 146.372 + } 146.373 + return buf.toString(); 146.374 + } 146.375 + } 146.376 + 146.377 + class Indifier extends TreeScanner<Void, Void> implements TaskListener { 146.378 + 146.379 + MethodSymbol bsm; 146.380 + Symtab syms; 146.381 + Names names; 146.382 + 146.383 + Indifier(Symtab syms, Names names) { 146.384 + this.syms = syms; 146.385 + this.names = names; 146.386 + } 146.387 + 146.388 + @Override 146.389 + public void started(TaskEvent e) { 146.390 + //do nothing 146.391 + } 146.392 + 146.393 + @Override 146.394 + public void finished(TaskEvent e) { 146.395 + if (e.getKind() == TaskEvent.Kind.ANALYZE) { 146.396 + scan(e.getCompilationUnit(), null); 146.397 + } 146.398 + } 146.399 + 146.400 + @Override 146.401 + public Void visitMethodInvocation(MethodInvocationTree node, Void p) { 146.402 + super.visitMethodInvocation(node, p); 146.403 + JCMethodInvocation apply = (JCMethodInvocation)node; 146.404 + JCIdent ident = (JCIdent)apply.meth; 146.405 + Symbol oldSym = ident.sym; 146.406 + if (!oldSym.isConstructor()) { 146.407 + Object[] staticArgs = new Object[arity.arity]; 146.408 + for (int i = 0; i < arity.arity ; i++) { 146.409 + staticArgs[i] = saks[i].getValue(syms, names); 146.410 + } 146.411 + ident.sym = new Symbol.DynamicMethodSymbol(oldSym.name, oldSym.owner, REF_invokeStatic, bsm, oldSym.type, staticArgs); 146.412 + } 146.413 + return null; 146.414 + } 146.415 + 146.416 + @Override 146.417 + public Void visitMethod(MethodTree node, Void p) { 146.418 + super.visitMethod(node, p); 146.419 + if (node.getName().toString().equals("bsm")) { 146.420 + bsm = ((JCMethodDecl)node).sym; 146.421 + } 146.422 + return null; 146.423 + } 146.424 + } 146.425 + 146.426 + static class DiagChecker implements javax.tools.DiagnosticListener<JavaFileObject> { 146.427 + 146.428 + boolean diagFound; 146.429 + ArrayList<String> diags = new ArrayList<>(); 146.430 + 146.431 + public void report(Diagnostic<? extends JavaFileObject> diagnostic) { 146.432 + diags.add(diagnostic.getMessage(Locale.getDefault())); 146.433 + diagFound = true; 146.434 + } 146.435 + 146.436 + String printDiags() { 146.437 + StringBuilder buf = new StringBuilder(); 146.438 + for (String s : diags) { 146.439 + buf.append(s); 146.440 + buf.append("\n"); 146.441 + } 146.442 + return buf.toString(); 146.443 + } 146.444 + } 146.445 +}
147.1 --- a/test/tools/javac/positions/T6264029.out Thu Oct 11 09:50:52 2012 -0700 147.2 +++ b/test/tools/javac/positions/T6264029.out Thu Oct 11 17:00:54 2012 -0700 147.3 @@ -1,3 +1,2 @@ 147.4 -T6264029.java:15:19: compiler.warn.unchecked.call.mbr.of.raw.type: T6264029A(K), T6264029A 147.5 T6264029.java:15:41: compiler.warn.unchecked.call.mbr.of.raw.type: T6264029A(K), T6264029A 147.6 -2 warnings 147.7 +1 warning
148.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 148.2 +++ b/test/tools/javac/processing/T7196462.java Thu Oct 11 17:00:54 2012 -0700 148.3 @@ -0,0 +1,44 @@ 148.4 +/* 148.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 148.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 148.7 + * 148.8 + * This code is free software; you can redistribute it and/or modify it 148.9 + * under the terms of the GNU General Public License version 2 only, as 148.10 + * published by the Free Software Foundation. 148.11 + * 148.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 148.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 148.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 148.15 + * version 2 for more details (a copy is included in the LICENSE file that 148.16 + * accompanied this code). 148.17 + * 148.18 + * You should have received a copy of the GNU General Public License version 148.19 + * 2 along with this work; if not, write to the Free Software Foundation, 148.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 148.21 + * 148.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 148.23 + * or visit www.oracle.com if you need additional information or have any 148.24 + * questions. 148.25 + */ 148.26 + 148.27 +/* 148.28 + * @test 148.29 + * @bug 7196462 148.30 + * @summary JavacProcessingEnvironment should tolerate BasicJavacTask 148.31 + * @library ../lib 148.32 + * @build JavacTestingAbstractProcessor T7196462 148.33 + * @compile/process -processor T7196462 T7196462.java 148.34 + */ 148.35 + 148.36 +import java.util.*; 148.37 +import javax.annotation.processing.*; 148.38 +import javax.lang.model.element.*; 148.39 +import com.sun.source.util.*; 148.40 + 148.41 +public class T7196462 extends JavacTestingAbstractProcessor { 148.42 + public boolean process(Set<? extends TypeElement> annos,RoundEnvironment rEnv) { 148.43 + JavacTask t = JavacTask.instance(processingEnv); 148.44 + System.err.println(t); 148.45 + return true; 148.46 + } 148.47 +}
149.1 --- a/test/tools/javac/quid/T6999438.out Thu Oct 11 09:50:52 2012 -0700 149.2 +++ b/test/tools/javac/quid/T6999438.out Thu Oct 11 17:00:54 2012 -0700 149.3 @@ -1,4 +1,4 @@ 149.4 -T6999438.java:8:8: compiler.err.expected: token.identifier 149.5 +T6999438.java:8:9: compiler.err.illegal.char: 35 149.6 T6999438.java:8:10: compiler.err.illegal.start.of.type 149.7 T6999438.java:8:25: compiler.err.expected: token.identifier 149.8 T6999438.java:8:26: compiler.err.expected: ';'
150.1 --- a/test/tools/javac/typeAnnotations/newlocations/BasicTest.out Thu Oct 11 09:50:52 2012 -0700 150.2 +++ b/test/tools/javac/typeAnnotations/newlocations/BasicTest.out Thu Oct 11 17:00:54 2012 -0700 150.3 @@ -9,13 +9,9 @@ 150.4 BasicTest.java:52:22: compiler.err.illegal.start.of.expr 150.5 BasicTest.java:52:31: compiler.err.expected: ';' 150.6 BasicTest.java:52:37: compiler.err.expected: token.identifier 150.7 -BasicTest.java:53:21: compiler.err.illegal.start.of.expr 150.8 -BasicTest.java:53:23: compiler.err.expected: ';' 150.9 BasicTest.java:53:30: compiler.err.expected: token.identifier 150.10 -BasicTest.java:53:32: compiler.err.illegal.start.of.type 150.11 -BasicTest.java:53:37: compiler.err.expected: token.identifier 150.12 -BasicTest.java:53:38: compiler.err.expected: ';' 150.13 -BasicTest.java:56:17: compiler.err.expected: token.identifier 150.14 +BasicTest.java:53:32: compiler.err.lambda.not.supported.in.source: 1.8 150.15 +BasicTest.java:53:31: compiler.err.expected: -> 150.16 BasicTest.java:56:23: compiler.err.expected: token.identifier 150.17 BasicTest.java:56:24: compiler.err.expected2: '(', '[' 150.18 BasicTest.java:56:25: compiler.err.expected: ';' 150.19 @@ -63,4 +59,4 @@ 150.20 BasicTest.java:74:25: compiler.err.illegal.start.of.type 150.21 BasicTest.java:74:33: compiler.err.expected: ';' 150.22 BasicTest.java:77:2: compiler.err.premature.eof 150.23 -65 errors 150.24 +61 errors
151.1 --- a/test/tools/javac/varargs/6313164/T6313164.out Thu Oct 11 09:50:52 2012 -0700 151.2 +++ b/test/tools/javac/varargs/6313164/T6313164.out Thu Oct 11 17:00:54 2012 -0700 151.3 @@ -1,4 +1,4 @@ 151.4 -T6313164.java:12:8: compiler.err.cant.apply.symbol.1: kindname.method, foo1, p1.A[], p1.B,p1.B, kindname.class, p1.B, (compiler.misc.inaccessible.varargs.type: p1.A, kindname.class, T6313164) 151.5 +T6313164.java:12:8: compiler.err.cant.apply.symbol: kindname.method, foo1, p1.A[], p1.B,p1.B, kindname.class, p1.B, (compiler.misc.inaccessible.varargs.type: p1.A, kindname.class, T6313164) 151.6 T6313164.java:14:13: compiler.err.prob.found.req: (compiler.misc.inaccessible.varargs.type: p1.A, kindname.class, T6313164) 151.7 T6313164.java:15:13: compiler.err.prob.found.req: (compiler.misc.inaccessible.varargs.type: p1.A, kindname.class, T6313164) 151.8 - compiler.note.unchecked.filename: B.java
152.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 152.2 +++ b/test/tools/javac/varargs/6313164/T7175433.java Thu Oct 11 17:00:54 2012 -0700 152.3 @@ -0,0 +1,59 @@ 152.4 +/* 152.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 152.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 152.7 + * 152.8 + * This code is free software; you can redistribute it and/or modify it 152.9 + * under the terms of the GNU General Public License version 2 only, as 152.10 + * published by the Free Software Foundation. 152.11 + * 152.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 152.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 152.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 152.15 + * version 2 for more details (a copy is included in the LICENSE file that 152.16 + * accompanied this code). 152.17 + * 152.18 + * You should have received a copy of the GNU General Public License version 152.19 + * 2 along with this work; if not, write to the Free Software Foundation, 152.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 152.21 + * 152.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 152.23 + * or visit www.oracle.com if you need additional information or have any 152.24 + * questions. 152.25 + */ 152.26 + 152.27 +/* 152.28 + * @test 152.29 + * @bug 7175433 6313164 152.30 + * @summary Inference cleanup: add helper class to handle inference variables 152.31 + * 152.32 + */ 152.33 + 152.34 +import java.util.List; 152.35 + 152.36 +class Bar { 152.37 + 152.38 + private class Foo { } 152.39 + 152.40 + <Z> List<Z> m(Object... o) { T7175433.assertTrue(true); return null; } 152.41 + <Z> List<Z> m(Foo... o) { T7175433.assertTrue(false); return null; } 152.42 + 152.43 + Foo getFoo() { return null; } 152.44 +} 152.45 + 152.46 +public class T7175433 { 152.47 + 152.48 + static int assertionCount; 152.49 + 152.50 + static void assertTrue(boolean b) { 152.51 + assertionCount++; 152.52 + if (!b) { 152.53 + throw new AssertionError(); 152.54 + } 152.55 + } 152.56 + 152.57 + public static void main(String[] args) { 152.58 + Bar b = new Bar(); 152.59 + b.m(b.getFoo()); 152.60 + assertTrue(assertionCount == 1); 152.61 + } 152.62 +}
153.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 153.2 +++ b/test/tools/javadoc/T4696488.java Thu Oct 11 17:00:54 2012 -0700 153.3 @@ -0,0 +1,56 @@ 153.4 +/* 153.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 153.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 153.7 + * 153.8 + * This code is free software; you can redistribute it and/or modify it 153.9 + * under the terms of the GNU General Public License version 2 only, as 153.10 + * published by the Free Software Foundation. 153.11 + * 153.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 153.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 153.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 153.15 + * version 2 for more details (a copy is included in the LICENSE file that 153.16 + * accompanied this code). 153.17 + * 153.18 + * You should have received a copy of the GNU General Public License version 153.19 + * 2 along with this work; if not, write to the Free Software Foundation, 153.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 153.21 + * 153.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 153.23 + * or visit www.oracle.com if you need additional information or have any 153.24 + * questions. 153.25 + */ 153.26 + 153.27 +import com.sun.tools.doclets.internal.toolkit.Configuration; 153.28 + 153.29 +/** 153.30 + * @test 153.31 + * @bug 4696488 153.32 + * @summary javadoc doesn't handle UNC paths for destination directory 153.33 + * @author Jesse Glick 153.34 + * @run main T4696488 T4696488.java 153.35 + */ 153.36 +public class T4696488 { 153.37 + 153.38 + public static void main(String... args) { 153.39 + System.setProperty("file.separator", "/"); 153.40 + assertAddTrailingFileSep("/path/to/dir", "/path/to/dir/"); 153.41 + assertAddTrailingFileSep("/path/to/dir/", "/path/to/dir/"); 153.42 + assertAddTrailingFileSep("/path/to/dir//", "/path/to/dir/"); 153.43 + System.setProperty("file.separator", "\\"); 153.44 + assertAddTrailingFileSep("C:\\path\\to\\dir", "C:\\path\\to\\dir\\"); 153.45 + assertAddTrailingFileSep("C:\\path\\to\\dir\\", "C:\\path\\to\\dir\\"); 153.46 + assertAddTrailingFileSep("C:\\path\\to\\dir\\\\", "C:\\path\\to\\dir\\"); 153.47 + assertAddTrailingFileSep("\\\\server\\share\\path\\to\\dir", "\\\\server\\share\\path\\to\\dir\\"); 153.48 + assertAddTrailingFileSep("\\\\server\\share\\path\\to\\dir\\", "\\\\server\\share\\path\\to\\dir\\"); 153.49 + assertAddTrailingFileSep("\\\\server\\share\\path\\to\\dir\\\\", "\\\\server\\share\\path\\to\\dir\\"); 153.50 + } 153.51 + 153.52 + private static void assertAddTrailingFileSep(String input, String expectedOutput) { 153.53 + String output = Configuration.addTrailingFileSep(input); 153.54 + if (!expectedOutput.equals(output)) { 153.55 + throw new Error("expected " + expectedOutput + " but was " + output); 153.56 + } 153.57 + } 153.58 + 153.59 +}