Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the limitations of Scala's Manifests?

Scala's Manifests are a way to get around some type erasure problems due to the JVM's lack of reified generics.

They are discussed in several other questions; here are a few:

  • What is a Manifest in Scala and when do you need it?
  • How does Scala's (2.8) Manifest work?
  • How do I get around type erasure on Scala? Or, why can't I get the type parameter of my collections?
  • How can I use Scala's Manifest class to instantiate the erased class at runtime?
  • Manifest vs ClassManifest. What does this Scala error mean?

One of the comments mentions that “This feature is experimental, and there are cases in which it doesn't work. Still, it can go a long way.” (Daniel Sobral)

What are the cases where the Manifest approach breaks down and why?

like image 911
Jean-Philippe Pellet Avatar asked Apr 16 '11 06:04

Jean-Philippe Pellet


2 Answers

The most important case should be open Tickets in the Scala teams bug tracking system. I found the following:

  • manifests + intersection types violate val-binding abstraction
  • Compiler cannot determine implicit Manifest for type constructor
  • ClassManifest.typeArguments returns empty list on array manifests
  • manifests need to account for variance

I believe the general idea is, that Manifests will be part of the planned/upcomming Scala reflection library and apart from using them in the context of Arrays is "on your own risk" ( see ).

like image 96
Alexander Battisti Avatar answered Nov 18 '22 19:11

Alexander Battisti


One more:

    scala> class C;
    defined class C

    scala> trait T;
    defined trait T

    scala> manifest[C] <:< manifest[C with T]
    res0: Boolean = true

I've not even reported it since, according to this, manifests are deprecated in 2.10 so they are not fixing bugs with them.

like image 28
jsalvata Avatar answered Nov 18 '22 20:11

jsalvata