Uploaded image for project: 'Scala Programming Language'
  1. Scala Programming Language
  2. SI-5608

Typer error when instantiating value class from value in array

    Details

      Description

      Here's a simple test program:

      object Main {
        def main(args:Array[String]) {
          val ns = Array(3L, 3L, 3L)
          val a:A = new A(ns(0))
        }
      }
       
      class A(val u:Long) extends AnyVal
      

      It currently crashes with an error in typer:

      exception when typing new <error>(ns.apply(0).$asInstanceOf[<notype>]())
      class type required but <notype> found in file test.scala
      scala.reflect.internal.Types$TypeError: class type required but <notype> found
              at scala.tools.nsc.typechecker.Contexts$Context.issue(Contexts.scala:317)
      

      If you save the dereference Long in a val and then instantiate A, things are fine.

        Attachments

          Activity

          Hide
          d_m Erik Osheim added a comment -

          I should add that if you cast to A (rather than construct A) things seem to work:

          ns(0).asInstanceOf[A]
          

          Show
          d_m Erik Osheim added a comment - I should add that if you cast to A (rather than construct A) things seem to work: ns(0).asInstanceOf[A]
          Hide
          vogt Christopher Vogt added a comment - - edited

          confirmed in 8f42361d71d11e9522052dcb5d9be020df7e5cc5

          I attached the complete error message as error.txt

          Show
          vogt Christopher Vogt added a comment - - edited confirmed in 8f42361d71d11e9522052dcb5d9be020df7e5cc5 I attached the complete error message as error.txt
          Hide
          extempore Paul Phillips added a comment -

          453d615fb3

          Show
          extempore Paul Phillips added a comment - 453d615fb3

            People

            • Assignee:
              extempore Paul Phillips
              Reporter:
              d_m Erik Osheim
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: