src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java
changeset 59285 7799a51dbe30
parent 59021 cfc7bb9a5a92
equal deleted inserted replaced
59284:88502b1cf76f 59285:7799a51dbe30
    47 import com.sun.tools.javac.code.TypeMetadata.Annotations;
    47 import com.sun.tools.javac.code.TypeMetadata.Annotations;
    48 import com.sun.tools.javac.code.Types.FunctionDescriptorLookupError;
    48 import com.sun.tools.javac.code.Types.FunctionDescriptorLookupError;
    49 import com.sun.tools.javac.comp.ArgumentAttr.LocalCacheContext;
    49 import com.sun.tools.javac.comp.ArgumentAttr.LocalCacheContext;
    50 import com.sun.tools.javac.comp.Check.CheckContext;
    50 import com.sun.tools.javac.comp.Check.CheckContext;
    51 import com.sun.tools.javac.comp.DeferredAttr.AttrMode;
    51 import com.sun.tools.javac.comp.DeferredAttr.AttrMode;
       
    52 import com.sun.tools.javac.comp.MatchBindingsComputer.BindingSymbol;
    52 import com.sun.tools.javac.jvm.*;
    53 import com.sun.tools.javac.jvm.*;
    53 import static com.sun.tools.javac.resources.CompilerProperties.Fragments.Diamond;
    54 import static com.sun.tools.javac.resources.CompilerProperties.Fragments.Diamond;
    54 import static com.sun.tools.javac.resources.CompilerProperties.Fragments.DiamondInvalidArg;
    55 import static com.sun.tools.javac.resources.CompilerProperties.Fragments.DiamondInvalidArg;
    55 import static com.sun.tools.javac.resources.CompilerProperties.Fragments.DiamondInvalidArgs;
    56 import static com.sun.tools.javac.resources.CompilerProperties.Fragments.DiamondInvalidArgs;
    56 import com.sun.tools.javac.resources.CompilerProperties.Errors;
    57 import com.sun.tools.javac.resources.CompilerProperties.Errors;
   108     final TreeMaker make;
   109     final TreeMaker make;
   109     final ConstFold cfolder;
   110     final ConstFold cfolder;
   110     final Enter enter;
   111     final Enter enter;
   111     final Target target;
   112     final Target target;
   112     final Types types;
   113     final Types types;
       
   114     final Preview preview;
   113     final JCDiagnostic.Factory diags;
   115     final JCDiagnostic.Factory diags;
   114     final TypeAnnotations typeAnnotations;
   116     final TypeAnnotations typeAnnotations;
   115     final DeferredLintHandler deferredLintHandler;
   117     final DeferredLintHandler deferredLintHandler;
   116     final TypeEnvs typeEnvs;
   118     final TypeEnvs typeEnvs;
   117     final Dependencies dependencies;
   119     final Dependencies dependencies;
   118     final Annotate annotate;
   120     final Annotate annotate;
   119     final ArgumentAttr argumentAttr;
   121     final ArgumentAttr argumentAttr;
       
   122     final MatchBindingsComputer matchBindingsComputer;
   120 
   123 
   121     public static Attr instance(Context context) {
   124     public static Attr instance(Context context) {
   122         Attr instance = context.get(attrKey);
   125         Attr instance = context.get(attrKey);
   123         if (instance == null)
   126         if (instance == null)
   124             instance = new Attr(context);
   127             instance = new Attr(context);
   143         analyzer = Analyzer.instance(context);
   146         analyzer = Analyzer.instance(context);
   144         deferredAttr = DeferredAttr.instance(context);
   147         deferredAttr = DeferredAttr.instance(context);
   145         cfolder = ConstFold.instance(context);
   148         cfolder = ConstFold.instance(context);
   146         target = Target.instance(context);
   149         target = Target.instance(context);
   147         types = Types.instance(context);
   150         types = Types.instance(context);
       
   151         preview = Preview.instance(context);
   148         diags = JCDiagnostic.Factory.instance(context);
   152         diags = JCDiagnostic.Factory.instance(context);
   149         annotate = Annotate.instance(context);
   153         annotate = Annotate.instance(context);
   150         typeAnnotations = TypeAnnotations.instance(context);
   154         typeAnnotations = TypeAnnotations.instance(context);
   151         deferredLintHandler = DeferredLintHandler.instance(context);
   155         deferredLintHandler = DeferredLintHandler.instance(context);
   152         typeEnvs = TypeEnvs.instance(context);
   156         typeEnvs = TypeEnvs.instance(context);
   153         dependencies = Dependencies.instance(context);
   157         dependencies = Dependencies.instance(context);
   154         argumentAttr = ArgumentAttr.instance(context);
   158         argumentAttr = ArgumentAttr.instance(context);
       
   159         matchBindingsComputer = MatchBindingsComputer.instance(context);
   155 
   160 
   156         Options options = Options.instance(context);
   161         Options options = Options.instance(context);
   157 
   162 
   158         Source source = Source.instance(context);
   163         Source source = Source.instance(context);
   159         allowPoly = Feature.POLY.allowedInSource(source);
   164         allowPoly = Feature.POLY.allowedInSource(source);
   160         allowTypeAnnos = Feature.TYPE_ANNOTATIONS.allowedInSource(source);
   165         allowTypeAnnos = Feature.TYPE_ANNOTATIONS.allowedInSource(source);
   161         allowLambda = Feature.LAMBDA.allowedInSource(source);
   166         allowLambda = Feature.LAMBDA.allowedInSource(source);
   162         allowDefaultMethods = Feature.DEFAULT_METHODS.allowedInSource(source);
   167         allowDefaultMethods = Feature.DEFAULT_METHODS.allowedInSource(source);
   163         allowStaticInterfaceMethods = Feature.STATIC_INTERFACE_METHODS.allowedInSource(source);
   168         allowStaticInterfaceMethods = Feature.STATIC_INTERFACE_METHODS.allowedInSource(source);
       
   169         allowReifiableTypesInInstanceof =
       
   170                 Feature.REIFIABLE_TYPES_INSTANCEOF.allowedInSource(source) &&
       
   171                 (!preview.isPreview(Feature.REIFIABLE_TYPES_INSTANCEOF) || preview.isEnabled());
   164         sourceName = source.name;
   172         sourceName = source.name;
   165         useBeforeDeclarationWarning = options.isSet("useBeforeDeclarationWarning");
   173         useBeforeDeclarationWarning = options.isSet("useBeforeDeclarationWarning");
   166 
   174 
   167         statInfo = new ResultInfo(KindSelector.NIL, Type.noType);
   175         statInfo = new ResultInfo(KindSelector.NIL, Type.noType);
   168         varAssignmentInfo = new ResultInfo(KindSelector.ASG, Type.noType);
   176         varAssignmentInfo = new ResultInfo(KindSelector.ASG, Type.noType);
   190     boolean allowDefaultMethods;
   198     boolean allowDefaultMethods;
   191 
   199 
   192     /** Switch: static interface methods enabled?
   200     /** Switch: static interface methods enabled?
   193      */
   201      */
   194     boolean allowStaticInterfaceMethods;
   202     boolean allowStaticInterfaceMethods;
       
   203 
       
   204     /** Switch: reifiable types in instanceof enabled?
       
   205      */
       
   206     boolean allowReifiableTypesInInstanceof;
   195 
   207 
   196     /**
   208     /**
   197      * Switch: warn about use of variable before declaration?
   209      * Switch: warn about use of variable before declaration?
   198      * RFE: 6425594
   210      * RFE: 6425594
   199      */
   211      */
   290              !((base == null ||
   302              !((base == null ||
   291                TreeInfo.isThisQualifier(base)) &&
   303                TreeInfo.isThisQualifier(base)) &&
   292                isAssignableAsBlankFinal(v, env)))) {
   304                isAssignableAsBlankFinal(v, env)))) {
   293             if (v.isResourceVariable()) { //TWR resource
   305             if (v.isResourceVariable()) { //TWR resource
   294                 log.error(pos, Errors.TryResourceMayNotBeAssigned(v));
   306                 log.error(pos, Errors.TryResourceMayNotBeAssigned(v));
       
   307             } else if ((v.flags() & MATCH_BINDING) != 0) {
       
   308                 log.error(pos, Errors.PatternBindingMayNotBeAssigned(v));
   295             } else {
   309             } else {
   296                 log.error(pos, Errors.CantAssignValToFinalVar(v));
   310                 log.error(pos, Errors.CantAssignValToFinalVar(v));
   297             }
   311             }
   298         }
   312         }
   299     }
   313     }
  1296     }
  1310     }
  1297 
  1311 
  1298     public void visitDoLoop(JCDoWhileLoop tree) {
  1312     public void visitDoLoop(JCDoWhileLoop tree) {
  1299         attribStat(tree.body, env.dup(tree));
  1313         attribStat(tree.body, env.dup(tree));
  1300         attribExpr(tree.cond, env, syms.booleanType);
  1314         attribExpr(tree.cond, env, syms.booleanType);
       
  1315         if (!breaksOutOf(tree, tree.body)) {
       
  1316             //include condition's body when false after the while, if cannot get out of the loop
       
  1317             List<BindingSymbol> bindings = matchBindingsComputer.getMatchBindings(tree.cond, false);
       
  1318 
       
  1319             bindings.forEach(env.info.scope::enter);
       
  1320             bindings.forEach(BindingSymbol::preserveBinding);
       
  1321         }
  1301         result = null;
  1322         result = null;
  1302     }
  1323     }
  1303 
  1324 
  1304     public void visitWhileLoop(JCWhileLoop tree) {
  1325     public void visitWhileLoop(JCWhileLoop tree) {
  1305         attribExpr(tree.cond, env, syms.booleanType);
  1326         attribExpr(tree.cond, env, syms.booleanType);
  1306         attribStat(tree.body, env.dup(tree));
  1327         // include condition's bindings when true in the body:
       
  1328         Env<AttrContext> whileEnv = bindingEnv(env, matchBindingsComputer.getMatchBindings(tree.cond, true));
       
  1329         try {
       
  1330             attribStat(tree.body, whileEnv.dup(tree));
       
  1331         } finally {
       
  1332             whileEnv.info.scope.leave();
       
  1333         }
       
  1334         if (!breaksOutOf(tree, tree.body)) {
       
  1335             //include condition's bindings when false after the while, if cannot get out of the loop
       
  1336             List<BindingSymbol> bindings =
       
  1337                     matchBindingsComputer.getMatchBindings(tree.cond, false);
       
  1338 
       
  1339             bindings.forEach(env.info.scope::enter);
       
  1340             bindings.forEach(BindingSymbol::preserveBinding);
       
  1341         }
  1307         result = null;
  1342         result = null;
       
  1343     }
       
  1344 
       
  1345     private boolean breaksOutOf(JCTree loop, JCTree body) {
       
  1346         preFlow(body);
       
  1347         return flow.breaksOutOf(env, loop, body, make);
  1308     }
  1348     }
  1309 
  1349 
  1310     public void visitForLoop(JCForLoop tree) {
  1350     public void visitForLoop(JCForLoop tree) {
  1311         Env<AttrContext> loopEnv =
  1351         Env<AttrContext> loopEnv =
  1312             env.dup(env.tree, env.info.dup(env.info.scope.dup()));
  1352             env.dup(env.tree, env.info.dup(env.info.scope.dup()));
  1313         try {
  1353         try {
  1314             attribStats(tree.init, loopEnv);
  1354             attribStats(tree.init, loopEnv);
  1315             if (tree.cond != null) attribExpr(tree.cond, loopEnv, syms.booleanType);
  1355             List<BindingSymbol> matchBindings = List.nil();
  1316             loopEnv.tree = tree; // before, we were not in loop!
  1356             if (tree.cond != null) {
  1317             attribStats(tree.step, loopEnv);
  1357                 attribExpr(tree.cond, loopEnv, syms.booleanType);
  1318             attribStat(tree.body, loopEnv);
  1358                 // include condition's bindings when true in the body and step:
       
  1359                 matchBindings = matchBindingsComputer.getMatchBindings(tree.cond, true);
       
  1360             }
       
  1361             Env<AttrContext> bodyEnv = bindingEnv(loopEnv, matchBindings);
       
  1362             try {
       
  1363                 bodyEnv.tree = tree; // before, we were not in loop!
       
  1364                 attribStats(tree.step, bodyEnv);
       
  1365                 attribStat(tree.body, bodyEnv);
       
  1366             } finally {
       
  1367                 bodyEnv.info.scope.leave();
       
  1368             }
  1319             result = null;
  1369             result = null;
  1320         }
  1370         }
  1321         finally {
  1371         finally {
  1322             loopEnv.info.scope.leave();
  1372             loopEnv.info.scope.leave();
       
  1373         }
       
  1374         if (!breaksOutOf(tree, tree.body)) {
       
  1375             //include condition's body when false after the while, if cannot get out of the loop
       
  1376             List<BindingSymbol> bindings =
       
  1377                     matchBindingsComputer.getMatchBindings(tree.cond, false);
       
  1378 
       
  1379             bindings.forEach(env.info.scope::enter);
       
  1380             bindings.forEach(BindingSymbol::preserveBinding);
  1323         }
  1381         }
  1324     }
  1382     }
  1325 
  1383 
  1326     public void visitForeachLoop(JCEnhancedForLoop tree) {
  1384     public void visitForeachLoop(JCEnhancedForLoop tree) {
  1327         Env<AttrContext> loopEnv =
  1385         Env<AttrContext> loopEnv =
  1671 
  1729 
  1672         ResultInfo condInfo = tree.polyKind == PolyKind.STANDALONE ?
  1730         ResultInfo condInfo = tree.polyKind == PolyKind.STANDALONE ?
  1673                 unknownExprInfo :
  1731                 unknownExprInfo :
  1674                 resultInfo.dup(conditionalContext(resultInfo.checkContext));
  1732                 resultInfo.dup(conditionalContext(resultInfo.checkContext));
  1675 
  1733 
  1676         Type truetype = attribTree(tree.truepart, env, condInfo);
  1734 
  1677         Type falsetype = attribTree(tree.falsepart, env, condInfo);
  1735         // x ? y : z
       
  1736         // include x's bindings when true in y
       
  1737         // include x's bindings when false in z
       
  1738 
       
  1739         Type truetype;
       
  1740         Env<AttrContext> trueEnv = bindingEnv(env, matchBindingsComputer.getMatchBindings(tree.cond, true));
       
  1741         try {
       
  1742             truetype = attribTree(tree.truepart, trueEnv, condInfo);
       
  1743         } finally {
       
  1744             trueEnv.info.scope.leave();
       
  1745         }
       
  1746 
       
  1747         Type falsetype;
       
  1748         Env<AttrContext> falseEnv = bindingEnv(env, matchBindingsComputer.getMatchBindings(tree.cond, false));
       
  1749         try {
       
  1750             falsetype = attribTree(tree.falsepart, falseEnv, condInfo);
       
  1751         } finally {
       
  1752             falseEnv.info.scope.leave();
       
  1753         }
  1678 
  1754 
  1679         Type owntype = (tree.polyKind == PolyKind.STANDALONE) ?
  1755         Type owntype = (tree.polyKind == PolyKind.STANDALONE) ?
  1680                 condType(List.of(tree.truepart.pos(), tree.falsepart.pos()),
  1756                 condType(List.of(tree.truepart.pos(), tree.falsepart.pos()),
  1681                          List.of(truetype, falsetype)) : pt();
  1757                          List.of(truetype, falsetype)) : pt();
  1682         if (condtype.constValue() != null &&
  1758         if (condtype.constValue() != null &&
  1827         FLOAT,
  1903         FLOAT,
  1828         DOUBLE,
  1904         DOUBLE,
  1829         BOOLEAN,
  1905         BOOLEAN,
  1830     };
  1906     };
  1831 
  1907 
       
  1908     Env<AttrContext> bindingEnv(Env<AttrContext> env, List<BindingSymbol> bindings) {
       
  1909         Env<AttrContext> env1 = env.dup(env.tree, env.info.dup(env.info.scope.dup()));
       
  1910         bindings.forEach(env1.info.scope::enter);
       
  1911         return env1;
       
  1912     }
       
  1913 
  1832     public void visitIf(JCIf tree) {
  1914     public void visitIf(JCIf tree) {
  1833         attribExpr(tree.cond, env, syms.booleanType);
  1915         attribExpr(tree.cond, env, syms.booleanType);
  1834         attribStat(tree.thenpart, env);
  1916 
  1835         if (tree.elsepart != null)
  1917         // if (x) { y } [ else z ]
  1836             attribStat(tree.elsepart, env);
  1918         // include x's bindings when true in y
       
  1919         // include x's bindings when false in z
       
  1920 
       
  1921         List<BindingSymbol> thenBindings = matchBindingsComputer.getMatchBindings(tree.cond, true);
       
  1922         Env<AttrContext> thenEnv = bindingEnv(env, thenBindings);
       
  1923 
       
  1924         try {
       
  1925             attribStat(tree.thenpart, thenEnv);
       
  1926         } finally {
       
  1927             thenEnv.info.scope.leave();
       
  1928         }
       
  1929 
       
  1930         preFlow(tree.thenpart);
       
  1931         boolean aliveAfterThen = flow.aliveAfter(env, tree.thenpart, make);
       
  1932         boolean aliveAfterElse;
       
  1933         List<BindingSymbol> elseBindings = matchBindingsComputer.getMatchBindings(tree.cond, false);
       
  1934 
       
  1935         if (tree.elsepart != null) {
       
  1936             Env<AttrContext> elseEnv = bindingEnv(env, elseBindings);
       
  1937             try {
       
  1938                 attribStat(tree.elsepart, elseEnv);
       
  1939             } finally {
       
  1940                 elseEnv.info.scope.leave();
       
  1941             }
       
  1942             preFlow(tree.elsepart);
       
  1943             aliveAfterElse = flow.aliveAfter(env, tree.elsepart, make);
       
  1944         } else {
       
  1945             aliveAfterElse = true;
       
  1946         }
       
  1947 
  1837         chk.checkEmptyIf(tree);
  1948         chk.checkEmptyIf(tree);
       
  1949 
       
  1950         List<BindingSymbol> afterIfBindings = List.nil();
       
  1951 
       
  1952         if (aliveAfterThen && !aliveAfterElse) {
       
  1953             afterIfBindings = thenBindings;
       
  1954         } else if (aliveAfterElse && !aliveAfterThen) {
       
  1955             afterIfBindings = elseBindings;
       
  1956         }
       
  1957 
       
  1958         afterIfBindings.forEach(env.info.scope::enter);
       
  1959         afterIfBindings.forEach(BindingSymbol::preserveBinding);
       
  1960 
  1838         result = null;
  1961         result = null;
  1839     }
  1962     }
       
  1963 
       
  1964         void preFlow(JCTree tree) {
       
  1965             new PostAttrAnalyzer() {
       
  1966                 @Override
       
  1967                 public void scan(JCTree tree) {
       
  1968                     if (tree == null ||
       
  1969                             (tree.type != null &&
       
  1970                             tree.type == Type.stuckType)) {
       
  1971                         //don't touch stuck expressions!
       
  1972                         return;
       
  1973                     }
       
  1974                     super.scan(tree);
       
  1975                 }
       
  1976             }.scan(tree);
       
  1977         }
  1840 
  1978 
  1841     public void visitExec(JCExpressionStatement tree) {
  1979     public void visitExec(JCExpressionStatement tree) {
  1842         //a fresh environment is required for 292 inference to work properly ---
  1980         //a fresh environment is required for 292 inference to work properly ---
  1843         //see Infer.instantiatePolymorphicSignatureInstance()
  1981         //see Infer.instantiatePolymorphicSignatureInstance()
  1844         Env<AttrContext> localEnv = env.dup(tree);
  1982         Env<AttrContext> localEnv = env.dup(tree);
  3519     }
  3657     }
  3520 
  3658 
  3521     public void visitBinary(JCBinary tree) {
  3659     public void visitBinary(JCBinary tree) {
  3522         // Attribute arguments.
  3660         // Attribute arguments.
  3523         Type left = chk.checkNonVoid(tree.lhs.pos(), attribExpr(tree.lhs, env));
  3661         Type left = chk.checkNonVoid(tree.lhs.pos(), attribExpr(tree.lhs, env));
  3524         Type right = chk.checkNonVoid(tree.rhs.pos(), attribExpr(tree.rhs, env));
  3662         // x && y
       
  3663         // include x's bindings when true in y
       
  3664 
       
  3665         // x || y
       
  3666         // include x's bindings when false in y
       
  3667 
       
  3668         List<BindingSymbol> matchBindings;
       
  3669         switch (tree.getTag()) {
       
  3670             case AND:
       
  3671                 matchBindings = matchBindingsComputer.getMatchBindings(tree.lhs, true);
       
  3672                 break;
       
  3673             case OR:
       
  3674                 matchBindings = matchBindingsComputer.getMatchBindings(tree.lhs, false);
       
  3675                 break;
       
  3676             default:
       
  3677                 matchBindings = List.nil();
       
  3678                 break;
       
  3679         }
       
  3680         Env<AttrContext> rhsEnv = bindingEnv(env, matchBindings);
       
  3681         Type right;
       
  3682         try {
       
  3683             right = chk.checkNonVoid(tree.rhs.pos(), attribExpr(tree.rhs, rhsEnv));
       
  3684         } finally {
       
  3685             rhsEnv.info.scope.leave();
       
  3686         }
       
  3687 
  3525         // Find operator.
  3688         // Find operator.
  3526         Symbol operator = tree.operator = operators.resolveBinary(tree, tree.getTag(), left, right);
  3689         Symbol operator = tree.operator = operators.resolveBinary(tree, tree.getTag(), left, right);
  3527         Type owntype = types.createErrorType(tree.type);
  3690         Type owntype = types.createErrorType(tree.type);
  3528         if (operator != operators.noOpSymbol &&
  3691         if (operator != operators.noOpSymbol &&
  3529                 !left.isErroneous() &&
  3692                 !left.isErroneous() &&
  3585     }
  3748     }
  3586 
  3749 
  3587     public void visitTypeTest(JCInstanceOf tree) {
  3750     public void visitTypeTest(JCInstanceOf tree) {
  3588         Type exprtype = chk.checkNullOrRefType(
  3751         Type exprtype = chk.checkNullOrRefType(
  3589                 tree.expr.pos(), attribExpr(tree.expr, env));
  3752                 tree.expr.pos(), attribExpr(tree.expr, env));
  3590         Type clazztype = attribType(tree.clazz, env);
  3753         Type clazztype;
       
  3754         JCTree typeTree;
       
  3755         if (tree.pattern.getTag() == BINDINGPATTERN) {
       
  3756             attribTree(tree.pattern, env, unknownExprInfo);
       
  3757             clazztype = tree.pattern.type;
       
  3758             JCBindingPattern pattern = (JCBindingPattern) tree.pattern;
       
  3759             typeTree = pattern.vartype;
       
  3760             if (!clazztype.hasTag(TYPEVAR)) {
       
  3761                 clazztype = chk.checkClassOrArrayType(pattern.vartype.pos(), clazztype);
       
  3762             }
       
  3763         } else {
       
  3764             clazztype = attribType(tree.pattern, env);
       
  3765             typeTree = tree.pattern;
       
  3766         }
  3591         if (!clazztype.hasTag(TYPEVAR)) {
  3767         if (!clazztype.hasTag(TYPEVAR)) {
  3592             clazztype = chk.checkClassOrArrayType(tree.clazz.pos(), clazztype);
  3768             clazztype = chk.checkClassOrArrayType(typeTree.pos(), clazztype);
  3593         }
  3769         }
  3594         if (!clazztype.isErroneous() && !types.isReifiable(clazztype)) {
  3770         if (!clazztype.isErroneous() && !types.isReifiable(clazztype)) {
  3595             log.error(tree.clazz.pos(), Errors.IllegalGenericTypeForInstof);
  3771             boolean valid = false;
  3596             clazztype = types.createErrorType(clazztype);
  3772             if (allowReifiableTypesInInstanceof) {
  3597         }
  3773                 if (preview.isPreview(Feature.REIFIABLE_TYPES_INSTANCEOF)) {
  3598         chk.validate(tree.clazz, env, false);
  3774                     preview.warnPreview(tree.expr.pos(), Feature.REIFIABLE_TYPES_INSTANCEOF);
       
  3775                 }
       
  3776                 Warner warner = new Warner();
       
  3777                 if (!types.isCastable(exprtype, clazztype, warner)) {
       
  3778                     chk.basicHandler.report(tree.expr.pos(),
       
  3779                                             diags.fragment(Fragments.InconvertibleTypes(exprtype, clazztype)));
       
  3780                 } else if (warner.hasLint(LintCategory.UNCHECKED)) {
       
  3781                     log.error(tree.expr.pos(),
       
  3782                               Errors.InstanceofReifiableNotSafe(exprtype, clazztype));
       
  3783                 } else {
       
  3784                     valid = true;
       
  3785                 }
       
  3786             } else {
       
  3787                 log.error(typeTree.pos(), Errors.IllegalGenericTypeForInstof);
       
  3788             }
       
  3789             if (!valid) {
       
  3790                 clazztype = types.createErrorType(clazztype);
       
  3791             }
       
  3792         }
       
  3793         chk.validate(typeTree, env, false);
  3599         chk.checkCastable(tree.expr.pos(), exprtype, clazztype);
  3794         chk.checkCastable(tree.expr.pos(), exprtype, clazztype);
  3600         result = check(tree, syms.booleanType, KindSelector.VAL, resultInfo);
  3795         result = check(tree, syms.booleanType, KindSelector.VAL, resultInfo);
       
  3796     }
       
  3797 
       
  3798     public void visitBindingPattern(JCBindingPattern tree) {
       
  3799         ResultInfo varInfo = new ResultInfo(KindSelector.TYP, resultInfo.pt, resultInfo.checkContext);
       
  3800         tree.type = attribTree(tree.vartype, env, varInfo);
       
  3801         VarSymbol v = tree.symbol = new BindingSymbol(tree.name, tree.vartype.type, env.info.scope.owner);
       
  3802         if (chk.checkUnique(tree.pos(), v, env.info.scope)) {
       
  3803             chk.checkTransparentVar(tree.pos(), v, env.info.scope);
       
  3804         }
       
  3805         annotate.queueScanTreeAndTypeAnnotate(tree.vartype, env, v, tree.pos());
       
  3806         annotate.flush();
       
  3807         result = tree.type;
  3601     }
  3808     }
  3602 
  3809 
  3603     public void visitIndexed(JCArrayAccess tree) {
  3810     public void visitIndexed(JCArrayAccess tree) {
  3604         Type owntype = types.createErrorType(tree.type);
  3811         Type owntype = types.createErrorType(tree.type);
  3605         Type atype = attribExpr(tree.indexed, env);
  3812         Type atype = attribExpr(tree.indexed, env);
  4989             if (tree.clazz != null && tree.clazz.type != null)
  5196             if (tree.clazz != null && tree.clazz.type != null)
  4990                 validateAnnotatedType(tree.clazz, tree.clazz.type);
  5197                 validateAnnotatedType(tree.clazz, tree.clazz.type);
  4991             super.visitTypeCast(tree);
  5198             super.visitTypeCast(tree);
  4992         }
  5199         }
  4993         public void visitTypeTest(JCInstanceOf tree) {
  5200         public void visitTypeTest(JCInstanceOf tree) {
  4994             if (tree.clazz != null && tree.clazz.type != null)
  5201             if (tree.pattern != null && !(tree.pattern instanceof JCPattern) && tree.pattern.type != null)
  4995                 validateAnnotatedType(tree.clazz, tree.clazz.type);
  5202                 validateAnnotatedType(tree.pattern, tree.pattern.type);
  4996             super.visitTypeTest(tree);
  5203             super.visitTypeTest(tree);
  4997         }
  5204         }
  4998         public void visitNewClass(JCNewClass tree) {
  5205         public void visitNewClass(JCNewClass tree) {
  4999             if (tree.clazz != null && tree.clazz.type != null) {
  5206             if (tree.clazz != null && tree.clazz.type != null) {
  5000                 if (tree.clazz.hasTag(ANNOTATED_TYPE)) {
  5207                 if (tree.clazz.hasTag(ANNOTATED_TYPE)) {
  5251             }
  5458             }
  5252             super.visitVarDef(that);
  5459             super.visitVarDef(that);
  5253         }
  5460         }
  5254 
  5461 
  5255         @Override
  5462         @Override
       
  5463         public void visitBindingPattern(JCBindingPattern that) {
       
  5464             if (that.symbol == null) {
       
  5465                 that.symbol = new BindingSymbol(that.name, that.type, syms.noSymbol);
       
  5466                 that.symbol.adr = 0;
       
  5467             }
       
  5468             super.visitBindingPattern(that);
       
  5469         }
       
  5470 
       
  5471         @Override
  5256         public void visitNewClass(JCNewClass that) {
  5472         public void visitNewClass(JCNewClass that) {
  5257             if (that.constructor == null) {
  5473             if (that.constructor == null) {
  5258                 that.constructor = new MethodSymbol(0, names.init,
  5474                 that.constructor = new MethodSymbol(0, names.init,
  5259                         dummyMethodType(), syms.noSymbol);
  5475                         dummyMethodType(), syms.noSymbol);
  5260             }
  5476             }