Skip to content

Commit

Permalink
Tighten java annot value parsing (scala#21650)
Browse files Browse the repository at this point in the history
  • Loading branch information
dwijnand authored Sep 27, 2024
2 parents eb5c3e8 + 07dce3f commit 4e997d1
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/parsing/JavaParsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -369,8 +369,8 @@ object JavaParsers {
def annotation(): Option[Tree] = {
def classOrId(): Tree =
val id = qualId()
if in.lookaheadToken == CLASS then
in.nextToken()
if in.token == DOT && in.lookaheadToken == CLASS then
accept(DOT)
accept(CLASS)
TypeApply(
Select(
Expand Down
4 changes: 4 additions & 0 deletions tests/pos/i20026/J.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package p;

@TestInstance(TestInstance.Lifecycle.PER_CLASS)
class J { }
1 change: 1 addition & 0 deletions tests/pos/i20026/S.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
class S
15 changes: 15 additions & 0 deletions tests/pos/i20026/TestInstance.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package p;

import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Inherited
public @interface TestInstance {
enum Lifecycle { PER_CLASS, PER_METHOD; }
Lifecycle value();
}

0 comments on commit 4e997d1

Please sign in to comment.