-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
We should never be able to encounter them in usage of macros --- because macros will expand to normal trees without quote and splices. The particular test case is actually problematic: The macro did not expand in `base_0.scala`.
- Loading branch information
1 parent
5454110
commit b09e900
Showing
4 changed files
with
47 additions
and
2 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,4 @@ | ||
// base_0.scala | ||
trait BaseTest extends AnyFreeSpecLike { | ||
"empty-test" - {} // ok if we comment out this line | ||
} |
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,37 @@ | ||
// macros_0.scala | ||
object source { | ||
import scala.quoted._ | ||
|
||
class Position() | ||
|
||
object Position { | ||
def withPosition[T]( | ||
fun: Expr[Position => T] | ||
)(using quotes: Quotes, typeOfT: Type[T]): Expr[T] = { | ||
'{ | ||
${ fun }.apply(new source.Position()) | ||
} | ||
} | ||
} | ||
} | ||
|
||
trait AnyFreeSpecLike { | ||
import scala.language.implicitConversions | ||
|
||
protected final class FreeSpecStringWrapper( | ||
string: String, | ||
pos: source.Position | ||
) { | ||
def -(fun: => Unit): Unit = fun | ||
} | ||
|
||
inline implicit def convertToFreeSpecStringWrapper( | ||
s: String | ||
): FreeSpecStringWrapper = { | ||
${ | ||
source.Position.withPosition[FreeSpecStringWrapper]('{ | ||
(pos: source.Position) => new FreeSpecStringWrapper(s, pos) | ||
}) | ||
} | ||
} | ||
} |
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 @@ | ||
class MyTest extends BaseTest { | ||
"empty-test" - {} | ||
private val myObject = new {} | ||
} |