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

Scalac does not respect an implicit def when recompiling

    Details

      Description

      Given src/main/scala/pack/age/Foo.scala:hello

      package pack.age
      
      class Baz 
      
      object Implicits  {
      	implicit def Baz(n: Int): Baz = new Baz
      }
      

      and src/main/scala/pack/age/Bar.scala:

      package pack.age
      
      import pack.age.Implicits._
      
      object Quux {
      	def baz : Baz   = 1
      }
      

      When first run, scalac src/main/scala/pack/age/Foo.scala src/main/scala/pack/age/Bar.scala compiles both fine, and places the class files in the pack directory.

      However, if rerun, scalac src/main/scala/pack/age/Foo.scala src/main/scala/pack/age/Bar.scala fails with the following error:

      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
      

      This is a simplification of the bug reported in a stackoverflow question (http://stackoverflow.com/questions/9959199/error-in-scala-maven-recompilation-without-code-change). All the above code can be downloaded from github (https://github.com/rampion/scalac-compile-bug).

        Activity

        Hide
        DaveScala added a comment -

        The above bug seems to happen with top level imports of implicits.

        Object level imports compiles over and over again

        package pack.age 
        
        object Quux { 
            import pack.age.Implicits._ 
            def baz : Baz   = 1 
        } 
        

        More info on scala-user list:
        http://groups.google.com/group/scala-user/browse_thread/thread/cf1a3ae39ecf1c81

        Show
        DaveScala added a comment - The above bug seems to happen with top level imports of implicits. Object level imports compiles over and over again package pack.age object Quux { import pack.age.Implicits._ def baz : Baz = 1 } More info on scala-user list: http://groups.google.com/group/scala-user/browse_thread/thread/cf1a3ae39ecf1c81
        Hide
        Philipp Haller added a comment -

        Test in pending/pos/t5639.

        Show
        Philipp Haller added a comment - Test in pending/pos/t5639.
        Hide
        Jason Zaugg added a comment - - edited

        This is a regression from 2.7.7 to 2.8.0. The class seems to be incorrectly shadowing the imported implicit of the same name.

          ~/code/scratch/20120518 cat Bar.scala
        import Implicits._
        
        class Baz
        
        object Test {
          implicitly[Int]
        }
        
        object Implicits  {
          implicit val Baz: Int = 0
        }
          ~/code/scratch/20120518 rm -rf out/* 
          ~/code/scratch/20120518 scalac210 -language:implicitConversions -d out -classpath out Bar.scala 
          ~/code/scratch/20120518 scalac210 -language:implicitConversions -d out -classpath out Bar.scala 
        Bar.scala:6: error: could not find implicit value for parameter e: Int
          implicitly[Int]
                    ^
        one error found
        
        Show
        Jason Zaugg added a comment - - edited This is a regression from 2.7.7 to 2.8.0. The class seems to be incorrectly shadowing the imported implicit of the same name. ~/code/scratch/20120518 cat Bar.scala import Implicits._ class Baz object Test { implicitly[Int] } object Implicits { implicit val Baz: Int = 0 } ~/code/scratch/20120518 rm -rf out/* ~/code/scratch/20120518 scalac210 -language:implicitConversions -d out -classpath out Bar.scala ~/code/scratch/20120518 scalac210 -language:implicitConversions -d out -classpath out Bar.scala Bar.scala:6: error: could not find implicit value for parameter e: Int implicitly[Int] ^ one error found
        Hide
        Adriaan Moors added a comment -

        i don't feel comfortable fixing this in 2.10.x
        the required behavior change may change the meaning of programs that (unwittingly) rely on this bug

        Show
        Adriaan Moors added a comment - i don't feel comfortable fixing this in 2.10.x the required behavior change may change the meaning of programs that (unwittingly) rely on this bug
        Hide
        Adriaan Moors added a comment -

        Unassigning and rescheduling to M6 as previous deadline was missed.

        Show
        Adriaan Moors added a comment - Unassigning and rescheduling to M6 as previous deadline was missed.
        Hide
        Adriaan Moors added a comment -

        Since 2.11.0-RC1 is one week away, pushing all non-blockers without PR to 2.11.1-RC1. Please undo the change if I missed work in progress.

        Show
        Adriaan Moors added a comment - Since 2.11.0-RC1 is one week away, pushing all non-blockers without PR to 2.11.1-RC1. Please undo the change if I missed work in progress.

          People

          • Assignee:
            Jason Zaugg
            Reporter:
            Noah Luck Easterly
          • Votes:
            2 Vote for this issue
            Watchers:
            9 Start watching this issue

            Dates

            • Created:
              Updated:

              Development