Skip to content
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 2.0: ResourceSaver.save() with using combined SaverFlags shows an invalid warning INT_AS_ENUM_WITHOUT_CAST #74593

Closed
MikeSchulze opened this issue Mar 8, 2023 · 3 comments · Fixed by #75691

Comments

@MikeSchulze
Copy link

Godot version

v4.0.stable.official [92bee43]

System information

Windows 10, MacOS

Issue description

I actually fixing all the warnings that popup in my plugin after remove the default exclude script checks for the addons folder.

Using ResourceSaver.save says:
The flags bitmask can be specified to customize the save behavior using SaverFlags flags.

But let the compiler do report incorrect warnings
using the flags as bitmask (ResourceSaver.FLAG_BUNDLE_RESOURCES|ResourceSaver.FLAG_REPLACE_SUBRESOURCE_PATHS) is popup warnings.

[Ignorieren]Zeile 10 (INT_AS_ENUM_WITHOUT_CAST):Integer used when an enum value is expected. If this is intended cast the integer to the enum type.
[Ignorieren]Zeile 10 (INT_AS_ENUM_WITHOUT_MATCH):Cannot pass 66 as Enum "ResourceSaver.SaverFlags": no enum member has matching value.

Steps to reproduce

ResourceSaver.save(GDScript.new(), "res://test.gd", ResourceSaver.FLAG_BUNDLE_RESOURCES|ResourceSaver.FLAG_REPLACE_SUBRESOURCE_PATHS)

Minimal reproduction project

N/A

@akien-mga akien-mga added this to the 4.x milestone Mar 8, 2023
@dalexeev
Copy link
Member

dalexeev commented Mar 8, 2023

I think the problem is due to the signature of the ResourceSaver.save() method. For example in Object.connect(), the flags parameter is int, not the enum.

It looks like the reason is BitField<T>. More examples:

@tool
extends EditorScript

func _run() -> void:
    var button := Button.new()
    # Warnings: INT_AS_ENUM_WITHOUT_CAST, INT_AS_ENUM_WITHOUT_MATCH
    button.button_mask = MOUSE_BUTTON_MASK_LEFT | MOUSE_BUTTON_MASK_RIGHT

    # OK
    button.button_mask = MOUSE_BUTTON_MASK_LEFT

    var tp := TextParagraph.new()
    # Warnings: INT_AS_ENUM_WITHOUT_CAST, INT_AS_ENUM_WITHOUT_MATCH
    tp.justification_flags = TextServer.JUSTIFICATION_WORD_BOUND \
            | TextServer.JUSTIFICATION_CONSTRAIN_ELLIPSIS

    # OK
    tp.justification_flags = TextServer.JUSTIFICATION_WORD_BOUND

    # OK (int, not BitField<T>)
    connect(&"property_list_changed", func (): pass, CONNECT_DEFERRED | CONNECT_ONE_SHOT)

MikeSchulze added a commit to MikeSchulze/gdUnit4 that referenced this issue Mar 9, 2023
# Why
By default addons are excluded from code validation, after inclusion the
plugin displays over 1800 warnings and some errors

![image](https://user-images.githubusercontent.com/347037/223846970-74dc362b-dcd2-48a0-9a6b-7137e4c1671b.png)


# What
- fix the errors
- reduce the warnings
- update inline documentation  
- apply formatting rules

# Open issues
-Only 23 warnings left, covered by the listed Godot issues

![image](https://user-images.githubusercontent.com/347037/224134816-2f3729bd-4aac-4cc5-af6d-3934b49a1b2f.png)

- invalid warnings about enum
[74593](godotengine/godot#74593)
  - INT_AS_ENUM_WITHOUT_CAST
  - INT_AS_ENUM_WITHOUT_MATCH 
- disable warnings not work
[56592](godotengine/godot#56592)
   - shadowed_global_identifier
@dalexeev
Copy link
Member

Closed by #75691 since I copied this small fix in the PR. #74641 renamed.

@dalexeev
Copy link
Member

dalexeev commented Jun 1, 2023

Closed for both master and 4.0.

@akien-mga akien-mga modified the milestones: 4.x, 4.1 Jun 1, 2023
@YuriSizov YuriSizov changed the title GDScript 2.0: ResourceSaver.save() with using combined SaverFlags shows an invalid warning INT_AS_ENUM_WITHOUT_CAST` GDScript 2.0: ResourceSaver.save() with using combined SaverFlags shows an invalid warning INT_AS_ENUM_WITHOUT_CAST Jun 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants