Skip to content

Commit

Permalink
Allow infix enum
Browse files Browse the repository at this point in the history
Fixes #18933
  • Loading branch information
nicolasstucki committed Nov 21, 2023
1 parent 8f37647 commit 5f4f7c6
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
4 changes: 3 additions & 1 deletion compiler/src/dotty/tools/dotc/parsing/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions tests/neg/i18933.check
Original file line number Diff line number Diff line change
@@ -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`
3 changes: 3 additions & 0 deletions tests/neg/i18933.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
enum Extends[A, B]:
case A(a: A)
infix case B(b: B) // error // error
4 changes: 4 additions & 0 deletions tests/pos/i18933.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
//> using options -Werror

infix enum Extends[A, B]:
case Ev[B, A <: B]() extends (A Extends B)

0 comments on commit 5f4f7c6

Please sign in to comment.