Skip to content

Commit

Permalink
Merge pull request #7798 from psilospore/11416
Browse files Browse the repository at this point in the history
11416 MethodType.toString prints in scala format
  • Loading branch information
SethTisue committed Feb 6, 2020
2 parents 5b7baea + 44955a6 commit fb0c104
Show file tree
Hide file tree
Showing 125 changed files with 1,332 additions and 1,321 deletions.
6 changes: 6 additions & 0 deletions src/reflect/scala/reflect/internal/Symbols.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2817,11 +2817,17 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
keyString,
varianceString + nameString + infoString + flagsExplanationString
)

/** String representation of symbol's definition. It uses the
* symbol's raw info to avoid forcing types.
*/
def defString = defStringCompose(signatureString)

def defStringWithoutImplicit = compose(
keyString,
varianceString + nameString + signatureString + flagsExplanationString
)

/** String representation of symbol's definition, using the supplied
* info rather than the symbol's.
*/
Expand Down
6 changes: 5 additions & 1 deletion src/reflect/scala/reflect/internal/TypeDebugging.scala
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ trait TypeDebugging {

object str {
def parentheses(xs: List[_]): String = xs.mkString("(", ", ", ")")
def params(params: List[Symbol]): String = {
val paramsStrPre = if (params.nonEmpty && params.head.isImplicit) "(implicit " else "("
params map (_.defStringWithoutImplicit) mkString (paramsStrPre, ", ", ")")
}
def brackets(xs: List[_]): String = if (xs.isEmpty) "" else xs.mkString("[", ", ", "]")
def tparams(tparams: List[Type]): String = brackets(tparams map debug)
def parents(ps: List[Type]): String = (ps map debug).mkString(" with ")
Expand All @@ -152,7 +156,7 @@ trait TypeDebugging {
}
def debugString(tp: Type) = debug(tp)
}
def paramString(tp: Type) = typeDebug.str parentheses (tp.params map (_.defString))
def paramString(tp: Type) = typeDebug.str params tp.params
def typeParamsString(tp: Type) = typeDebug.str brackets (tp.typeParams map (_.defString))
def debugString(tp: Type) = typeDebug debugString tp
}
9 changes: 7 additions & 2 deletions src/reflect/scala/reflect/internal/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2897,7 +2897,12 @@ trait Types
//TODO this may be generalised so that the only constraint is dependencies are acyclic
def approximate: MethodType = MethodType(params, resultApprox)

override def safeToString = paramString(this) + resultType
//Format (a: A)(b: B)(implicit c: C, d: D): E
override def safeToString = {
s"${paramString(this)}${
resultType match { case _: MethodType => "" case _ => ": "}
}$resultType"
}

