typetools / typetools/checker-framework

Unclear error message in enums

Open
#2,896 0 comments 0 reactions 1 assignee View on GitHub

@wmdietl is already working on this.

Since Nov 18, 2019.

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

Description

In enumerations, the enum elements are implicitly assigned, leading to an unintuitive error. Consider this enum,

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

public enum C {
    @Untainted A
}

When I run javac -processor TaintingChecker C.java I get the error,

C.java:4: error: [assignment.type.incompatible] incompatible types in assignment.
    @Untainted A
               ^
  found   : @Tainted C
  required: @Untainted C

The error is that A is actually a field which is assigned to a default constructed instance of C, which is Tainted. However, there's no explicit assignment in the code so without knowledge of how Java implements enums this error is confusing.

When enum fields are set to invalid values, it should be clear that it's because they're implicitly being assigned to a newly constructed value. Perhaps add a different error name for invalid assignments in enums.

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.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.