From ae10c353493a3129f168a5b0620e342a0d5786c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind=20Raddum=20Berg?= Date: Sat, 14 Oct 2023 00:34:36 +0200 Subject: [PATCH] FollowAliases: Recover from more circular things by catching `StackOverflowError` --- .../converter/internal/ts/FollowAliases.scala | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/ts/src/main/scala/org/scalablytyped/converter/internal/ts/FollowAliases.scala b/ts/src/main/scala/org/scalablytyped/converter/internal/ts/FollowAliases.scala index 6dc6be2865..9098f97dd6 100644 --- a/ts/src/main/scala/org/scalablytyped/converter/internal/ts/FollowAliases.scala +++ b/ts/src/main/scala/org/scalablytyped/converter/internal/ts/FollowAliases.scala @@ -2,17 +2,15 @@ package org.scalablytyped.converter.internal package ts object FollowAliases { - def apply(scope: TsTreeScope, skipValidation: Boolean = false)(tpe: TsType): TsType = { - tpe match { + def apply(scope: TsTreeScope, skipValidation: Boolean = false)(tpe: TsType): TsType = + try tpe match { case typeRef: TsTypeRef => scope .lookupType(typeRef.name, skipValidation) .collectFirst { case ta: TsDeclTypeAlias => val next = FillInTParams(ta, typeRef.tparams).alias - // this is a consequence of interface augmentation. see for instance `Locals` in express - if (next == tpe) TsTypeRef.any.copy(comments = Comments(Comment.warning(s"circular ${TsTypeFormatter(tpe)}"))) - else apply(scope, skipValidation)(next) + apply(scope, skipValidation)(next) /* see through thin interfaces which might be translated into type aliases */ case i @ TsDeclInterface(_, _, _, _, IArray.exactlyOne(_), Empty, _) => apply(scope, skipValidation)(FillInTParams(i, typeRef.tparams).inheritance.head) @@ -23,8 +21,12 @@ object FollowAliases { case TsTypeUnion(types) => TsTypeUnion.simplified(types.map(FollowAliases(scope, skipValidation))) case other => other + } catch { + case _: StackOverflowError => + val formatted = TsTypeFormatter(tpe) + scope.logger.error(s"Recovered from SOE while following type alias $formatted") + TsTypeRef.any.copy(comments = Comments(Comment.warning(s"circular $formatted"))) } - } def typeRef(scope: TsTreeScope)(tr: TsTypeRef): TsTypeRef = scope