scala / scala3

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

Nested similar lambdas result in duplicate method in ClassDef #20460

Open jypma opened 4 months ago

jypma commented 4 months ago

Compiler version

3.3.3, 3.4.2

3.4.2 slightly changes the error message to duplicate static method

Minimized code

Only full code is available. The bug is found by ScalaJS' validity checker of ClassDef. It can be reproduced as follows:

git checkout https://github.com/jypma/lazagna.git
cd lazagna
git checkout 88e946e # currently this is master
sbt
project client
fullLinkJS

Output

[info] Full optimizing /home/jan/workspace/lazagna/draw-client/target/scala-3.3.3/client-opt [error] file:/home/jan/workspace/lazagna/draw-client/src/main/scala/draw/client/tools/SelectTool.scala(206:26:MethodDef): duplicate method 'draw$client$tools$SelectTool$$$$$$anonfun$$anonfun$1(draw.client.render.RenderedObject)draw.data.ObjectState' [error] There were 1 ClassDef checking errors. [error] (Compile / fullLinkJS) There were 1 ClassDef checking errors.

Expectation

The code compiles (and runs in scalaJS) fine. The cause is the .map(_.state) on line 202 of SelectTool.scala. If I replace that with a named function, the error goes away. There's on other .map(_.state) on line 219, I'm not sure if that's the one resulting in a duplicate.

Gedochao commented 4 months ago

The github repo link is https://github.com/jypma/lazagna We need to minimise this into a code snippet. @jypma would you be able to help?