Details

      Description

      Depending on order of traits, private members can shadow inherited members and prevent compilation. This does not happen with separate compilation.

      scala> :pa
      // Entering paste mode (ctrl-D to finish)
       
      trait A { private val x = 1 }
      trait B { val x = 2 }
      trait C extends B with A { println(x) }
       
      // Exiting paste mode, now interpreting.
       
      <console>:9: error: value x in trait A cannot be accessed in C
             trait C extends B with A { println(x) }
                                                ^
       
      scala> :reset
      Resetting interpreter state.
       
      scala> trait A { private val x = 1 }
      defined trait A
       
      scala> trait B { val x = 2 }
      defined trait B
       
      scala> trait C extends B with A { println(x) }
      defined trait C
      

      Expected behavior (to me anyway) is that private members (which are not inherited) should not shadow inherited members when resolving symbols in subclasses. But in either case behavior should be consistent between combined and separate compilation.

      Edit: damn this editor/formatter.

        Attachments

          Issue Links

            Activity

            Hide
            moors Adriaan Moors added a comment -

            As always, there's another catch: test/files/run/t2755.scala CCEs if you don't eliminate subtypes… it's probably related to another issue with Array.
            If we take the glb instead of the intersection, this problem doesn't arise.

            Show
            moors Adriaan Moors added a comment - As always, there's another catch: test/files/run/t2755.scala CCEs if you don't eliminate subtypes… it's probably related to another issue with Array. If we take the glb instead of the intersection, this problem doesn't arise.
            Hide
            moors Adriaan Moors added a comment -

            We already do this for extractor patterns btw:

                  def makeTypedUnApply() = {
                    // the union of the expected type and the inferred type of the argument to unapply
                    val glbType        = glb(ensureFullyDefined(pt) :: unapplyArg.tpe_* :: Nil)
            

            Show
            moors Adriaan Moors added a comment - We already do this for extractor patterns btw: def makeTypedUnApply() = { // the union of the expected type and the inferred type of the argument to unapply val glbType = glb(ensureFullyDefined(pt) :: unapplyArg.tpe_* :: Nil)
            Hide
            moors Adriaan Moors added a comment -

            well, duh – glb removes the upper type as well of course

            Show
            moors Adriaan Moors added a comment - well, duh – glb removes the upper type as well of course
            Hide
            moors Adriaan Moors added a comment -
            Show
            moors Adriaan Moors added a comment - Shooting at dusk: https://github.com/scala/scala/pull/3535
            Hide
            moors Adriaan Moors added a comment -

            I think this issue can be closed, opening a new one for the pattern typing. That will have to wait until 2.12, unfortunately.

            Show
            moors Adriaan Moors added a comment - I think this issue can be closed, opening a new one for the pattern typing. That will have to wait until 2.12, unfortunately.

              People

              • Assignee:
                retronym Jason Zaugg
                Reporter:
                rnorris Rob Norris
              • Votes:
                0 Vote for this issue
                Watchers:
                5 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: