Fix lookup symbol for enum members to search a correct code definition
This commit is contained in:
parent
4359c28fea
commit
c29bfc801a
|
@ -128,7 +128,7 @@ static GDScriptParser::DataType make_script_meta_type(const Ref<Script> &p_scrip
|
|||
|
||||
// In enum types, native_type is used to store the class (native or otherwise) that the enum belongs to.
|
||||
// This disambiguates between similarly named enums in base classes or outer classes
|
||||
static GDScriptParser::DataType make_enum_type(const StringName &p_enum_name, const String &p_base_name, const bool p_meta = false) {
|
||||
static GDScriptParser::DataType make_enum_type(const StringName &p_enum_name, const String &p_base_name, const bool p_meta = false, GDScriptParser::ClassNode *p_class = nullptr, const String &p_script_path = "") {
|
||||
GDScriptParser::DataType type;
|
||||
type.type_source = GDScriptParser::DataType::ANNOTATED_EXPLICIT;
|
||||
type.kind = GDScriptParser::DataType::ENUM;
|
||||
|
@ -136,6 +136,8 @@ static GDScriptParser::DataType make_enum_type(const StringName &p_enum_name, co
|
|||
type.enum_type = p_enum_name;
|
||||
type.is_constant = true;
|
||||
type.is_meta_type = p_meta;
|
||||
type.class_type = p_class;
|
||||
type.script_path = p_script_path;
|
||||
|
||||
// For enums, native_type is only used to check compatibility in is_type_compatible()
|
||||
// We can set anything readable here for error messages, as long as it uniquely identifies the type of the enum
|
||||
|
@ -1064,7 +1066,7 @@ void GDScriptAnalyzer::resolve_class_member(GDScriptParser::ClassNode *p_class,
|
|||
check_class_member_name_conflict(p_class, member.m_enum->identifier->name, member.m_enum);
|
||||
|
||||
member.m_enum->set_datatype(resolving_datatype);
|
||||
GDScriptParser::DataType enum_type = make_enum_type(member.m_enum->identifier->name, p_class->fqcn, true);
|
||||
GDScriptParser::DataType enum_type = make_enum_type(member.m_enum->identifier->name, p_class->fqcn, true, p_class, parser->script_path);
|
||||
|
||||
const GDScriptParser::EnumNode *prev_enum = current_enum;
|
||||
current_enum = member.m_enum;
|
||||
|
@ -1157,7 +1159,7 @@ void GDScriptAnalyzer::resolve_class_member(GDScriptParser::ClassNode *p_class,
|
|||
// Also update the original references.
|
||||
member.enum_value.parent_enum->values.set(member.enum_value.index, member.enum_value);
|
||||
|
||||
member.enum_value.identifier->set_datatype(make_enum_type(UNNAMED_ENUM, p_class->fqcn, false));
|
||||
member.enum_value.identifier->set_datatype(make_enum_type(UNNAMED_ENUM, p_class->fqcn, false, p_class, parser->script_path));
|
||||
} break;
|
||||
case GDScriptParser::ClassNode::Member::CLASS:
|
||||
check_class_member_name_conflict(p_class, member.m_class->identifier->name, member.m_class);
|
||||
|
@ -4099,7 +4101,7 @@ void GDScriptAnalyzer::reduce_identifier(GDScriptParser::IdentifierNode *p_ident
|
|||
const GDScriptParser::EnumNode::Value &element = current_enum->values[i];
|
||||
if (element.identifier->name == p_identifier->name) {
|
||||
StringName enum_name = current_enum->identifier ? current_enum->identifier->name : UNNAMED_ENUM;
|
||||
GDScriptParser::DataType type = make_enum_type(enum_name, parser->current_class->fqcn, false);
|
||||
GDScriptParser::DataType type = make_enum_type(enum_name, parser->current_class->fqcn, false, parser->current_class, parser->script_path);
|
||||
if (element.parent_enum->identifier) {
|
||||
type.enum_type = element.parent_enum->identifier->name;
|
||||
}
|
||||
|
|
|
@ -3749,11 +3749,18 @@ static Error _lookup_symbol_from_base(const GDScriptParser::DataType &p_base, co
|
|||
}
|
||||
} break;
|
||||
case GDScriptParser::DataType::ENUM: {
|
||||
if (base_type.enum_values.has(p_symbol)) {
|
||||
r_result.type = ScriptLanguage::LOOKUP_RESULT_CLASS_CONSTANT;
|
||||
r_result.class_name = String(base_type.native_type).get_slicec('.', 0);
|
||||
r_result.class_member = p_symbol;
|
||||
return OK;
|
||||
if (base_type.class_type && base_type.class_type->has_member(base_type.enum_type)) {
|
||||
GDScriptParser::EnumNode *base_enum = base_type.class_type->get_member(base_type.enum_type).m_enum;
|
||||
for (const GDScriptParser::EnumNode::Value &value : base_enum->values) {
|
||||
if (value.identifier && value.identifier->name == p_symbol) {
|
||||
r_result.type = ScriptLanguage::LOOKUP_RESULT_SCRIPT_LOCATION;
|
||||
r_result.class_path = base_type.script_path;
|
||||
r_result.location = value.line;
|
||||
Error err = OK;
|
||||
r_result.script = GDScriptCache::get_shallow_script(r_result.class_path, err);
|
||||
return err;
|
||||
}
|
||||
}
|
||||
}
|
||||
base_type.kind = GDScriptParser::DataType::UNRESOLVED;
|
||||
} break;
|
||||
|
|
Loading…
Reference in New Issue