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

In Enumeration implicit conversion with explicit return type and call withName hangs (without error) #4805

Closed
scabug opened this issue Jul 14, 2011 · 4 comments

Comments

@scabug
Copy link

scabug commented Jul 14, 2011

See attachments planets3.scala and planets5.scala

The only difference is that planets3.scala has runtime casting:
implicit def valueToPlanetVal(x: Value) = x.asInstanceOf[Val]

and planets5.scala an explicit return type:
implicit def valueToPlanetVal(x: Value) : Val = x

Both compile without errors.
planets3.scala is running well.

planets5.scala hangs and never exutes the last line and without an error message:
println("Mars mass: " + Planet.withName("Mars").mass + " kg")

@scabug
Copy link
Author

scabug commented Jul 14, 2011

Imported From: https://issues.scala-lang.org/browse/SI-4805?orig=1
Reporter: DaveScala (davescala)
Affected Versions: 2.9.0
See #5211
Attachments:

@scabug
Copy link
Author

scabug commented Aug 17, 2011

Trond Olsen (tolsen77) said (edited on Aug 17, 2011 11:20:16 PM UTC):
Here is a simplified example of the looping implicit:
{noformat}class A
class B(val name: String) extends A
implicit def aToB(a: A): B = { println("aToB"); a }

println((new A).name)
// leads to infinite loop on implicit aToB()
{noformat}

Is this a programmer error, or should the typechecker make sure an implicit shouldn't be applicable within its own definition?

On second thought, it should fail completely. It's entirely nonsensical since a should never become a B, except the implicit is of a different opinion, hehe.

@scabug
Copy link
Author

scabug commented Nov 21, 2011

@soc said:
Verified on: 2.10.0.r26005-b20111114020239

@scabug
Copy link
Author

scabug commented Oct 25, 2012

@adriaanm said:
Yes, don't do that :-)

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