-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1286 from Friendseeker/pending-macro-test-case
Add pending test case for #1171
- Loading branch information
Showing
6 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
package app | ||
class A |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
zinc/src/sbt-test/macros/macro-type-change/app/changes/A.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package app | ||
class A { | ||
val hello: String = "" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
20
zinc/src/sbt-test/macros/macro-type-change/macros/Macros.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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))) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |