From 5f4f7c61d40a49845dc7aaa5f24868c89fe1821e Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Thu, 16 Nov 2023 09:00:17 +0100 Subject: [PATCH] Allow `infix enum` Fixes #18933 --- compiler/src/dotty/tools/dotc/parsing/Parsers.scala | 4 +++- tests/neg/i18933.check | 10 ++++++++++ tests/neg/i18933.scala | 3 +++ tests/pos/i18933.scala | 4 ++++ 4 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 tests/neg/i18933.check create mode 100644 tests/neg/i18933.scala create mode 100644 tests/pos/i18933.scala diff --git a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala index aec3ad42feef..697989eb2407 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala @@ -3919,7 +3919,9 @@ object Parsers { } private def checkAccessOnly(mods: Modifiers, where: String): Modifiers = - val mods1 = mods & (AccessFlags | Enum) + // We allow `infix to mark the `enum`s type as infix. + // Syntax rules disallow the soft infix modifier on `case`s. + val mods1 = mods & (AccessFlags | Enum | Infix) if mods1 ne mods then syntaxError(em"Only access modifiers are allowed on enum $where") mods1 diff --git a/tests/neg/i18933.check b/tests/neg/i18933.check new file mode 100644 index 000000000000..dc4db455c2de --- /dev/null +++ b/tests/neg/i18933.check @@ -0,0 +1,10 @@ +-- Error: tests/neg/i18933.scala:3:8 ----------------------------------------------------------------------------------- +3 | infix case B(b: B) // error // error + | ^^^^ + | end of statement expected but 'case' found +-- [E006] Not Found Error: tests/neg/i18933.scala:3:2 ------------------------------------------------------------------ +3 | infix case B(b: B) // error // error + | ^^^^^ + | Not found: infix + | + | longer explanation available when compiling with `-explain` diff --git a/tests/neg/i18933.scala b/tests/neg/i18933.scala new file mode 100644 index 000000000000..7802c3961a25 --- /dev/null +++ b/tests/neg/i18933.scala @@ -0,0 +1,3 @@ +enum Extends[A, B]: + case A(a: A) + infix case B(b: B) // error // error diff --git a/tests/pos/i18933.scala b/tests/pos/i18933.scala new file mode 100644 index 000000000000..7424344d5edf --- /dev/null +++ b/tests/pos/i18933.scala @@ -0,0 +1,4 @@ +//> using options -Werror + +infix enum Extends[A, B]: + case Ev[B, A <: B]() extends (A Extends B)