8046977: ClassCastException: typing information needed for method reference bridging not preserved

Reviewed-by: mcimadamore
This commit is contained in:
Srikanth Adayapalam 2015-01-20 21:49:55 +01:00 committed by Joel Borggrén-Franck
parent 8944d18416
commit 22e2343e57
3 changed files with 17 additions and 3 deletions

View File

@ -2783,7 +2783,8 @@ public class Attr extends JCTree.Visitor {
@SuppressWarnings("fallthrough")
void checkReferenceCompatible(JCMemberReference tree, Type descriptor, Type refType, CheckContext checkContext, boolean speculativeAttr) {
Type returnType = checkContext.inferenceContext().asUndetVar(descriptor.getReturnType());
InferenceContext inferenceContext = checkContext.inferenceContext();
Type returnType = inferenceContext.asUndetVar(descriptor.getReturnType());
Type resType;
switch (tree.getMode()) {
@ -2812,10 +2813,20 @@ public class Attr extends JCTree.Visitor {
if (incompatibleReturnType != null) {
checkContext.report(tree, diags.fragment("incompatible.ret.type.in.mref",
diags.fragment("inconvertible.types", resType, descriptor.getReturnType())));
} else {
if (inferenceContext.free(refType)) {
// we need to wait for inference to finish and then replace inference vars in the referent type
inferenceContext.addFreeTypeListener(List.of(refType),
instantiatedContext -> {
tree.referentType = instantiatedContext.asInstType(refType);
});
} else {
tree.referentType = refType;
}
}
if (!speculativeAttr) {
List<Type> thrownTypes = checkContext.inferenceContext().asUndetVars(descriptor.getThrownTypes());
List<Type> thrownTypes = inferenceContext.asUndetVars(descriptor.getThrownTypes());
if (chk.unhandled(refType.getThrownTypes(), thrownTypes).nonEmpty()) {
log.error(tree, "incompatible.thrown.types.in.mref", refType.getThrownTypes());
}

View File

@ -889,7 +889,9 @@ public class LambdaToMethod extends TreeTranslator {
convertArgs(tree.sym, args.toList(), tree.varargsElement)).
setType(tree.sym.erasure(types).getReturnType());
apply = transTypes.coerce(apply, localContext.generatedRefSig().getReturnType());
apply = transTypes.coerce(attrEnv, apply,
types.erasure(localContext.tree.referentType.getReturnType()));
setVarargsIfNeeded(apply, tree.varargsElement);
return apply;
}

View File

@ -2101,6 +2101,7 @@ public abstract class JCTree implements Tree, Cloneable, DiagnosticPosition {
public PolyKind refPolyKind;
public boolean ownerAccessible;
public OverloadKind overloadKind;
public Type referentType;
public enum OverloadKind {
OVERLOADED,