Skip to content
Open
Changes from 2 commits
Commits
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
13 changes: 13 additions & 0 deletions src/checkers/inference/util/SlotDefaultTypeResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import com.sun.source.tree.AnnotatedTypeTree;
import com.sun.source.tree.ArrayTypeTree;
import com.sun.source.tree.ClassTree;
import com.sun.source.tree.ExpressionTree;
import com.sun.source.tree.NewClassTree;
import com.sun.source.tree.ParameterizedTypeTree;
import com.sun.source.tree.PrimitiveTypeTree;
import com.sun.source.tree.Tree;
Expand Down Expand Up @@ -185,5 +187,16 @@ public Void visitAnnotatedType(AnnotatedTypeTree tree, Void unused) {

return super.visitAnnotatedType(tree, unused);
}

@Override
public Void visitNewClass(NewClassTree tree, Void unused) {
AnnotatedTypeMirror defaultType = getDefaultTypeFor(tree);
ExpressionTree type = tree.getIdentifier();
if ((type instanceof ParameterizedTypeTree) && !((ParameterizedTypeTree) type).getTypeArguments().isEmpty())

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I think you need to loop through the type arguments and put the corresponding types into defaultTypes. You can take visitParameterizedType as a reference.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I have a small example like new ArrayList<String>(), and I find super.VisitNewClass() already recursively call the visitParameterizedType() method for tree ArrayList<String>. So, I don't think I need to call that method again.

Besides, what are the type arguments of a new class tree?
As said in the javadoc in NewClassTree.java

A tree node to declare a new instance of a class. For example:
     new typeArguments identifier ( arguments )
         classBody

The typearguments is in front of the identifier. And when I played around with this example new ArrayList<String>(), using tree.getTypeArguments() returns an empty list.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You're right, I forgot the typeArguments are not arguments to the class' type parameters. Those are arguments to type parameters on the constructor.

return super.visitNewClass(tree, unused);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

We probably don't need the logic here. We should always save defaultType to the cache before visiting child nodes.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Without the if branch, CI failed on the test case AnonymousProblem.java. It raised the assertion error from the visitParameterizedType
The reason is because: (take new ArrayList<String>() as an example). the NewClassTree does not have String as the type argument, which has 0 type argument, but the ParameterizedTypeTree has 1 type argument, and thus cause the assertion failure.


defaultTypes.put(type, defaultType);
return super.visitNewClass(tree, unused);
}
}
}