godot icon indicating copy to clipboard operation
godot copied to clipboard

GDScript 2.0: `ResourceSaver.save()` with using combined `SaverFlags` shows an invalid warning `INT_AS_ENUM_WITHOUT_CAST``

Open MikeSchulze opened this issue 2 years ago • 1 comments

Godot version

v4.0.stable.official [92bee43ad]

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

MikeSchulze avatar Mar 08 '23 08:03 MikeSchulze

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)

dalexeev avatar Mar 08 '23 16:03 dalexeev

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

dalexeev avatar Apr 14 '23 19:04 dalexeev

Closed for both master and 4.0.

dalexeev avatar Jun 01 '23 06:06 dalexeev