Skip to content

Type argument inference crash: lambda assigned to a raw functional interface returns a generic call #2158

Description

@aosen-xiong
import java.util.List;
import java.util.function.Supplier;

class RawLambda {
    static <T> List<T> never() {
        throw new Error();
    }

    void m() {
        Supplier s = () -> never();
    }
}

javac -processor nullness RawLambda.java (plain javac accepts it):

RawLambda.java:10: error: [type.argument.inference.crashed] Type argument inference crashed for RawLambda.never
        Supplier s = () -> never();
                                ^
  error: An exception occurred:  False bound for: Constraint: inference type: java.util.List<T> <: /*INFERENCE FAILED for:*/ ? extends Object Result: FALSE

With -AconvertTypeArgInferenceCrashToWarning=false, the exception is thrown from:

FalseBoundException: False bound for: Constraint: inference type: java.util.List<T> <: /*INFERENCE FAILED for:*/ ? extends Object Result: FALSE
  at ...typeinference8.constraint.ConstraintSet.reduceOneStep(ConstraintSet.java:458)
  at ...typeinference8.constraint.ConstraintSet.reduce(ConstraintSet.java:391)
  at ...typeinference8.InvocationTypeInference.createB3(InvocationTypeInference.java:443)
  at ...typeinference8.InvocationTypeInference.infer(InvocationTypeInference.java:170)
  at ...typeinference8.DefaultTypeArgumentInference.inferTypeArgs(DefaultTypeArgumentInference.java:108)

Supplier<?>, Supplier<Object>, and Supplier<? extends Object> do not crash; a field initializer, a cast (Supplier) () -> never(), and a block lambda body do. Also reproduces with the Interning and Tainting Checkers.

Found in reactor-core: Queues.java:481-492 (static final Supplier ZERO_SUPPLIER = () -> Hooks.wrapQueue(new ZeroQueue<>());) and MonoTimeout.java:47 (final static Function NEVER = e -> Flux.never();), 7 sites in total. Possibly related: #2086 (fixed), but this still crashes on master.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions