godotengine / godot

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

GDScript Editor setting "Highlight Type Safe Lines" not working as intended #99034

Open michal-gora opened 3 days ago

michal-gora commented 3 days ago

Tested versions

Reproducible in 4.3.stable

System information

Linux Ubuntu (KDE plasma)

Issue description

The setting "highlight type safe code" does not work as intended. When turning on the setting (which it is by default) and changing theme colors ("Line Number Color" green and "Safe Line Number Color" blue) to be better visible, this is the result of my example code. image This behaviour seems inconsistent. Expected behaviour: Additionally green highlighting in line 9, 10, 14

I was trying to find the original issue/pull request adding this setting feature to find the intended documented behaviour so I am not sure if I might be misunderstanding this bug report, in that case I will close the issue again.

Steps to reproduce

  1. Go to 'Editor > Editor Settings > Text Editor > Appearance > Gutters > Highlight Type Safe Lines' and enable it.
  2. Go to 'Editor > Editor Settings > Text Editor > Theme > Highlighting > Line Number Color' and 'Editor > Editor Settings > Text Editor > Theme > Highlighting > Line Number Color' and change colors to something more vibrant.
  3. Create following script:

    func hello():
    var basecase: int = 42
    basecase = 3
    
    var unsafe = 12
    unsafe = 4
    unsafe = "lol"
    
    var veryunsafe = 24
    veryunsafe = "hi"
    veryunsafe = 4

Minimal reproduction project (MRP)

bug-report-type-safe-line-highlighting.zip

dalexeev commented 2 days ago

The unsafe lines feature highlight lines that contain unsafe operations, i.e. that may cause type errors at runtime.

Actually, in this example, all lines should be highlighted as safe because untyped local variables can take any value. We just don't have good control flow analysis. We could track the current type of a local variable at all points in a function. For an untyped or Variant-typed local variable, only uses can be unsafe, not assignments.