New compiler: When in the body of a static struct function and finding an otherwise unknown symbol, imply static access #2629
+433
−273
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #2067
Currently, whenever the new compiler is compiling the body of a non-static struct function and it encounters an unknown identifier
i
in an expression, it doesn't give up yet. It looks upthis.i
first, and if that subexpression is valid, the compiler uses it.This PR generalises this concept to static struct functions: When the compiler is compiling the body of a static struct function for the struct
str
and it encounters an unknown identifieri
in an expression, it doesn't give up yet. It looks upstr.i
, and if that subexpression is valid, then the compiler uses it.This PR also fixes the following bugs:
s
extends another structt
andt
has an attribute or a functionaf
thenthis.af
(oraf
when otherwise unknown) should referencet::af
. This didn't always work but should work now.s
has a non-static attributea
then callings::a
from astatic
function should fail because the specific object isn't known to which the attribute refers – only the class is known. This used to be flagged for functions but not for attributes. It should now also be flagged for attributes.Added googletests for the new use cases and the bugs.
This PR also cleans up comments in the code (in a separate commit). No functional changes in that commit.