Details

      Description

      In foo/bar/package.scala:

      package foo
      
      package object bar {
        class Val(b: Boolean)
        implicit def boolean2Val(b: Boolean) = new Val(b)
      }
      

      In foo/bar/A.scala:

      package foo.bar
      
      class A {
        val s: Val = false
      }
      
      > scalac foo\bar\package.scala foo\bar\A.scala
      foo\bar\A.scala:4: error: type mismatch;
       found   : Boolean(false)
       required: foo.bar.package.Val
      Note that implicit conversions are not applicable because they are ambiguous:
       both method boolean2Val in package bar of type (b: Boolean)foo.bar.package.Val
       and method boolean2Val in package bar of type (b: Boolean)foo.bar.package.Val
       are possible conversion functions from Boolean(false) to foo.bar.package.Val
        val s: Val = false
                     ^
      one error found
      
      > scalac -version
      Scala compiler version 2.8.0.final -- Copyright 2002-2010, LAMP/EPFL
      

        Activity

        Hide
        Paul Phillips added a comment -

        There's no reason to put classes in package objects: I think we should prohibit it, at least in the short term, since you get weird behaviors like this.

        Note that implicit conversions are not applicable because they are ambiguous:
         both method boolean2ValSI-9273 in package barSI-9264 of type (bSI-11195: BooleanSI-3807)foo.bar.packageSI-9265.ValSI-9272
         and method boolean2ValSI-9273 in package barSI-9264 of type (bSI-11195: BooleanSI-3807)foo.bar.package.ValSI-9272
         are possible conversion functions from BooleanSI-3807(false) to fooSI-9261.barSI-9263.packageSI-9265.ValSI-9272
        

        So I guess foo.bar.packageSI-9265.ValSI-9272 != foo.bar.package.ValSI-9272. Is that the package object vs. the package object class?

        Show
        Paul Phillips added a comment - There's no reason to put classes in package objects: I think we should prohibit it, at least in the short term, since you get weird behaviors like this. Note that implicit conversions are not applicable because they are ambiguous: both method boolean2ValSI-9273 in package barSI-9264 of type (bSI-11195: BooleanSI-3807)foo.bar.packageSI-9265.ValSI-9272 and method boolean2ValSI-9273 in package barSI-9264 of type (bSI-11195: BooleanSI-3807)foo.bar.package.ValSI-9272 are possible conversion functions from BooleanSI-3807(false) to fooSI-9261.barSI-9263.packageSI-9265.ValSI-9272 So I guess foo.bar.packageSI-9265.ValSI-9272 != foo.bar.package.ValSI-9272. Is that the package object vs. the package object class?
        Hide
        Lukas Rytz added a comment -

        it looks like package object related issues are assigned to martin, so doing the same here until somebody takes a closer look at them.

        Show
        Lukas Rytz added a comment - it looks like package object related issues are assigned to martin, so doing the same here until somebody takes a closer look at them.
        Hide
        s wade added a comment -

        I just sent a similar question to the scala-user list. Test.scala fails to compile, test2.scala does compile (2.9.0.1, java 1.6.0_26):

        test.scala
        object `package` {
          trait Score { def toString : String }
          trait Test[+T <: Score] { def apply(s : String) : T }
        
          case class FT(f : Float) extends Score
          implicit object FT extends Test[FT] { def apply(s : String) : FT = new FT(s.toFloat) }
        
          case class IT(i : Int) extends Score
          implicit object IT extends Test[IT] { def apply(s : String) : IT = new IT(s.toInt) }
        }
        
        class TT[+T <: Score](implicit val tb : Test[T]) {
          def read(s : String) : T = tb(s)
        }
        
        object Tester {
          val tt = new TT[FT]
          val r = tt.read("1.0")
          r.toString
        }
        
        test2.scala
        object Tester {
          trait Score { def toString : String }
          trait Test[+T <: Score] { def apply(s : String) : T }
        
          case class FT(f : Float) extends Score
          implicit object FT extends Test[FT] { def apply(s : String) : FT = new FT(s.toFloat) }
        
          case class IT(i : Int) extends Score
          implicit object IT extends Test[IT] { def apply(s : String) : IT = new IT(s.toInt) }
          class TT[+T <: Score](implicit val tb : Test[T]) {
            def read(s : String) : T = tb(s)
          }
        
          val tt = new TT[FT]
          val r = tt.read("1.0")
          r.toString
        }
        
        
        Show
        s wade added a comment - I just sent a similar question to the scala-user list. Test.scala fails to compile, test2.scala does compile (2.9.0.1, java 1.6.0_26): test.scala object `package` { trait Score { def toString : String } trait Test[+T <: Score] { def apply(s : String) : T } case class FT(f : Float) extends Score implicit object FT extends Test[FT] { def apply(s : String) : FT = new FT(s.toFloat) } case class IT(i : Int) extends Score implicit object IT extends Test[IT] { def apply(s : String) : IT = new IT(s.toInt) } } class TT[+T <: Score](implicit val tb : Test[T]) { def read(s : String) : T = tb(s) } object Tester { val tt = new TT[FT] val r = tt.read("1.0") r.toString } test2.scala object Tester { trait Score { def toString : String } trait Test[+T <: Score] { def apply(s : String) : T } case class FT(f : Float) extends Score implicit object FT extends Test[FT] { def apply(s : String) : FT = new FT(s.toFloat) } case class IT(i : Int) extends Score implicit object IT extends Test[IT] { def apply(s : String) : IT = new IT(s.toInt) } class TT[+T <: Score](implicit val tb : Test[T]) { def read(s : String) : T = tb(s) } val tt = new TT[FT] val r = tt.read("1.0") r.toString }
        Hide
        Paul Phillips added a comment -

        Fixed in d7981e784e .

        Show
        Paul Phillips added a comment - Fixed in d7981e784e .

          People

          • Assignee:
            Paul Phillips
            Reporter:
            Ittay Dror
            TracCC:
            Paul Phillips
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development