586 List<Type> typeargtypes, |
586 List<Type> typeargtypes, |
587 Warner warn) { |
587 Warner warn) { |
588 MethodResolutionContext prevContext = currentResolutionContext; |
588 MethodResolutionContext prevContext = currentResolutionContext; |
589 try { |
589 try { |
590 currentResolutionContext = new MethodResolutionContext(); |
590 currentResolutionContext = new MethodResolutionContext(); |
591 currentResolutionContext.attrMode = DeferredAttr.AttrMode.CHECK; |
591 currentResolutionContext.attrMode = (resultInfo.pt == Infer.anyPoly) ? |
|
592 AttrMode.SPECULATIVE : DeferredAttr.AttrMode.CHECK; |
592 if (env.tree.hasTag(JCTree.Tag.REFERENCE)) { |
593 if (env.tree.hasTag(JCTree.Tag.REFERENCE)) { |
593 //method/constructor references need special check class |
594 //method/constructor references need special check class |
594 //to handle inference variables in 'argtypes' (might happen |
595 //to handle inference variables in 'argtypes' (might happen |
595 //during an unsticking round) |
596 //during an unsticking round) |
596 currentResolutionContext.methodCheck = |
597 currentResolutionContext.methodCheck = |
1030 |
1031 |
1031 @Override |
1032 @Override |
1032 protected ResultInfo dup(CheckContext newContext) { |
1033 protected ResultInfo dup(CheckContext newContext) { |
1033 return new MethodResultInfo(pt, newContext); |
1034 return new MethodResultInfo(pt, newContext); |
1034 } |
1035 } |
|
1036 |
|
1037 @Override |
|
1038 protected ResultInfo dup(Type newPt, CheckContext newContext) { |
|
1039 return new MethodResultInfo(newPt, newContext); |
|
1040 } |
1035 } |
1041 } |
1036 |
1042 |
1037 /** |
1043 /** |
1038 * Most specific method applicability routine. Given a list of actual types A, |
1044 * Most specific method applicability routine. Given a list of actual types A, |
1039 * a list of formal types F1, and a list of formal types F2, the routine determines |
1045 * a list of formal types F1, and a list of formal types F2, the routine determines |
1090 public boolean compatible(Type found, Type req, Warner warn) { |
1096 public boolean compatible(Type found, Type req, Warner warn) { |
1091 if (allowFunctionalInterfaceMostSpecific && |
1097 if (allowFunctionalInterfaceMostSpecific && |
1092 unrelatedFunctionalInterfaces(found, req) && |
1098 unrelatedFunctionalInterfaces(found, req) && |
1093 (actual != null && actual.getTag() == DEFERRED)) { |
1099 (actual != null && actual.getTag() == DEFERRED)) { |
1094 DeferredType dt = (DeferredType) actual; |
1100 DeferredType dt = (DeferredType) actual; |
1095 DeferredType.SpeculativeCache.Entry e = |
1101 JCTree speculativeTree = dt.speculativeTree(deferredAttrContext); |
1096 dt.speculativeCache.get(deferredAttrContext.msym, deferredAttrContext.phase); |
1102 if (speculativeTree != deferredAttr.stuckTree) { |
1097 if (e != null && e.speculativeTree != deferredAttr.stuckTree) { |
1103 return functionalInterfaceMostSpecific(found, req, speculativeTree); |
1098 return functionalInterfaceMostSpecific(found, req, e.speculativeTree); |
|
1099 } |
1104 } |
1100 } |
1105 } |
1101 return compatibleBySubtyping(found, req); |
1106 return compatibleBySubtyping(found, req); |
1102 } |
1107 } |
1103 |
1108 |
1145 result &= false; |
1150 result &= false; |
1146 } |
1151 } |
1147 |
1152 |
1148 @Override |
1153 @Override |
1149 public void visitConditional(JCConditional tree) { |
1154 public void visitConditional(JCConditional tree) { |
1150 scan(tree.truepart); |
1155 scan(asExpr(tree.truepart)); |
1151 scan(tree.falsepart); |
1156 scan(asExpr(tree.falsepart)); |
1152 } |
1157 } |
1153 |
1158 |
1154 @Override |
1159 @Override |
1155 public void visitReference(JCMemberReference tree) { |
1160 public void visitReference(JCMemberReference tree) { |
1156 Type desc_t = types.findDescriptorType(t); |
1161 Type desc_t = types.findDescriptorType(t); |
1175 (retValIsPrimitive != ret_s.isPrimitive()); |
1180 (retValIsPrimitive != ret_s.isPrimitive()); |
1176 } else { |
1181 } else { |
1177 result &= compatibleBySubtyping(ret_t, ret_s); |
1182 result &= compatibleBySubtyping(ret_t, ret_s); |
1178 } |
1183 } |
1179 } |
1184 } |
|
1185 } |
|
1186 |
|
1187 @Override |
|
1188 public void visitParens(JCParens tree) { |
|
1189 scan(asExpr(tree.expr)); |
1180 } |
1190 } |
1181 |
1191 |
1182 @Override |
1192 @Override |
1183 public void visitLambda(JCLambda tree) { |
1193 public void visitLambda(JCLambda tree) { |
1184 Type desc_t = types.findDescriptorType(t); |
1194 Type desc_t = types.findDescriptorType(t); |
1212 } |
1222 } |
1213 //where |
1223 //where |
1214 |
1224 |
1215 private List<JCExpression> lambdaResults(JCLambda lambda) { |
1225 private List<JCExpression> lambdaResults(JCLambda lambda) { |
1216 if (lambda.getBodyKind() == JCTree.JCLambda.BodyKind.EXPRESSION) { |
1226 if (lambda.getBodyKind() == JCTree.JCLambda.BodyKind.EXPRESSION) { |
1217 return List.of((JCExpression) lambda.body); |
1227 return List.of(asExpr((JCExpression) lambda.body)); |
1218 } else { |
1228 } else { |
1219 final ListBuffer<JCExpression> buffer = new ListBuffer<>(); |
1229 final ListBuffer<JCExpression> buffer = new ListBuffer<>(); |
1220 DeferredAttr.LambdaReturnScanner lambdaScanner = |
1230 DeferredAttr.LambdaReturnScanner lambdaScanner = |
1221 new DeferredAttr.LambdaReturnScanner() { |
1231 new DeferredAttr.LambdaReturnScanner() { |
1222 @Override |
1232 @Override |
1223 public void visitReturn(JCReturn tree) { |
1233 public void visitReturn(JCReturn tree) { |
1224 if (tree.expr != null) { |
1234 if (tree.expr != null) { |
1225 buffer.append(tree.expr); |
1235 buffer.append(asExpr(tree.expr)); |
1226 } |
1236 } |
1227 } |
1237 } |
1228 }; |
1238 }; |
1229 lambdaScanner.scan(lambda.body); |
1239 lambdaScanner.scan(lambda.body); |
1230 return buffer.toList(); |
1240 return buffer.toList(); |
1231 } |
1241 } |
|
1242 } |
|
1243 |
|
1244 private JCExpression asExpr(JCExpression expr) { |
|
1245 if (expr.type.hasTag(DEFERRED)) { |
|
1246 JCTree speculativeTree = ((DeferredType)expr.type).speculativeTree(deferredAttrContext); |
|
1247 if (speculativeTree != deferredAttr.stuckTree) { |
|
1248 expr = (JCExpression)speculativeTree; |
|
1249 } |
|
1250 } |
|
1251 return expr; |
1232 } |
1252 } |
1233 } |
1253 } |
1234 |
1254 |
1235 } |
1255 } |
1236 |
1256 |