Skip to content
Open
Show file tree
Hide file tree
Changes from 20 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 @@ -273,6 +273,8 @@ protected AnnotatedTypeMirror combineAnnotationWithType(
if (!isTypeVarExtends) {
isTypeVarExtends = true;
AnnotatedTypeVariable atv = (AnnotatedTypeVariable) declared.shallowCopy();
AnnotationMirror primaryAnnotation =
atv.getAnnotationInHierarchy(receiverAnnotation);
IdentityHashMap<AnnotatedTypeMirror, AnnotatedTypeMirror> mappings =
new IdentityHashMap<>();

Expand All @@ -284,9 +286,18 @@ 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.removeAnnotationInHierarchy(receiverAnnotation);
AnnotatedTypeMirror result =
AnnotatedTypeCopierWithReplacement.replace(atv, mappings);
if (primaryAnnotation != null) {
result.replaceAnnotation(
combineAnnotationWithAnnotation(receiverAnnotation, primaryAnnotation));
}

isTypeVarExtends = false;
return result;
Expand Down Expand Up @@ -404,7 +415,12 @@ private AnnotatedTypeMirror substituteTVars(AnnotatedTypeMirror lhs, AnnotatedTy

// Base case where actual type argument is extracted
if (lhs.getKind() == TypeKind.DECLARED) {
// Replace type variable with its actual type argument
rhs = getTypeVariableSubstitution((AnnotatedDeclaredType) lhs, atv);
Comment thread
aosen-xiong marked this conversation as resolved.
// If the type variable use has a primary annotation, apply it to the substitute.
if (!atv.getAnnotationsField().isEmpty()) {
rhs.replaceAnnotations(atv.getAnnotations());
}
}
} else if (rhs.getKind() == TypeKind.DECLARED) {
AnnotatedDeclaredType adt = (AnnotatedDeclaredType) rhs.shallowCopy();
Expand Down
31 changes: 31 additions & 0 deletions framework/tests/viewpointtest/AnnoOnTypeVariableUse.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import viewpointtest.quals.*;

@SuppressWarnings("cast.unsafe.constructor.invocation")
class AnnoOnTypeVariableUse<E> {
@ReceiverDependentQual E rdq;
@A E a;
@B E b;
E c;

void test() {
AnnoOnTypeVariableUse<@B Element> d = new @A AnnoOnTypeVariableUse<>();
// d.element = @A |> @RDQ = @A
d.rdq = new @A Element();
// :: error: (assignment.type.incompatible)
d.rdq = new @B Element();
// d.a = @A |> @A = @A
d.a = new @A Element();
// :: error: (assignment.type.incompatible)
d.a = new @B Element();
// d.b = @A |> @B = @B
d.b = new @B Element();
// :: error: (assignment.type.incompatible)
d.b = new @A Element();
// :: error: (assignment.type.incompatible)
d.c = new @A Element();
// d.c = @B type argument subsitution with unannotated field
d.c = new @B Element();
}

class Element {}
}
Loading