-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CyclicReference exception during macro expansion with transparent inline #16582
Comments
The snippets lack I'm afraid the difference in behaviour between |
Indeed, there is a difference in behaviour between In the context of a macro, we could try to catch this error and give a hint on why this could have happened. |
The cycle in this case it that in val o2 = ownerDoesNotWork(2)
|
The current error is -- Error: t/Test_2.scala:5:27 --------------------------------------------------
5 | val o2 = ownerDoesNotWork(2)
| ^^^^^^^^^^^^^^^^^^^
| Exception occurred while executing macro expansion.
| dotty.tools.dotc.core.CyclicReference: Recursive value o2 needs type
|
|-----------------------------------------------------------------------------
|Inline stack trace
|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|This location contains code that was inlined from Macro_1.scala:7
7 | ${ownerWorksImpl('in)}
| ^^^^^^^^^^^^^^^^^^^^^^
----------------------------------------------------------------------------- This error seems to be enough.
|
The only thing missing from the message is the stack trace |
Thank you both for the explanation. I admit I am having trouble wrapping my mind around these details. @nicolasstucki |
Meant to be automatically closed when #16749 is merged. |
Compiler version
Scala version 3.2.1
Minimized code
Used as follows:
Output
At the
owner0.tree
line, whenownerDoesNotWork
is used, I get the following exception:This exception is also generated during other calls such as
Symbol.children
,Symbol.flags
andSymbol.declaredFields
.Expectation
The documentation found here states that " the tree for a symbol might not be defined". As per the linked best practices section, I have used the
-Yretain-trees
thus:So I assume that the tree should be available. Here the tree does seem to be available, but causes a loop. Seems like a possible bug.
However, the best practice says that we should "avoid
Symbol.Tree
". This may mean that in some conditions, possibly such as this one, no tree may be available. In other words, its not a bug. In such a case, if I follow, the above guidelines. how can I check for and deconstruct aValDef
(or any other element, for that matter)?I have made many attempts and failed. In the example below I seem to only have access to a
TermRef
. I can deconstruct that but am unable to cast it to aValDef
, even when the reference states it is (or points to) one. I assume I have to de-reference it, but cannot see how.The text was updated successfully, but these errors were encountered: