### Godot version

4.0 rc1

### System information

Windows 11, GTX 1080Ti, Vulkan

### Issue description

Automplete can't find any variables and methods on custom classes when the nodes are loaded with `@onready`:

simple_rotate.gd:
```gdscript
extends Node2D
class_name SimpleRotate

@export var shouldRotate : bool = true
```

machine.gd:
```gdscript
@onready var wheel1 : SimpleRotate = $Wheel

func start_motor():
	wheel1.sho... # Doesn't autocomplete, it can't find shouldRotate 
```

If I add another cast like below, autocomplete does work:
machine.gd:
```gdscript
@onready var wheel1 : SimpleRotate = $Wheel as SimpleRotate

func start_motor():
	wheel1.shouldRotate = true # Autocomplete works
```

To make things even weirder, it does work if I make Wheel into a unique name and access it using %:
machine.gd:
```gdscript
@onready var wheel1 : SimpleRotate = $"%Wheel"

func start_motor():
	wheel1.shouldRotate = true # Autocomplete works
```


### Steps to reproduce

- Create a script with a class_name
- Add that script to a node
- Create another script referencing the node with the type of the script
- Try to let automcomplete find any methods or variables on the script with the class_name
- Notice that it fails

### Minimal reproduction project

N/A
GDScriptTokenizer tokenizer;
	tokenizer.set_source_code(p_code);
	int indent = 0;
	GDScriptTokenizer::Token current = tokenizer.scan();
	while (current.type != GDScriptTokenizer::Token::TK_EOF && current.type != GDScriptTokenizer::Token::ERROR) {
		if (current.type == GDScriptTokenizer::Token::INDENT) {
			indent++;
		} else if (current.type == GDScriptTokenizer::Token::DEDENT) {
			indent--;
		}
		if (indent == 0 && current.type == GDScriptTokenizer::Token::FUNC) {
			current = tokenizer.scan();
			if (current.is_identifier()) {
				String identifier = current.get_identifier();
				if (identifier == p_function) {
					return current.start_line;
				}
			}
		}
		current = tokenizer.scan();
	}
	return -1;
}
Script *GDScriptLanguage::create_script() const {
	return memnew(GDScript);
}
thread_local int GDScriptLanguage::_debug_parse_err_line = -1;
thread_local String GDScriptLanguage::_debug_parse_err_file;
thread_local String GDScriptLanguage::_debug_error;
bool GDScriptLanguage::debug_break_parse(const String &p_file, int p_line, const String &p_error) {