### 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
break;
			}
		} else if (!hide_on_item_selection || !pop->is_hide_on_item_selection()) {
			break;
		}
		pop->hide();
		next = next->get_parent();
		pop = Object::cast_to<PopupMenu>(next);
	}
	
	
	bool need_hide = true;
	if (items[p_idx].checkable_type) {
		if (!hide_on_checkable_item_selection) {
			need_hide = false;
		}
	} else if (0 < items[p_idx].max_states) {
		if (!hide_on_multistate_item_selection) {
			need_hide = false;
		}
	} else if (!hide_on_item_selection) {
		need_hide = false;
	}
	if (need_hide) {
		hide();
	}
	emit_signal(SNAME("id_pressed"), id);
	emit_signal(SNAME("index_pressed"), p_idx);
}
void PopupMenu::remove_item(int p_idx) {