typetools / typetools/checker-framework

Polymorphic qualifier substitution in member references

Open
#2,931 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

While working on #2876 I've noticed that polymorphic qualifier substitution does not seem to work for member references.

Take:

import java.util.function.Supplier;
import testlib.util.Encrypted;
import testlib.util.PolyEncrypted;

class PolyMemberRef {
  @SuppressWarnings("return.type.incompatible") // impl
  @PolyEncrypted String id(@PolyEncrypted PolyMemberRef this) { return this.toString(); }

  void giveUnq(Supplier<String> s) {}
  void giveEnc(Supplier<@Encrypted String> s) {}

  void foo(PolyMemberRef u, @Encrypted PolyMemberRef e) {
    giveUnq(u::id);
    giveEnc(e::id);
  }
}

Run something like: ./checker/bin-devel/javac -cp framework/build/classes/java/test -processor org.checkerframework.common.subtyping.SubtypingChecker -Aquals=testlib.util.Encrypted,testlib.util.PolyEncrypted,org.checkerframework.common.subtyping.qual.Unqualified PolyMemberRef.java

And you'll get an error:

PolyMemberRef.java:14: error: [methodref.return.invalid] Incompatible return type
    giveEnc(e::id);
            ^
  Method
    String id(PolyMemberRef this) in PolyMemberRef
  is not a valid method reference for
    @Encrypted String get(Supplier<@Encrypted String> this) in java.util.function.Supplier
  found   : String
  required: @Encrypted String
1 error

The receiver used in the member reference should be used to resolve the polymorphic qualifier.

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 running the provided javac command with the PolyMemberRef.java reproducer and confirm that the encrypted member reference is rejected. Trace the checker’s member-reference handling and polymorphic qualifier substitution, then verify that using the encrypted receiver permits giveEnc(e::id) while the unqualified case still passes.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.