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

Set var arg type before calling viewpointAdaptConstructor #783

Merged
merged 8 commits into from
Jun 23, 2024
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -2915,10 +2915,6 @@ public ParameterizedExecutableType constructorFromUse(NewClassTree tree) {
AnnotatedExecutableType con = getAnnotatedType(ctor); // get unsubstituted type
constructorFromUsePreSubstitution(tree, con);

if (viewpointAdapter != null) {
viewpointAdapter.viewpointAdaptConstructor(type, ctor, con);
}

if (tree.getClassBody() != null) {
// Because the anonymous constructor can't have explicit annotations on its parameters,
// they are copied from the super constructor invoked in the anonymous constructor. To
Expand Down Expand Up @@ -2967,6 +2963,10 @@ public ParameterizedExecutableType constructorFromUse(NewClassTree tree) {
con = AnnotatedTypes.asMemberOf(types, this, type, ctor, con);
}

if (viewpointAdapter != null) {
viewpointAdapter.viewpointAdaptConstructor(type, ctor, con);
}

Map<TypeVariable, AnnotatedTypeMirror> typeParamToTypeArg =
AnnotatedTypes.findTypeArguments(processingEnv, this, tree, ctor, con);
List<AnnotatedTypeMirror> typeargs;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package tests;
package org.checkerframework.framework.test.junit;

import org.checkerframework.framework.test.CheckerFrameworkPerDirectoryTest;
import org.junit.runners.Parameterized;
Expand Down
27 changes: 27 additions & 0 deletions framework/tests/viewpointtest/VarargType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import viewpointtest.quals.*;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add the usual starter text with a link to the issue that this test is for?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests that actually use some annotations would be nice.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add the usual starter text with a link to the issue that this test is for?

Done

Tests that actually use some annotations would be nice.

Done


public class VarargType {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the Type in the class name referring to?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed it to VarargsConstructor.


VarargType(String str, Object... args) {}

void foo() {
VarargType a = new VarargType("testStr", new Object());
}

// inner class
class Inner {
Inner(String str, Object... args) {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about only the varargs parameter and then test with:

  • new Inner()
  • new Inner(new Object())
  • Varargtype.this.new Inner()
  • Varargtype.this.new Inner(new Object())

To test more of the tricky combinations with inner classes.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added.


void foo() {
Inner a = new Inner("testStr", new Object());
}
}

// anonymous class
Object o =
new Object() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't test that the varargs constructor can be used to create an anonymous class. It should be something like new VarargType(...) { /* either nothing or some code */ }

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, thanks!

void foo() {
VarargType a = new VarargType("testStr", new Object());
}
};
}
Loading