From efe0ab336144d2d965bf355db02762f5cf539c7f Mon Sep 17 00:00:00 2001 From: Akshay Nair Date: Sat, 14 Jan 2023 10:37:51 +0530 Subject: feat: adds func to try/catch --- src/eval-env/builtins.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/eval-env/builtins.ts b/src/eval-env/builtins.ts index f67fcc6..ed94943 100644 --- a/src/eval-env/builtins.ts +++ b/src/eval-env/builtins.ts @@ -31,7 +31,12 @@ const applyFunc = (ctx: Ctx, fn: Type | undefined, val: string): Type => { const typeParameters = functionNode.getTypeParameters() ?? [] if (typeParameters.length > 0) { - typeParameters[0]?.getConstraint()?.replaceWithText(val) + const constraint = typeParameters[0]?.getConstraint() + if (constraint) { + constraint?.replaceWithText(val) + } else { + typeParameters[0]?.setConstraint(val) + } } return resValueNode?.getType() @@ -126,9 +131,7 @@ export default (ctx: Ctx, args: Type[]) => ({ const resultType = applyFunc(ctx, chainToKind, `(${ctx.getResultExpr(resultKey)})['output']`) - const res = await ctx.evaluateType(ctx, resultType) - - return res + return ctx.evaluateType(ctx, resultType) }, Try: async () => { @@ -139,11 +142,8 @@ export default (ctx: Ctx, args: Type[]) => ({ return await ctx.evaluateType(ctx, effTyp) } catch (e) { const error = JSON.stringify((e as any)?.message ?? e) - const catchResExpr = `(${ctx.typeToString( - catchK - )} & { input: ${error} })['return']` - const [resultKey, _] = ctx.createResult(catchResExpr) - return [resultKey] + const resultType = applyFunc(ctx, catchK, error) + return ctx.evaluateType(ctx, resultType) } }, -- cgit v1.3.1