Skip to content

Make Map.keySet() handle multiple argments to @KeyFor #2358

@mernst

Description

@mernst

Currently, the return type of Map.keySet() is Set<@KeyFor("this")>, with this appropriately viewpoint-adapted.
However, the keys should be "this" and all the keys on the receiver's key type.

A test case appears at checker/tests/nullness/KeyForMultiple.java

The current output is

$ch/bin/javac -processor nullness KeyForMultiple.java
KeyForMultiple.java:21: error: [assignment.type.incompatible] incompatible types in assignment.
        Set<@KeyFor({"sharedBooks", "sharedCounts1"}) String> otherChars1 = sharedCounts1.keySet();
                                                                                                ^
  found   : Set<@KeyFor("sharedCounts1") String>
  required: Set<@KeyFor({"sharedBooks", "sharedCounts1"}) String>
KeyForMultiple.java:39: error: [assignment.type.incompatible] incompatible types in assignment.
        Set<@KeyFor({"sharedBooks", "sharedCounts2"}) String> otherChars2 = sharedCounts2.keySet();
                                                                                                ^
  found   : Set<@KeyFor("sharedCounts2") String>
  required: Set<@KeyFor({"sharedBooks", "sharedCounts2"}) String>
2 errors

(This seems to be the same as issue #414, but that issue was closed as fixed, and the problem still exists.)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions