Skip to content

Commit acfe9c5

Browse files
cushonkluever
authored andcommitted
Fix a crash on c-style arrays in parameters
Fixes #374 ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=286467734
1 parent 81aaab9 commit acfe9c5

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

core/src/main/java/com/google/googlejavaformat/java/JavaInputAstVisitor.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -2542,18 +2542,20 @@ private void visitToDeclare(
25422542
String equals,
25432543
Optional<String> trailing) {
25442544
sync(node);
2545+
TypeWithDims extractedDims = DimensionHelpers.extractDims(node.getType(), SortedDims.YES);
2546+
Optional<TypeWithDims> typeWithDims = Optional.of(extractedDims);
25452547
declareOne(
25462548
kind,
25472549
annotationsDirection,
25482550
Optional.of(node.getModifiers()),
2549-
node.getType(),
2551+
extractedDims.node,
25502552
node.getName(),
25512553
"",
25522554
equals,
25532555
initializer,
25542556
trailing,
25552557
/* receiverExpression= */ Optional.empty(),
2556-
/* typeWithDims= */ Optional.empty());
2558+
typeWithDims);
25572559
}
25582560

25592561
/** Does not omit the leading '<', which should be associated with the type name. */
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import java.lang.annotation.ElementType;
2+
import java.lang.annotation.Target;
3+
4+
@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})
5+
@interface MyTypeAnno {}
6+
7+
public class GjfFailure {
8+
void m(int a @MyTypeAnno []) {}
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import java.lang.annotation.ElementType;
2+
import java.lang.annotation.Target;
3+
4+
@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})
5+
@interface MyTypeAnno {}
6+
7+
public class GjfFailure {
8+
void m(int a @MyTypeAnno []) {}
9+
}

0 commit comments

Comments
 (0)