godotengine / godotengine/godot
Returning untyped arrays and dictionaries is not caught by static checking
- Dominant language
- C++
- Stars
- 117k
- Forks
- 26.8k
- PR merge metrics
- PR metrics pending
Description
### Tested versions
- Reproducible in v4.4.dev (current master)
### System information
Godot v4.4.dev (517ec7cdb) - Arch Linux #1 SMP PREEMPT_DYNAMIC Fri, 22 Nov 2024 16:04:27 +0000 on Wayland - X11 display driver, Multi-window, 1 monitor - Vulkan (Forward+) - dedicated Quadro T2000 (nvidia; 565.57.01) - Intel(R) Core(TM) i7-10750H CPU @ 2.60GHz (12 threads)
### Issue description
Returning an untyped dictionary or array from a function that is supposed to return a typed dictionary/array does not show up as an error in the editor but crashes at runtime. I'd expect it to show up as an error like when trying to return a dictionary/array with different key/value types.
### Steps to reproduce
```gdscript
# Crashes when being called
func function_returning_untyped_dict() -> Dictionary[int, String]:
var untyped_dict := {}
return untyped_dict
# Crashes when being called
func function_returning_untyped_array() -> Array[int]:
var untyped_array := []
return untyped_array
# Parse error
func function_returning_wrongly_typed_array() -> Array[int]:
var untyped_array: Array[String] = []
return untyped_array
```
Only the 3rd one throws a parse error, while the first two ones crash at runtime when the functions are actually called.
### Minimal reproduction project (MRP)
[typed-dict-return-text.zip](https://github.com/user-attachments/files/18052688/typed-dict-return-text.zip)
Contributor guide
Research direction
Use the minimal reproduction project and the three GDScript functions named in the issue as the starting point. Trace how return types are statically checked for untyped dictionaries and arrays, then verify that both cases report an editor or parse error like the incorrectly typed array and no longer crash when called.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100