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

Setter syntax with context bound bug #9258

Closed
scabug opened this issue Apr 1, 2015 · 4 comments
Closed

Setter syntax with context bound bug #9258

scabug opened this issue Apr 1, 2015 · 4 comments

Comments

@scabug
Copy link

scabug commented Apr 1, 2015

Implicit parameters with one type parameter fails to compile
With 2, 3 and possibly more it works.

trait WithThree[A, B, C]

case class Holder[T](_elem: T) {
  def elem_=[U>:T](newElem: U)(implicit ev: U <:< AnyVal) = copy(_elem=newElem)
  def elem = _elem

  def elem3_=[U>:T](newElem: U)(implicit ev: WithThree[T, T, T]) = copy(_elem=newElem)
  def elem3 = elem

  def typeClassElem = _elem
  def typeClassElem[U>:T](newElem: U)(implicit n: Numeric[U]) = copy[U](_elem=n.negate(newElem))
}

object HolderTest {
  implicit val three: WithThree[Nothing, Nothing, Nothing] = ???
  val hBottom: Holder[Nothing] = ???
  val hTop: Holder[AnyVal] = hBottom.elem = 3
  val hParam: Holder[Int] = hBottom.elem3 = 3
//  val hType: Holder[Int] = hBottom.typeClassElem = 3 // <-- Doesnt compile
}
@scabug
Copy link
Author

scabug commented Apr 1, 2015

Imported From: https://issues.scala-lang.org/browse/SI-9258?orig=1
Reporter: Raul Bache (arneball)
Affected Versions: 2.11.6

@SethTisue
Copy link
Member

Scala 3.6.3:

-- [E052] Type Error: ----------------------------------------------------------
19 |  val hType: Holder[Int] = hBottom.typeClassElem = 3 // <-- Doesnt compile
   |                           ^^^^^^^^^^^^^^^^^^^^^^^^^
   |                           Reassignment to val <none>
   |
   | longer explanation available when compiling with `-explain`

@SethTisue SethTisue added this to the Backlog milestone Feb 26, 2025
@som-snytt
Copy link

@SethTisue isn't this just a typo?

def typeClassElem_=

error: value typeClassElem_= is not a member of Holder[Nothing]

@som-snytt
Copy link

scala/scala3#22671

@som-snytt som-snytt closed this as not planned Won't fix, can't repro, duplicate, stale Feb 26, 2025
@SethTisue SethTisue removed this from the Backlog milestone Feb 26, 2025
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

3 participants