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

Presentation compiler fails to resolve implicit defined in package object

    Details

      Description

      The following was exctrated from the Coursera Reactive class assignment:

      // nodescala/package.scala
      import scala.concurrent.Future
      
      package object nodescala {
        implicit class FutureCompanionOps[T](val f: Future.type) extends AnyVal {
          def always[T](value: T): Future[T] = Promise[T].success(value).future
        }
      }
      
      // nodescala/NodeScalaSuite.scala
      package nodescala
      
      import scala.concurrent.Future
      
      class NodeScalaSuite {
        Future.always(517) //<-- error reported
      }
      

      The reported error is: "value always is not a member of object scala.concurrent.Future"

      I've managed to create a presentation compiler test that demonstrates the problem, will be pushing a patch with the failing test soon.

        Activity

        Hide
        Iulian Dragos added a comment -

        Normally you can set that in the `.flags` file...

        Show
        Iulian Dragos added a comment - Normally you can set that in the `.flags` file...
        Hide
        Mirco Dotta added a comment -

        I've updated the commit and that lead to a pretty interesting discovery - have a read at the commit message for details https://github.com/dotta/scala/commit/7cab3dbc68c93061155dfa25a9938d6fccd12386

        Show
        Mirco Dotta added a comment - I've updated the commit and that lead to a pretty interesting discovery - have a read at the commit message for details https://github.com/dotta/scala/commit/7cab3dbc68c93061155dfa25a9938d6fccd12386
        Hide
        Jason Zaugg added a comment -

        In your failing test, the parser emits `package <empty> { import s.c.Future; package nodescala {} }`.

        This logic in Namers:

            /** All PackageClassInfoTypes come from here. */
            private def createPackageSymbol(pos: Position, pid: RefTree): Symbol = {
              val pkgOwner = pid match {
                case Ident(_)                 => if (owner.isEmptyPackageClass) rootMirror.RootClass else owner
                case Select(qual: RefTree, _) => createPackageSymbol(pos, qual).moduleClass
              }
        

        .. needs to be reflected in BrowserTraverser.

        Show
        Jason Zaugg added a comment - In your failing test, the parser emits `package <empty> { import s.c.Future; package nodescala {} }`. This logic in Namers: /** All PackageClassInfoTypes come from here. */ private def createPackageSymbol(pos: Position, pid: RefTree): Symbol = { val pkgOwner = pid match { case Ident(_) => if (owner.isEmptyPackageClass) rootMirror.RootClass else owner case Select(qual: RefTree, _) => createPackageSymbol(pos, qual).moduleClass } .. needs to be reflected in BrowserTraverser.
        Show
        Jason Zaugg added a comment - WIP: https://github.com/retronym/scala/compare/issue/implicit-resolution-goes-wrong
        Show
        Jason Zaugg added a comment - https://github.com/scala/scala/pull/3282

          People

          • Assignee:
            Jason Zaugg
            Reporter:
            Mirco Dotta
          • Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development