-
Notifications
You must be signed in to change notification settings - Fork 1.1k
DefDef.copy does not allow changing anything other than function body #7626
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
Comments
I have some follow-up thoughts from trying to work around this issue. To properly generate a function with arbitrary arity you also need to make the parameters. If not, more internal compiler errors happen (Tasty pickler sees same symbol twice, is unhappy...). If you have a function you want to replicate, I figured out you can call The remaining problem is: how do we ask for a fresh function symbol? There are some useful transformations / refactors (think domain-specific inlining) you just can't write if macros are not allowed to properly make local copies of existing definitions. That is, if we just had a variant of |
Copy should not change the symbol. Indeed, what we need is |
@nicolasstucki Since this is evolving into more "making an API for generating new symbols", I've posted a new "Other" issue #8114 for discussing that and tracking further efforts. Let me know what you think of the ideas going forward. |
Replaced by #8114. Now possible using |
minimized code
expectation
Referencing
foo
should produce the value1
by generating both the definition of and a call to an inner function namedrealName
that returns the corresponding value.Instead, we get a ClassCastError at runtime because Dotty's codegen keeps using shouldBeHidden's return type of
Nothing
instead of the copy's updatedInt
type. Inspecting the bytecode shows that the name of the generated method isshouldBeHidden
, notrealName
.Similarly, attempting to change anything else (other than the definition body) about
shouldBeHidden
has little or no effect, leading to either compiler errors or incorrect codegen.DefDef.copy
seems like the easiest way to generate computed-arity (local) functions, so it's unfortunate that transforming things other than the function body does not work.The text was updated successfully, but these errors were encountered: