Repository: godot
Issue: `take_over_path` and extending the same named class twice
Labels: bug,topic:gdscript,confirmed,crash

### Godot version

v4.1.2.stable.official [399c9dc39]
v4.2.beta1.official [b1371806a]

### System information

Godot v4.1.2.stable - Windows 10.0.19045 - Vulkan (Forward+) - dedicated NVIDIA GeForce RTX 3080 (NVIDIA; 31.0.15.3699) - AMD Ryzen 7 5800X 8-Core Processor (16 Threads)

### Issue description

```gdscript
func _init() -> void:
	var extend_0 = load("res://extends/extend0.gd")
	extend_0.new()
	extend_0.take_over_path("res://base.gd")
	var extend_1 = load("res://extends/extend1.gd")
	extend_1.new()
	extend_1.take_over_path("res://base.gd")
```

Running this code causes a game crash with no error message in the editor output.

The following error is printed if the editor is run with the console:

```
ERROR: FATAL: Condition "!exists" is true.
   at: operator[] (./core/templates/hash_map.h:504)
```

This pattern was used to build an ["inheritance chain"](https://blog.cy.md/2022/05/27/modding-for-godot/) for [modding](https://github.com/GodotModding/godot-mod-loader) in Godot 3.5.

In Godot 4.1, after loading the first script and taking over the path of the named class, it crashes the game as soon as the second script that extends the same-named class is loaded, in the above example:

```gdscript
var extend_1 = load("res://extends/extend1.gd")
```

This all works as expected if the `class_name Base` is removed from *res://base.gd*.

### Steps to reproduce

1. Create a script with a `class_name`:
```gdscript
class_name Base
extends Node

func _ready() -> void:
    print("base")

func do_stuff() -> void:
    print("do_stuff")
```

2. Create 2 scripts that extend the named class:

```gdscript
# extend0.gd
extends "res://base.gd"

func _ready() -> void:
    super._ready()
    print("extend0 - _ready()")

func do_stuff() -> void:
    super.do_stuff()
    print("extend0 - do_stuff()")
```

```gdscript
# extend1.gd
extends "res://base.gd"

func _ready() -> void:
    super._ready()
    print("extend1 - _ready()")
```

3. Create an autoload with the following code:

```gdscript
func _init() -> void:
    var extend_0 = load("res://extends/extend0.gd")
    extend_0.new()
    extend_0.take_over_path("res://base.gd")
    var extend_1 = load("res://extends/extend1.gd")
    extend_1.new()
    extend_1.take_over_path("res://base.gd")
```

**Minimal reproduction project description**

*res://base.gd*
- The named class (`class_name Base`) that is extended and taken over by `res://extends/extend0.gd` and `res://extends/extend1.gd`.
- The `class_name Base` can be commented out to toggle between working and not working.

*res://extends/extend0.gd and res://extends/extend1.gd*
- These scripts can be viewed as two mods that want to modify the same vanilla game script.

*res://singletons/extender.gd*
- An autoload that handles the extending of the script. Each "script extension" is loaded, and `take_over_path` is used to take over the base script.

*res://VanillaThing.gd*
- Represents a vanilla game script that calls the modified `do_stuff` method on the `Base` class.
- If everything works as intended, calling `do_stuff` from here should print:

```
do_stuff
extend0 - do_stuff()
```

### Minimal reproduction project

[Script Extending.zip](https://github.com/godotengine/godot/files/12999139/Script.Extending.zip)