Scala Programming Language
  1. Scala Programming Language
  2. SI-3758

ClassManifest.typeArguments returns empty list on array manifests

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Critical Critical
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: Scala 2.10.0
    • Component/s: Misc Compiler
    • Labels:
      None
    • Environment:

      manifest

      Description

      I was told on the mailing list this is a bug so I'll just copy and paste from there (see below). I was using Scala 2.8.0 Final.

      I was hoping to retrieve the manifest of an array's element type like so:

      scala> manifest[Array[Double]].typeArguments
      

      This returns an empty list. Looking at the Manifest.arrayManifest method, I see that it is implemented as

      override def arrayManifest: Manifest[Array[T]] =
          Manifest.classType[Array[T]](arrayClass[T](erasure))
      

      This explains why the above retuns Nil but it looks like implementing it as

        override def arrayManifest: Manifest[Array[T]] =
          Manifest.classType[Array[T]](arrayClass[T](erasure), this)
      

      would solve the problem.

        Activity

        Hide
        Paul Phillips added a comment -

        After looking at it I'm not sure it's a bug, or at least not sure it's not intentional. I would agree it's undesirable, and one ought to be able to retrieve type arguments without having to special case arrays. The reasoning for the current approach would be that with Arrays the type argument is "built in" to the top level manifest, so you don't actually have type arguments: i.e. Array[Int] has a first-class runtime representation, unlike List[Int]. Code like this is what shows us the author was well aware there were no type args on arrays:

        protected def argString = 
          if (typeArguments.nonEmpty) typeArguments.mkString("[", ", ", "]")
          else if (erasure.isArray) "["+ClassManifest.fromClass(erasure.getComponentType)+"]"
          else ""  
        

        So I won't touch this pending feedback. (The suggested patch does have the intended effect.)

        Show
        Paul Phillips added a comment - After looking at it I'm not sure it's a bug, or at least not sure it's not intentional. I would agree it's undesirable, and one ought to be able to retrieve type arguments without having to special case arrays. The reasoning for the current approach would be that with Arrays the type argument is "built in" to the top level manifest, so you don't actually have type arguments: i.e. Array [Int] has a first-class runtime representation, unlike List [Int] . Code like this is what shows us the author was well aware there were no type args on arrays: protected def argString = if (typeArguments.nonEmpty) typeArguments.mkString("[", ", ", "]") else if (erasure.isArray) "["+ClassManifest.fromClass(erasure.getComponentType)+"]" else "" So I won't touch this pending feedback. (The suggested patch does have the intended effect.)
        Hide
        Paul Phillips added a comment -

        27d19715af

        Show
        Paul Phillips added a comment - 27d19715af

          People

          • Assignee:
            Paul Phillips
            Reporter:
            Stefan Weber
            TracCC:
            Paul Phillips
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development