Skip to content

Commit 5293c0f

Browse files
committed
Allow infix enum
Fixes #18933
1 parent 312e4bb commit 5293c0f

File tree

4 files changed

+20
-1
lines changed

4 files changed

+20
-1
lines changed

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3928,7 +3928,9 @@ object Parsers {
39283928
}
39293929

39303930
private def checkAccessOnly(mods: Modifiers, where: String): Modifiers =
3931-
val mods1 = mods & (AccessFlags | Enum)
3931+
// We allow `infix to mark the `enum`s type as infix.
3932+
// Syntax rules disallow the soft infix modifier on `case`s.
3933+
val mods1 = mods & (AccessFlags | Enum | Infix)
39323934
if mods1 ne mods then
39333935
syntaxError(em"Only access modifiers are allowed on enum $where")
39343936
mods1

tests/neg/i18933.check

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
-- Error: tests/neg/i18933.scala:3:8 -----------------------------------------------------------------------------------
2+
3 | infix case B(b: B) // error // error
3+
| ^^^^
4+
| end of statement expected but 'case' found
5+
-- [E006] Not Found Error: tests/neg/i18933.scala:3:2 ------------------------------------------------------------------
6+
3 | infix case B(b: B) // error // error
7+
| ^^^^^
8+
| Not found: infix
9+
|
10+
| longer explanation available when compiling with `-explain`

tests/neg/i18933.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
enum Extends[A, B]:
2+
case A(a: A)
3+
infix case B(b: B) // error // error

tests/pos/i18933.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
//> using options -Werror
2+
3+
infix enum Extends[A, B]:
4+
case Ev[B, A <: B]() extends (A Extends B)

0 commit comments

Comments
 (0)