godotengine / godotengine/godot

Cannot find member "erase" in typed Dictionary

Open
#115,451 4 comments 0 reactions 0 assignees View on GitHub
documentation enhancement topic:core
Dominant language
C++
Stars
117k
Forks
26.8k
PR merge metrics
PR metrics pending

Description

### Tested versions

- v4.5.1.stable.official [f62fdbde1]
- v4.6.stable.official [89cea1439]

### System information

Godot v4.5.1.stable - macOS Sequoia (15.7.3) - Multi-window, 2 monitors - OpenGL 3 (Compatibility) - Apple M4 - Apple M4 (10 threads) - 24.00 GiB memory

### Issue description

Typed dictionary doesn't let me bind the [`erase`](https://docs.godotengine.org/en/stable/classes/class_dictionary.html#class-dictionary-method-erase) method.

Image

I think this is a result of the _javascript-ish_ GDScript behavior where these two are equivalent

```gdscript
var dict: Dictionary[String, int] = { "foo": 42 }
print(dict["foo"])
print(dict.foo)
```

- When I make the dictionary _untyped_, the error goes away.
- The editor _knows_ I mean the `erase` method, because it shows the method documentation on hover. Perhaps with typed dictionaries, there should be an exception for this behavior?
- The dot syntax for _string key lookup_ seems to have a higher priority than _method lookup_ dot syntax. For example `dict.erase.call("key")` fails because there isn't an `"erase"` key. Is that intentional?

### Steps to reproduce

I have a global (singleton) called `Events`

```gdscript
extends Node
signal BUILDING_DESTROYED(building_id: int)
```

Then you should be able to connect this signal straight to a [`Dictionary.erase`](https://docs.godotengine.org/en/stable/classes/class_dictionary.html#class-dictionary-method-erase) method, since the signal provides a key to the dictionary.

```gdscript
extends Node
var data: Dictionary[int, String] = {}
func _ready() -> void:
Events.BUILDING_DESTROYED.connect(data.erase)
```

But this results in an error.

### Minimal reproduction project (MRP)

[mrp-dictionary-erase.zip](https://github.com/user-attachments/files/24885461/mrp-dictionary-erase.zip)

Contributor guide

Open the contributing guide

Research direction

Start with the typed Dictionary example and the minimal reproduction project, then compare the typed and untyped `erase` cases described in the issue. Trace how `data.erase` and `dict.erase.call("key")` are resolved, and confirm the intended precedence between string-key lookup and method lookup. Done means the reported typed-dictionary behavior is resolved with coverage for the reproduction.

Written by the indexing model from the issue text.

Assessment

Domain
game-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.