Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lub annotations on anonymous constructors #6837

Merged
merged 6 commits into from
Oct 5, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions checker/tests/mustcall/FunctionalInterfaces.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Test that the correct type is assigned to instantiations of functional
// interfaces.
// https://github.com/typetools/checker-framework/issues/6823

import java.io.Closeable;
import org.checkerframework.checker.mustcall.qual.*;

public abstract class FunctionalInterfaces {

@FunctionalInterface
public interface Actor extends Closeable {
void act();

@Override
default void close() {}
}

public static class ActorImpl implements Actor {
@Override
public void act() {}
}

public abstract void run(@MustCall({}) Actor a);

public static void method() {}

public void normalConstruction() {

// :: error: (assignment)
@MustCall({}) Actor a = new ActorImpl();
}

public void inlineClass() {

class ActorImplInline implements Actor {
@Override
public void act() {}
}

// :: error: (assignment)
@MustCall({}) Actor a = new ActorImplInline();
}

public void anonymousClass() {

// :: error: (assignment)
@MustCall({}) Actor a =
new Actor() {
public void act() {}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2826,7 +2826,13 @@ protected ParameterizedExecutableType constructorFromUse(
p.addAll(1, superCon.getParameterTypes());
con.setParameterTypes(p);
}
con.getReturnType().replaceAnnotations(superCon.getReturnType().getPrimaryAnnotations());
Set<? extends AnnotationMirror> lub =
qualHierarchy.leastUpperBoundsShallow(
type.getPrimaryAnnotations(),
type.getUnderlyingType(),
superCon.getReturnType().getPrimaryAnnotations(),
superCon.getReturnType().getUnderlyingType());
con.getReturnType().replaceAnnotations(lub);
} else {
con = AnnotatedTypes.asMemberOf(types, this, type, ctor, con);
}
Expand Down
Loading