forked from scala/scala
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
eb6751b
commit 0b7ccc5
Showing
22 changed files
with
308 additions
and
18 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
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 @@ | ||
package tastytest | ||
|
||
final case class Position(sourceName: String, line: Int) |
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,16 @@ | ||
import scala.util.Random | ||
|
||
import scala.reflect.macros.blackbox.Context | ||
|
||
package object tastytest { | ||
|
||
object Macros { | ||
def posImpl(c: Context): c.Expr[Position] = { | ||
import c.universe._ | ||
val fileName = c.enclosingPosition.source.path.split('/').last | ||
val line = c.enclosingPosition.line | ||
c.Expr(q"new Position($fileName, $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,14 @@ | ||
package tastytest | ||
|
||
import scala.reflect.macros.blackbox.Context | ||
|
||
final case class Position(sourceName: String, line: Int) | ||
|
||
object Position { | ||
def posImpl(c: Context): c.Expr[Position] = { | ||
import c.universe._ | ||
val fileName = c.enclosingPosition.source.path.split('/').last | ||
val line = c.enclosingPosition.line | ||
c.Expr(q"new Position($fileName, $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,9 @@ | ||
import scala.util.Random | ||
|
||
package object tastytest { | ||
|
||
object Macros { | ||
|
||
} | ||
|
||
} |
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 @@ | ||
TestMacroCompat_fail.scala:7: error: can't find term required by object tastytest.MacroCompat: tastytest.`package`.Macros.posImpl; perhaps it is missing from the classpath. | ||
val result = MacroCompat.testCase("foo")(pos) | ||
^ | ||
1 error |
11 changes: 11 additions & 0 deletions
11
test/tasty/neg-move-macros/src-2/TestMacroCompat_fail.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,11 @@ | ||
package tastytest | ||
|
||
object TestMacroCompat { | ||
import MacroCompat._ | ||
|
||
def test = { | ||
val result = MacroCompat.testCase("foo")(pos) | ||
println(result) | ||
} | ||
|
||
} |
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,24 @@ | ||
package tastytest | ||
|
||
import scala.language.experimental.macros | ||
|
||
object MacroCompat { | ||
|
||
implicit def pos: Position = macro Macros.posImpl // implemented in test/tasty/run/pre/tastytest/package.scala | ||
implicit inline def pos: Position = ${ Macros3.posImpl } | ||
|
||
def testCase(test: => Any)(using Position): String = | ||
s"${String.valueOf(test)} @@ ${summon[Position]}" | ||
|
||
object Macros3 { | ||
import quoted._ | ||
|
||
def posImpl(using qctx: QuoteContext): Expr[Position] = { | ||
import qctx.tasty.{given _} | ||
val name = qctx.tasty.rootPosition.sourceFile.jpath.getFileName.toString | ||
val line = qctx.tasty.rootPosition.startLine + 1 | ||
'{ Position(${Expr(name)}, ${Expr(line)}) } | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.