typetools / typetools/checker-framework

@BottomAll and @TopAll annotations

Open
#521 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Compiling this code with the Map Key Checker fails:

public abstract class Parent<T> {
    public Parent(List<? super T> list) {}
}

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

because the unannotated T in ? super T is interpreted as having the annotation for the actual type argument, which is CharSequence in Parent<CharSequence>, which is defaulted to @UnknownKeyFor. The T in ? super T needs to have the bottom type for the type system.

The programmer could explicitly annotate it for each type system, but that could get wordy and tedious.

Instead, we should create @BottomAll and @TopAll annotations (analogously to @PolyAll). These annotations only have an effect if a type does not have an explicit annotation for the particular type system. For example, a programmer could write @PreppyCheckerWearsPoloShirt @HipsterCheckerWearsSkinnyJeans @BottomAll which means the bottom annotation in every type system except the preppy and hipster type systems.

The @BottomAll and @TopAll annotations are intended to be written on wildcard bounds and possibly in other places.

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 by locating the existing @PolyAll annotation and the annotation definitions used by the Map Key Checker. Check how annotations on wildcard bounds are interpreted, then verify that @BottomAll and @TopAll provide defaults per type system while explicit annotations take precedence and the reported Parent/Child example compiles.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.