Skip to content

Implicit numeric conversion #3252

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

Closed
allanrenucci opened this issue Oct 4, 2017 · 1 comment
Closed

Implicit numeric conversion #3252

allanrenucci opened this issue Oct 4, 2017 · 1 comment

Comments

@allanrenucci
Copy link
Contributor

scala> val i: Long = List(1, 2, 3).sum 
1 |val i: Long = List(1, 2, 3).sum
  |                               ^
  |                               found:    scala.math.Numeric[Int] => Int
  |                               required: Long
odersky added a commit to dotty-staging/dotty that referenced this issue Oct 4, 2017
adaptNoArgs would do an implicit argument search only if the result type
conformed to the expected type. scala#3252 shows that this needs to be revised.
@odersky odersky closed this as completed in 96cabbb Oct 5, 2017
odersky added a commit that referenced this issue Oct 5, 2017
@allanrenucci
Copy link
Contributor Author

allanrenucci commented Oct 5, 2017

I am reopening this issue because the following code snippet still does not compile:

object Test {
  def totalDuration(results: List[Long], cond: Boolean): Long =
    results.map(r => if (cond) r else 0).sum
}
[info] Running dotty.tools.dotc.Main -d out Test.scala -classpath scala-2.12/dotty-library_2.12-0.4.0-bin-SNAPSHOT-nonbootstrapped.jar
-- Error: tests/allan/Test.scala:3:44 ------------------------------------------
3 |    results.map(r => if (cond) r else 0).sum
  |                                            ^
  |no implicit argument of type scala.math.Numeric[B] found for parameter num of method sum in trait TraversableOnce

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

No branches or pull requests

1 participant