Fix NPE with empty pattern list

This commit is contained in:
Clément Fournier 2024-10-07 16:40:37 +02:00
parent 00bf6fe2f7
commit 2c1a7f026e
No known key found for this signature in database
GPG Key ID: 6F9389D8E390BD4C
3 changed files with 79 additions and 38 deletions

View File

@ -1889,13 +1889,13 @@ void RecordPattern():
(Annotation())* ReferenceType() RecordStructurePattern() (Annotation())* ReferenceType() RecordStructurePattern()
} }
void RecordStructurePattern() #void: void RecordStructurePattern() #PatternList:
{} {}
{ {
"(" [ ComponentPatternList() ] ")" "(" [ ComponentPatternList() ] ")"
} }
void ComponentPatternList() #PatternList : void ComponentPatternList() #void :
{} {}
{ {
ComponentPattern() ( "," ComponentPattern() )* ComponentPattern() ( "," ComponentPattern() )*

View File

@ -97,4 +97,13 @@ public class RecordPatterns {
System.out.println("String " + s); System.out.println("String " + s);
} }
} }
record Empty(){}
void foo(Object o) {
boolean x = o instanceof Empty;
x = o instanceof Empty();
}
;
} }

View File

@ -1,7 +1,7 @@
+- CompilationUnit[@PackageName = ""] +- CompilationUnit[@PackageName = ""]
+- ClassDeclaration[@Abstract = false, @Annotation = false, @Anonymous = false, @BinaryName = "RecordPatterns", @CanonicalName = "RecordPatterns", @EffectiveVisibility = Visibility.V_PUBLIC, @Enum = false, @Final = false, @Interface = false, @Local = false, @Nested = false, @PackageName = "", @Record = false, @RegularClass = true, @RegularInterface = false, @SimpleName = "RecordPatterns", @Static = false, @TopLevel = true, @UnnamedToplevelClass = false, @Visibility = Visibility.V_PUBLIC] +- ClassDeclaration[@Abstract = false, @Annotation = false, @Anonymous = false, @BinaryName = "RecordPatterns", @CanonicalName = "RecordPatterns", @EffectiveVisibility = Visibility.V_PUBLIC, @Enum = false, @Final = false, @Interface = false, @Local = false, @Nested = false, @PackageName = "", @Record = false, @RegularClass = true, @RegularInterface = false, @SimpleName = "RecordPatterns", @Static = false, @TopLevel = true, @UnnamedToplevelClass = false, @Visibility = Visibility.V_PUBLIC]
+- ModifierList[@EffectiveModifiers = (JModifier.PUBLIC), @ExplicitModifiers = (JModifier.PUBLIC)] +- ModifierList[@EffectiveModifiers = (JModifier.PUBLIC), @ExplicitModifiers = (JModifier.PUBLIC)]
+- ClassBody[@Empty = false, @Size = 18] +- ClassBody[@Empty = false, @Size = 21]
+- RecordDeclaration[@Abstract = false, @Annotation = false, @Anonymous = false, @BinaryName = "RecordPatterns$Point", @CanonicalName = "RecordPatterns.Point", @EffectiveVisibility = Visibility.V_PACKAGE, @Enum = false, @Final = true, @Interface = false, @Local = false, @Nested = true, @PackageName = "", @Record = true, @RegularClass = false, @RegularInterface = false, @SimpleName = "Point", @Static = true, @TopLevel = false, @UnnamedToplevelClass = false, @Visibility = Visibility.V_PACKAGE] +- RecordDeclaration[@Abstract = false, @Annotation = false, @Anonymous = false, @BinaryName = "RecordPatterns$Point", @CanonicalName = "RecordPatterns.Point", @EffectiveVisibility = Visibility.V_PACKAGE, @Enum = false, @Final = true, @Interface = false, @Local = false, @Nested = true, @PackageName = "", @Record = true, @RegularClass = false, @RegularInterface = false, @SimpleName = "Point", @Static = true, @TopLevel = false, @UnnamedToplevelClass = false, @Visibility = Visibility.V_PACKAGE]
| +- ModifierList[@EffectiveModifiers = (JModifier.STATIC, JModifier.FINAL), @ExplicitModifiers = ()] | +- ModifierList[@EffectiveModifiers = (JModifier.STATIC, JModifier.FINAL), @ExplicitModifiers = ()]
| +- RecordComponentList[@Empty = false, @Size = 2, @Varargs = false] | +- RecordComponentList[@Empty = false, @Size = 2, @Varargs = false]
@ -512,38 +512,70 @@
| +- StringLiteral[@CompileTimeConstant = true, @ConstValue = "String ", @Empty = false, @Image = "\"String \"", @Length = 7, @LiteralText = "\"String \"", @ParenthesisDepth = 0, @Parenthesized = false, @TextBlock = false] | +- StringLiteral[@CompileTimeConstant = true, @ConstValue = "String ", @Empty = false, @Image = "\"String \"", @Length = 7, @LiteralText = "\"String \"", @ParenthesisDepth = 0, @Parenthesized = false, @TextBlock = false]
| +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "s", @Name = "s", @ParenthesisDepth = 0, @Parenthesized = false] | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "s", @Name = "s", @ParenthesisDepth = 0, @Parenthesized = false]
+- MethodDeclaration[@Abstract = false, @Arity = 1, @EffectiveVisibility = Visibility.V_PACKAGE, @Final = false, @Name = "test4", @Overridden = false, @Static = false, @Varargs = false, @Visibility = Visibility.V_PACKAGE, @Void = true] +- MethodDeclaration[@Abstract = false, @Arity = 1, @EffectiveVisibility = Visibility.V_PACKAGE, @Final = false, @Name = "test4", @Overridden = false, @Static = false, @Varargs = false, @Visibility = Visibility.V_PACKAGE, @Void = true]
+- ModifierList[@EffectiveModifiers = (), @ExplicitModifiers = ()] | +- ModifierList[@EffectiveModifiers = (), @ExplicitModifiers = ()]
+- VoidType[] | +- VoidType[]
+- FormalParameters[@Empty = false, @Size = 1] | +- FormalParameters[@Empty = false, @Size = 1]
| +- FormalParameter[@EffectiveVisibility = Visibility.V_LOCAL, @Final = false, @Varargs = false, @Visibility = Visibility.V_LOCAL] | | +- FormalParameter[@EffectiveVisibility = Visibility.V_LOCAL, @Final = false, @Varargs = false, @Visibility = Visibility.V_LOCAL]
| +- ModifierList[@EffectiveModifiers = (), @ExplicitModifiers = ()] | | +- ModifierList[@EffectiveModifiers = (), @ExplicitModifiers = ()]
| +- ClassType[@FullyQualified = false, @PackageQualifier = null, @SimpleName = "Box"] | | +- ClassType[@FullyQualified = false, @PackageQualifier = null, @SimpleName = "Box"]
| | +- TypeArguments[@Diamond = false, @Empty = false, @Size = 1] | | | +- TypeArguments[@Diamond = false, @Empty = false, @Size = 1]
| | +- ClassType[@FullyQualified = false, @PackageQualifier = null, @SimpleName = "Box"] | | | +- ClassType[@FullyQualified = false, @PackageQualifier = null, @SimpleName = "Box"]
| | +- TypeArguments[@Diamond = false, @Empty = false, @Size = 1] | | | +- TypeArguments[@Diamond = false, @Empty = false, @Size = 1]
| | +- ClassType[@FullyQualified = false, @PackageQualifier = null, @SimpleName = "String"] | | | +- ClassType[@FullyQualified = false, @PackageQualifier = null, @SimpleName = "String"]
| +- VariableId[@ArrayType = false, @EffectiveVisibility = Visibility.V_LOCAL, @EnumConstant = false, @ExceptionBlockParameter = false, @Field = false, @Final = false, @ForLoopVariable = false, @ForeachVariable = false, @FormalParameter = true, @LambdaParameter = false, @LocalVariable = false, @Name = "bo", @PatternBinding = false, @RecordComponent = false, @ResourceDeclaration = false, @Static = false, @TypeInferred = false, @Unnamed = false, @Visibility = Visibility.V_LOCAL] | | +- VariableId[@ArrayType = false, @EffectiveVisibility = Visibility.V_LOCAL, @EnumConstant = false, @ExceptionBlockParameter = false, @Field = false, @Final = false, @ForLoopVariable = false, @ForeachVariable = false, @FormalParameter = true, @LambdaParameter = false, @LocalVariable = false, @Name = "bo", @PatternBinding = false, @RecordComponent = false, @ResourceDeclaration = false, @Static = false, @TypeInferred = false, @Unnamed = false, @Visibility = Visibility.V_LOCAL]
+- Block[@Empty = false, @Size = 1, @containsComment = false] | +- Block[@Empty = false, @Size = 1, @containsComment = false]
+- IfStatement[@Else = false] | +- IfStatement[@Else = false]
+- InfixExpression[@CompileTimeConstant = false, @Operator = BinaryOp.INSTANCEOF, @ParenthesisDepth = 0, @Parenthesized = false] | +- InfixExpression[@CompileTimeConstant = false, @Operator = BinaryOp.INSTANCEOF, @ParenthesisDepth = 0, @Parenthesized = false]
| +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "bo", @Name = "bo", @ParenthesisDepth = 0, @Parenthesized = false] | | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "bo", @Name = "bo", @ParenthesisDepth = 0, @Parenthesized = false]
| +- PatternExpression[@CompileTimeConstant = false, @ParenthesisDepth = 0, @Parenthesized = false] | | +- PatternExpression[@CompileTimeConstant = false, @ParenthesisDepth = 0, @Parenthesized = false]
| +- RecordPattern[] | | +- RecordPattern[]
| +- ClassType[@FullyQualified = false, @PackageQualifier = null, @SimpleName = "Box"] | | +- ClassType[@FullyQualified = false, @PackageQualifier = null, @SimpleName = "Box"]
| +- PatternList[@Empty = false, @Size = 1] | | +- PatternList[@Empty = false, @Size = 1]
| +- RecordPattern[] | | +- RecordPattern[]
| +- ClassType[@FullyQualified = false, @PackageQualifier = null, @SimpleName = "Box"] | | +- ClassType[@FullyQualified = false, @PackageQualifier = null, @SimpleName = "Box"]
| +- PatternList[@Empty = false, @Size = 1] | | +- PatternList[@Empty = false, @Size = 1]
| +- TypePattern[@EffectiveVisibility = Visibility.V_PACKAGE, @Visibility = Visibility.V_PACKAGE] | | +- TypePattern[@EffectiveVisibility = Visibility.V_PACKAGE, @Visibility = Visibility.V_PACKAGE]
| +- ModifierList[@EffectiveModifiers = (), @ExplicitModifiers = ()] | | +- ModifierList[@EffectiveModifiers = (), @ExplicitModifiers = ()]
| +- VariableId[@ArrayType = false, @EffectiveVisibility = Visibility.V_LOCAL, @EnumConstant = false, @ExceptionBlockParameter = false, @Field = false, @Final = false, @ForLoopVariable = false, @ForeachVariable = false, @FormalParameter = false, @LambdaParameter = false, @LocalVariable = false, @Name = "s", @PatternBinding = true, @RecordComponent = false, @ResourceDeclaration = false, @Static = false, @TypeInferred = true, @Unnamed = false, @Visibility = Visibility.V_LOCAL] | | +- VariableId[@ArrayType = false, @EffectiveVisibility = Visibility.V_LOCAL, @EnumConstant = false, @ExceptionBlockParameter = false, @Field = false, @Final = false, @ForLoopVariable = false, @ForeachVariable = false, @FormalParameter = false, @LambdaParameter = false, @LocalVariable = false, @Name = "s", @PatternBinding = true, @RecordComponent = false, @ResourceDeclaration = false, @Static = false, @TypeInferred = true, @Unnamed = false, @Visibility = Visibility.V_LOCAL]
+- Block[@Empty = false, @Size = 1, @containsComment = false] | +- Block[@Empty = false, @Size = 1, @containsComment = false]
+- ExpressionStatement[] | +- ExpressionStatement[]
+- MethodCall[@CompileTimeConstant = false, @Image = "println", @MethodName = "println", @ParenthesisDepth = 0, @Parenthesized = false] | +- MethodCall[@CompileTimeConstant = false, @Image = "println", @MethodName = "println", @ParenthesisDepth = 0, @Parenthesized = false]
+- FieldAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "out", @Name = "out", @ParenthesisDepth = 0, @Parenthesized = false] | +- FieldAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "out", @Name = "out", @ParenthesisDepth = 0, @Parenthesized = false]
| +- TypeExpression[@CompileTimeConstant = false, @ParenthesisDepth = 0, @Parenthesized = false] | | +- TypeExpression[@CompileTimeConstant = false, @ParenthesisDepth = 0, @Parenthesized = false]
| +- ClassType[@FullyQualified = false, @PackageQualifier = null, @SimpleName = "System"] | | +- ClassType[@FullyQualified = false, @PackageQualifier = null, @SimpleName = "System"]
+- ArgumentList[@Empty = false, @Size = 1] | +- ArgumentList[@Empty = false, @Size = 1]
+- InfixExpression[@CompileTimeConstant = false, @Operator = BinaryOp.ADD, @ParenthesisDepth = 0, @Parenthesized = false] | +- InfixExpression[@CompileTimeConstant = false, @Operator = BinaryOp.ADD, @ParenthesisDepth = 0, @Parenthesized = false]
+- StringLiteral[@CompileTimeConstant = true, @ConstValue = "String ", @Empty = false, @Image = "\"String \"", @Length = 7, @LiteralText = "\"String \"", @ParenthesisDepth = 0, @Parenthesized = false, @TextBlock = false] | +- StringLiteral[@CompileTimeConstant = true, @ConstValue = "String ", @Empty = false, @Image = "\"String \"", @Length = 7, @LiteralText = "\"String \"", @ParenthesisDepth = 0, @Parenthesized = false, @TextBlock = false]
+- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "s", @Name = "s", @ParenthesisDepth = 0, @Parenthesized = false] | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "s", @Name = "s", @ParenthesisDepth = 0, @Parenthesized = false]
+- RecordDeclaration[@Abstract = false, @Annotation = false, @Anonymous = false, @BinaryName = "RecordPatterns$Empty", @CanonicalName = "RecordPatterns.Empty", @EffectiveVisibility = Visibility.V_PACKAGE, @Enum = false, @Final = true, @Interface = false, @Local = false, @Nested = true, @PackageName = "", @Record = true, @RegularClass = false, @RegularInterface = false, @SimpleName = "Empty", @Static = true, @TopLevel = false, @UnnamedToplevelClass = false, @Visibility = Visibility.V_PACKAGE]
| +- ModifierList[@EffectiveModifiers = (JModifier.STATIC, JModifier.FINAL), @ExplicitModifiers = ()]
| +- RecordComponentList[@Empty = true, @Size = 0, @Varargs = false]
| +- RecordBody[@Empty = true, @Size = 0]
+- MethodDeclaration[@Abstract = false, @Arity = 1, @EffectiveVisibility = Visibility.V_PACKAGE, @Final = false, @Name = "foo", @Overridden = false, @Static = false, @Varargs = false, @Visibility = Visibility.V_PACKAGE, @Void = true]
| +- ModifierList[@EffectiveModifiers = (), @ExplicitModifiers = ()]
| +- VoidType[]
| +- FormalParameters[@Empty = false, @Size = 1]
| | +- FormalParameter[@EffectiveVisibility = Visibility.V_LOCAL, @Final = false, @Varargs = false, @Visibility = Visibility.V_LOCAL]
| | +- ModifierList[@EffectiveModifiers = (), @ExplicitModifiers = ()]
| | +- ClassType[@FullyQualified = false, @PackageQualifier = null, @SimpleName = "Object"]
| | +- VariableId[@ArrayType = false, @EffectiveVisibility = Visibility.V_LOCAL, @EnumConstant = false, @ExceptionBlockParameter = false, @Field = false, @Final = false, @ForLoopVariable = false, @ForeachVariable = false, @FormalParameter = true, @LambdaParameter = false, @LocalVariable = false, @Name = "o", @PatternBinding = false, @RecordComponent = false, @ResourceDeclaration = false, @Static = false, @TypeInferred = false, @Unnamed = false, @Visibility = Visibility.V_LOCAL]
| +- Block[@Empty = false, @Size = 2, @containsComment = false]
| +- LocalVariableDeclaration[@EffectiveVisibility = Visibility.V_LOCAL, @Final = false, @TypeInferred = false, @Visibility = Visibility.V_LOCAL]
| | +- ModifierList[@EffectiveModifiers = (), @ExplicitModifiers = ()]
| | +- PrimitiveType[@Kind = PrimitiveTypeKind.BOOLEAN]
| | +- VariableDeclarator[@Initializer = true, @Name = "x"]
| | +- VariableId[@ArrayType = false, @EffectiveVisibility = Visibility.V_LOCAL, @EnumConstant = false, @ExceptionBlockParameter = false, @Field = false, @Final = false, @ForLoopVariable = false, @ForeachVariable = false, @FormalParameter = false, @LambdaParameter = false, @LocalVariable = true, @Name = "x", @PatternBinding = false, @RecordComponent = false, @ResourceDeclaration = false, @Static = false, @TypeInferred = false, @Unnamed = false, @Visibility = Visibility.V_LOCAL]
| | +- InfixExpression[@CompileTimeConstant = false, @Operator = BinaryOp.INSTANCEOF, @ParenthesisDepth = 0, @Parenthesized = false]
| | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "o", @Name = "o", @ParenthesisDepth = 0, @Parenthesized = false]
| | +- TypeExpression[@CompileTimeConstant = false, @ParenthesisDepth = 0, @Parenthesized = false]
| | +- ClassType[@FullyQualified = false, @PackageQualifier = null, @SimpleName = "Empty"]
| +- ExpressionStatement[]
| +- AssignmentExpression[@CompileTimeConstant = false, @Compound = false, @Operator = AssignmentOp.ASSIGN, @ParenthesisDepth = 0, @Parenthesized = false]
| +- VariableAccess[@AccessType = AccessType.WRITE, @CompileTimeConstant = false, @Image = "x", @Name = "x", @ParenthesisDepth = 0, @Parenthesized = false]
| +- InfixExpression[@CompileTimeConstant = false, @Operator = BinaryOp.INSTANCEOF, @ParenthesisDepth = 0, @Parenthesized = false]
| +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "o", @Name = "o", @ParenthesisDepth = 0, @Parenthesized = false]
| +- PatternExpression[@CompileTimeConstant = false, @ParenthesisDepth = 0, @Parenthesized = false]
| +- RecordPattern[]
| +- ClassType[@FullyQualified = false, @PackageQualifier = null, @SimpleName = "Empty"]
| +- PatternList[@Empty = true, @Size = 0]
+- EmptyDeclaration[]