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

Implicit is not considered if method in question has a(n unused) type parameter #5107

Open
scabug opened this issue Oct 22, 2011 · 2 comments
Labels
fixed in Scala 3 This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/) implicit infer
Milestone

Comments

@scabug
Copy link

scabug commented Oct 22, 2011

Consider this code, defining a simple class with a method named **:

class Foo() {
  def **(s: String) = "Foo"
}

Now we add a new classes and correspondent implicits to "add more supported types" to Foos ** method:

class Weird(foo: Foo) {
  def **[M](w: Weird) = new Weird(foo)
}

implicit def foo2weird(foo: Foo) = new Weird(foo)
class Weirder[T](foo: T) {
  def **[M](w: Weirder[T]) = new Weirder(foo)
}

implicit def foo2weirder(foo: Foo) = new Weirder(foo)
class Weirdest[T](foo: T) {
  def **(w: Weirdest[T]) = new Weirdest(foo)
}

implicit def foo2weirdest(foo: Foo) = new Weirdest(foo)

While the first and the last work, the second one fails:

// Works:
foo ** new Weird(new Foo)
// Fails:
foo ** new Weirder(new Foo)
/*
error: type mismatch;
 found   : Weirder[Foo]
 required: String
              f ** new Weirder(new Foo)
                   ^
*/
// Works again:
foo ** new Weirdest(new Foo)

The only difference between the second and the third example is the removal of the (unused) type parameter M.

It looks like as if the implicit method didn't even get considered when it had the type parameter.

This bug report is a result of http://stackoverflow.com/questions/7649517/

I already tried to read the spec to figure out if this is as expected or if this is a bug, but especially in 6.26.3 I haven't understood it fully.

I hope this can be fixed, because this behavior precludes any possibility of working with numbers where one of arguments is a parametrized type.

So while 5 * BigInt(5) will work, things like 5 * Complex[Long](...) (math), 5 * Currency[€](...) (money), 5 * QuantityMass` will not be possible.

@scabug
Copy link
Author

scabug commented Oct 22, 2011

Imported From: https://issues.scala-lang.org/browse/SI-5107?orig=1
Reporter: @soc
Affected Versions: 2.9.2, 2.10.0

@scabug
Copy link
Author

scabug commented Dec 14, 2012

@soc said:
It seems that it doesn't even consider the implicit **, because scala -Xlog-implicits doesn't print anything.

@scabug scabug added this to the Backlog milestone Apr 7, 2017
@adriaanm adriaanm removed their assignment Sep 28, 2018
@som-snytt som-snytt added the fixed in Scala 3 This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/) label Apr 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fixed in Scala 3 This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/) implicit infer
Projects
None yet
Development

No branches or pull requests

3 participants