Skip to content

Commit 5f4f7c6

Browse files
committed
Allow infix enum
Fixes scala#18933
1 parent 8f37647 commit 5f4f7c6

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
@@ -3919,7 +3919,9 @@ object Parsers {
39193919
}
39203920

39213921
private def checkAccessOnly(mods: Modifiers, where: String): Modifiers =
3922-
val mods1 = mods & (AccessFlags | Enum)
3922+
// We allow `infix to mark the `enum`s type as infix.
3923+
// Syntax rules disallow the soft infix modifier on `case`s.
3924+
val mods1 = mods & (AccessFlags | Enum | Infix)
39233925
if mods1 ne mods then
39243926
syntaxError(em"Only access modifiers are allowed on enum $where")
39253927
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)