scala / scala3

The Scala 3 compiler, also known as Dotty.
https://dotty.epfl.ch
Apache License 2.0
5.88k stars 1.06k forks source link

Type toString for both mono and polymorphic functions uses the plain-printed output #16676

Open Sporarum opened 1 year ago

Sporarum commented 1 year ago

Compiler version

Scala 3.2.0 / 3.2.1-RC2

Minimized example & Output

val function: Int => Int = (x: Int) => x
val polyfunction: [T] => T => T = [U] => (x: U) => x

function // somethingLambdaSomething: scala.Function1[Int, Int]
polyfunction // <function1>: 
/* scala.Polyfunction {
 *   def apply[T >: scala.Nothing <: scala.Any](x$1: T): T
 * }
 */

https://scastie.scala-lang.org/9VXAH9QKTyeSYE8UYdV5eQ

Expectation

val function: Int => Int = (x: Int) => x
val polyfunction: [T] => T => T = [U] => (x: U) => x

function // somethingLambdaSomething: Int => Int
polyfunction // <function1>: [T] => T => T

It's not that bad for Function1, but for polymorphic functions, it's really hard to parse, especially to newcomers !

scala-center-bot commented 1 year ago

This issue was picked for the Issue Spree No. 27 of 07 March 2023 which takes place in a week from now. @Sporarum, @KuceraMartin, @mprzysucha will be working on it. If you have any insight into the issue or guidance on how to fix it, please leave it here.

Sporarum commented 1 year ago

Hello everyone, I'm preparing some preliminaries for the spree For this purpose, I opened a branch on dotty staging: fix-i16676

Sporarum commented 1 year ago

From what I have seen so far, there seems to be a high likelihood that this is an issue with Mdoc and not an issue with the compiler, as for example:

polyfunction: Nothing

Correctly prints out [T] => (x: T) => T in the narrowing error message:

https://scastie.scala-lang.org/XwdltwxWTT6EbIMDi8t2ZQ

Sporarum commented 1 year ago

The only places I have been able to replicate the issue is in scastie and in metals worksheets which both use Mdoc

Sporarum commented 1 year ago

Opened issue on Mdoc

mbovel commented 1 year ago

Removing the Spree label as @Sporarum is assigned to this issue.

Sporarum commented 1 year ago

As this seems not to be an issue with Mdoc in the end, more exploration is needed, I will therefore put it back as a Spree issue

Reasons for why it is probably not Mdoc can be found here: https://github.com/scalameta/mdoc/issues/758