@@ -1225,8 +1225,8 @@ public ClassNode visitTypeDeclaration(final TypeDeclarationContext ctx) {
12251225 public ClassNode visitClassDeclaration (final ClassDeclarationContext ctx ) {
12261226 String packageName = Optional .ofNullable (this .moduleNode .getPackageName ()).orElse ("" );
12271227 String className = this .visitIdentifier (ctx .identifier ());
1228- if ("var" .equals (className )) {
1229- throw createParsingFailedException ("var cannot be used for type declarations" , ctx .identifier ());
1228+ if ("var" .equals (className ) || "val" . equals ( className ) ) {
1229+ throw createParsingFailedException (className + " cannot be used for type declarations" , ctx .identifier ());
12301230 }
12311231
12321232 boolean isAnnotation = asBoolean (ctx .AT ());
@@ -1747,8 +1747,8 @@ public MethodNode visitCompactConstructorDeclaration(final CompactConstructorDec
17471747 throw createParsingFailedException ("Only record can have compact constructor" , ctx );
17481748 }
17491749
1750- if (new ModifierManager (this , ctx .getNodeMetaData (COMPACT_CONSTRUCTOR_DECLARATION_MODIFIERS )).containsAny (VAR )) {
1751- throw createParsingFailedException ("var cannot be used for compact constructor declaration" , ctx );
1750+ if (new ModifierManager (this , ctx .getNodeMetaData (COMPACT_CONSTRUCTOR_DECLARATION_MODIFIERS )).containsAny (VAL , VAR )) {
1751+ throw createParsingFailedException ("val/ var cannot be used for compact constructor declaration" , ctx );
17521752 }
17531753
17541754 String methodName = this .visitMethodName (ctx .methodName ());
@@ -1785,8 +1785,8 @@ public void visitPropertyExpression(final PropertyExpression expression) {
17851785 public MethodNode visitMethodDeclaration (final MethodDeclarationContext ctx ) {
17861786 ModifierManager modifierManager = createModifierManager (ctx );
17871787
1788- if (modifierManager .containsAny (VAR )) {
1789- throw createParsingFailedException ("var cannot be used for method declarations " , ctx );
1788+ if (modifierManager .containsAny (VAL , VAR )) {
1789+ throw createParsingFailedException ("val/ var cannot be used for method return types " , ctx );
17901790 }
17911791
17921792 String methodName = this .visitMethodName (ctx .methodName ());
@@ -4691,7 +4691,7 @@ private boolean isSyntheticPublic(final boolean isAnnotationDeclaration, final b
46914691 return true ;
46924692 }
46934693
4694- if (hasReturnType && (modifierManager .containsAny (DEF , VAR ))) {
4694+ if (hasReturnType && (modifierManager .containsAny (DEF , VAL , VAR ))) {
46954695 return true ;
46964696 }
46974697
0 commit comments