### 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
}
			if (!type.enumeration.is_empty()) {
				_find_enumeration_candidates(completion_context, type.enumeration, options);
				r_forced = options.size() > 0;
			} else {
				_find_identifiers(completion_context, false, options, 0);
				r_forced = true;
			}
		} break;
		case GDScriptParser::COMPLETION_METHOD:
			is_function = true;
			[[fallthrough]];
		case GDScriptParser::COMPLETION_IDENTIFIER: {
			_find_identifiers(completion_context, is_function, options, 0);
		} break;
		case GDScriptParser::COMPLETION_ATTRIBUTE_METHOD:
			is_function = true;
			[[fallthrough]];
		case GDScriptParser::COMPLETION_ATTRIBUTE: {
			r_forced = true;
			const GDScriptParser::SubscriptNode *attr = static_cast<const GDScriptParser::SubscriptNode *>(completion_context.node);
			if (attr->base) {
				GDScriptCompletionIdentifier base;
				bool found_type = _get_subscript_type(completion_context, attr, base.type);
				if (!found_type && !_guess_expression_type(completion_context, attr->base, base)) {
					break;
				}
				_find_identifiers_in_base(base, is_function, options, 0);
			}
		} break;