Skip to content

Commit

Permalink
Don't recursively call the function if the underlining type is raw
Browse files Browse the repository at this point in the history
  • Loading branch information
Ao-senXiong committed Aug 19, 2024
1 parent 13bd97b commit 718847c
Showing 1 changed file with 17 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -303,15 +303,16 @@ protected AnnotatedTypeMirror combineAnnotationWithType(
AnnotationMirror resultAnnotation =
combineAnnotationWithAnnotation(
receiverAnnotation, extractAnnotationMirror(adt));

// Recursively combine type arguments and store to map
for (AnnotatedTypeMirror typeArgument : adt.getTypeArguments()) {
// Recursively adapt the type arguments of this adt
AnnotatedTypeMirror combinedTypeArgument =
combineAnnotationWithType(receiverAnnotation, typeArgument);
mappings.put(typeArgument, combinedTypeArgument);
// Don't recursively combine type arguments if the type is raw
if (!adt.isUnderlyingTypeRaw()) {
// Recursively combine type arguments and store to map
for (AnnotatedTypeMirror typeArgument : adt.getTypeArguments()) {
// Recursively adapt the type arguments of this adt
AnnotatedTypeMirror combinedTypeArgument =
combineAnnotationWithType(receiverAnnotation, typeArgument);
mappings.put(typeArgument, combinedTypeArgument);
}
}

// Construct result type
AnnotatedTypeMirror result = AnnotatedTypeCopierWithReplacement.replace(adt, mappings);
result.replaceAnnotation(resultAnnotation);
Expand Down Expand Up @@ -413,11 +414,14 @@ private AnnotatedTypeMirror substituteTVars(AnnotatedTypeMirror lhs, AnnotatedTy
AnnotatedDeclaredType adt = (AnnotatedDeclaredType) rhs.shallowCopy();
IdentityHashMap<AnnotatedTypeMirror, AnnotatedTypeMirror> mappings =
new IdentityHashMap<>();

for (AnnotatedTypeMirror formalTypeParameter : adt.getTypeArguments()) {
AnnotatedTypeMirror actualTypeArgument = substituteTVars(lhs, formalTypeParameter);
mappings.put(formalTypeParameter, actualTypeArgument);
// The following code does the wrong thing!
// Don't recursively substitute type arguments if the type is raw
if (!adt.isUnderlyingTypeRaw()) {
for (AnnotatedTypeMirror formalTypeParameter : adt.getTypeArguments()) {
AnnotatedTypeMirror actualTypeArgument =
substituteTVars(lhs, formalTypeParameter);
mappings.put(formalTypeParameter, actualTypeArgument);
// The following code does the wrong thing!
}
}
// We must use AnnotatedTypeReplacer to replace the formal type parameters with actual
// type arguments, but not replace with its main qualifier
Expand Down

0 comments on commit 718847c

Please sign in to comment.