-
Notifications
You must be signed in to change notification settings - Fork 19
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
Re-assign enclosing object properties to local vals. #21
Comments
What is the difference between a read / write property of the class and a method? In Scala those are one and the same. Isn't it possible to inline those instead of renaming them? |
I think that in the following class class Foo {
val Int x = 0
def x: Int = x
} The first member is a property and the second a method. Regarding inlining, I am not sure whether you can get hold on the method definition from the macro context in order to do the inlining. Moreover, using methods (like the I would therefore restrict the use of enclosing object methods in the first step and focus only on the properties. |
I meant inlining their value, but I guess we don't know it at compile time. My point is that at the call site we cannot distinguish between On the other hand, why restrict access to no-argument methods, when they shouldn't have side effects anyway? At the same time it's easy enough to prohibit calls to methods with arguments. |
You can lookup the exact type of a select (val, var, def) through its symbol. |
Yes indeed, I still have a lot to learn about the Scala reflection API. You can just use |
Didn't know about that method, good hint! |
@ParkL I just realized that it doesn't matter if you get |
@joroKr21 Will do! Thanks for the advice! I'm new to the whole thing so all help is greatly appreciated :) I guess there's even more cases to think about ... Andreas and I just found out one more thing that's weird (at least to me), but it may be a hint at the underlying problem: If I paste my test-quasiquote (with the assignment) into the scala console it renders as expected with an If this rings a bell, please let me know. Anyway I'll be looking into this on Monday! Have a nice weekend! |
@ParkL This might be something for the scala macros mailing list / JIRA. |
What happens in between is typechecking that resolves the assignment to the compiler-generated setter import scala.reflect.runtime.universe._
import scala.reflect.runtime.currentMirror
import scala.tools.reflect.ToolBox
val tb = currentMirror.mkToolBox()
val code = q"class Outer { var x = 1; class Inner { x = 2 } }"
showCode(code)
showCode(tb.typecheck(code)) In contrast method- or block-local vars remain assignments, which I guess is why they differentiate between these cases. |
Code bracketed with
parallelize
is normalized as a first step of the compiler chain.As part of the normalization
u
) should be prohibited (resolved via [MACROS] Issue 84: Semantic checks for unstable applications in enclo… #141)g
) should be prohibited (resolved via [MACROS] Issue 84: Semantic checks for unstable applications in enclo… #141)For example, in the following code example the "parallelized" code accesses
k
.As part of the normalization, the code should be rewritten as:
The text was updated successfully, but these errors were encountered: