godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
91.04k stars 21.18k forks source link

Script editor incorrectly placing `@warning_ignore` when clicikng `[Ignore]` link on multi-line expression #80174

Open JSchrepp opened 1 year ago

JSchrepp commented 1 year ago

Godot version

4.0.3

System information

Windows 11

Issue description

The editor gives a button/link [Ignore] preceding warnings to insert a suppression annotation for the developer on the line above. However, this insertion doesn't take code syntax into account and will blindly insert the annotation above the detected line, only giving it correct indentation. Multi-line expressions are unable to handle this, and the entire area of code lights up with errors. Code sample provided in reproduction steps. Manually moving the warning above the full expression successfully suppresses the warning.

I expect one of two things:

  1. The editor insert the suppression mechanism in a safe place
  2. The suppression mechanism not interrupt expressions

I imagine 1 is the easiest solution to take, as annotations are code and they need to be placed in valid locations according to their function. But I'd like to take a moment to state that something like 2 would be amazing. Many languages implement arbitrary warning suppression via directives. E.g. a lot of the C family of languages uses #pragma to instruct the compiler to hold off on specific warnings in the file until otherwise stated. I don't know how possible that is for an interpreted language vs a compiled one, it's really not my domain, but it would be amazing if it were possible.

Side-note, I found myself trying to suppress this warning after running into #74397 on a nameless script

Steps to reproduce

Sample code to reproduce:

func instance_func():
    @warning_ignore("static_called_on_instance")
    print([
        0,
        static_func() # fails
    ])
    print([
        static_func(), # fails
        0
    ])
    print([0, static_func()]) # works
    print([static_func(), # works
        0
    ])
    return 0 + \
        static_func() # fails

static func static_func() -> int:
    return 0

Paste this in a script and click the [Ignore] text in the warnings list beneath the text editor image

Minimal reproduction project

N/A. Reproduction just takes the given snippet in a fresh project.

dalexeev commented 1 year ago