-
Notifications
You must be signed in to change notification settings - Fork 18
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
Clarify defaulting of type variable uses #746
Conversation
@@ -452,6 +452,9 @@ public static boolean noStringMatchesAnyRegex( | |||
* @param iterable an iterable | |||
* @return a list of the results of applying {@code f} to the elements of {@code iterable} | |||
*/ | |||
@SuppressWarnings( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Ao-senXiong Can you try to understand why the behavior for the two test cases in the PR changed?
I tried to only clean-up the code, but these two tests changed behavior.
The changes do make sense to me, but they do come as a bit of a surprise.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, also :framework:checkInterning
and :dataflow:checkResourceLeak
start to fail, so I must have goofed up somewhere...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would also be nice to minimize test cases for these two type systems, to detect these problems earlier.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Working on this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@wmdietl Here is the minimal test case to reproduce interning checking failure in this branch:
public class Demo {
public <T extends Dummy<?,?>> T test(){
T t = getT();
return t;
}
public <T extends Dummy<?, ?>> T getT(){
return null;
}
public class Dummy<A,B>{
}
}
java -jar checker/dist/checker.jar -processor org.checkerframework.checker.interning.InterningChecker Demo.java
Demo.java:5: error: [return.type.incompatible] incompatible types in return.
return t;
^
type of expression: T[ extends @UnknownInterned Demo.@UnknownInterned Dummy<?[ extends @UnknownInterned Object super @InternedDistinct Void], ?[ extends @UnknownInterned Object super @InternedDistinct Void]> super @UnknownInterned Void]
method return type: T[ extends @UnknownInterned Demo.@UnknownInterned Dummy<?[ extends @UnknownInterned Object super @InternedDistinct Void], ?[ extends @UnknownInterned Object super @InternedDistinct Void]> super @InternedDistinct Void]
The lower bound of type parameter is not incompatible. If I use the master branch, it is fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A follow up here, looks like the type refinement works fine, however, the actual type of right hand side is changed.
In master:
InterningVisitor about to test whether actual is a subtype of expected (at Demo.java:4:15): actual tree = METHOD_INVOCATION getT()
actual: TYPEVAR T[ extends @UnknownInterned Demo.@UnknownInterned Dummy<?[ extends @UnknownInterned Object super @InternedDistinct Void], ?[ extends @UnknownInterned Object super @InternedDistinct Void]> super @InternedDistinct Void]
expected: TYPEVAR T[ extends @UnknownInterned Demo.@UnknownInterned Dummy<?[ extends @UnknownInterned Object super @InternedDistinct Void], ?[ extends @UnknownInterned Object super @InternedDistinct Void]> super @UnknownInterned Void]
In this branch
InterningVisitor about to test whether actual is a subtype of expected (at Demo.java:4:15): actual tree = METHOD_INVOCATION getT()
actual: TYPEVAR T[ extends @UnknownInterned Demo.@UnknownInterned Dummy<?[ extends @UnknownInterned Object super @InternedDistinct Void], ?[ extends @UnknownInterned Object super @InternedDistinct Void]> super @UnknownInterned Void]
expected: TYPEVAR T[ extends @UnknownInterned Demo.@UnknownInterned Dummy<?[ extends @UnknownInterned Object super @InternedDistinct Void], ?[ extends @UnknownInterned Object super @InternedDistinct Void]> super @UnknownInterned Void]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can also be confirmed by this test case works fine in this branch. I will debug and see why the right hand side of return type of method invocation is changed.
public class Demo {
public <T extends Dummy<?,?>> T test(){
T t = null;
return t;
}
public class Dummy<A,B>{
}
}
this.atypeFactory = atypeFactory; | ||
this.qualHierarchy = atypeFactory.getQualifierHierarchy(); | ||
this.scope = scope; | ||
this.type = type; | ||
this.shouldDefaultTypeVarLocals = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the previous version, I set this at the outer level, which stored an incorrect value.
The value of GATF#getShouldDefaultTypeVarLocals()
changes when determining the LHS type of a local variable.
This change made the all-systems
test pass again. The RegexUtil
suppression is still necessary.
If no other tests fail, that seems acceptable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
./gradlew checkResourceLeak
still gives errors like this:
dataflow/src/main/java/org/checkerframework/dataflow/analysis/ForwardAnalysisImpl.java:535: error: [builder:required.method.not.known] The checker cannot determine the must call methods of newThenStore or any of its aliases, so it could not determine if they were called. Typically, this error indicates that you need to write an @MustCall annotation (often on an unconstrained generic type).
S newThenStore = mergeStores(s, thenStore, shouldWiden);
^
The type of object is: S.
Reason for going out of scope: regular method exit
I tried adding @MustCall
to the S type parameter bound, but get the same failures.
@Ao-senXiong Can you see whether your previous test cases now pass and then see what the problem with the Resource Checker is?
Update: The problems I had reported with this PR have apparently been fixed by some other commit, whether to here, to The upgrade to 3.42.0-eisop4 will not require any changes to any of our code checked by the JSpecify reference checker (aside from adding an explicit type argument to one call, which is well below the threshold of worrying about, especially with the type-inference revamp that landed upstream on the horizon). |
Wait, no, sorry, I confused myself again: The errors are in |
No description provided.