85 attr = Attr.instance(context); |
86 attr = Attr.instance(context); |
86 chk = Check.instance(context); |
87 chk = Check.instance(context); |
87 diags = JCDiagnostic.Factory.instance(context); |
88 diags = JCDiagnostic.Factory.instance(context); |
88 enter = Enter.instance(context); |
89 enter = Enter.instance(context); |
89 infer = Infer.instance(context); |
90 infer = Infer.instance(context); |
|
91 rs = Resolve.instance(context); |
90 log = Log.instance(context); |
92 log = Log.instance(context); |
91 syms = Symtab.instance(context); |
93 syms = Symtab.instance(context); |
92 make = TreeMaker.instance(context); |
94 make = TreeMaker.instance(context); |
93 types = Types.instance(context); |
95 types = Types.instance(context); |
94 Names names = Names.instance(context); |
96 Names names = Names.instance(context); |
461 */ |
463 */ |
462 class StructuralStuckChecker extends TreeScanner implements DeferredTypeCompleter { |
464 class StructuralStuckChecker extends TreeScanner implements DeferredTypeCompleter { |
463 |
465 |
464 ResultInfo resultInfo; |
466 ResultInfo resultInfo; |
465 InferenceContext inferenceContext; |
467 InferenceContext inferenceContext; |
|
468 Env<AttrContext> env; |
466 |
469 |
467 public Type complete(DeferredType dt, ResultInfo resultInfo, DeferredAttrContext deferredAttrContext) { |
470 public Type complete(DeferredType dt, ResultInfo resultInfo, DeferredAttrContext deferredAttrContext) { |
468 this.resultInfo = resultInfo; |
471 this.resultInfo = resultInfo; |
469 this.inferenceContext = deferredAttrContext.inferenceContext; |
472 this.inferenceContext = deferredAttrContext.inferenceContext; |
|
473 this.env = dt.env.dup(dt.tree, dt.env.info.dup()); |
470 dt.tree.accept(this); |
474 dt.tree.accept(this); |
471 dt.speculativeCache.put(deferredAttrContext.msym, stuckTree, deferredAttrContext.phase); |
475 dt.speculativeCache.put(deferredAttrContext.msym, stuckTree, deferredAttrContext.phase); |
472 return Type.noType; |
476 return Type.noType; |
473 } |
477 } |
474 |
478 |
509 if (inferenceContext.inferencevars.contains(pt)) { |
513 if (inferenceContext.inferencevars.contains(pt)) { |
510 //ok |
514 //ok |
511 return; |
515 return; |
512 } else { |
516 } else { |
513 try { |
517 try { |
514 //TODO: we should speculative determine if there's a match |
|
515 //based on arity - if yes, method is applicable. |
|
516 types.findDescriptorType(pt); |
518 types.findDescriptorType(pt); |
517 } catch (Types.FunctionDescriptorLookupError ex) { |
519 } catch (Types.FunctionDescriptorLookupError ex) { |
518 checkContext.report(null, ex.getDiagnostic()); |
520 checkContext.report(null, ex.getDiagnostic()); |
|
521 } |
|
522 JCExpression exprTree = (JCExpression)attribSpeculative(tree.getQualifierExpression(), env, |
|
523 attr.memberReferenceQualifierResult(tree)); |
|
524 ListBuffer<Type> argtypes = ListBuffer.lb(); |
|
525 for (Type t : types.findDescriptorType(pt).getParameterTypes()) { |
|
526 argtypes.append(syms.errType); |
|
527 } |
|
528 JCMemberReference mref2 = new TreeCopier<Void>(make).copy(tree); |
|
529 mref2.expr = exprTree; |
|
530 Pair<Symbol, ?> lookupRes = |
|
531 rs.resolveMemberReference(tree, env, mref2, exprTree.type, tree.name, argtypes.toList(), null, true); |
|
532 switch (lookupRes.fst.kind) { |
|
533 //note: as argtypes are erroneous types, type-errors must |
|
534 //have been caused by arity mismatch |
|
535 case Kinds.ABSENT_MTH: |
|
536 case Kinds.WRONG_MTH: |
|
537 case Kinds.WRONG_MTHS: |
|
538 case Kinds.STATICERR: |
|
539 case Kinds.MISSING_ENCL: |
|
540 checkContext.report(null, diags.fragment("incompatible.arg.types.in.mref")); |
519 } |
541 } |
520 } |
542 } |
521 } |
543 } |
522 } |
544 } |
523 } |
545 } |