From b1e730dd250db9fe4495dbbb21f80411f724bc8e Mon Sep 17 00:00:00 2001 From: ASDAlexander77 Date: Wed, 15 Jul 2026 18:46:32 +0000 Subject: [PATCH] Improve handling of unregistered types in MLIRGen by replacing assertions with checks and early returns --- tslang/lib/TypeScript/MLIRGenImpl.h | 35 +++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/tslang/lib/TypeScript/MLIRGenImpl.h b/tslang/lib/TypeScript/MLIRGenImpl.h index 0deaffd38..283035c45 100644 --- a/tslang/lib/TypeScript/MLIRGenImpl.h +++ b/tslang/lib/TypeScript/MLIRGenImpl.h @@ -9842,7 +9842,11 @@ class MLIRGenImpl auto cont = mlir::TypeSwitch(type) .Case([&](auto ifaceType) { auto interfaceInfo = getInterfaceInfoByFullName(ifaceType.getName().getValue()); - assert(interfaceInfo); + if (!interfaceInfo) + { + // not registered (e.g. forward/ambient reference), nothing to export + return true; + } for (auto& method : interfaceInfo->methods) { @@ -9858,7 +9862,11 @@ class MLIRGenImpl }) .Case([&](auto classType) { auto classInfo = getClassInfoByFullName(classType.getName().getValue()); - assert(classInfo); + if (!classInfo) + { + // not registered (e.g. forward/ambient reference), nothing to export + return true; + } for (auto& method : classInfo->methods) { @@ -9903,20 +9911,33 @@ class MLIRGenImpl auto cont = mlir::TypeSwitch(type) .Case([&](auto ifaceType) { auto interfaceInfo = getInterfaceInfoByFullName(ifaceType.getName().getValue()); - assert(interfaceInfo); + if (!interfaceInfo) + { + // not registered (e.g. forward/ambient reference), nothing to export + return true; + } + addInterfaceDeclarationToExport(interfaceInfo); return true; }) .Case([&](auto classType) { auto classInfo = getClassInfoByFullName(classType.getName().getValue()); - assert(classInfo); + if (!classInfo) + { + // not registered (e.g. forward/ambient reference), nothing to export + return true; + } + addClassDeclarationToExport(classInfo); return true; }) .Case([&](auto enumType) { auto enumInfo = getEnumInfoByFullName(enumType.getName().getValue()); - assert(enumInfo); - assert(enumInfo->enumType == enumType); + if (!enumInfo || enumInfo->enumType != enumType) + { + // not registered (e.g. forward/ambient reference), nothing to export + return true; + } addEnumDeclarationToExport(enumInfo->name, enumInfo->elementNamespace, enumType); return true; @@ -9926,7 +9947,7 @@ class MLIRGenImpl }); return cont; - } + } void addTypeDeclarationToExport(StringRef name, NamespaceInfo::TypePtr elementNamespace, mlir::Type type) {