### Godot version

4.0.2

### System information

Windows 11

### Issue description

Changing node type from PopupMenu to ItemList causes Godot to crash

### Steps to reproduce

Change node type from PopupMenu to ItemList

### Minimal reproduction project

n/a
Node *n = get_node(items[p_over].submenu);
	ERR_FAIL_COND_MSG(!n, "Item subnode does not exist: " + items[p_over].submenu + ".");
	Popup *submenu_popup = Object::cast_to<Popup>(n);
	ERR_FAIL_COND_MSG(!submenu_popup, "Item subnode is not a Popup: " + items[p_over].submenu + ".");
	if (submenu_popup->is_visible()) {
		return; 
	}
	Point2 this_pos = get_position();
	Rect2 this_rect(this_pos, get_size());
	float scroll_offset = control->get_position().y;
	submenu_popup->reset_size(); 
	Size2 submenu_size = submenu_popup->get_size();
	Point2 submenu_pos;
	if (control->is_layout_rtl()) {
		submenu_pos = this_pos + Point2(-submenu_size.width, items[p_over]._ofs_cache + scroll_offset);
	} else {
		submenu_pos = this_pos + Point2(this_rect.size.width, items[p_over]._ofs_cache + scroll_offset);
	}
	
	if (submenu_pos.x < get_parent_rect().position.x) {
		submenu_pos.x = this_pos.x + submenu_size.width;
	}
	if (submenu_pos.x + submenu_size.width > get_parent_rect().position.x + get_parent_rect().size.width) {
		submenu_pos.x = this_pos.x - submenu_size.width;
	}
	submenu_popup->set_position(submenu_pos);
	PopupMenu *submenu_pum = Object::cast_to<PopupMenu>(submenu_popup);
	if (!submenu_pum) {
		submenu_popup->popup();