godot
                                
                                
                                
                                    godot copied to clipboard
                            
                            
                            
                        "Parser error: Could not resolve member" when a dictionary of preloads contains the scene trying to access said dictionary
Tested versions
- Reproducible in: v4.3.dev4.mono.official [df78c0636], v4.3.dev5.mono.official [89f70e98d]
 - Not occurring in v4.3.dev3.mono.official [36e943b6b], or v4.2.
 
System information
Godot v4.3.dev5.mono - Windows 10.0.19045 - Vulkan (Forward+) - dedicated Radeon RX 570 Series (Advanced Micro Devices, Inc.; 31.0.14057.5006) - AMD Ryzen 7 5700X 8-Core Processor (16 Threads)
Issue description
What's intended is to use a dictionary of preloaded scenes as a source to load up in-game menus from, like below:
var scenes: Dictionary = {
	'ExampleMenu': preload('res://example_menu.tscn'),
	'ExampleMenuTwo': preload('res://example_menu_2.tscn')
}
This is stored inside of the "MenuManager" scene's only script, and is made globally accessible by having a global.gd autoload declare the following:
extends Node
var menu_manager: MenuManager
...and then have the MenuManager scene assign itself in its _enter_tree() function:
func _enter_tree() -> void:
	Global.menu_manager = self
	print(self)
	print(Global.menu_manager)
As early as 4.3 snapshot 4, trying to access this dictionary from a scene that is itself preloaded in said dictionary, such as with the line var inst: Control = Global.menu_manager.scenes['ExampleMenuTwo'].instantiate(), this starts causing the Parser Error: Could not resolve member "scenes". error which prevents the game from running. If, in this case, ExampleMenu is removed from the definition of scenes, then everything works as normal.
Steps to reproduce
Create two scenes to test with, and in another scene / script, define a dictionary including both of them.
var scenes: Dictionary = {
	'ExampleMenu': preload('res://example_menu.tscn'),
	'ExampleMenuTwo': preload('res://example_menu_2.tscn')
}
Have a script within example_menu.tscn - attached to any node within the scene - that tries to access this dictionary.
func _on_button_pressed() -> void:
	assert(Global.menu_manager)
	assert(Global.menu_manager.scenes)
	var inst: Control = Global.menu_manager.scenes['ExampleMenuTwo'].instantiate()
	add_child(inst)
This will cause the parser error.
Minimal reproduction project (MRP)
I've got a similar issue, in my case I store some resources that contain data about each different team the player can be part of.
Bisecting points to #85501 as the culprit
CC @Jordyfel @godotengine/gdscript
See also #90362.
For the MRP, my PR (#92326) fix it, but you need to make sure that you can save the global class without error (by commenting the autoload reference first) to make sure it's registered as a global class. Then, you can put back the commented line.