Skip to content

Lenient mode errors for returning nullable values from null-unmarked methods with a type-parameter return type #172

@cpovirk

Description

@cpovirk

At the current main-eisop (76b33c9) and still with #171:

class Issue172<E> {
  E e() {
    return null;
  }
}
$ ./demo Issue172.java
Issue172.java:3: error: [return.type.incompatible] incompatible types in return.
    return null;
           ^
  type of expression: null?
  method return type: E
1 error

This should be allowed because the return type should be read as E* (i.e., E with unspecified nullness), which permits null in lenient mode.

Since this error comes up only in null-unmarked code, we should be OK with suppressing the small number of times that it occurs. Still, I'm filing it for tracking.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions