typetools / typetools/checker-framework

Improve type.incompatible error messages for wildcards

Open
#520 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
1.1k
Forks
440
Avg merge
1d 12h
Merged PRs (30d)
134

Description

Compiling the following code:

import java.util.*;

import org.checkerframework.checker.nullness.qual.*;

public class Issue520 {
}

abstract class Parent<T> {
    protected final List<? super @KeyForBottom T> list;

    public Parent(List<? super @KeyForBottom T> list) {
        this.list = list;
    }
}

abstract class Child extends Parent<CharSequence> {
    public Child(List<? super CharSequence> list) {
        super(list);
    }

    public void add(CharSequence seq) {
        list.add(seq);
    }
}

with the Nullness Checker issues the following error:

Issue520.java:26: error: [argument.type.incompatible] incompatible types in argument.
        list.add(seq);
             ^
  found   : @UnknownKeyFor CharSequence
  required: ? extends @UnknownKeyFor Object super @KeyForBottom CharSequence
1 error

That found type is within that required range, so no error should be issued.

A test case appears as file
checker-framework/checker/tests/nullness/Issue520.java

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with checker/tests/nullness/Issue520.java and run the Nullness Checker test for it. Trace the [argument.type.incompatible] diagnostic produced for list.add(seq), then make the wildcard case pass without reporting an error and verify the test succeeds.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
compilers, devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.