Skip to content

Commit

Permalink
All primitive types are @Interned
Browse files Browse the repository at this point in the history
Fixes typetools#6371.

The interning checker does not apply `@Interned` to every occurrence of
every primitive type.  This allows some language constructs to
fabricate non-interned primitive values, leading to false positives.

For instance, in the new `loopVariables` test, the loop variable `i`
was assigned the type `@UnknownInterned long`.  Thus `i` could not be
used as an argument to `addExact` which requires interned arguments.
  • Loading branch information
Calvin-L committed Oct 15, 2024
1 parent 6573486 commit 8026afc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,13 @@ public Void visitDeclared(AnnotatedDeclaredType t, Void p) {
}
return super.visitDeclared(t, p);
}

@Override
public Void visitPrimitive(AnnotatedPrimitiveType t, Void p) {
// case 4: primitive types are interned
t.replaceAnnotation(INTERNED);
return super.visitPrimitive(t, p);
}
}

/**
Expand Down
6 changes: 6 additions & 0 deletions checker/tests/interning/UnboxUninterned.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,10 @@ void negation() {
int i1 = -x.intValue();
int i2 = -x;
}

void loopVariables(java.util.List<Long> list) {
for (long i : list) {
long unused = Math.addExact(i, 0L);
}
}
}

0 comments on commit 8026afc

Please sign in to comment.