equal
deleted
inserted
replaced
38 import com.sun.tools.javac.tree.JCTree.*; |
38 import com.sun.tools.javac.tree.JCTree.*; |
39 import com.sun.tools.javac.code.Lint; |
39 import com.sun.tools.javac.code.Lint; |
40 import com.sun.tools.javac.code.Lint.LintCategory; |
40 import com.sun.tools.javac.code.Lint.LintCategory; |
41 import com.sun.tools.javac.code.Type.*; |
41 import com.sun.tools.javac.code.Type.*; |
42 import com.sun.tools.javac.code.Symbol.*; |
42 import com.sun.tools.javac.code.Symbol.*; |
|
43 import com.sun.tools.javac.comp.DeferredAttr.DeferredAttrContext; |
43 import com.sun.tools.javac.comp.Infer.InferenceContext; |
44 import com.sun.tools.javac.comp.Infer.InferenceContext; |
44 import com.sun.tools.javac.comp.Infer.InferenceContext.FreeTypeListener; |
45 import com.sun.tools.javac.comp.Infer.InferenceContext.FreeTypeListener; |
45 |
46 |
46 import static com.sun.tools.javac.code.Flags.*; |
47 import static com.sun.tools.javac.code.Flags.*; |
47 import static com.sun.tools.javac.code.Flags.ANNOTATION; |
48 import static com.sun.tools.javac.code.Flags.ANNOTATION; |
66 private final Names names; |
67 private final Names names; |
67 private final Log log; |
68 private final Log log; |
68 private final Resolve rs; |
69 private final Resolve rs; |
69 private final Symtab syms; |
70 private final Symtab syms; |
70 private final Enter enter; |
71 private final Enter enter; |
|
72 private final DeferredAttr deferredAttr; |
71 private final Infer infer; |
73 private final Infer infer; |
72 private final Types types; |
74 private final Types types; |
73 private final JCDiagnostic.Factory diags; |
75 private final JCDiagnostic.Factory diags; |
74 private boolean warnOnSyntheticConflicts; |
76 private boolean warnOnSyntheticConflicts; |
75 private boolean suppressAbortOnBadClassFile; |
77 private boolean suppressAbortOnBadClassFile; |
98 names = Names.instance(context); |
100 names = Names.instance(context); |
99 log = Log.instance(context); |
101 log = Log.instance(context); |
100 rs = Resolve.instance(context); |
102 rs = Resolve.instance(context); |
101 syms = Symtab.instance(context); |
103 syms = Symtab.instance(context); |
102 enter = Enter.instance(context); |
104 enter = Enter.instance(context); |
|
105 deferredAttr = DeferredAttr.instance(context); |
103 infer = Infer.instance(context); |
106 infer = Infer.instance(context); |
104 this.types = Types.instance(context); |
107 this.types = Types.instance(context); |
105 diags = JCDiagnostic.Factory.instance(context); |
108 diags = JCDiagnostic.Factory.instance(context); |
106 Options options = Options.instance(context); |
109 Options options = Options.instance(context); |
107 lint = Lint.instance(context); |
110 lint = Lint.instance(context); |
431 * Obtain a warner for this check context |
434 * Obtain a warner for this check context |
432 */ |
435 */ |
433 public Warner checkWarner(DiagnosticPosition pos, Type found, Type req); |
436 public Warner checkWarner(DiagnosticPosition pos, Type found, Type req); |
434 |
437 |
435 public Infer.InferenceContext inferenceContext(); |
438 public Infer.InferenceContext inferenceContext(); |
|
439 |
|
440 public DeferredAttr.DeferredAttrContext deferredAttrContext(); |
436 } |
441 } |
437 |
442 |
438 /** |
443 /** |
439 * This class represent a check context that is nested within another check |
444 * This class represent a check context that is nested within another check |
440 * context - useful to check sub-expressions. The default behavior simply |
445 * context - useful to check sub-expressions. The default behavior simply |
461 } |
466 } |
462 |
467 |
463 public Infer.InferenceContext inferenceContext() { |
468 public Infer.InferenceContext inferenceContext() { |
464 return enclosingContext.inferenceContext(); |
469 return enclosingContext.inferenceContext(); |
465 } |
470 } |
|
471 |
|
472 public DeferredAttrContext deferredAttrContext() { |
|
473 return enclosingContext.deferredAttrContext(); |
|
474 } |
466 } |
475 } |
467 |
476 |
468 /** |
477 /** |
469 * Check context to be used when evaluating assignment/return statements |
478 * Check context to be used when evaluating assignment/return statements |
470 */ |
479 */ |
480 return convertWarner(pos, found, req); |
489 return convertWarner(pos, found, req); |
481 } |
490 } |
482 |
491 |
483 public InferenceContext inferenceContext() { |
492 public InferenceContext inferenceContext() { |
484 return infer.emptyContext; |
493 return infer.emptyContext; |
|
494 } |
|
495 |
|
496 public DeferredAttrContext deferredAttrContext() { |
|
497 return deferredAttr.emptyDeferredAttrContext; |
485 } |
498 } |
486 }; |
499 }; |
487 |
500 |
488 /** Check that a given type is assignable to a given proto-type. |
501 /** Check that a given type is assignable to a given proto-type. |
489 * If it is, return the type, otherwise return errType. |
502 * If it is, return the type, otherwise return errType. |
815 Type last = useVarargs ? formals.last() : null; |
828 Type last = useVarargs ? formals.last() : null; |
816 if (sym.name==names.init && |
829 if (sym.name==names.init && |
817 sym.owner == syms.enumSym) |
830 sym.owner == syms.enumSym) |
818 formals = formals.tail.tail; |
831 formals = formals.tail.tail; |
819 List<JCExpression> args = argtrees; |
832 List<JCExpression> args = argtrees; |
|
833 DeferredAttr.DeferredTypeMap checkDeferredMap = |
|
834 deferredAttr.new DeferredTypeMap(DeferredAttr.AttrMode.CHECK, sym, env.info.pendingResolutionPhase); |
820 while (formals.head != last) { |
835 while (formals.head != last) { |
821 JCTree arg = args.head; |
836 JCTree arg = args.head; |
822 Warner warn = convertWarner(arg.pos(), arg.type, formals.head); |
837 Warner warn = convertWarner(arg.pos(), arg.type, formals.head); |
823 assertConvertible(arg, arg.type, formals.head, warn); |
838 assertConvertible(arg, arg.type, formals.head, warn); |
824 args = args.tail; |
839 args = args.tail; |
833 args = args.tail; |
848 args = args.tail; |
834 } |
849 } |
835 } else if ((sym.flags() & VARARGS) != 0 && allowVarargs) { |
850 } else if ((sym.flags() & VARARGS) != 0 && allowVarargs) { |
836 // non-varargs call to varargs method |
851 // non-varargs call to varargs method |
837 Type varParam = owntype.getParameterTypes().last(); |
852 Type varParam = owntype.getParameterTypes().last(); |
838 Type lastArg = argtypes.last(); |
853 Type lastArg = checkDeferredMap.apply(argtypes.last()); |
839 if (types.isSubtypeUnchecked(lastArg, types.elemtype(varParam)) && |
854 if (types.isSubtypeUnchecked(lastArg, types.elemtype(varParam)) && |
840 !types.isSameType(types.erasure(varParam), types.erasure(lastArg))) |
855 !types.isSameType(types.erasure(varParam), types.erasure(lastArg))) |
841 log.warning(argtrees.last().pos(), "inexact.non-varargs.call", |
856 log.warning(argtrees.last().pos(), "inexact.non-varargs.call", |
842 types.elemtype(varParam), varParam); |
857 types.elemtype(varParam), varParam); |
843 } |
858 } |
845 warnUnchecked(env.tree.pos(), |
860 warnUnchecked(env.tree.pos(), |
846 "unchecked.meth.invocation.applied", |
861 "unchecked.meth.invocation.applied", |
847 kindName(sym), |
862 kindName(sym), |
848 sym.name, |
863 sym.name, |
849 rs.methodArguments(sym.type.getParameterTypes()), |
864 rs.methodArguments(sym.type.getParameterTypes()), |
850 rs.methodArguments(argtypes), |
865 rs.methodArguments(Type.map(argtypes, checkDeferredMap)), |
851 kindName(sym.location()), |
866 kindName(sym.location()), |
852 sym.location()); |
867 sym.location()); |
853 owntype = new MethodType(owntype.getParameterTypes(), |
868 owntype = new MethodType(owntype.getParameterTypes(), |
854 types.erasure(owntype.getReturnType()), |
869 types.erasure(owntype.getReturnType()), |
855 types.erasure(owntype.getThrownTypes()), |
870 types.erasure(owntype.getThrownTypes()), |