protected void reportMC(DiagnosticPosition pos, MethodCheckDiag diag, InferenceContext inferenceContext, Object... args) { boolean inferDiag = inferenceContext != infer.emptyContext; InapplicableMethodException ex = inferDiag ? infer.inferenceException : inapplicableMethodException; if (inferDiag && (!diag.inferKey.equals(diag.basicKey))) { Object[] args2 = new Object[args.length + 1]; System.arraycopy(args, 0, args2, 1, args.length); args2[0] = inferenceContext.inferenceVars(); args = args2; } String key = inferDiag ? diag.inferKey : diag.basicKey; throw ex.setMessage(diags.create(DiagnosticType.FRAGMENT, log.currentSource(), pos, key, args)); }
protected void reportMC(DiagnosticPosition pos, MethodCheckDiag diag, InferenceContext inferenceContext, Object... args) { boolean inferDiag = inferenceContext != infer.emptyContext; InapplicableMethodException ex = inferDiag ? infer.inferenceException : inapplicableMethodException; if (inferDiag && (!diag.inferKey.equals(diag.basicKey))) { Object[] args2 = new Object[args.length + 1]; System.arraycopy(args, 0, args2, 1, args.length); args2[0] = inferenceContext.inferenceVars(); args = args2; } String key = inferDiag ? diag.inferKey : diag.basicKey; throw ex.setMessage(diags.create(DiagnosticType.FRAGMENT, log.currentSource(), pos, key, args)); }
@Override public void visitReference(JCMemberReference tree) { scan(tree.expr); if (inferenceContext.inferenceVars().contains(pt)) { stuckVars.add(pt); return; } if (!types.isFunctionalInterface(pt)) { return; } Type descType = types.findDescriptorType(pt); List<Type> freeArgVars = inferenceContext.freeVarsIn(descType.getParameterTypes()); if (freeArgVars.nonEmpty() && tree.overloadKind == JCMemberReference.OverloadKind.OVERLOADED) { stuckVars.addAll(freeArgVars); depVars.addAll(inferenceContext.freeVarsIn(descType.getReturnType())); } }
public void apply(UndetVar uv, InferenceContext inferenceContext, Warner warn) { Infer infer = inferenceContext.infer(); for (Type b : uv.getBounds(InferenceBound.EQ)) { if (inferenceContext.inferenceVars().contains(b)) { UndetVar uv2 = (UndetVar)inferenceContext.asUndetVar(b); if (uv2.isCaptured()) continue; //alpha == beta //0. set beta == alpha addBound(InferenceBound.EQ, uv2, inferenceContext.asInstType(uv.qtype), infer); //1. copy all alpha's bounds to beta's for (InferenceBound ib : InferenceBound.values()) { for (Type b2 : uv.getBounds(ib)) { if (b2 != uv2) { addBound(ib, uv2, inferenceContext.asInstType(b2), infer); } } } //2. copy all beta's bounds to alpha's for (InferenceBound ib : InferenceBound.values()) { for (Type b2 : uv2.getBounds(ib)) { if (b2 != uv) { addBound(ib, uv, inferenceContext.asInstType(b2), infer); } } } } } } };
/** * Instantiate inference variables in legacy mode (JLS 15.12.2.7, 15.12.2.8). * During overload resolution, instantiation is done by doing a partial * inference process using eq/lower bound instantiation. During check, * we also instantiate any remaining vars by repeatedly using eq/upper * instantiation, until all variables are solved. */ public void solveLegacy(boolean partial, Warner warn, EnumSet<InferenceStep> steps) { while (true) { boolean stuck = !solveBasic(steps); if (restvars().isEmpty() || partial) { //all variables have been instantiated - exit break; } else if (stuck) { //some variables could not be instantiated because of cycles in //upper bounds - provide a (possibly recursive) default instantiation instantiateAsUninferredVars(restvars(), this); break; } else { //some variables have been instantiated - replace newly instantiated //variables in remaining upper bounds and continue for (Type t : undetvars) { UndetVar uv = (UndetVar)t; uv.substBounds(inferenceVars(), instTypes(), types); } } } checkWithinBounds(this, warn); }
public void apply(UndetVar uv, InferenceContext inferenceContext, Warner warn) { Infer infer = inferenceContext.infer(); for (Type b : uv.getBounds(InferenceBound.EQ)) { if (inferenceContext.inferenceVars().contains(b)) { UndetVar uv2 = (UndetVar)inferenceContext.asFree(b); if (uv2.isCaptured()) continue; //alpha == beta //0. set beta == alpha addBound(InferenceBound.EQ, uv2, inferenceContext.asInstType(uv.qtype), infer); //1. copy all alpha's bounds to beta's for (InferenceBound ib : InferenceBound.values()) { for (Type b2 : uv.getBounds(ib)) { if (b2 != uv2) { addBound(ib, uv2, inferenceContext.asInstType(b2), infer); } } } //2. copy all beta's bounds to alpha's for (InferenceBound ib : InferenceBound.values()) { for (Type b2 : uv2.getBounds(ib)) { if (b2 != uv) { addBound(ib, uv, inferenceContext.asInstType(b2), infer); } } } } } } };
/** * Instantiate inference variables in legacy mode (JLS 15.12.2.7, 15.12.2.8). * During overload resolution, instantiation is done by doing a partial * inference process using eq/lower bound instantiation. During check, * we also instantiate any remaining vars by repeatedly using eq/upper * instantiation, until all variables are solved. */ public void solveLegacy(boolean partial, Warner warn, EnumSet<InferenceStep> steps) { while (true) { boolean stuck = !solveBasic(steps); if (restvars().isEmpty() || partial) { //all variables have been instantiated - exit break; } else if (stuck) { //some variables could not be instantiated because of cycles in //upper bounds - provide a (possibly recursive) default instantiation instantiateAsUninferredVars(restvars(), this); break; } else { //some variables have been instantiated - replace newly instantiated //variables in remaining upper bounds and continue for (Type t : undetvars) { UndetVar uv = (UndetVar)t; uv.substBounds(inferenceVars(), instTypes(), types); } } } checkWithinBounds(this, warn); }
public void apply(UndetVar uv, InferenceContext inferenceContext, Warner warn) { Infer infer = inferenceContext.infer(); uv.substBounds(inferenceContext.inferenceVars(), inferenceContext.instTypes(), infer.types); infer.checkCompatibleUpperBounds(uv, inferenceContext); if (uv.inst != null) { Type inst = uv.inst; for (Type u : uv.getBounds(InferenceBound.UPPER)) { if (!isSubtype(inst, inferenceContext.asUndetVar(u), warn, infer)) { infer.reportBoundError(uv, BoundErrorKind.UPPER); } } for (Type l : uv.getBounds(InferenceBound.LOWER)) { if (!isSubtype(inferenceContext.asUndetVar(l), inst, warn, infer)) { infer.reportBoundError(uv, BoundErrorKind.LOWER); } } for (Type e : uv.getBounds(InferenceBound.EQ)) { if (!isSameType(inst, inferenceContext.asUndetVar(e), infer)) { infer.reportBoundError(uv, BoundErrorKind.EQ); } } } }
public void apply(UndetVar uv, InferenceContext inferenceContext, Warner warn) { Infer infer = inferenceContext.infer(); uv.substBounds(inferenceContext.inferenceVars(), inferenceContext.instTypes(), infer.types); infer.checkCompatibleUpperBounds(uv, inferenceContext); if (uv.inst != null) { Type inst = uv.inst; for (Type u : uv.getBounds(InferenceBound.UPPER)) { if (!isSubtype(inst, inferenceContext.asFree(u), warn, infer)) { infer.reportBoundError(uv, BoundErrorKind.UPPER); } } for (Type l : uv.getBounds(InferenceBound.LOWER)) { if (!isSubtype(inferenceContext.asFree(l), inst, warn, infer)) { infer.reportBoundError(uv, BoundErrorKind.LOWER); } } for (Type e : uv.getBounds(InferenceBound.EQ)) { if (!isSameType(inst, inferenceContext.asFree(e), infer)) { infer.reportBoundError(uv, BoundErrorKind.EQ); } } } } @Override
public void apply(UndetVar uv, InferenceContext inferenceContext, Warner warn) { Infer infer = inferenceContext.infer(); for (Type b : uv.getBounds(InferenceBound.UPPER)) { if (inferenceContext.inferenceVars().contains(b)) { UndetVar uv2 = (UndetVar)inferenceContext.asUndetVar(b); if (uv2.isCaptured()) continue; //alpha <: beta //0. set beta :> alpha addBound(InferenceBound.LOWER, uv2, inferenceContext.asInstType(uv.qtype), infer); //1. copy alpha's lower to beta's for (Type l : uv.getBounds(InferenceBound.LOWER)) { addBound(InferenceBound.LOWER, uv2, inferenceContext.asInstType(l), infer); } //2. copy beta's upper to alpha's for (Type u : uv2.getBounds(InferenceBound.UPPER)) { addBound(InferenceBound.UPPER, uv, inferenceContext.asInstType(u), infer); } } } } },
public void apply(UndetVar uv, InferenceContext inferenceContext, Warner warn) { Infer infer = inferenceContext.infer(); for (Type b : uv.getBounds(InferenceBound.LOWER)) { if (inferenceContext.inferenceVars().contains(b)) { UndetVar uv2 = (UndetVar)inferenceContext.asUndetVar(b); if (uv2.isCaptured()) continue; //alpha :> beta //0. set beta <: alpha addBound(InferenceBound.UPPER, uv2, inferenceContext.asInstType(uv.qtype), infer); //1. copy alpha's upper to beta's for (Type u : uv.getBounds(InferenceBound.UPPER)) { addBound(InferenceBound.UPPER, uv2, inferenceContext.asInstType(u), infer); } //2. copy beta's lower to alpha's for (Type l : uv2.getBounds(InferenceBound.LOWER)) { addBound(InferenceBound.LOWER, uv, inferenceContext.asInstType(l), infer); } } } } },
public void apply(UndetVar uv, InferenceContext inferenceContext, Warner warn) { Infer infer = inferenceContext.infer(); for (Type b : uv.getBounds(InferenceBound.UPPER)) { if (inferenceContext.inferenceVars().contains(b)) { UndetVar uv2 = (UndetVar)inferenceContext.asFree(b); if (uv2.isCaptured()) continue; //alpha <: beta //0. set beta :> alpha addBound(InferenceBound.LOWER, uv2, inferenceContext.asInstType(uv.qtype), infer); //1. copy alpha's lower to beta's for (Type l : uv.getBounds(InferenceBound.LOWER)) { addBound(InferenceBound.LOWER, uv2, inferenceContext.asInstType(l), infer); } //2. copy beta's upper to alpha's for (Type u : uv2.getBounds(InferenceBound.UPPER)) { addBound(InferenceBound.UPPER, uv, inferenceContext.asInstType(u), infer); } } } } },
public void apply(UndetVar uv, InferenceContext inferenceContext, Warner warn) { Infer infer = inferenceContext.infer(); for (Type b : uv.getBounds(InferenceBound.LOWER)) { if (inferenceContext.inferenceVars().contains(b)) { UndetVar uv2 = (UndetVar)inferenceContext.asFree(b); if (uv2.isCaptured()) continue; //alpha :> beta //0. set beta <: alpha addBound(InferenceBound.UPPER, uv2, inferenceContext.asInstType(uv.qtype), infer); //1. copy alpha's upper to beta's for (Type u : uv.getBounds(InferenceBound.UPPER)) { addBound(InferenceBound.UPPER, uv2, inferenceContext.asInstType(u), infer); } //2. copy beta's lower to alpha's for (Type l : uv2.getBounds(InferenceBound.LOWER)) { addBound(InferenceBound.LOWER, uv, inferenceContext.asInstType(l), infer); } } } } },
@Override public void visitReference(JCMemberReference tree) { scan(tree.expr); if (inferenceContext.inferenceVars().contains(pt)) { stuckVars.add(pt); return; } if (!types.isFunctionalInterface(pt)) { return; } Type descType = types.findDescriptorType(pt); List<Type> freeArgVars = inferenceContext.freeVarsIn(descType.getParameterTypes()); if (freeArgVars.nonEmpty() && tree.overloadKind == JCMemberReference.OverloadKind.OVERLOADED) { stuckVars.addAll(freeArgVars); depVars.addAll(inferenceContext.freeVarsIn(descType.getReturnType())); } }
@Override public void visitLambda(JCLambda tree) { if (inferenceContext.inferenceVars().contains(pt)) { stuckVars.add(pt); } if (!types.isFunctionalInterface(pt)) { return; } Type descType = types.findDescriptorType(pt); List<Type> freeArgVars = inferenceContext.freeVarsIn(descType.getParameterTypes()); if (tree.paramKind == JCLambda.ParameterKind.IMPLICIT && freeArgVars.nonEmpty()) { stuckVars.addAll(freeArgVars); depVars.addAll(inferenceContext.freeVarsIn(descType.getReturnType())); } scanLambdaBody(tree, descType.getReturnType()); }
@Override public void visitLambda(JCLambda tree) { if (inferenceContext.inferenceVars().contains(pt)) { stuckVars.add(pt); } if (!types.isFunctionalInterface(pt)) { return; } Type descType = types.findDescriptorType(pt); List<Type> freeArgVars = inferenceContext.freeVarsIn(descType.getParameterTypes()); if (tree.paramKind == JCLambda.ParameterKind.IMPLICIT && freeArgVars.nonEmpty()) { stuckVars.addAll(freeArgVars); depVars.addAll(inferenceContext.freeVarsIn(descType.getReturnType())); } scanLambdaBody(tree, descType.getReturnType()); }
public void apply(UndetVar uv, InferenceContext inferenceContext, Warner warn) { Infer infer = inferenceContext.infer(); for (Type e : uv.getBounds(InferenceBound.EQ)) { if (e.containsAny(inferenceContext.inferenceVars())) continue; for (Type u : uv.getBounds(InferenceBound.UPPER)) { if (!isSubtype(e, inferenceContext.asFree(u), warn, infer)) { infer.reportBoundError(uv, BoundErrorKind.BAD_EQ_UPPER); } } for (Type l : uv.getBounds(InferenceBound.LOWER)) { if (!isSubtype(inferenceContext.asFree(l), e, warn, infer)) { infer.reportBoundError(uv, BoundErrorKind.BAD_EQ_LOWER); } } } } },
public void apply(UndetVar uv, InferenceContext inferenceContext, Warner warn) { Infer infer = inferenceContext.infer(); for (Type e : uv.getBounds(InferenceBound.EQ)) { if (e.containsAny(inferenceContext.inferenceVars())) continue; for (Type u : uv.getBounds(InferenceBound.UPPER)) { if (!isSubtype(e, inferenceContext.asUndetVar(u), warn, infer)) { infer.reportBoundError(uv, BoundErrorKind.BAD_EQ_UPPER); } } for (Type l : uv.getBounds(InferenceBound.LOWER)) { if (!isSubtype(inferenceContext.asUndetVar(l), e, warn, infer)) { infer.reportBoundError(uv, BoundErrorKind.BAD_EQ_LOWER); } } } } },
/** * Returns a list of free variables in a given type */ final List<Type> freeVarsIn(Type t) { ListBuffer<Type> buf = new ListBuffer<>(); for (Type iv : inferenceVars()) { if (t.contains(iv)) { buf.add(iv); } } return buf.toList(); }
/** * Returns a list of free variables in a given type */ final List<Type> freeVarsIn(Type t) { ListBuffer<Type> buf = new ListBuffer<>(); for (Type iv : inferenceVars()) { if (t.contains(iv)) { buf.add(iv); } } return buf.toList(); }