typetools / typetools/checker-framework
Unexpected return.type.incompatible: Set<V extends @KeyFor...> vs Set<V> on `return map.keySet()`
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 1.1k
- Forks
- 440
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 134
Description
Here's a part of the class in question
public class DefaultDirectedGraph<V, E extends DefaultEdge>
implements DirectedGraph<V, E> {
final Set<E> edges = new LinkedHashSet<>();
final Map<V, VertexInfo<V, E>> vertexMap = new LinkedHashMap<>();
final @NotOnlyInitialized EdgeFactory<V, E> edgeFactory;
@Override public Set<V> vertexSet() { // implement DirectedGraph nethod
return vertexMap.keySet();
}
checker-framework issues error as follows:
calcite/core/src/main/java/org/apache/calcite/util/graph/DefaultDirectedGraph.java:161: error: [return.type.incompatible] incompatible types in return.
return vertexMap.keySet();
^
type of expression: Set<V extends @KeyFor("this.vertexMap") Object>
method return type: Set<V extends Object>
I think it might be related to https://github.com/typetools/checker-framework/issues/1653, however, the difference here is that Set<V> signature is specified for a public API.
The method itself looks very much java.util.Map<K, V>.keySet() which return Set<V>.
Does that mean the methods like that always have to suppress return.type.incompatible error?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the reported vertexSet() method in calcite/core/src/main/java/org/apache/calcite/util/graph/DefaultDirectedGraph.java and compare its Map.keySet() return with the related Checker Framework issue 1653. Trace how the checker handles the @KeyFor type on the returned set; done means establishing whether this diagnostic is expected and documenting or fixing the behavior.
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
- Needs clarification
- Newbie friendliness
- 35/100