-
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.
Improve error message for CyclicReference in macros (#16749)
Closes #16582
- Loading branch information
Showing
4 changed files
with
58 additions
and
1 deletion.
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,15 @@ | ||
|
||
-- Error: tests/neg-macros/i16582/Test_2.scala:5:27 -------------------------------------------------------------------- | ||
5 | val o2 = ownerDoesNotWork(2) // error | ||
| ^^^^^^^^^^^^^^^^^^^ | ||
| Exception occurred while executing macro expansion. | ||
| dotty.tools.dotc.core.CyclicReference: Recursive value o2 needs type | ||
| | ||
| See full stack trace using -Ydebug | ||
|--------------------------------------------------------------------------------------------------------------------- | ||
|Inline stack trace | ||
|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
|This location contains code that was inlined from Macro_1.scala:7 | ||
7 | ${ownerWorksImpl('in)} | ||
| ^^^^^^^^^^^^^^^^^^^^^^ | ||
--------------------------------------------------------------------------------------------------------------------- |
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,29 @@ | ||
import scala.quoted.* | ||
|
||
inline def ownerWorks(in: Int): Any = | ||
${ownerWorksImpl('in)} | ||
|
||
transparent inline def ownerDoesNotWork(in: Int): Any = | ||
${ownerWorksImpl('in)} | ||
|
||
def ownerWorksImpl(in: Expr[Int])(using Quotes): Expr[String] = | ||
import quotes.reflect.* | ||
val position = Position.ofMacroExpansion | ||
val file = position.sourceFile | ||
val owner0 = Symbol.spliceOwner.maybeOwner | ||
println("owner0 = " + owner0) | ||
val ownerName = owner0.tree match { | ||
case ValDef(name, _, _) => | ||
name | ||
case DefDef(name, _, _, _) => | ||
name | ||
case t => report.errorAndAbort(s"unexpected tree shape: ${t.show}") | ||
} | ||
val path = file.path | ||
val line = position.startLine | ||
val column = position.startColumn | ||
val v = in.valueOrAbort | ||
val out = Expr(s"val $ownerName $v: $file @ ${position.startLine}") | ||
out | ||
|
||
|
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 @@ | ||
def test= | ||
val o1 = ownerWorks(1) | ||
println(o1) | ||
|
||
val o2 = ownerDoesNotWork(2) // error | ||
println(o2) |