Skip to content
demonstration of a bug when compiling scala code that uses implicits
Shell Scala
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
src/main/scala/pack/age
README.md
bug

README.md

This just demonstrates a simplified version of the scalac bug described in this stack overflow question.

To see the bug for yourself, run the bug script:

    #!/usr/bin/env bash

    # This script just demonstrates the bug.  When run on my system
    # (OSX 10.6.8, using scalac-2.9.1.final) it produces the following output:
    #
    #   % bug
    #   initialize
    #   compile once (succeeds)
    #   compile again (fails)
    #   src/main/scala/pack/age/Bar.scala:6: error: type mismatch;
    #    found   : Int(1)
    #    required: pack.age.Baz
    #     def baz : Baz   = 1
    #                       ^
    #   one error found
    #   %

       echo "initialize" \
    && rm -rf pack \
    && echo "compile once (succeeds)" \
    && scalac-2.9 src/main/scala/pack/age/Foo.scala src/main/scala/pack/age/Bar.scala \
    && echo "compile again (fails)" \
    && scalac-2.9 src/main/scala/pack/age/Foo.scala src/main/scala/pack/age/Bar.scala

Since Foo.scala just defines a custom data type and an implicit,

    package pack.age

    class Baz 

    object Implicits  {
      implicit def Baz(n: Int): Baz = new Baz
    }

and Bar.scala just uses this implicit to define a method

    package pack.age

    import pack.age.Implicits._

    object Quux {
      def baz : Baz   = 1
    }

I'm guessing this has to do with how scalac finds implicits at compile-time.

Something went wrong with that request. Please try again.