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
At the moment isInstanceOf/asInstanceOf don't support (upper bounded) type parameters so it parametric polymorphism is not possible even if the type parameter has a manifest. All the manifest does is turning unchecked warnings off, there is still a class cast exception which is why a manifest solution makes the problem even worse.
In C# you can do just this and it works:
if (e is E) call((E)e);
but in Scala you cannot do this even with a typeparameter with manifest:
if (e.isInstanceOf[E]) call(e.asInstanceOf[E])
is only turning of the unchecked warnings in hackish way
Work around 2
if (manifest[E].erasure.cast(e).isInstanceOf[E]) call(manifest[E].erasure.cast(e).asInstanceOf[E])
brings the unchecked warning it back so it is circular
Both workarounds generate a class cast exception so a manifest doesn't help much:
java.lang.ClassCastException: Cannot cast impl.Lit to extension.EvalExp
See enclosed:
expressionproblem.cs
expressionproblem.scala
The text was updated successfully, but these errors were encountered:
@paulp said:
No unchecked warnings, prints -5. You appear to have multiple misapprehensions about how things work at runtime. You're never calling getClass on an instance whose type neither the compiler nor you know; from such beginnings one cannot be too surprised at CCEs.
At the moment isInstanceOf/asInstanceOf don't support (upper bounded) type parameters so it parametric polymorphism is not possible even if the type parameter has a manifest. All the manifest does is turning unchecked warnings off, there is still a class cast exception which is why a manifest solution makes the problem even worse.
In C# you can do just this and it works:
but in Scala you cannot do this even with a typeparameter with manifest:
if (e.isInstanceOf[E]) call(e.asInstanceOf[E])
Work around 1
is only turning of the unchecked warnings in hackish way
Work around 2
brings the unchecked warning it back so it is circular
Both workarounds generate a class cast exception so a manifest doesn't help much:
java.lang.ClassCastException: Cannot cast impl.Lit to extension.EvalExp
See enclosed:
expressionproblem.cs
expressionproblem.scala
The text was updated successfully, but these errors were encountered: