-
Notifications
You must be signed in to change notification settings - Fork 1.1k
ScalaTest macros #5491
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
Comments
While working on ScalaTest, generally quote/splice improves a lot experience (though we still lack useful constructors #5567 ). However, there is a potential problem, which is encountered when working on ScalaTest. There are two projects in ScalaTest:
In Scala2, If there is always mutual dependencies between macros project and its main project, quotes & splices will be useless for writing macros. Macro authors will be forced to use constructors & extractors to break the cycles. |
Can't you define the macros in the same project as the classes they quote? In both scala.reflect and Squid, that's how it works. It's just that you won't be able to call these macros from the same project. For example, in scala.reflect you can write: class A { val x = 42 }
def A: Int = macro `A macro`
def `A macro`(c: whitebox.Context): c.Expr[Int] = {
c.universe.reify{new A().x} // similar to a typed quote
} |
@LPTK If the macros are not used in the main project, then it makes sense to merge the two projects. This is the walkaround I took dotty-staging/scalatest@642050c for ScalaTest. However, I assume there are a lot of projects where the macros are used in the main project and refer to symbols defined in the main project, then things become subtle. |
ScalaTest use val tree = c.parse("{ "+codeStr+" }")
if (!containsAnyValNullStatement(c)(List(tree))) {
c.typeCheck(tree) // parse and type check code snippet
|
@nicolasstucki Just discussed with @cheeseng and @bvenners, I learned that macros like Github search for assertDoesNotCompile shows 299 results. |
@liufengyun can we close this issue? All the macro related issues have been fixed. All remaining tasks have their own issue. |
We may close now. We need to make an upstream PR after the meta-programming API refactoring. |
This is thread for issues about implementation of ScalaTest macros (related meta issue #5489)
TODOS
c.parse
+c.typecheck
c.parse
+c.typecheck
c.parse
+c.typecheck
c.parse
+c.typecheck
c.parse
+c.typecheck
Issues
List[Expr[T]]
toExpr[List[T]]
conversion in the library #5543)import Term._
andimport refl._
are tedious>
operation that work on unknown types. Blocked by Add TASTy reflect constructors #5438 Some useful tree constructors #5567def typeOf[T]: Type
will be helpful===
case Syntax for method types or tree constructors useful in meta-programming #5563IsSelectModule
not friendly Proposal for replacing IsXxx extractors in tasty-reflect #7204copy
not usefulselectApply
on any termThe text was updated successfully, but these errors were encountered: