amnaredo / test

0 stars 0 forks source link

eta-expansion and implicit argument passing #193

Open amnaredo opened 3 years ago

amnaredo commented 3 years ago

I get a different behaviour when calling map(f) vs map(v => f(v)), where f calls pprint.tokenize.

libraryDependencies += "com.lihaoyi" %% "pprint" % "0.4.1"

case class Entry(id: Int, text: String)
val entry = Entry(1, "hello")

def toPrettyString[T](o: T)(implicit pp: pprint.PPrint[T]) =
  pprint.tokenize(o)(pp).mkString

println(toPrettyString(entry))                            // I get Entry(1, "hello"), as expected

List(entry).map(toPrettyString).foreach(println)          // I get Entry(1,hello), not what I want
List(entry).map(e => toPrettyString(e)).foreach(println)  // I get Entry(1, "hello"), as expected

It seems that this is a bug in Scala itself (not pprint), but I open this issue so that you are aware of it and when it is solved.

http://stackoverflow.com/questions/40049207/scala-different-behaviour-when-calling-mapf-vs-mapv-fv https://issues.scala-lang.org/browse/SI-7641

ID: 178 Original Author: dportabella

amnaredo commented 3 years ago

Bug bankruptcy Original Author: lihaoyi