You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
First, a short description. It seems that if I put an implicit for some other type in a companion object and import that implicit into scope of the class it isn't found during implicit resolution until it is referenced explicitly once(or defined above the class). Example below.
objectMainextendsApp {
classA(vala:String) { overridedeftoString=s"A: $a"}
objectA {
implicitvaldefault=newA("A") //found by default
}
objectB {
deffunc(fn: =>Int)(implicita: A) = println(a)
}
classBroken {
defdoSomething= {
importBroken._// or Broken.actualB.func { 123 } // Uses A.default, not Broken.actual for implicit
}
}
objectBroken {
implicitvalactual=newA("Broken")
}
classFixed {
defdoSomething= {
importFixed._
println(actual) //reference actualB.func { 123 } // uses Fixed.actual
}
}
objectFixed {
implicitvalactual=newA("Fixed")
}
objectWTF {
implicitvalactual=newA("WTF")
}
classWTF {
defdoSomething= {
importWTF._B.func { 123 } // With object definition first this works without referencing actual
}
}
(newBroken).doSomething
(newFixed).doSomething
(newWTF).doSomething
}
If object A doesn't have a default implicit it does error out saying no implicits are found as in the related Jira.
The problem I have though is that it compiles and finds what is obviously NOT the expected implicit. I understand this has been addressed in many situations of "implicit not found" but I've yet to see one addressed as "wrong implicit found" which I think is much worse and why I've opened this bug report.
The text was updated successfully, but these errors were encountered:
@retronym said:
Can you please: post a complete example (no ...), and show a transcript of one or more calls to scalac that includes the compiler errors? If you can test this out on 2.11.0-M4 or later it would also help to see if this is a duplicate.
William Thurston (jhspaybar) said:
The output of a successful compilation is linked at the bottom of the jira with full code in all elided areas. I will include it here as well. There is also NO ERROR in this place. It simply doesn't exhibit what the behavior should be. It finds the object A default rather than Broken.actual
http://stackoverflow.com/questions/18724500/implicits-compiler-bug
Also pasted below
First, a short description. It seems that if I put an implicit for some other type in a companion object and import that implicit into scope of the class it isn't found during implicit resolution until it is referenced explicitly once(or defined above the class). Example below.
output:
A: A
A: Fixed
A: Fixed
A: WTF
http://ideone.com/1Vtepf
If object A doesn't have a default implicit it does error out saying no implicits are found as in the related Jira.
The problem I have though is that it compiles and finds what is obviously NOT the expected implicit. I understand this has been addressed in many situations of "implicit not found" but I've yet to see one addressed as "wrong implicit found" which I think is much worse and why I've opened this bug report.
The text was updated successfully, but these errors were encountered: