Thu, 05 Jan 2017 18:58:06 +0000
8168774: Polymorhic signature method check crashes javac
Summary: Check for polysig method assumes arity is greater than zero
Reviewed-by: vromero
duke@1 | 1 | /* |
vromero@1850 | 2 | * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. |
duke@1 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@1 | 4 | * |
duke@1 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@1 | 6 | * under the terms of the GNU General Public License version 2 only, as |
ohair@554 | 7 | * published by the Free Software Foundation. Oracle designates this |
duke@1 | 8 | * particular file as subject to the "Classpath" exception as provided |
ohair@554 | 9 | * by Oracle in the LICENSE file that accompanied this code. |
duke@1 | 10 | * |
duke@1 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@1 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@1 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@1 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@1 | 15 | * accompanied this code). |
duke@1 | 16 | * |
duke@1 | 17 | * You should have received a copy of the GNU General Public License version |
duke@1 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@1 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@1 | 20 | * |
ohair@554 | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
ohair@554 | 22 | * or visit www.oracle.com if you need additional information or have any |
ohair@554 | 23 | * questions. |
duke@1 | 24 | */ |
duke@1 | 25 | |
duke@1 | 26 | package com.sun.tools.javac.code; |
duke@1 | 27 | |
mcimadamore@80 | 28 | import java.util.EnumSet; |
mcimadamore@136 | 29 | import java.util.Locale; |
mcimadamore@80 | 30 | |
mcimadamore@1352 | 31 | import com.sun.source.tree.MemberReferenceTree; |
mcimadamore@80 | 32 | import com.sun.tools.javac.api.Formattable; |
mcimadamore@136 | 33 | import com.sun.tools.javac.api.Messages; |
jjg@1357 | 34 | import static com.sun.tools.javac.code.Flags.*; |
jjg@1374 | 35 | import static com.sun.tools.javac.code.TypeTag.CLASS; |
jjg@1374 | 36 | import static com.sun.tools.javac.code.TypeTag.PACKAGE; |
jjg@1374 | 37 | import static com.sun.tools.javac.code.TypeTag.TYPEVAR; |
duke@1 | 38 | |
duke@1 | 39 | /** Internal symbol kinds, which distinguish between elements of |
duke@1 | 40 | * different subclasses of Symbol. Symbol kinds are organized so they can be |
duke@1 | 41 | * or'ed to sets. |
duke@1 | 42 | * |
jjg@581 | 43 | * <p><b>This is NOT part of any supported API. |
jjg@581 | 44 | * If you write code that depends on this, you do so at your own risk. |
duke@1 | 45 | * This code and its internal interfaces are subject to change or |
duke@1 | 46 | * deletion without notice.</b> |
duke@1 | 47 | */ |
duke@1 | 48 | public class Kinds { |
duke@1 | 49 | |
duke@1 | 50 | private Kinds() {} // uninstantiable |
duke@1 | 51 | |
duke@1 | 52 | /** The empty set of kinds. |
duke@1 | 53 | */ |
duke@1 | 54 | public final static int NIL = 0; |
duke@1 | 55 | |
duke@1 | 56 | /** The kind of package symbols. |
duke@1 | 57 | */ |
duke@1 | 58 | public final static int PCK = 1 << 0; |
duke@1 | 59 | |
duke@1 | 60 | /** The kind of type symbols (classes, interfaces and type variables). |
duke@1 | 61 | */ |
duke@1 | 62 | public final static int TYP = 1 << 1; |
duke@1 | 63 | |
duke@1 | 64 | /** The kind of variable symbols. |
duke@1 | 65 | */ |
duke@1 | 66 | public final static int VAR = 1 << 2; |
duke@1 | 67 | |
duke@1 | 68 | /** The kind of values (variables or non-variable expressions), includes VAR. |
duke@1 | 69 | */ |
duke@1 | 70 | public final static int VAL = (1 << 3) | VAR; |
duke@1 | 71 | |
duke@1 | 72 | /** The kind of methods. |
duke@1 | 73 | */ |
duke@1 | 74 | public final static int MTH = 1 << 4; |
duke@1 | 75 | |
vromero@1850 | 76 | /** Poly kind, for deferred types. |
vromero@1850 | 77 | */ |
vromero@1850 | 78 | public final static int POLY = 1 << 5; |
vromero@1850 | 79 | |
duke@1 | 80 | /** The error kind, which includes all other kinds. |
duke@1 | 81 | */ |
vromero@1850 | 82 | public final static int ERR = (1 << 6) - 1; |
duke@1 | 83 | |
duke@1 | 84 | /** The set of all kinds. |
duke@1 | 85 | */ |
duke@1 | 86 | public final static int AllKinds = ERR; |
duke@1 | 87 | |
duke@1 | 88 | /** Kinds for erroneous symbols that complement the above |
duke@1 | 89 | */ |
vromero@2193 | 90 | public static final int ERRONEOUS = 1 << 7; |
vromero@2193 | 91 | public static final int AMBIGUOUS = ERRONEOUS + 1; // ambiguous reference |
vromero@2193 | 92 | public static final int HIDDEN = ERRONEOUS + 2; // hidden method or field |
vromero@2193 | 93 | public static final int STATICERR = ERRONEOUS + 3; // nonstatic member from static context |
vromero@2193 | 94 | public static final int MISSING_ENCL = ERRONEOUS + 4; // missing enclosing class |
vromero@2193 | 95 | public static final int ABSENT_VAR = ERRONEOUS + 5; // missing variable |
vromero@2193 | 96 | public static final int WRONG_MTHS = ERRONEOUS + 6; // methods with wrong arguments |
vromero@2193 | 97 | public static final int WRONG_MTH = ERRONEOUS + 7; // one method with wrong arguments |
vromero@2193 | 98 | public static final int ABSENT_MTH = ERRONEOUS + 8; // missing method |
vromero@2193 | 99 | public static final int ABSENT_TYP = ERRONEOUS + 9; // missing type |
vromero@2193 | 100 | public static final int WRONG_STATICNESS = ERRONEOUS + 10; // wrong staticness for method references |
mcimadamore@80 | 101 | |
mcimadamore@80 | 102 | public enum KindName implements Formattable { |
jjg@597 | 103 | ANNOTATION("kindname.annotation"), |
mcimadamore@80 | 104 | CONSTRUCTOR("kindname.constructor"), |
mcimadamore@80 | 105 | INTERFACE("kindname.interface"), |
mcimadamore@302 | 106 | ENUM("kindname.enum"), |
mcimadamore@80 | 107 | STATIC("kindname.static"), |
mcimadamore@80 | 108 | TYPEVAR("kindname.type.variable"), |
mcimadamore@80 | 109 | BOUND("kindname.type.variable.bound"), |
mcimadamore@80 | 110 | VAR("kindname.variable"), |
mcimadamore@80 | 111 | VAL("kindname.value"), |
mcimadamore@80 | 112 | METHOD("kindname.method"), |
mcimadamore@80 | 113 | CLASS("kindname.class"), |
mcimadamore@1085 | 114 | STATIC_INIT("kindname.static.init"), |
mcimadamore@1085 | 115 | INSTANCE_INIT("kindname.instance.init"), |
mcimadamore@80 | 116 | PACKAGE("kindname.package"); |
mcimadamore@80 | 117 | |
vromero@1442 | 118 | private final String name; |
mcimadamore@80 | 119 | |
mcimadamore@80 | 120 | KindName(String name) { |
mcimadamore@80 | 121 | this.name = name; |
mcimadamore@80 | 122 | } |
mcimadamore@80 | 123 | |
mcimadamore@80 | 124 | public String toString() { |
mcimadamore@80 | 125 | return name; |
mcimadamore@80 | 126 | } |
mcimadamore@80 | 127 | |
mcimadamore@80 | 128 | public String getKind() { |
mcimadamore@80 | 129 | return "Kindname"; |
mcimadamore@80 | 130 | } |
mcimadamore@80 | 131 | |
mcimadamore@136 | 132 | public String toString(Locale locale, Messages messages) { |
mcimadamore@80 | 133 | String s = toString(); |
mcimadamore@136 | 134 | return messages.getLocalizedString(locale, "compiler.misc." + s); |
mcimadamore@80 | 135 | } |
mcimadamore@80 | 136 | } |
mcimadamore@80 | 137 | |
mcimadamore@80 | 138 | /** A KindName representing a given symbol kind |
mcimadamore@80 | 139 | */ |
mcimadamore@80 | 140 | public static KindName kindName(int kind) { |
mcimadamore@80 | 141 | switch (kind) { |
mcimadamore@80 | 142 | case PCK: return KindName.PACKAGE; |
mcimadamore@80 | 143 | case TYP: return KindName.CLASS; |
mcimadamore@80 | 144 | case VAR: return KindName.VAR; |
mcimadamore@80 | 145 | case VAL: return KindName.VAL; |
mcimadamore@80 | 146 | case MTH: return KindName.METHOD; |
mcimadamore@80 | 147 | default : throw new AssertionError("Unexpected kind: "+kind); |
mcimadamore@80 | 148 | } |
mcimadamore@80 | 149 | } |
mcimadamore@80 | 150 | |
mcimadamore@1352 | 151 | public static KindName kindName(MemberReferenceTree.ReferenceMode mode) { |
mcimadamore@1352 | 152 | switch (mode) { |
mcimadamore@1352 | 153 | case INVOKE: return KindName.METHOD; |
mcimadamore@1352 | 154 | case NEW: return KindName.CONSTRUCTOR; |
mcimadamore@1352 | 155 | default : throw new AssertionError("Unexpected mode: "+ mode); |
mcimadamore@1352 | 156 | } |
mcimadamore@1352 | 157 | } |
mcimadamore@1352 | 158 | |
mcimadamore@80 | 159 | /** A KindName representing a given symbol |
mcimadamore@80 | 160 | */ |
mcimadamore@80 | 161 | public static KindName kindName(Symbol sym) { |
mcimadamore@80 | 162 | switch (sym.getKind()) { |
mcimadamore@80 | 163 | case PACKAGE: |
mcimadamore@80 | 164 | return KindName.PACKAGE; |
mcimadamore@80 | 165 | |
mcimadamore@80 | 166 | case ENUM: |
mcimadamore@302 | 167 | return KindName.ENUM; |
mcimadamore@302 | 168 | |
mcimadamore@80 | 169 | case ANNOTATION_TYPE: |
mcimadamore@80 | 170 | case CLASS: |
mcimadamore@80 | 171 | return KindName.CLASS; |
mcimadamore@80 | 172 | |
mcimadamore@302 | 173 | case INTERFACE: |
mcimadamore@302 | 174 | return KindName.INTERFACE; |
mcimadamore@302 | 175 | |
mcimadamore@80 | 176 | case TYPE_PARAMETER: |
mcimadamore@80 | 177 | return KindName.TYPEVAR; |
mcimadamore@80 | 178 | |
mcimadamore@80 | 179 | case ENUM_CONSTANT: |
mcimadamore@80 | 180 | case FIELD: |
mcimadamore@80 | 181 | case PARAMETER: |
mcimadamore@80 | 182 | case LOCAL_VARIABLE: |
mcimadamore@80 | 183 | case EXCEPTION_PARAMETER: |
jjg@899 | 184 | case RESOURCE_VARIABLE: |
mcimadamore@80 | 185 | return KindName.VAR; |
mcimadamore@80 | 186 | |
mcimadamore@302 | 187 | case CONSTRUCTOR: |
mcimadamore@302 | 188 | return KindName.CONSTRUCTOR; |
mcimadamore@302 | 189 | |
mcimadamore@80 | 190 | case METHOD: |
mcimadamore@1085 | 191 | return KindName.METHOD; |
mcimadamore@80 | 192 | case STATIC_INIT: |
mcimadamore@1085 | 193 | return KindName.STATIC_INIT; |
mcimadamore@80 | 194 | case INSTANCE_INIT: |
mcimadamore@1085 | 195 | return KindName.INSTANCE_INIT; |
mcimadamore@80 | 196 | |
mcimadamore@80 | 197 | default: |
mcimadamore@80 | 198 | if (sym.kind == VAL) |
mcimadamore@80 | 199 | // I don't think this can happen but it can't harm |
mcimadamore@80 | 200 | // playing it safe --ahe |
mcimadamore@80 | 201 | return KindName.VAL; |
mcimadamore@80 | 202 | else |
mcimadamore@80 | 203 | throw new AssertionError("Unexpected kind: "+sym.getKind()); |
mcimadamore@80 | 204 | } |
mcimadamore@80 | 205 | } |
mcimadamore@80 | 206 | |
mcimadamore@80 | 207 | /** A set of KindName(s) representing a set of symbol's kinds. |
mcimadamore@80 | 208 | */ |
mcimadamore@80 | 209 | public static EnumSet<KindName> kindNames(int kind) { |
mcimadamore@80 | 210 | EnumSet<KindName> kinds = EnumSet.noneOf(KindName.class); |
mcimadamore@80 | 211 | if ((kind & VAL) != 0) |
mcimadamore@80 | 212 | kinds.add(((kind & VAL) == VAR) ? KindName.VAR : KindName.VAL); |
mcimadamore@80 | 213 | if ((kind & MTH) != 0) kinds.add(KindName.METHOD); |
mcimadamore@80 | 214 | if ((kind & TYP) != 0) kinds.add(KindName.CLASS); |
mcimadamore@80 | 215 | if ((kind & PCK) != 0) kinds.add(KindName.PACKAGE); |
mcimadamore@80 | 216 | return kinds; |
mcimadamore@80 | 217 | } |
mcimadamore@80 | 218 | |
mcimadamore@80 | 219 | /** A KindName representing the kind of a given class/interface type. |
mcimadamore@80 | 220 | */ |
mcimadamore@80 | 221 | public static KindName typeKindName(Type t) { |
vromero@1853 | 222 | if (t.hasTag(TYPEVAR) || |
vromero@1853 | 223 | t.hasTag(CLASS) && (t.tsym.flags() & COMPOUND) != 0) |
mcimadamore@80 | 224 | return KindName.BOUND; |
vromero@1853 | 225 | else if (t.hasTag(PACKAGE)) |
mcimadamore@80 | 226 | return KindName.PACKAGE; |
mcimadamore@80 | 227 | else if ((t.tsym.flags_field & ANNOTATION) != 0) |
mcimadamore@80 | 228 | return KindName.ANNOTATION; |
mcimadamore@80 | 229 | else if ((t.tsym.flags_field & INTERFACE) != 0) |
mcimadamore@80 | 230 | return KindName.INTERFACE; |
mcimadamore@80 | 231 | else |
mcimadamore@80 | 232 | return KindName.CLASS; |
mcimadamore@80 | 233 | } |
mcimadamore@80 | 234 | |
vromero@2193 | 235 | /** A KindName representing the kind of a missing symbol, given an |
mcimadamore@80 | 236 | * error kind. |
mcimadamore@80 | 237 | * */ |
mcimadamore@80 | 238 | public static KindName absentKind(int kind) { |
mcimadamore@80 | 239 | switch (kind) { |
mcimadamore@80 | 240 | case ABSENT_VAR: |
mcimadamore@80 | 241 | return KindName.VAR; |
vromero@2193 | 242 | case WRONG_MTHS: case WRONG_MTH: case ABSENT_MTH: case WRONG_STATICNESS: |
mcimadamore@80 | 243 | return KindName.METHOD; |
mcimadamore@80 | 244 | case ABSENT_TYP: |
mcimadamore@80 | 245 | return KindName.CLASS; |
mcimadamore@80 | 246 | default: |
mcimadamore@80 | 247 | throw new AssertionError("Unexpected kind: "+kind); |
mcimadamore@80 | 248 | } |
mcimadamore@80 | 249 | } |
duke@1 | 250 | } |