Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue 1008 #1009

Merged
merged 3 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
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