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

partial function defined in value class method results in spurious implementation restriction

    Details

      Description

      scala> class Foo(val a: Int) extends AnyVal { def foo = { {case x => x}: PartialFunction[Int, Int]; () }}
      <console>:7: error: implementation restriction: nested class is not allowed in value class
      This restriction is planned to be removed in subsequent releases.
             class Foo(val a: Int) extends AnyVal { def foo = { {case x => x}: PartialFunction[Int, Int]; () }}

        Activity

        Hide
        Paul Phillips added a comment -

        It's "spurious" in the sense that you shouldn't have to know that partial functions are implemented with anonymous objects; but it's genuine in the sense that partial functions are implemented with anonymous objects.

        Show
        Paul Phillips added a comment - It's "spurious" in the sense that you shouldn't have to know that partial functions are implemented with anonymous objects; but it's genuine in the sense that partial functions are implemented with anonymous objects.
        Hide
        Jason Zaugg added a comment -

        I'm trying to remember exactly why the restriction exists (5d9cde105e); I suspect it is because we can't define an $outer pointer. But I don't think that is relevant for this case.

        class Foo extends AnyVal {
          def foo = () => 0 // okay
          def bar = {case x => x} : PartialFunction[Int, Int] // should also be okay IMO
        }
        
        Show
        Jason Zaugg added a comment - I'm trying to remember exactly why the restriction exists (5d9cde105e); I suspect it is because we can't define an $outer pointer. But I don't think that is relevant for this case. class Foo extends AnyVal { def foo = () => 0 // okay def bar = {case x => x} : PartialFunction[Int, Int] // should also be okay IMO }
        Show
        Jason Zaugg added a comment - https://github.com/scala/scala/pull/2648
        Hide
        Paul Phillips added a comment -

        > I'm trying to remember exactly why the restriction exists (5d9cde105e); I suspect it is because we can't define an $outer pointer.

        Yes, that's why.

        Show
        Paul Phillips added a comment - > I'm trying to remember exactly why the restriction exists (5d9cde105e); I suspect it is because we can't define an $outer pointer. Yes, that's why.

          People

          • Assignee:
            Jason Zaugg
            Reporter:
            Ismael Juma
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development