-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot call macro defined in the same source file error #12498
Comments
I could not reproduce it on master. It might be fixed or it might depend on the way it is compiled. @mbore how did you compile this code? |
I've tested it with the |
@nicolasstucki I’ve found one more unexpected behaviour related to this issue. Compiler versionScala Version: 3.0.0 Minimized codeUpdated Main.scala case class Person(name: String, age: Int)
object Main extends App {
println(Wrapper(Person("a", 1)).showTypeRepr)
}
object Main2 extends App {
println(Wrapper(Person("a", 1)).showTypeRepr)
}
Output[error] 6 | println(Wrapper(Person("a", 1)).showTypeRepr)
[error] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[error] | Cannot call macro class Person defined in the same source file
[error] | This location contains code that was inlined from Main.scala:6 I'm not sure if this is an issue in dotty or sbt. |
It looks like it is an incremental compilation issue |
@nicolasstucki yes, although the scalatest variant (linked) also is reproducible on a clean build |
@mbore @nicolasstucki @adamw Updating from ScalaTest discussion here: I made an example project here to reproduce the problem without ScalaTest: https://github.com/cheeseng/scala3-inline-problem just run the following to see the error:
Note that if this object TestData in https://github.com/cheeseng/scala3-inline-problem/blob/main/src/test/scala/Test1.scala#L1 is moved into a separate file, the error does go away. But if the following:
is suppose to work, I don't see why the example does not work. |
@mbore @nicolasstucki @adamw, Fyi I updated the example in https://github.com/cheeseng/scala3-inline-problem to use scala 3.0.2-RC1 but unfortunately it still encounters the same error:
|
Reproduces cleanly for me:
|
I'm getting the same issue: Needless to say, the |
@nicolasstucki just to ping that the problem can still the reproduced consistently in https://github.com/cheeseng/scala3-inline-problem , I have updated the scala version to the latest 3.1.3 and it still has the problem. |
Minimizationtests/pos-macros/Macro_1.scala import scala.quoted.*
class Wrapper[T](t: T):
inline def showType: String = ${ Wrapper.showTypeImpl[T]}
object Wrapper:
def showTypeImpl[U](using Quotes): Expr[String] = Expr("foo") tests/pos-macros/Test_2.scala class Person
def test = Wrapper(new Person).showType Note: must be compiled separately (if we suspend the second compilation unit, it works) |
The `macroDependencies` method collects all the definitions that are required to interpret the contents of the splice (using JVM-reflection). We do not care about type parameters because those are erased and the interpreter emulates erased semantics. Fixes scala#12498
How I fixed it
Note: when adding the |
A hero! Thank you @nicolasstucki! |
The `macroDependencies` method collects all the definitions that are required to interpret the contents of the splice (using JVM-reflection). We do not care about type parameters because those are erased and the interpreter emulates erased semantics. Fixes scala#12498
The `macroDependencies` method collects all the definitions that are required to interpret the contents of the splice (using JVM-reflection). We do not care about type parameters because those are erased and the interpreter emulates erased semantics. Fixes scala#12498
We can have different kinds of type references in the contents of a splice. We do not care about types because those are erased and the interpreter emulates erased semantics. These types are in |Tree|s that extend |TypeTree| or |RefTree| referring to type. Fixes scala#12498
We can have different kinds of type references in the contents of a splice. We do not care about types because those are erased and the interpreter emulates erased semantics. These types are in `Tree`s that extend `TypeTree` or `RefTree` referring to type. Fixes scala#12498
Compiler version
3.0.1-RC1
Minimized code
MainMacro.scala
Test1.scala
Output
Expectation
It should compile, I guess.
The text was updated successfully, but these errors were encountered: