godotengine / godotengine/godot
print() of empty array using format string does not work
- Dominant language
- C++
- Stars
- 117k
- Forks
- 26.8k
- PR merge metrics
- PR metrics pending
Description
### Tested versions
Godot Engine v4.4.dev7.official.46c8f8c5c
### System information
Godot v4.4.dev7 - Windows 10 (build 19045)
### Issue description
the print of an empty array with a format string does not work like expected.
the print of an empty dictionary with a format string works but has 2 spaces between the brackets.
```
output test1: %s
Expected output: []
Debugger Message: ... _ready(): String formatting error: not enough arguments for format string. ...
output test2: %s
Expected output: []
Debugger Message: ... _ready(): String formatting error: not enough arguments for format string. ...
output test3: %s
Expected output: []
Debugger Message: ... _ready(): String formatting error: not enough arguments for format string. ...
output test4: { }
Expected output: {}
output test5: 0
Expected output: 0
output test6: []
Expected output: []
```
### Steps to reproduce
```
extends Control
func _ready() -> void:
var test1 : Array
print('output test1: %s' % test1)
print('Expected output: []')
print('Debugger Message: ... _ready(): String formatting error: not enough arguments for format string. ...')
print()
var test2 : Array = []
print('output test2: %s' % test2)
print('Expected output: []')
print('Debugger Message: ... _ready(): String formatting error: not enough arguments for format string. ...')
print()
var test3 : Array [int] = []
print('output test3: %s' % test3)
print('Expected output: []')
print('Debugger Message: ... _ready(): String formatting error: not enough arguments for format string. ...')
print()
var test4 : Dictionary
print('output test4: %s' % test4)
print('Expected output: {}')
print()
var test5 : int
print('output test5: %s' % test5)
print('Expected output: 0')
print()
var test6 : Array
prints('output test6:', test6)
print('Expected output: []')
```
### Minimal reproduction project (MRP)
see steps to reproduce
Contributor guide
Research direction
Run the provided GDScript reproduction in Godot v4.4.dev7 and compare the format-string cases with the direct print case. Trace the implementation responsible for string formatting and array or dictionary output; done means empty arrays format as [] without an error and empty dictionaries format as {} without extra spaces.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- game-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100