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

Value class defined in a method gives spurious error.

    Details

      Description

      object K {
         def q = {
            final class Y(val j: Int) extends AnyVal
            3
         }
      }
      
      K.scala:3: error: recursive method q needs result type
            final class Y(val j: Int) extends AnyVal
                        ^
      

      If the result type of q is explicitly annotated, the expected error message "value class may not be a local class" results.

        Activity

        Hide
        Josh Suereth added a comment -

        Another value class issue.

        Show
        Josh Suereth added a comment - Another value class issue.
        Hide
        Martin Odersky added a comment -

        Throwing this back, as it seems not critical and fairly type-checker generic. No doubt something triggered the recursion check.

        Show
        Martin Odersky added a comment - Throwing this back, as it seems not critical and fairly type-checker generic. No doubt something triggered the recursion check.
        Hide
        Paul Phillips added a comment -
        Show
        Paul Phillips added a comment - Took a casual stab with https://github.com/scala/scala/pull/1626
        Hide
        Adriaan Moors added a comment - - edited

        Paul's patch also avoids a crash on this code, reported by Mirco in https://groups.google.com/d/msg/scala-internals/Cp-YuueuqAs/JvSU9LncdjwJ

        object Foo {
          def main(args: Array[String]) = execute {
            class VInt(val v: Int) extends AnyVal
          }
        
          def execute(body: => Unit): Unit = body
        } 
        

        Is this something we want to support in 2.10.0?

        Show
        Adriaan Moors added a comment - - edited Paul's patch also avoids a crash on this code, reported by Mirco in https://groups.google.com/d/msg/scala-internals/Cp-YuueuqAs/JvSU9LncdjwJ object Foo { def main(args: Array[String]) = execute { class VInt(val v: Int) extends AnyVal } def execute(body: => Unit): Unit = body } Is this something we want to support in 2.10.0?
        Hide
        Adriaan Moors added a comment -

        (Note that Mirco says this would hamper experimenting with value classes in the worksheet.)

        Show
        Adriaan Moors added a comment - (Note that Mirco says this would hamper experimenting with value classes in the worksheet.)
        Hide
        Mark Harrah added a comment -

        Note that Paul's patch avoids the crash, but will still report an error. It doesn't add support for local value classes, which are disallowed as a current implementation restriction.

        Show
        Mark Harrah added a comment - Note that Paul's patch avoids the crash, but will still report an error. It doesn't add support for local value classes, which are disallowed as a current implementation restriction.
        Hide
        Adriaan Moors added a comment -
        Show
        Adriaan Moors added a comment - fixed in master by https://github.com/scala/scala/pull/1626 backport for 2.10.1 pending as https://github.com/scala/scala/pull/1647

          People

          • Assignee:
            Adriaan Moors
            Reporter:
            Mark Harrah
          • Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development