Skip to content

Commit

Permalink
Fix issue 1008 (#1009)
Browse files Browse the repository at this point in the history
  • Loading branch information
msridhar authored Jul 29, 2024
1 parent 5584291 commit 882ec59
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -557,11 +557,14 @@ public static void compareGenericTypeParameterNullabilityForCall(
(Type.ArrayType) formalParams.get(formalParams.size() - 1).type;
Type varargsElementType = varargsArrayType.elemtype;
for (int i = formalParams.size() - 1; i < actualParams.size(); i++) {
Type actualParameter = getTreeType(actualParams.get(i), state);
if (actualParameter != null) {
if (!subtypeParameterNullability(varargsElementType, actualParameter, state)) {
Type actualParameterType = getTreeType(actualParams.get(i), state);
// If the actual parameter type is assignable to the varargs array type, then the call site
// is passing the varargs directly in an array, and we should skip our check.
if (actualParameterType != null
&& !state.getTypes().isAssignable(actualParameterType, varargsArrayType)) {
if (!subtypeParameterNullability(varargsElementType, actualParameterType, state)) {
reportInvalidParametersNullabilityError(
varargsElementType, actualParameter, actualParams.get(i), state, analysis);
varargsElementType, actualParameterType, actualParams.get(i), state, analysis);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1839,6 +1839,23 @@ public void boxInteger() {
.doTest();
}

@Test
public void issue1008() {
// testing for no crash
makeHelper()
.addSourceLines(
"EnumCombinations.java",
"package com.uber;",
"public class EnumCombinations {",
" public static void combinations(Class<? extends Enum<?>> first, Class<? extends Enum<?>>... others) {",
" }",
" public static void args(Class<? extends Enum<?>> first, Class<? extends Enum<?>>... others) {",
" combinations(first, others);",
" }",
"}")
.doTest();
}

private CompilationTestHelper makeHelper() {
return makeTestHelperWithArgs(
Arrays.asList(
Expand Down

0 comments on commit 882ec59

Please sign in to comment.