Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duplicate implicits in package object #3999

Closed
scabug opened this issue Nov 15, 2010 · 5 comments
Closed

Duplicate implicits in package object #3999

scabug opened this issue Nov 15, 2010 · 5 comments
Assignees
Milestone

Comments

@scabug
Copy link

@scabug scabug commented Nov 15, 2010

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
@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Nov 15, 2010

Imported From: https://issues.scala-lang.org/browse/SI-3999?orig=1
Reporter: Ittay Dror (ittayd)
Other Milestones: 2.10.0

@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Nov 15, 2010

@paulp said:
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?

@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Nov 16, 2010

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

@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Aug 4, 2011

s wade (swadenator) said:
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
}
@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Jan 29, 2012

@paulp said:
Fixed in d7981e784e .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.