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
java.lang.ClassCastException:classPlayground$View$$$Lambda$12376/0x00007ff68d5a4208 cannot be cast to classPlayground$FunctionalComponent
Expectation
Ideally this should compile and run without any errors.
Does it need to cast? I would have thought that the compiler has already checked that View conforms to the refinement and so component is already known to be a FunctionalComponent.
If it does need to cast then is there any way for there to be a runtime check to tell whether it is boxed or unboxed? I'm guessing it is assuming that it is boxed when in fact it is not which is why there is a ClassCastException.
I found a lot of old Scala 2 issues such as scala/bug#6336 which seemed to restrict how value classes were used with refinements which seems less than ideal but if that is indeed the only answer it would be better to not compile than compile and fail at runtime.
The text was updated successfully, but these errors were encountered:
I think it might be related to how value classes are implemented, these might expose some kind of unsoundness related to it.
Since it can be found in both Scala 2 and Scala 3 there is a chance that we won't be able to fix it in backward compatibile manner.
Scala 3-only workaround which works correctly is to use opaque types:
opaquetypeFunctionalComponent[P] =P=>StringobjectFunctionalComponent:defapply[P](fc: P=>String):FunctionalComponent[P] = fc
I agree that it would be the best to make sure we can catch the invalid usage of value classess at compile time, maybe at least this part should be achievable.
Uh oh!
There was an error while loading. Please reload this page.
Compiler version
3.4.0 Next, 3.3.2 LTS, 2.13.12
Minimized code
https://scastie.scala-lang.org/nHksLLQJR8GiiOws7Pt2rA
Output
Expectation
Ideally this should compile and run without any errors.
Does it need to cast? I would have thought that the compiler has already checked that
View
conforms to the refinement and socomponent
is already known to be aFunctionalComponent
.If it does need to cast then is there any way for there to be a runtime check to tell whether it is boxed or unboxed? I'm guessing it is assuming that it is boxed when in fact it is not which is why there is a
ClassCastException
.I found a lot of old Scala 2 issues such as scala/bug#6336 which seemed to restrict how value classes were used with refinements which seems less than ideal but if that is indeed the only answer it would be better to not compile than compile and fail at runtime.
The text was updated successfully, but these errors were encountered: