-
-
Notifications
You must be signed in to change notification settings - Fork 21.3k
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
GDScript enum fixes & refactor #69590
Conversation
62043d3
to
4db278c
Compare
7e850d4
to
bfa54c1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i know it's still a draft, but this looks great! nice job refactoring :)
what happens with this script?: enum E1 {V0, V1}
enum E2 {V1, V0}
func _ready():
print(V0, V1) it doesn't look like the values are added as members, or checked for name conflicts, enum {
V0,
V1
} |
Oooooh, excellent comments, thanks @rune-scape! I am done for the day, but will think & tackle these when I can! I've implemented everything I wanted for this PR, so your comments are super timely :) |
That's a really cool one! I tried keeping things consistent & backwards compatible. Firstly, for native classes, So the two behaviors existed but were used inconsistently between native & gdscript types. I figured the only way to move forward without breaking existing code was to allow both types of access to both types of enums. Good thought on maybe using But now you're right, it creates issues with shadowing that need some work. GDScript seems pretty lenient on allowing shadowing with warnings rather than errors, so I'm tempted to implement this:
I'm tempted to either not add any warnings at all, or to add warnings to 2 only, since it might be less obvious that you are doing it. |
c50429e
to
5652856
Compare
I actually realized that I should be able to use So that + adding shadow warnings are on my list, but hopefully that's it? |
2030e9c
to
a6c0894
Compare
Alright, I think this PR is done :) There's some issues with shadowing outer class members that needs work in |
0ea2876
to
864372e
Compare
3032ba8
to
a5004f6
Compare
This may fixes #70915 as well. Can you verify that? :) |
It actually does - I confirmed the bug is still there on Beta 10, but doesn't happen in this PR :) Thanks for linking! |
Glad to her! |
Not with the current test framework as far as I can tell. Currently it just attempts to parse scripts. The most you can do is preload, but I don't think there's a scene tree we can use. Maybe I'm wrong though :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks okay to me.
Thanks! Outstanding work 🎉 |
This PR fixes a bunch of issues with enums. Also, 80% of it is unit tests ;)
Needs #71028 before it passes tests :)At a glance
Fix being able to assign to enum values.
Fix unsafe enum assignments not marking nodes unsafe.
Fix native enum exports generating warning. Fixes Enum initialized export generates incorrect warning #69118.
Fix enum casts with values not existing in enum target not yielding error.
Fix no errors being generated when using non-existent enum values. Fixes GDScript 2.0: When using named enums, accessing invalid members won't be caught while editing #60545.
Fix accessing non-existent properties of native types (including enums) not yielding error.
Fix no errors being generated when using non-existent methods on enums. Fixes Calling enum's nonexisting method causes a crash #61466.
Fix being able to use non-const dictionary methods on enum types, e.g.
MyEnum.clear()
.Fix code autocompletion for enums. Only enum values and const dictionary methods show up now. Fixes Named enums does not provide hints #61427.
Fix (native & gdscript) enum values not being accessible in certain ways, e.g.
NativeClass.EnumType.ENUM_VAL
, etc.Fix enum and native enum types not being usable as variable, function parameter, function return types. Fixes GDScript 2.0: Function return type
enum
error (Trying to return value of type "int" from a function which the return type is "Dictionary") #57966.Fix Stack overflow when using @export variable with enum type and set, get #70915.
Added comprehensive unit tests.
Improved error messages with more information.
Code refactor & other assorted improvements and fixes.
And yes, maybe I did name a lot of these "fixes" instead of "implements" because we are in feature freeze ;)
Fixes & features
It does a general refactor of how enums are handled internally and in GDScript, cleaning up the code & making it slightly more consistent across GDScript enums and native enums. It also aims to unify warnings&errors between in-editor, runtime, and export debug/release templates (native enum behavior on release templates now working due to #64253).
For native enums, e.g. with
TileSet
, you can now useTileSet.TILE_SHAPE_SQUARE
orTileSet.TileShape.TILE_SHAPE_SQUARE
, and a warning will be issued if the native type does not have an accessed property.Typing with enums now works properly for variables, function parameters and function returns, and comprehensive unit tests have been added to check this. Example which is now possible, and will throw errors if the wrong enum is used.