Skip to content

[SIP-71] into modifier doesn't work with enums #23399

Open
@prolativ

Description

@prolativ

Compiler version

3.7.3-RC1-bin-20250619-b1da8fc-NIGHTLY

Minimized code

import scala.language.experimental.into

into enum MyEnum:
  case MyString(s: String)
  case MyInt(i: Int)

import MyEnum.*

given Conversion[String, MyEnum] = MyString(_)
given Conversion[Int, MyEnum] = MyInt(_)

def takeMyEnum(f: MyEnum) = f

@main def test = 
  val f1 = takeMyEnum(123)
  val f2 = takeMyEnum("abc")

Output

[error] Only access modifiers are allowed on enum definitions
[error] into enum MyEnum:
[error]           ^^^^^^

Expectation

This snippet should compile without an error or a warning, similarly to the non-enum version of the code

import scala.language.experimental.into

into sealed trait MyEnum

object MyEnum:
  case class MyString(s: String) extends MyEnum
  case class MyInt(i: Int) extends MyEnum

import MyEnum.*

given Conversion[String, MyEnum] = MyString(_)
given Conversion[Int, MyEnum] = MyInt(_)

def takeMyEnum(f: MyEnum) = f

@main def test = 
  val f1 = takeMyEnum(123)
  val f2 = takeMyEnum("abc")

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions