Skip to content

Commit

Permalink
Add a Scala 2 test sources project, and test Scala 2 macro reading.
Browse files Browse the repository at this point in the history
  • Loading branch information
sjrd committed Dec 14, 2023
1 parent 1a83796 commit 19b3b2e
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
13 changes: 13 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import org.scalajs.jsenv.nodejs.NodeJSEnv

val usedScalaCompiler = "3.3.1"
val usedTastyRelease = usedScalaCompiler
val scala2Version = "2.13.12"

val SourceDeps = config("sourcedeps").hide

Expand Down Expand Up @@ -61,6 +62,17 @@ lazy val root = project.in(file("."))
publish / skip := true,
)

lazy val scala2TestSources = crossProject(JSPlatform, JVMPlatform)
.crossType(CrossType.Pure)
.in(file("scala2-test-sources"))
.settings(commonSettings)
.settings(
scalaVersion := scala2Version,
publish / skip := true,
scalacOptions += "-Xfatal-warnings",
libraryDependencies += "org.scala-lang" % "scala-reflect" % scalaVersion.value % "provided",
)

lazy val testSources = crossProject(JSPlatform, JVMPlatform)
.crossType(CrossType.Pure)
.in(file("test-sources"))
Expand All @@ -70,6 +82,7 @@ lazy val testSources = crossProject(JSPlatform, JVMPlatform)
scalacOptions += "-Xfatal-warnings",
javacOptions += "-parameters",
)
.dependsOn(scala2TestSources)

lazy val tastyQuery =
crossProject(JSPlatform, JVMPlatform).in(file("tasty-query"))
Expand Down
11 changes: 11 additions & 0 deletions scala2-test-sources/src/main/scala/scalatwo/Macros.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package scalatwo

import scala.language.experimental.macros

import scala.reflect.macros.blackbox.Context

object Macros {
def foo[X](x: X): Any = macro fooImpl[X]

def fooImpl[X](c: Context)(x: c.Expr[X]): c.Expr[Any] = ???
}
16 changes: 16 additions & 0 deletions tasty-query/shared/src/test/scala/tastyquery/TypeSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3661,4 +3661,20 @@ class TypeSuite extends UnrestrictedUnpicklingSuite {
val GenericJavaClass = ctx.findTopLevelClass("javadefined.GenericJavaClass")
assert(clue(GenericJavaClass.getDecl(typeName("MyInner"))).exists(_.isClass))
}

testWithContext("scala-2-macro-definition") {
val MacrosClass = ctx.findTopLevelModuleClass("scalatwo.Macros")
val macroImplAnnotClass = ctx.findTopLevelClass("scala.reflect.macros.internal.macroImpl")

val foo = MacrosClass.findNonOverloadedDecl(termName("foo"))
assert(foo.isMacro)

val annotImplMacro = foo.getAnnotation(macroImplAnnotClass).get
annotImplMacro.arguments.head match
case TypeApply(Apply(macroIdent @ Ident(macroName), _), _) =>
assert(clue(macroName) == nme.m_macro)
assert(clue(macroIdent.symbol) == defn.scala2MacroInfoFakeMethod)
case arg =>
fail("unexpected argument to @macroImpl", clues(arg))
}
}

0 comments on commit 19b3b2e

Please sign in to comment.