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

structural type conformance allows values as AnyRefs, then doesn't box them #5356

Closed
scabug opened this issue Jan 4, 2012 · 4 comments
Closed
Assignees

Comments

@scabug
Copy link

@scabug scabug commented Jan 4, 2012

This issue originates here: http://stackoverflow.com/questions/8422690/generic-method-convertible-to-structural-type-in-scala

Code to reproduce:

val a = implicitly[Int => { def toInt : Int }]
a(1).toInt

The REPL shows that the implicit works and the exception gets thrown when trying to invoke toInt:

scala> val a = implicitly[Int => { def toInt : Int }]
a: Int => AnyRef{def toInt: Int} = <function1>

scala> a(1)
res1: AnyRef{def toInt: Int} = 1

scala> a(1).toInt
java.lang.NoSuchMethodException
	at scala.runtime.BoxesRunTime.toInteger(Unknown Source)
	at .<init>(<console>:9)
	at .<clinit>(<console>:9)
	at .<init>(<console>:11)
	at .<clinit>(<console>)
	at $print(<console>)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:601)
	at scala.tools.nsc.interpreter.IMain$ReadEvalPrint.call(IMain.scala:751)
	at scala.tools.nsc.interpreter.IMain$Request$$anonfun$13.apply(IMain.scala:992)
	at scala.tools.nsc.interpreter.Line.scala$tools$nsc$interpreter$Line$$runAndSetState(Line.scala:41)
	at scala.tools.nsc.interpreter.Line$$anonfun$1.apply$mcV$sp(Line.scala:47)
	at scala.tools.nsc.io.package$$anon$2.run(package.scala:19)
	at java.lang.Thread.run(Thread.java:722)
@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Jan 4, 2012

Imported From: https://issues.scala-lang.org/browse/SI-5356?orig=1
Reporter: @soc
Affected Versions: 2.9.1, 2.10.0

@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Jan 5, 2012

@paulp said:
This is unrelated to implicits; it's more directly demonstrated as

(1: { def toInt: Int }).toInt
@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Jan 5, 2012

@paulp said:
Oh good, hadn't heard from RichInt in a while.

scala> (1: { def toInt: Int }).getClass
res2: Class[_ <: AnyRef] = class scala.runtime.RichInt
@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Jan 5, 2012

@paulp said:
be46e48713

@scabug scabug closed this Jan 5, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.