diff --git a/Userland/Libraries/LibIDL/IDLParser.cpp b/Userland/Libraries/LibIDL/IDLParser.cpp index 44f803352a..f50b9427aa 100644 --- a/Userland/Libraries/LibIDL/IDLParser.cpp +++ b/Userland/Libraries/LibIDL/IDLParser.cpp @@ -815,6 +815,8 @@ void Parser::parse_non_interface_entities(bool allow_interface, Interface& inter consume_whitespace(); } +static void resolve_union_typedefs(Interface& interface, UnionType& union_); + static void resolve_typedef(Interface& interface, NonnullRefPtr& type, HashMap* extended_attributes = {}) { if (is(*type)) { @@ -825,6 +827,12 @@ static void resolve_typedef(Interface& interface, NonnullRefPtr& type, Has return; } + // Resolve anonymous union types until we get named types that can be resolved in the next step. + if (is(*type) && type->name().is_empty()) { + resolve_union_typedefs(interface, type->as_union()); + return; + } + auto it = interface.typedefs.find(type->name()); if (it == interface.typedefs.end()) return; @@ -847,18 +855,23 @@ static void resolve_typedef(Interface& interface, NonnullRefPtr& type, Has // So whatever referenced NestedUnion ends up with the following resolved union: // UnionType(UnionType(A, B), UnionType(C, D)) // Note that flattening unions is handled separately as per the spec. - if (is(*type)) { - auto& union_type = type->as_union(); - auto& member_types = static_cast>&>(union_type.member_types()); - for (auto& member_type : member_types) - resolve_typedef(interface, member_type); - } + if (is(*type)) + resolve_union_typedefs(interface, type->as_union()); } + +static void resolve_union_typedefs(Interface& interface, UnionType& union_) +{ + auto& member_types = static_cast>&>(union_.member_types()); + for (auto& member_type : member_types) + resolve_typedef(interface, member_type); +} + static void resolve_parameters_typedefs(Interface& interface, Vector& parameters) { for (auto& parameter : parameters) resolve_typedef(interface, parameter.type, ¶meter.extended_attributes); } + template void resolve_function_typedefs(Interface& interface, FunctionType& function) {