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

scalac sometimes ignores companion implicits

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Critical Critical
    • Resolution: Fixed
    • Affects Version/s: Scala 2.10.1, Scala 2.11.0-M2
    • Fix Version/s: Scala 2.10.2
    • Component/s: Type Inference
    • Labels:
      None

      Description

      trait Fooable[T]
      object Fooable {
        implicit def conjure[T]: Fooable[T] = {
          println("conjure")
          new Fooable[T]{}
        }
      
      }
      
      object Main extends App {
        implicit def traversable[T, Coll[_] <: Traversable[_]](implicit
      elem: Fooable[T]): Fooable[Coll[T]] = {
          println("traversable")
          new Fooable[Coll[T]]{}
        }
        implicitly[Fooable[List[Any]]] 
      }
      

      Should print "conjure", then "traversable". Currently it prints just "conjure". Details: http://groups.google.com/group/scala-internals/browse_thread/thread/f284df8ee19c2aba

        Issue Links

          Activity

          Hide
          Eugene Burmako added a comment - - edited

          An interesting twist of events is that this bug is fixed in scalad, the type debugger. Now the question is how exactly this happened.

          11:40 ~/Projects/Master/sandbox (master)$ scalad Test.scala -Xprint:typer
          Initial compilation of sources...
          [[syntax trees at end of                     typer]] // Test.scala
          package <empty> {
            abstract trait Fooable[T >: Nothing <: Any] extends scala.AnyRef;
            object Fooable extends scala.AnyRef {
              def <init>(): Fooable.type = {
                Fooable.super.<init>();
                ()
              };
              implicit def conjure[T >: Nothing <: Any]: Fooable[T] = {
                scala.this.Predef.println("conjure");
                {
                  final class $anon extends AnyRef with Fooable[T] {
                    def <init>(): anonymous class $anon = {
                      $anon.super.<init>();
                      ()
                    };
                    <empty>
                  };
                  new $anon()
                }
              }
            };
            object Test extends AnyRef with App {
              def <init>(): Test.type = {
                Test.super.<init>();
                ()
              };
              implicit def traversable[T >: Nothing <: Any, Coll[_ >: Nothing <: Any] >: [_]Nothing <: [_]Traversable[_]](implicit elem: Fooable[T]): Fooable[Coll[T]] = {
                scala.this.Predef.println("traversable");
                {
                  final class $anon extends AnyRef with Fooable[Coll[T]] {
                    def <init>(): anonymous class $anon = {
                      $anon.super.<init>();
                      ()
                    };
                    <empty>
                  };
                  new $anon()
                }
              };
              scala.this.Predef.implicitly[Fooable[List[Any]]](Test.this.traversable[Any, List](Fooable.conjure[Any]))
            }
          }
          
          Initial compilation finished. Starting UI...
          
          Show
          Eugene Burmako added a comment - - edited An interesting twist of events is that this bug is fixed in scalad, the type debugger. Now the question is how exactly this happened. 11:40 ~/Projects/Master/sandbox (master)$ scalad Test.scala -Xprint:typer Initial compilation of sources... [[syntax trees at end of typer]] // Test.scala package <empty> { abstract trait Fooable[T >: Nothing <: Any] extends scala.AnyRef; object Fooable extends scala.AnyRef { def <init>(): Fooable.type = { Fooable.super.<init>(); () }; implicit def conjure[T >: Nothing <: Any]: Fooable[T] = { scala.this.Predef.println("conjure"); { final class $anon extends AnyRef with Fooable[T] { def <init>(): anonymous class $anon = { $anon.super.<init>(); () }; <empty> }; new $anon() } } }; object Test extends AnyRef with App { def <init>(): Test.type = { Test.super.<init>(); () }; implicit def traversable[T >: Nothing <: Any, Coll[_ >: Nothing <: Any] >: [_]Nothing <: [_]Traversable[_]](implicit elem: Fooable[T]): Fooable[Coll[T]] = { scala.this.Predef.println("traversable"); { final class $anon extends AnyRef with Fooable[Coll[T]] { def <init>(): anonymous class $anon = { $anon.super.<init>(); () }; <empty> }; new $anon() } }; scala.this.Predef.implicitly[Fooable[List[Any]]](Test.this.traversable[Any, List](Fooable.conjure[Any])) } } Initial compilation finished. Starting UI...
          Hide
          Eugene Burmako added a comment -

          Hubert has kindly provided a fix for this one. I will submit a pull request once we're done with the paper (somewhen in the beginning of April).

          Show
          Eugene Burmako added a comment - Hubert has kindly provided a fix for this one. I will submit a pull request once we're done with the paper (somewhen in the beginning of April).
          Hide
          Eugene Burmako added a comment -

          I'll do the backporting next week.

          Show
          Eugene Burmako added a comment - I'll do the backporting next week.
          Hide
          Hubert Plociniczak added a comment -

          I cleaned it up already yesterday (https://github.com/hubertp/scala-dev/tree/topic/minor-typer-cleanup). PR is coming today. Sorry Eugene

          Show
          Hubert Plociniczak added a comment - I cleaned it up already yesterday ( https://github.com/hubertp/scala-dev/tree/topic/minor-typer-cleanup ). PR is coming today. Sorry Eugene
          Show
          Hubert Plociniczak added a comment - https://github.com/scala/scala/pull/2428
          Show
          Eugene Burmako added a comment - https://github.com/scala/scala/pull/2494
          Show
          Eugene Burmako added a comment - https://github.com/scala/scala/commit/fdead2b3793fd530e05331649e655576f30e59e9

            People

            • Assignee:
              Hubert Plociniczak
              Reporter:
              Eugene Burmako
            • Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development