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

Error infering String Type as Object with getOrElse #10250

Open
scabug opened this issue Mar 23, 2017 · 3 comments
Open

Error infering String Type as Object with getOrElse #10250

scabug opened this issue Mar 23, 2017 · 3 comments

Comments

@scabug
Copy link

scabug commented Mar 23, 2017

scala> import play.api.libs.json._ ; Option("a").getOrElse("b") : Json.JsValueWrapper
<console>:13: error: type mismatch;
 found   : Object
 required: play.api.libs.json.Json.JsValueWrapper
        Option("a").getOrElse("b") : Json.JsValueWrapper
                                           ^
@scabug
Copy link
Author

scabug commented Mar 23, 2017

Imported From: https://issues.scala-lang.org/browse/SI-10250?orig=1
Reporter: Mohammed Azougarh (momoAG)
Affected Versions: 2.12.1

@fmilano
Copy link

fmilano commented Jan 10, 2018

I confirm that this is happening to me in 2.12.4

@SethTisue
Copy link
Member

reproducible without the external dependency with:

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

scala> import scala.language.implicitConversions
import scala.language.implicitConversions

scala> class Foo; implicit def string2foo(s: String): Foo = new Foo
defined class Foo
string2foo: (s: String)Foo

scala> (Option("a").getOrElse("b"): String): Foo
res0: Foo = Foo@646427f7

scala> Option("a").getOrElse("b"): Foo
<console>:15: error: type mismatch;
 found   : Object
 required: Foo
       Option("a").getOrElse("b"): Foo
                            ^

whereas in Dotty:

scala> Option("a").getOrElse("b"): Foo 
val res0: Foo = Foo@7ea08277

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