Skip to content

Can't define value class's value as implicit #9601

@scabug

Description

@scabug

Seems you can't define a value class's value as implicit:

class IntW(implicit val n: Int) extends AnyVal

Foo.scala:1: error: value class may not be a member of another class
class Foo(implicit val n: Int) extends AnyVal
      ^
one error found

The use of Int here as an implicit class is just for reproduction purpose, it wouldn't be wise to do so.

The current workaround is to drop the implicit and define an implicit method:

class IntW(val n: Int) extends AnyVal {
  private implicit def implicitInt: Int = n 
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    fixed in Scala 3This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/)valueclass

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions