Static ifs and identifier resolution #1218
zagortenay333
started this conversation in
General
Replies: 1 comment
-
Procedure scopes act very differently to file scopes for numerous reasons. Currently Odin works like this for procedure scopes:
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm about to add static ifs to my language like the ones Jai and Odin have, and I noticed that there is something rather awkward about their semantics that isn't addressed by you or Jonathan explicitly (that I could find).
Since a static if can inject a variable definition into a scope, it acts as a blocker on identifier resolution. Of course, the identifiers that appear in the static ifs condition cannot be blocked, because the static if could not be resolved at all.
Now, depending on the order in which one atempts to resolve the static ifs, you'll get different outcomes. The problem is exacerbated by having two or more static ifs in the same scope and by allowing forward references of constant local variables.
In the following example the x in the first static if doesn't resolve at all:
But in the following case it does resolve to the x defined in the second static if! The presence of the x in the outer scope causes it to pick up the x in the inner scope which is weird:
In the following scenario everything resolves:
The resolution order of static ifs must be defined as part of the language semantics or else different compilers would produce different behaviour, or (worse even) the same compiler could exibit non-deterministic behaviour.
One possible definition would be something like:
Any thoughts?
I compiled the examples above with
Odin-0.12.0
.Beta Was this translation helpful? Give feedback.
All reactions