Skip to content
Browse files

Merge pull request #1958 from JamesIry/SI-6434_2.10.x

SI-6434 Pretty print function types with by name arg as (=> A) => B
  • Loading branch information...
2 parents 884737c + 8297843 commit 6fd92774fe1cbee4ec68af359fa57cbd4ad8fc01 @paulp paulp committed Jan 24, 2013
Showing with 22 additions and 2 deletions.
  1. +4 −2 src/reflect/scala/reflect/internal/Types.scala
  2. +10 −0 test/files/run/t6434.check
  3. +8 −0 test/files/run/t6434.scala
View
6 src/reflect/scala/reflect/internal/Types.scala
@@ -2481,8 +2481,10 @@ trait Types extends api.Types { self: SymbolTable =>
// from (T1, T2) => R.
targs match {
case in :: out :: Nil if !isTupleType(in) =>
- // A => B => C should be (A => B) => C or A => (B => C)
- val in_s = if (isFunctionType(in)) "(" + in + ")" else "" + in
+ // A => B => C should be (A => B) => C or A => (B => C).
+ // Also if A is byname, then we want (=> A) => B because => is right associative and => A => B
+ // would mean => (A => B) which is a different type
+ val in_s = if (isFunctionType(in) || isByNameParamType(in)) "(" + in + ")" else "" + in
val out_s = if (isFunctionType(out)) "(" + out + ")" else "" + out
in_s + " => " + out_s
case xs =>
View
10 test/files/run/t6434.check
@@ -0,0 +1,10 @@
+Type in expressions to have them evaluated.
+Type :help for more information.
+
+scala> def f(x: => Int): Int = x
+f: (x: => Int)Int
+
+scala> f _
+res0: (=> Int) => Int = <function1>
+
+scala>
View
8 test/files/run/t6434.scala
@@ -0,0 +1,8 @@
+import scala.tools.partest.ReplTest
+
+object Test extends ReplTest {
+ def code =
+"""def f(x: => Int): Int = x
+f _
+"""
+}

0 comments on commit 6fd9277

Please sign in to comment.
Something went wrong with that request. Please try again.