-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle types touched during Macro macro expansion
We still don't have a good way to get touched types, in the future this can be provided by compiler via attachment
- Loading branch information
1 parent
c68a4c2
commit 8fac3a0
Showing
16 changed files
with
139 additions
and
10 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
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
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
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
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,2 @@ | ||
package A | ||
class A |
4 changes: 4 additions & 0 deletions
4
zinc/src/sbt-test/macros/macro-type-change-2/A/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 A | ||
class A { | ||
val hello: String = "" | ||
} |
12 changes: 12 additions & 0 deletions
12
zinc/src/sbt-test/macros/macro-type-change-2/app/App.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,12 @@ | ||
package app | ||
|
||
import Macros._ | ||
import A.A | ||
|
||
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") | ||
} | ||
} |
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 @@ | ||
{ | ||
"projects": [ | ||
{ | ||
"name": "app", | ||
"dependsOn": [ | ||
"macros", | ||
"A" | ||
], | ||
"scalaVersion": "2.13.12" | ||
}, | ||
{ | ||
"name": "macros", | ||
"scalaVersion": "2.13.12" | ||
}, | ||
{ | ||
"name": "A", | ||
"scalaVersion": "2.13.12" | ||
} | ||
] | ||
} |
20 changes: 20 additions & 0 deletions
20
zinc/src/sbt-test/macros/macro-type-change-2/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 A/changes/A.scala A/A.scala | ||
> app/run true |
File renamed without changes.