decompile: Fix bug in lookup tags

A lookup tag with no type attribute would crash the decompiler, even if
that was valid. This wasn't caught by the tests since blueprint never
generates such XML.

Also fixed a bug in the tests that caused decompiler-only tests not to
run.
This commit is contained in:
James Westman 2025-04-25 20:13:01 -05:00
parent a83c7e936d
commit a12d3f5c81
No known key found for this signature in database
GPG key ID: CE2DBA0ADB654EA6
5 changed files with 39 additions and 13 deletions

View file

@ -255,7 +255,11 @@ def decompile_element(
ctx._node_stack.append(xml)
ctx.start_block()
gir = decompiler(*args, **kwargs)
try:
gir = decompiler(*args, **kwargs)
except TypeError as e:
raise UnsupportedError(tag=xml.tag)
if not decompiler._skip_children:
for child in xml.children:
@ -266,8 +270,6 @@ def decompile_element(
except UnsupportedError as e:
raise e
except TypeError as e:
raise UnsupportedError(tag=xml.tag)
def decompile(data: str) -> str:

View file

@ -302,12 +302,18 @@ expr.children = [
@decompiler("lookup", skip_children=True, cdata=True)
def decompile_lookup(
ctx: DecompileCtx, gir: gir.GirContext, cdata: str, name: str, type: str
ctx: DecompileCtx,
gir: gir.GirContext,
cdata: str,
name: str,
type: T.Optional[str] = None,
):
if ctx.parent_node is not None and ctx.parent_node.tag == "property":
ctx.print("expr ")
if t := ctx.type_by_cname(type):
if type is None:
type = ""
elif t := ctx.type_by_cname(type):
type = decompile.full_name(t)
else:
type = "$" + type
@ -327,7 +333,7 @@ def decompile_lookup(
if constant == ctx.template_class:
ctx.print("template." + name)
elif constant == "":
ctx.print("item as <" + type + ">." + name)
ctx.print(f"item as <{type}>.{name}")
else:
ctx.print(constant + "." + name)
return