scala / scala3

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

Tuple arguments in partial function marked as synthetic #16110

Open tgodzik opened 1 year ago

tgodzik commented 1 year ago

Compiler version

3.2.0

Minimized code

List(1,2,3).zipWithIndex.map { (x, y) =>
  println(x)
}

Output

x is marked as Synthetic both in the definition and in usage, which makes metals not show it to the user. We filter out synthetic symbols, since it usually meant that the symbol doesn't exist in the code.

Also the tree at x is a ValDef with a zero span, which means that we can't properly check if namePos contains the current cursor position.

Expectation

Neither x nor y is synthetic.

Anyone can point me to the change that caused it? It was working ok in 3.1.3

jkciesluk commented 1 year ago

x and y in the minimized code also lack Param flag. In 3.1.3 they didn't have it either, but back there they were methods, not values

mbovel commented 1 year ago
scala-cli compile -Xprint:typer -Yprint-debug -Ydebug-flags lambdaArgs.worksheet.sc

lambdaArgs.worksheet.sc:

List(1,2,3).zipWithIndex.map { (x, y) => x + 1}

Output:

scala.this.package.List.apply[scala.this.Int^(inf)](
      [1,2,3 : scala.this.Int^]
    ).zipWithIndex.map[scala.this.Int^(inf)](
      {
        {
          <method> <synthetic> <artifact> <touched> def $anonfun(
            <param> <synthetic> <touched> x$1: 

                scala.this.Tuple2[scala.this.Int @uncheckedVariance, 
                  scala.this.Int
                ]
              (inf)
          ): scala.this.Int^(inf) = 
            {
              <synthetic> <touched> val x: scala.this.Int(inf) = x$1._1
              <synthetic> <touched> val y: scala.this.Int(inf) = x$1._2
              {
                x.+(1)
              }
            }
          closure($anonfun)
        }
      }
    )

So, if I understand correctly val x and val y parameters should not be <synthetic>, is that right?

mbovel commented 1 year ago

Note: in the current version of metals, I get the following autocomplete suggestions:

image

This includes x$1 which is synthetic. Is it expected?

tgodzik commented 1 year ago

Note: in the current version of metals, I get the following autocomplete suggestions:

image

This includes x$1 which is synthetic. Is it expected?

It's not, but it does compile actually List(1,2,3).zipWithIndex.map { (x, y) => x$1} is a correct statement. This is coming from the compiler.

So, if I understand correctly val x and val y parameters should not be , is that right?

Ideally they wouldn't since those are real parameters defined by the user.