Skip to content

Commit

Permalink
Merge pull request #1286 from Friendseeker/pending-macro-test-case
Browse files Browse the repository at this point in the history
Add pending test case for #1171
  • Loading branch information
eed3si9n authored Nov 24, 2023
2 parents fc48fab + 98f78f5 commit 71fdc0d
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 0 deletions.
2 changes: 2 additions & 0 deletions zinc/src/sbt-test/macros/macro-type-change/app/A.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
package app
class A
11 changes: 11 additions & 0 deletions zinc/src/sbt-test/macros/macro-type-change/app/App.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package app

import Macros._

object App {
def main(args: Array[String]): Unit = {
val expected = args(0).toBoolean
val actual = Macros.hasAnyField[A]
assert(expected == actual, s"Expected $expected, obtained $actual")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package app
class A {
val hello: String = ""
}
15 changes: 15 additions & 0 deletions zinc/src/sbt-test/macros/macro-type-change/build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"projects": [
{
"name": "app",
"dependsOn": [
"macros"
],
"scalaVersion": "2.13.12"
},
{
"name": "macros",
"scalaVersion": "2.13.12"
}
]
}
20 changes: 20 additions & 0 deletions zinc/src/sbt-test/macros/macro-type-change/macros/Macros.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package Macros

import scala.language.experimental.macros

import scala.reflect.macros.blackbox.Context

object Macros {
def hasAnyField[T]: Boolean = macro hasAnyFieldImpl[T]

def hasAnyFieldImpl[T: c.WeakTypeTag](c: Context): c.Expr[Boolean] = {
import c.universe._

val hasField = weakTypeOf[T].members.exists {
case m: TermSymbol => m.isVal || m.isVar
case _ => false
}

c.Expr[Boolean](Literal(Constant(hasField)))
}
}
3 changes: 3 additions & 0 deletions zinc/src/sbt-test/macros/macro-type-change/pending
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
> app/run false
$ copy-file app/changes/A.scala app/A.scala
> app/run true

0 comments on commit 71fdc0d

Please sign in to comment.