You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The compiler plugin inserts a phase between the parser and the typer, but the phase doesn't do anything. The code in the tests directory defines a simple macro in Macro.scala and a call to the macro in Test.scala.
I believe both the placement of the compiler plugin and the existence of the macro matter -- if I change either one of them, i.e. run the plugin after the typer or remove the macro, then the issue stops happening.
Output
-- [E161] NamingError:/Users/matt/dotty-compiler-plugin-issue/tests/src/main/scala/Test.scala:3:03|objecttest {
|^|test is already defined asobject test in /Users/matt/dotty-compiler-plugin-issue/tests/src/main/scala/Test.scala
When I enable -Xprint:typer, the full sbt output that shows the duplicated object test looks like this:
[info] [[syntax trees at end of typer]] // /Users/matt/dotty-compiler-plugin-issue/tests/src/main/scala/Macro.scala
[info] packageexample {
[info] importscala.quoted.*
[info] finallazy module valMacro$package: example.Macro$package=
[info] new example.Macro$package()
[info] final module classMacro$package() extendsObject() {
[info] this: example.Macro$package.type=>
[info] private[example] defidMacroImpl[A>:Nothing<:Any](
[info] implicitevidence$1: quoted.Type[A], ctx: quoted.Quotes):
[info] quoted.Expr[A=>A] =
[info] '{
[info] {
[info] def$anonfun(a: A):A=
[info] {
[info] a
[info] }
[info] closure($anonfun)
[info] }
[info] }.apply(ctx)
[info] inlinedefidMacro[A>:Nothing<:Any]:A=>A=
[info] ${
[info] {
[info] def$anonfun(usingevidence$2: quoted.Quotes): quoted.Expr[A=>A] =
[info] example.Macro$package.inline$idMacroImpl[A](
[info] quoted.Type.of[A](evidence$2), evidence$2)
[info] closure($anonfun)
[info] }
[info] }:(A=>A)
[info] definline$idMacroImpl[A](implicitevidence$1: quoted.Type[A],
[info] implicitctx: quoted.Quotes): quoted.Expr[A=>A] =
[info] example.Macro$package.idMacroImpl[A](evidence$1, ctx)
[info] }
[info] }
[info] [[syntax trees at end of typer]] // /Users/matt/dotty-compiler-plugin-issue/tests/src/main/scala/Test.scala
[info] packageexample {
[info] finallazy module valtest: example.test =new example.test()
[info] final module classtest() extendsObject() { this: example.test.type=>
[info] valintId:Int=>Int= example.idMacro[Int]
[info] }
[info] }
[error] -- [E161] NamingError:/Users/matt/dotty-compiler-plugin-issue/tests/src/main/scala/Test.scala:3:0
[error] 3|objecttest {
[error] |^
[error] |test is already defined asobject test in /Users/matt/dotty-compiler-plugin-issue/tests/src/main/scala/Test.scala
[info] [[syntax trees at end of typer]] // /Users/matt/dotty-compiler-plugin-issue/tests/src/main/scala/Test.scala
[info] packageexample {
[info] finallazy module valtest$1: example.test =new example.test()
[info] final module classtest$2() extendsObject() { this: example.test.type=>
[info] valintId:Int=>Int= example.idMacro[Int]
[info] }
[info] }
Expectation
Compilation should succeed
The text was updated successfully, but these errors were encountered:
Hmm I see, this is a bit annoying to support since the parameter passed to the parent class isn't reachable from the symbol of the class, but it's clear that we should either support it or deprecate extending nowarn. This isn't exactly the same, but the following works in Scala 2 and 3 and could be a good alternative I think:
Compiler version
3.3.0, also the latest 3.3.1-RC5 and 3.4.0-RC1-bin-20230809-c5adafc-NIGHTLY
Minimized code
https://github.com/mrdziuban/dotty-compiler-plugin-issue/tree/duplicated-code
The compiler plugin inserts a phase between the parser and the typer, but the phase doesn't do anything. The code in the
tests
directory defines a simple macro inMacro.scala
and a call to the macro inTest.scala
.I believe both the placement of the compiler plugin and the existence of the macro matter -- if I change either one of them, i.e. run the plugin after the typer or remove the macro, then the issue stops happening.
Output
When I enable
-Xprint:typer
, the full sbt output that shows the duplicatedobject test
looks like this:Expectation
Compilation should succeed
The text was updated successfully, but these errors were encountered: