typetools / typetools/checker-framework

Properties not inhereted when converting array to an object.

Open
#2,603 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

False Positive (false warning or imprecision) Index
Dominant language
Java
Stars
1.1k
Forks
440
Avg merge
1d 12h
Merged PRs (30d)
134

Description

Consider the following code:

import org.checkerframework.checker.index.qual.IndexFor;
class tryit{
  void func_1(int[] ar, @IndexFor("#1") int a){
    func_2((Object) ar, a);
  }
  void func_2(Object ar, @IndexFor("#1") int a){
  }
}

Run it by typing in the terminal:
javac -processor index tryit.java

Output:

tryit.java:4: error: [argument.type.incompatible] incompatible types in argument.
	func_2((Object) ar, a);
	                    ^
  found   : @LTLengthOf(value="ar", offset={}) int
  required: @LTLengthOf(value="?", offset={}) int
1 error

However, clearly, a is a valid index for (Object) array

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 compiling the provided tryit.java example with javac -processor index and inspect the index checker's handling of the array-to-Object conversion. Done means the example no longer rejects a as an index for the converted array, with relevant checker tests added or updated if the existing test structure is found.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
compilers
Issue type
Bug
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.