-
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 #1282 from dwijnand/macro-under-compilation
- Loading branch information
Showing
9 changed files
with
83 additions
and
5 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
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,13 @@ | ||
package app | ||
|
||
object App { | ||
def main(args: Array[String]): Unit = { | ||
val res = lib.Macro.append("ABC") | ||
val exp = args(0) | ||
if (res != exp) { | ||
val e = new Exception(s"assertion failed: expected $exp, obtained $res") | ||
e.setStackTrace(Array()) | ||
throw e | ||
} | ||
} | ||
} |
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,6 @@ | ||
{ | ||
"projects": [ | ||
{ "name": "lib", "scalaVersion": "2.13.12" }, | ||
{ "name": "app", "scalaVersion": "2.13.12", "dependsOn": [ "lib" ] } | ||
] | ||
} |
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,5 @@ | ||
package lib | ||
|
||
class Access { | ||
def give = new Data().suffix | ||
} |
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,5 @@ | ||
package lib | ||
|
||
class Data { | ||
def suffix = "_" + new InternalApi().value | ||
} |
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,5 @@ | ||
package lib | ||
|
||
class InternalApi { | ||
def value: Int = 1 | ||
} |
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 @@ | ||
package lib | ||
|
||
import scala.language.experimental.macros | ||
|
||
import scala.reflect.macros.blackbox.Context | ||
|
||
object Macro { | ||
def append(s: String): String = macro impl | ||
|
||
def impl(c: Context)(s: c.Tree): c.Tree = { | ||
import c.universe._ | ||
val suffix = new Access().give | ||
q"""$s + $suffix""" | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
zinc/src/sbt-test/macros/macro-use/lib/changes/InternalApi.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,5 @@ | ||
package lib | ||
|
||
class InternalApi { | ||
def value: Int = 2 | ||
} |
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 ABC_1 | ||
$ copy-file lib/changes/InternalApi.scala lib/InternalApi.scala | ||
> app/run ABC_2 |