Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
scabug opened this issue Dec 21, 2015 · 2 comments
Open

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

scabug opened this issue Dec 21, 2015 · 2 comments
Milestone

Comments

@scabug
Copy link

scabug commented Dec 21, 2015

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 
}
@scabug
Copy link
Author

scabug commented Dec 21, 2015

Imported From: https://issues.scala-lang.org/browse/SI-9601?orig=1
Reporter: @dwijnand
Affected Versions: 2.11.7

@scabug scabug added this to the Backlog milestone Apr 7, 2017
@hrhino
Copy link

hrhino commented Dec 7, 2017

The error is now

scala> class IntW(implicit val n: Int) extends AnyVal
<console>:11: error: value class needs to have exactly one val parameter
       class IntW(implicit val n: Int) extends AnyVal
             ^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants