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

Comments

Projects
None yet
3 participants
@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

This comment has been minimized.

Copy link

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

@scabug scabug added typer infer labels Apr 7, 2017

@fmilano

This comment has been minimized.

Copy link

fmilano commented Jan 10, 2018

I confirm that this is happening to me in 2.12.4

@SethTisue

This comment has been minimized.

Copy link
Member

SethTisue commented Jan 10, 2018

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