Skip to content

Support invocation inference across narrowing reference conversions#8

Open
biboudis wants to merge 1 commit into
JDK-8372170from
JDK-8372170-inference
Open

Support invocation inference across narrowing reference conversions#8
biboudis wants to merge 1 commit into
JDK-8372170from
JDK-8372170-inference

Conversation

@biboudis

@biboudis biboudis commented Jul 8, 2026

Copy link
Copy Markdown
Owner

No description provided.

!targetType.hasTag(NONE) &&
!targetType.hasTag(ERROR) &&
targetType.isReference() &&
!targetInferenceContext.free(targetType) &&

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this can be replaced by targetType.hasTag(CLASS)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(e.g. the issue here is that a type variable might erase to a class type, which might lead you to lift more cases than needed. E.g. if we lift T to C<...> where T was an inference variable, we kind of lose T).

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure I follow, erasure during inference?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's the check in the line below -- which checks if |T| <: |R| where T is the target type and R is the return type. Basically, we're checking here if the relationship is "the wrong way around", and, if so, lift T to the same height as R. That's because with the new narrowing sealing conversion you can have legit cases of |T| <: |R| that are valid assignments.

private Type resultCompatibilityTarget(Type returnType, Type targetType,
InferenceContext inferenceContext, InferenceContext targetInferenceContext) {
if (returnType.hasTag(CLASS) &&
returnType.getTypeArguments().stream()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inferenceContext.free(returnType)?

}

private Type lift(Type targetType, Type returnType) {
return types.asSuper(targetType, returnType.tsym);

@vicente-romero-oracle vicente-romero-oracle Jul 8, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if we are dealing with arrays? better to use Infer::asSuper

}
Type qtype = inferenceContext.asUndetVar(from);
Type to = resultInfo.pt;
Type to = resultCompatibilityTarget(mt.getReturnType(), resultInfo.pt,

@vicente-romero-oracle vicente-romero-oracle Jul 9, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably the highest risk of semantic change is when qtype is an UndetVar, we need to test that case and look for any possible semantic change

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants