Skip to content

Commit 3699dd8

Browse files
committed
comment improvements
1 parent 6958035 commit 3699dd8

2 files changed

Lines changed: 4 additions & 0 deletions

File tree

‎nullaway/src/main/java/com/uber/nullaway/generics/GenericsChecks.java‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -814,6 +814,8 @@ && isAssignmentToField(tree)) {
814814
state.withPath(pathToRhs),
815815
(MethodInvocationTree) rhsTree,
816816
pathToRhs,
817+
// if a local is declared using `var`, don't use its javac-inferred type as part of
818+
// inference
817819
varLocalDeclaration ? null : lhsType,
818820
assignedToLocal,
819821
false);
@@ -823,6 +825,7 @@ && isAssignmentToField(tree)) {
823825
VariableTree varTree = (VariableTree) tree;
824826
Symbol symbol = ASTHelpers.getSymbol(varTree);
825827
if (symbol != null) {
828+
// if declared with `var` we should always get a non-null VarLocalKey for the symbol
826829
VarLocalKey key = castToNonNull(getVarLocalKey(symbol));
827830
inferredVarLocalTypes.put(key, rhsType);
828831
}

‎nullaway/src/test/java/com/uber/nullaway/jspecify/VarDeclaredLocalTests.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public void varInTryWithResources() {
5151
@NullMarked
5252
class Test {
5353
void test(Iterator<@Nullable Object> iterator) {
54+
// just testing that we don't crash here
5455
try (var stream = StreamSupport.stream(
5556
Spliterators.spliteratorUnknownSize(iterator, Spliterator.ORDERED), false)) {
5657
}

0 commit comments

Comments
 (0)