override def cloneInfo(owner: Symbol) = {
val vparams = cloneSymbolsAtOwner(params, owner)
Expand Down Expand Up @@ -2942,7 +2947,7 @@ trait Types
override def baseTypeSeqDepth: Depth = resultType.baseTypeSeqDepth
override def baseClasses: List[Symbol] = resultType.baseClasses
override def baseType(clazz: Symbol): Type = resultType.baseType(clazz)
override def safeToString: String = "=> "+ resultType
override def safeToString: String = resultType.toString
override def kind = "NullaryMethodType"
override def mapOver(map: TypeMap): Type = {
val result1 = map(resultType)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error_dependentMethodTpeConversionToFunction.scala:4: error: method with dependent type (x: AnyRef)x.type cannot be converted to function value
error_dependentMethodTpeConversionToFunction.scala:4: error: method with dependent type (x: AnyRef): x.type cannot be converted to function value
val x: Any => Any = foo
^
1 error
2 changes: 1 addition & 1 deletion test/files/neg/eta-expand-star.check
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
eta-expand-star.scala:6: error: too many arguments (2) for method apply: (v1: Seq[T])Unit in trait Function1
eta-expand-star.scala:6: error: too many arguments (2) for method apply: (v1: Seq[T]): Unit in trait Function1
g(1, 2)
^
1 error
2 changes: 1 addition & 1 deletion test/files/neg/implicit-log.check
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
implicit-log.scala:61: byVal is not a valid implicit value for Int(7) => ?{def unwrap: ?} because:
incompatible: (x: 7)7 does not match expected type Int(7) => ?{def unwrap: ?}
incompatible: (x: 7): 7 does not match expected type Int(7) => ?{def unwrap: ?}
val res = 7.unwrap() // doesn't work
^
implicit-log.scala:70: materializing requested scala.reflect.type.ClassTag[String] using scala.reflect.`package`.materializeClassTag[String]()
Expand Down
10 changes: 5 additions & 5 deletions test/files/neg/leibniz-liskov.check
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ leibniz-liskov.scala:13: error: Cannot prove that LeibnizLiskov.this.SA <:< Leib
leibniz-liskov.scala:14: error: Cannot prove that LeibnizLiskov.this.A <:< LeibnizLiskov.this.SB.
implicitly[A <:< SB]
^
leibniz-liskov.scala:18: error: no type parameters for method substituteCo: (ff: F[LeibnizLiskov.this.A])F[LeibnizLiskov.this.B] exist so that it can be applied to arguments (List[LeibnizLiskov.this.B])
leibniz-liskov.scala:18: error: no type parameters for method substituteCo: (ff: F[LeibnizLiskov.this.A]): F[LeibnizLiskov.this.B] exist so that it can be applied to arguments (List[LeibnizLiskov.this.B])
--- because ---
argument expression's type is not compatible with formal parameter type;
found : List[LeibnizLiskov.this.B]
Expand All @@ -28,7 +28,7 @@ leibniz-liskov.scala:18: error: type mismatch;
required: F[LeibnizLiskov.this.A]
aEqB.substituteCo (List(B(), B(), B()))
^
leibniz-liskov.scala:19: error: no type parameters for method substituteContra: (ft: F[LeibnizLiskov.this.B])F[LeibnizLiskov.this.A] exist so that it can be applied to arguments (List[LeibnizLiskov.this.A])
leibniz-liskov.scala:19: error: no type parameters for method substituteContra: (ft: F[LeibnizLiskov.this.B]): F[LeibnizLiskov.this.A] exist so that it can be applied to arguments (List[LeibnizLiskov.this.A])
--- because ---
argument expression's type is not compatible with formal parameter type;
found : List[LeibnizLiskov.this.A]
Expand All @@ -43,7 +43,7 @@ leibniz-liskov.scala:19: error: type mismatch;
leibniz-liskov.scala:20: error: Cannot prove that xs.type <:< List[LeibnizLiskov.this.B].
locally { val xs = aEqB.flip.liftCo[List](List(B(), B(), B())); implicitly[xs.type <:< List[B]] }
^
leibniz-liskov.scala:21: error: no type parameters for method substituteContra: (ft: F[U])F[T] exist so that it can be applied to arguments (List[T])
leibniz-liskov.scala:21: error: no type parameters for method substituteContra: (ft: F[U]): F[T] exist so that it can be applied to arguments (List[T])
--- because ---
argument expression's type is not compatible with formal parameter type;
found : List[T]
Expand All @@ -60,7 +60,7 @@ leibniz-liskov.scala:21: error: type mismatch;
required: List[U]
def convert1[T, U](l: List[T])(ev: T =:= U): List[U] = ev.substituteContra(l)
^
leibniz-liskov.scala:22: error: no type parameters for method substituteCo: (ff: F[T])F[U] exist so that it can be applied to arguments (List[U])
leibniz-liskov.scala:22: error: no type parameters for method substituteCo: (ff: F[T]): F[U] exist so that it can be applied to arguments (List[U])
--- because ---
argument expression's type is not compatible with formal parameter type;
found : List[U]
Expand Down Expand Up @@ -97,7 +97,7 @@ LeibnizLiskov.this.Consumes's type parameters do not match type F's expected par
type X is contravariant, but type _ is declared covariant
def convertConsume1[U, T](c: Consumes[T])(ev: U <:< T): Consumes[U] = ev.liftCo[Consumes](c)
^
leibniz-liskov.scala:35: error: no type parameters for method substituteCo: (ff: F[U])F[T] exist so that it can be applied to arguments (LeibnizLiskov.this.Consumes[T])
leibniz-liskov.scala:35: error: no type parameters for method substituteCo: (ff: F[U]): F[T] exist so that it can be applied to arguments (LeibnizLiskov.this.Consumes[T])
--- because ---
argument expression's type is not compatible with formal parameter type;
found : LeibnizLiskov.this.Consumes[T]
Expand Down
2 changes: 1 addition & 1 deletion test/files/neg/logImplicits.check
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ logImplicits.scala:4: applied implicit conversion from xs.type to ?{def size: ?}
logImplicits.scala:9: applied implicit conversion from String("abc") to ?{def map: ?} = implicit def augmentString(x: String): scala.collection.StringOps
def f = "abc" map (_ + 1)
^
logImplicits.scala:17: inferred view from String("abc") to Int via C.this.convert: (p: "abc")Int
logImplicits.scala:17: inferred view from String("abc") to Int via C.this.convert: (p: "abc"): Int
math.max(122, x: Int)
^
logImplicits.scala:21: applied implicit conversion from Int(1) to ?{def ->: ?} = final implicit def ArrowAssoc[A](self: A): ArrowAssoc[A]
Expand Down
8 changes: 4 additions & 4 deletions test/files/neg/macro-invalidimpl.check
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ macro [<macro bundle>].<method name>[[<type args>]]
def foo(x: Any): Any = macro Impls4.foo
^
Macros_Test_2.scala:27: error: ambiguous reference to overloaded definition,
both method foo in object Impls5 of type (c: scala.reflect.macros.blackbox.Context)(x: c.Expr[Any], y: c.Expr[Any])Nothing
and method foo in object Impls5 of type (c: scala.reflect.macros.blackbox.Context)(x: c.Expr[Any])Nothing
both method foo in object Impls5 of type (c: scala.reflect.macros.blackbox.Context)(x: c.Expr[Any], y: c.Expr[Any]): Nothing
and method foo in object Impls5 of type (c: scala.reflect.macros.blackbox.Context)(x: c.Expr[Any]): Nothing
match expected type ?
def foo(x: Any): Any = macro Impls5.foo
^
Macros_Test_2.scala:28: error: ambiguous reference to overloaded definition,
both method foo in object Impls5 of type (c: scala.reflect.macros.blackbox.Context)(x: c.Expr[Any], y: c.Expr[Any])Nothing
and method foo in object Impls5 of type (c: scala.reflect.macros.blackbox.Context)(x: c.Expr[Any])Nothing
both method foo in object Impls5 of type (c: scala.reflect.macros.blackbox.Context)(x: c.Expr[Any], y: c.Expr[Any]): Nothing
and method foo in object Impls5 of type (c: scala.reflect.macros.blackbox.Context)(x: c.Expr[Any]): Nothing
match expected type ?
def foo(x: Any, y: Any): Any = macro Impls5.foo
^
Expand Down
6 changes: 3 additions & 3 deletions test/files/neg/macro-invalidsig.check
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,13 @@ Macros_Test_2.scala:46: error: type arguments [U] do not conform to method foo's
Macros_Test_2.scala:50: error: type arguments [U] do not conform to method foo's type parameter bounds [U <: String]
def foo[U <: Int]: Any = macro Impls13.foo[U]
^
Macros_Test_2.scala:54: error: macro implementation reference has too few type arguments for method foo: [U](c: scala.reflect.macros.blackbox.Context)(implicit evidence$4: c.WeakTypeTag[U])Nothing
Macros_Test_2.scala:54: error: macro implementation reference has too few type arguments for method foo: [U](c: scala.reflect.macros.blackbox.Context)(implicit evidence$4: c.WeakTypeTag[U]): Nothing
def foo: Any = macro Impls14.foo
^
Macros_Test_2.scala:59: error: macro implementation reference has too few type arguments for method foo: [T, U, V](c: scala.reflect.macros.blackbox.Context)(implicit evidence$5: c.WeakTypeTag[T], implicit evidence$6: c.WeakTypeTag[U], implicit V: c.WeakTypeTag[V])c.Expr[Unit]
Macros_Test_2.scala:59: error: macro implementation reference has too few type arguments for method foo: [T, U, V](c: scala.reflect.macros.blackbox.Context)(implicit evidence$5: c.WeakTypeTag[T], evidence$6: c.WeakTypeTag[U], V: c.WeakTypeTag[V]): c.Expr[Unit]
def foo15[V]: Unit = macro Impls15.foo
^
Macros_Test_2.scala:60: error: wrong number of type parameters for method foo: [T, U, V](c: scala.reflect.macros.blackbox.Context)(implicit evidence$7: c.WeakTypeTag[T], implicit evidence$8: c.WeakTypeTag[U], implicit V: c.WeakTypeTag[V])c.Expr[Unit]
Macros_Test_2.scala:60: error: wrong number of type parameters for method foo: [T, U, V](c: scala.reflect.macros.blackbox.Context)(implicit evidence$7: c.WeakTypeTag[T], evidence$8: c.WeakTypeTag[U], V: c.WeakTypeTag[V]): c.Expr[Unit]
def foo16[V]: Unit = macro Impls16.foo[V]
^
16 errors
4 changes: 2 additions & 2 deletions test/files/neg/macro-invalidusage-badargs.check
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ Macros_Test_2.scala:6: error: too few argument lists for macro invocation
Macros_Test_2.scala:7: error: Int does not take parameters
foo(4)(2)
^
Macros_Test_2.scala:8: error: not enough arguments for macro method foo: (x: Int)Int.
Macros_Test_2.scala:8: error: not enough arguments for macro method foo: (x: Int): Int.
Unspecified value parameter x.
foo()
^
Macros_Test_2.scala:9: error: too many arguments (2) for macro method foo: (x: Int)Int
Macros_Test_2.scala:9: error: too many arguments (2) for macro method foo: (x: Int): Int
foo(4, 2)
^
5 errors
6 changes: 3 additions & 3 deletions test/files/neg/macro-invalidusage-badtargs.check
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
Macros_Test_2.scala:13: error: macro method foo1: (x: Int)Int does not take type parameters.
Macros_Test_2.scala:13: error: macro method foo1: (x: Int): Int does not take type parameters.
foo1[String](42)
^
Macros_Test_2.scala:14: error: wrong number of type parameters for macro method foo2: [T](x: Int)Int
Macros_Test_2.scala:14: error: wrong number of type parameters for macro method foo2: [T](x: Int): Int
foo2[String, String](42)
^
Macros_Test_2.scala:15: error: wrong number of type parameters for macro method foo3: [T, U](x: Int)Int
Macros_Test_2.scala:15: error: wrong number of type parameters for macro method foo3: [T, U](x: Int): Int
foo3[String](42)
^
Macros_Test_2.scala:16: error: String takes no type parameters, expected: 1
Expand Down
12 changes: 6 additions & 6 deletions test/files/neg/main1.check
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
main1.scala:5: warning: Foo has a valid main method (args: Array[String])Unit,
main1.scala:5: warning: Foo has a valid main method (args: Array[String]): Unit,
but foo1.Foo will not have an entry point on the JVM.
Reason: companion is a trait, which means no static forwarder can be generated.

object Foo { // companion is trait
^
main1.scala:12: warning: Foo has a valid main method (args: Array[String])Unit,
main1.scala:12: warning: Foo has a valid main method (args: Array[String]): Unit,
but foo2.Foo will not have an entry point on the JVM.
Reason: companion contains its own main method, which means no static forwarder can be generated.

object Foo { // companion has its own main
^
main1.scala:24: warning: Foo has a valid main method (args: Array[String])Unit,
main1.scala:24: warning: Foo has a valid main method (args: Array[String]): Unit,
but foo3.Foo will not have an entry point on the JVM.
Reason: companion contains its own main method (implementation restriction: no main is allowed, regardless of signature), which means no static forwarder can be generated.

object Foo { // Companion contains main, but not an interfering main.
^
main1.scala:33: warning: Foo has a valid main method (args: Array[String])Unit,
main1.scala:33: warning: Foo has a valid main method (args: Array[String]): Unit,
but foo4.Foo will not have an entry point on the JVM.
Reason: companion contains its own main method, which means no static forwarder can be generated.

object Foo extends Foo { // Inherits main from the class
^
main1.scala:41: warning: Foo has a valid main method (args: Array[String])Unit,
main1.scala:41: warning: Foo has a valid main method (args: Array[String]): Unit,
but foo5.Foo will not have an entry point on the JVM.
Reason: companion contains its own main method, which means no static forwarder can be generated.

Expand All @@ -35,7 +35,7 @@ main1.scala:53: warning: not a valid main method for p6.Main,

def main(args: Array[Int]) = ()
^
main1.scala:59: warning: Main has a main method (args: Array[Int])Unit,
main1.scala:59: warning: Main has a main method (args: Array[Int]): Unit,
but p7.Main will not have an entry point on the JVM.
Reason: companion is a trait, which means no static forwarder can be generated.

Expand Down
2 changes: 1 addition & 1 deletion test/files/neg/main2.check
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
main2.scala:7: warning: X has a valid main method (args: Array[String])Unit,
main2.scala:7: warning: X has a valid main method (args: Array[String]): Unit,
but p.X will not have an entry point on the JVM.
Reason: companion is a trait, which means no static forwarder can be generated.

Expand Down
2 changes: 1 addition & 1 deletion test/files/neg/multi-array.check
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
multi-array.scala:9: error: too many arguments (2) for constructor Array: (_length: Int)Array[T]
multi-array.scala:9: error: too many arguments (2) for constructor Array: (_length: Int): Array[T]
val a: Array[Int] = new Array(10, 10)
^
1 error
24 changes: 12 additions & 12 deletions test/files/neg/names-defaults-neg-pu.check
Original file line number Diff line number Diff line change
Expand Up @@ -39,26 +39,26 @@ names-defaults-neg-pu.scala:28: error: Int does not take parameters
test3(b = 3, a = 1)(3)
^
names-defaults-neg-pu.scala:37: error: ambiguous reference to overloaded definition,
both method f in object t1 of type (b: String, a: Int)String
and method f in object t1 of type (a: Int, b: String)String
both method f in object t1 of type (b: String, a: Int): String
and method f in object t1 of type (a: Int, b: String): String
match argument types (b: String,a: Int)
t1.f(b = "dkljf", a = 1)
^
names-defaults-neg-pu.scala:44: error: ambiguous reference to overloaded definition,
both method f in object t3 of type (a2: Int)(b: Int)String
and method f in object t3 of type (a1: Int)String
both method f in object t3 of type (a2: Int)(b: Int): String
and method f in object t3 of type (a1: Int): String
match argument types (Int)
t3.f(1)
^
names-defaults-neg-pu.scala:45: error: ambiguous reference to overloaded definition,
both method f in object t3 of type (a2: Int)(b: Int)String
and method f in object t3 of type (a1: Int)String
both method f in object t3 of type (a2: Int)(b: Int): String
and method f in object t3 of type (a1: Int): String
match argument types (Int)
t3.f(1)(2)
^
names-defaults-neg-pu.scala:51: error: ambiguous reference to overloaded definition,
both method g in object t7 of type (a: B)String
and method g in object t7 of type (a: C, b: Int*)String
both method g in object t7 of type (a: B): String
and method g in object t7 of type (a: C, b: Int*): String
match argument types (C)
t7.g(new C()) // ambiguous reference
^
Expand All @@ -72,19 +72,19 @@ names-defaults-neg-pu.scala:57: error: when using named arguments, the vararg pa
test5(b = "dlkj")
^
names-defaults-neg-pu.scala:63: error: ambiguous reference to overloaded definition,
both method f in object t8 of type (b: String, a: Int)String
and method f in object t8 of type (a: Int, b: Object)String
both method f in object t8 of type (b: String, a: Int): String
and method f in object t8 of type (a: Int, b: Object): String
match argument types (a: Int,b: String) and expected result type Any
println(t8.f(a = 0, b = "1")) // ambiguous reference
^
names-defaults-neg-pu.scala:67: error: not enough arguments for method apply: (a: Int, b: String)(c: Int*)Fact in object Fact.
names-defaults-neg-pu.scala:67: error: not enough arguments for method apply: (a: Int, b: String)(c: Int*): Fact in object Fact.
Unspecified value parameter b.
val fac = Fact(1)(2, 3)
^
names-defaults-neg-pu.scala:71: error: wrong number of arguments for pattern A1(x: Int, y: String)
A1() match { case A1(_) => () }
^
names-defaults-neg-pu.scala:78: error: no type parameters for method test4: (x: T[T[List[T[X forSome { type X }]]]])T[T[List[T[X forSome { type X }]]]] exist so that it can be applied to arguments (List[Int])
names-defaults-neg-pu.scala:78: error: no type parameters for method test4: (x: T[T[List[T[X forSome { type X }]]]]): T[T[List[T[X forSome { type X }]]]] exist so that it can be applied to arguments (List[Int])
--- because ---
argument expression's type is not compatible with formal parameter type;
found : List[Int]
Expand Down
4 changes: 2 additions & 2 deletions test/files/neg/names-defaults-neg-ref.check
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ class C extends B {
^
names-defaults-neg-ref.scala:21: error: incompatible type in overriding
def bar$default$1: String (defined in class B);
found : => Int
required: => String
found : Int
required: String
def bar(i: Int = 129083) = i
^
4 errors
Loading

0 comments on commit fb0c104

Please sign in to comment.