Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
c479361
fix viewpoint adaptation
AndrewShf Oct 27, 2023
0b71144
add comments
AndrewShf Nov 13, 2023
3f4b065
remove getannotationsfield().clear()
AndrewShf Nov 13, 2023
7d78a7d
reset annotated type variables in viewpoint adaptation
AndrewShf Nov 13, 2023
06c15e5
add comments
AndrewShf Nov 18, 2023
584d98f
Refine the comment
aosen-xiong Jul 3, 2024
371a623
Test case with expected failure
aosen-xiong Jul 3, 2024
e15a909
Merge branch 'master' into haifeng-viewpointAdpatOnGenerics
aosen-xiong Jul 3, 2024
eb4a8bd
Empty commit for CI
aosen-xiong Jul 3, 2024
48ef745
Assign @B to effectively @A should fail
aosen-xiong Jul 4, 2024
5db3b4c
Merge branch 'master' into haifeng-viewpointAdpatOnGenerics
aosen-xiong Aug 29, 2024
46f8fba
Clear comment how the code change fix the problem
aosen-xiong Sep 6, 2024
6c579aa
Merge branch 'master' into haifeng-viewpointAdpatOnGenerics
aosen-xiong Sep 6, 2024
b35a4ab
Merge branch 'master' into haifeng-viewpointAdpatOnGenerics
aosen-xiong Sep 8, 2024
d1220fd
Merge branch 'master' into haifeng-viewpointAdpatOnGenerics
wmdietl Nov 8, 2024
8ef1c18
Merge branch 'master' into haifeng-viewpointAdpatOnGenerics
wmdietl Nov 13, 2024
ed7cfbd
Also add unannotated type variable use in test
aosen-xiong Dec 18, 2024
cb70b07
Merge branch 'master' into haifeng-viewpointAdpatOnGenerics
wmdietl Jan 3, 2025
9f994a9
Merge branch 'master' into haifeng-viewpointAdpatOnGenerics
aosen-xiong Oct 21, 2025
5977355
Preserve type variable use annotations during viewpoint adaptation
aosen-xiong Jun 15, 2026
b88be07
Merge branch 'master' into haifeng-viewpointAdpatOnGenerics
aosen-xiong Jun 15, 2026
e598c25
Merge branch 'master' into haifeng-viewpointAdpatOnGenerics
aosen-xiong Jun 15, 2026
c61001f
Trigger CI
aosen-xiong Jun 15, 2026
8721ef9
Implement explicit type-variable use semantics
aosen-xiong Jun 23, 2026
58bc0b3
Consolidate type-variable use tests
aosen-xiong Jun 23, 2026
2581b3c
Refine type-variable use requalification
aosen-xiong Jun 23, 2026
34b82d2
Merge branch 'master' into haifeng-viewpointAdpatOnGenerics
aosen-xiong Jun 23, 2026
c8aa74f
Reset type variable mode when clearing stub annotations
aosen-xiong Jun 23, 2026
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedPrimitiveType;
import org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedTypeVariable;
import org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedWildcardType;
import org.checkerframework.javacutil.AnnotationUtils;
import org.checkerframework.javacutil.BugInCF;
import org.checkerframework.javacutil.ElementUtils;
import org.plumelib.util.IPair;
Expand Down Expand Up @@ -285,7 +286,12 @@ protected AnnotatedTypeMirror combineAnnotationWithType(
AnnotatedTypeMirror resLower =
combineAnnotationWithType(receiverAnnotation, atv.getLowerBound());
mappings.put(atv.getLowerBound(), resLower);

// The values of the mappings are the viewpoint adapted lower and upper bounds,
// and we wish to replace the old bounds of atv with the new mappings.
// However, we need to first remove the primary annotations of atv, otherwise
// in later replacement, the primary annotations would override our computed
// new mappings (see method fixupBoundAnnotations).
atv.clearAnnotations();
AnnotatedTypeMirror result =
AnnotatedTypeCopierWithReplacement.replace(atv, mappings);

Expand Down Expand Up @@ -408,6 +414,25 @@ private AnnotatedTypeMirror substituteTVars(AnnotatedTypeMirror lhs, AnnotatedTy
// Base case where actual type argument is extracted
if (lhs.getKind() == TypeKind.DECLARED) {
rhs = getTypeVariableSubstitution((AnnotatedDeclaredType) lhs, atv);
Comment thread
aosen-xiong marked this conversation as resolved.
// When substituting an annotated type variable use (e.g., fields, return type), we
// don't want to replace the type qualifier of it with the qualifier on the
// type argument, as specified in
// https://checkerframework.org/manual/#type-variable-use. However, method
// getTypeVariableSubstitution will replace the annotated type qualifier as well.
// We fix up the substitution by checking if the types of the lower and upper bound
// are the same. If they are the same: (1) either the type variable use is
// annotated, and we need to fix up the
// primary annotation of the substituted result (rhs) by replacing it with the
// previous annotated type qualifier (from atv); (2) or the use is not annotated,
// but
Comment thread
aosen-xiong marked this conversation as resolved.
Outdated
// the type parameter is declared with the same upper and lower bounds, and it's no
// harm doing the same replacement as (1) because the qualifiers of the substituted
// result (rhs) and the old type variable use (atv) must be the same.
if (AnnotationUtils.areSame(
atv.getLowerBound().getAnnotations(),
atv.getUpperBound().getAnnotations())) {
rhs.replaceAnnotations(atv.getLowerBound().getAnnotations());
}
}
} else if (rhs.getKind() == TypeKind.DECLARED) {
AnnotatedDeclaredType adt = (AnnotatedDeclaredType) rhs.shallowCopy();
Expand Down
17 changes: 17 additions & 0 deletions framework/tests/viewpointtest/AnnoOnTypeVariableUse.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import viewpointtest.quals.*;

@SuppressWarnings("cast.unsafe.constructor.invocation")
class AnnoOnTypeVariableUse<E> {
@ReceiverDependentQual E element;

static void test() {
AnnoOnTypeVariableUse<@B Element> d = new @A AnnoOnTypeVariableUse<@B Element>();
// d.element = @A |> @RDQ = @A
// thus expects no error here
d.element = new @A Element();
Comment thread
aosen-xiong marked this conversation as resolved.
Outdated
Comment thread
aosen-xiong marked this conversation as resolved.
Outdated
}
}

class Element {
int f = 1;
}