Skip to content

Commit

Permalink
GROOVY-11448: STC: subList bounds check
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Sep 5, 2024
1 parent 210ae70 commit f40842b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -4037,7 +4037,7 @@ private void checkForbiddenSpreadArgument(final ArgumentListExpression argumen
checkForbiddenSpreadArgument(arguments);
} else { // GROOVY-10597: allow spread for the ... param
List<Expression> list = arguments.getExpressions();
list = list.subList(0, parameters.length - 1);
list = list.subList(0, Math.min(parameters.length - 1, list.size())); // GROOVY-11448
checkForbiddenSpreadArgument(args(list));
}
}
Expand Down
9 changes: 9 additions & 0 deletions src/test/groovy/transform/stc/ClosuresSTCTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,15 @@ class ClosuresSTCTest extends StaticTypeCheckingTestCase {
'Cannot call closure that accepts [java.lang.Object, java.lang.Object] with [java.lang.String]'
}

// GROOVY-11448
void testCallClosure18() {
assertScript '''
def c = { int x = 0, int[] y = new int[0] -> return x }
assert c( ) == 0
assert c(1) == 1
'''
}

void testClosureReturnTypeInference1() {
assertScript '''
def c = { int a, int b -> return a + b }
Expand Down

0 comments on commit f40842b

Please sign in to comment.