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

update method receives a wrong index if apply method requires an implicit value #10021

Closed
scabug opened this issue Nov 3, 2016 · 4 comments
Closed

Comments

@scabug
Copy link

scabug commented Nov 3, 2016

Welcome to Scala 2.11.8 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_102).
Type in expressions for evaluation. Or try :help.

scala> {
     |   implicit def ev: Int = 8000
     |   object A {
     |     def apply(i: Int)(implicit ev: Int): Int = 100 
     |     def update(i: Int, value: Int): Unit = print(s"i=$i value=$value")
     |   }
     |   A(5) += 20 
     | }  
i=8000 value=120
@scabug
Copy link
Author

scabug commented Nov 3, 2016

Imported From: https://issues.scala-lang.org/browse/SI-10021?orig=1
Reporter: @Atry
Affected Versions: 2.11.8, 2.12.0
Duplicates #6714

@scabug
Copy link
Author

scabug commented Nov 7, 2016

@SethTisue said:
This may well be a bug, but it seems like such ill-advised code (strange signature for apply, implicit of type Int) that it's hard to imagine it getting attention if this is the only way to trigger it.

@scabug
Copy link
Author

scabug commented Nov 8, 2016

@Atry said (edited on Nov 8, 2016 1:49:08 AM UTC):
Another example

Welcome to Scala 2.11.8 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_102).
Type in expressions for evaluation. Or try :help.

scala> object A {
     |   def apply[A](i: A)(implicit ev: Ordering[Int]): Int = 100
     |   def update[A](i: A, value: Int): Unit = print(s"i=$i value=$value")
     | }
defined object A

scala> A(5) += 20
i=scala.math.Ordering$Int$@121314f7 value=120

@scabug
Copy link
Author

scabug commented Nov 8, 2016

@som-snytt said:
I took a look the other day and wasn't sure how the expansion should proceed.

A(5) = A(5) + 42
A(5)(ev) = A(5)(ev) + 42
A.apply(5).update(ev, A(5)(ev) + 42)

The apply(5) seems to be elided when it should error; I'm just reading off the scrap of paper, too beset with the ague to think about it.

@scabug scabug closed this as completed Mar 9, 2017
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

1 participant