godotengine / godotengine/godot

Cannot use keywords inside dictionary with Lua-style syntax

Open
#99,282 3 comments 0 reactions 0 assignees View on GitHub
documentation topic:gdscript
Dominant language
C++
Stars
117k
Forks
26.8k
PR merge metrics
PR metrics pending

Description

### Tested versions

Godot v4.4.dev4

### System information

Godot v4.4.dev4 - macOS 15.1.0 - Multi-window, 2 monitors - Metal (Mobile) - integrated Apple M1 Max (Apple7) - Apple M1 Max (10 threads)

### Issue description

Writing this
```gdscript
{class="xyz"}
```

Results in this parse error:
```
Expected expression as dictionary key.
Expected ":" or "=" after dictionary key.
Expected ":" after dictionary key.
Expected expression as dictionary value.
Expected closing "}" after dictionary elements.
Expected end of statement after expression, found "class" instead.
Expected statement, found "class" instead.
```

[Docs](https://docs.godotengine.org/en/stable/classes/class_dictionary.html#dictionary) say:
```gdscript
# Alternative Lua-style syntax.
# Doesn't require quotes around keys, but only string constants can be used as key names.
# Additionally, key names must start with a letter or an underscore.
# Here, `some_key` is a string literal, not a variable!
another_dict = {
some_key = 42,
}
```

In this case, I think class (and others keywords) should not be considered as keyword, but a string literal.

I know I could write `{"class"="xyz"}` or `{"class": "xyz"}`, but I think it breaks the developer experience.

For reference, Ruby allows using keywords as Hash key (Ruby's equivalent to Dictionary), because in this case it handles the keys as Symbol (similar Godot's StringName).

Screenshot 2024-11-15 at 10 53 31

### Steps to reproduce

Write `{class="xyz"}` in a script file.

### Minimal reproduction project (MRP)

N/A

Contributor guide

Open the contributing guide

Research direction

Reproduce the parser error with `{class="xyz"}` in a Godot script and compare it with the documented Lua-style dictionary syntax. Trace the GDScript parsing path for dictionary keys and verify that reserved words are handled as string keys without breaking ordinary keyword parsing. Done means the example parses successfully and relevant parser behavior is covered by tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
godot
Domain
compilers, game-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.