From f0a5ed83237465e70a0a1abdac5633f656e7cc54 Mon Sep 17 00:00:00 2001 From: ASDAlexander77 Date: Tue, 24 Nov 2026 14:48:49 +0000 Subject: [PATCH 1/2] Tuple inference for (...args: A) => T with mixed parameter types; -mm=own throw() at a yield* reaches the delegate (TSLANG 184) Co-Authored-By: Claude Opus 5.5 --- TSLANG_ISSUES.md | 21 +++ docs/whats-new.md | 1 + .../TypeScript/MLIRLogic/MLIRTypeHelper.h | 21 +++ tslang/lib/TypeScript/MLIRGenCast.cpp | 70 ++++++--- tslang/lib/TypeScript/MLIRGenFunctions.cpp | 133 +++++++++++++----- tslang/lib/TypeScript/MLIRGenGenerics.cpp | 36 ++++- tslang/lib/TypeScript/MLIRGenImpl.h | 32 ++++- tslang/test/tester/CMakeLists.txt | 2 + .../tests/00generic_arrow_through_generic.ts | 5 + 9 files changed, 258 insertions(+), 63 deletions(-) diff --git a/TSLANG_ISSUES.md b/TSLANG_ISSUES.md index 127520268..1bac88192 100644 --- a/TSLANG_ISSUES.md +++ b/TSLANG_ISSUES.md @@ -3072,3 +3072,24 @@ Looked at, still open: Tests `00arguments_length_given.ts` (gc, rc, own), `00generic_arrow_through_generic.ts` (gc, rc), `00generator_yield_star_throw.ts` (gc, rc). + +184 (183's leftovers, 2026-11-24). Fixed: +- A function whose parameters have different types given to `(...args: A) => T` (`call2((a: number, b: string) => + b + a, 1, "x")`): `A` is inferred as the tuple of them, `[number, string]`, as tsc infers it (tryInferFunction), + and the arguments given for `...args: A` are taken as that tuple, not inferred again as an array of their union. A + tuple of unnamed elements extends an array whose element each element extends (`[number, string] extends + unknown[]`, extendsType). The adapters read the function's parameters out of a rest tuple as out of a rest array + (restArrayOf, expandRestArguments). Parameters of one type are an array, as before. Works in every model for a + function or an arrow given directly. +- -mm=own: throw() of a generator paused in a `yield*` of a generator made there (`yield* inner()`) is handed to the + delegate's throw() (183 for the other models), for elements that own nothing (a number, a boolean), as the + generator's return() under -mm=own. The delegate is exchanged into a local of next() for the call and back, and + what was thrown is exchanged out of the generator's field into a local first: given from the field, the call was + taken for one that may overwrite the field it borrows. + +Looked at, still open: +- -mm=own: throw() at a `yield*` of strings or objects throws at the yield, as before: the step's result would be one + of two calls' ("a value is merged from several branches"). And a delegate named by a parameter (`yield* it`). +- A delegate whose type has `throw` but not `return` is not handed the exception (the library's Generator has both). + +Tests `00generic_arrow_through_generic.ts` (gc, rc; tuple cases added), `00generator_yield_star_throw.ts` (own added). diff --git a/docs/whats-new.md b/docs/whats-new.md index af8bb124a..b31737ad2 100644 --- a/docs/whats-new.md +++ b/docs/whats-new.md @@ -1,5 +1,6 @@ # What's new +- A function with parameters of different types can be given to `(...args: A) => T` (`A` is inferred as a tuple, `[number, string]`); under -mm=own, throw() of a generator paused in a `yield*` of numbers is handed to the delegate too - `arguments.length` counts the arguments given, not the parameters declared; a generic arrow can be given to a generic parameter (`wrap((x: T) => x)`), and a function to `(...args: A) => T`; throw() of a generator paused in a `yield*` is handed to the delegate's throw(), which may catch it and go on yielding - -mm=own: `for (const s of this.items) yield s` works in a generator method: the field is read again at each step (a field assigned during the loop is followed, unlike JavaScript's for-of) - -mm=own: a field read through a union of object shapes can be returned as a borrow of the argument (`getBox(s: Sq | Ci) { return s.box; }`); a method that throws an object through a `finally` that yields is a compile error at the call diff --git a/tslang/include/TypeScript/MLIRLogic/MLIRTypeHelper.h b/tslang/include/TypeScript/MLIRLogic/MLIRTypeHelper.h index 420795222..daa3170a4 100644 --- a/tslang/include/TypeScript/MLIRLogic/MLIRTypeHelper.h +++ b/tslang/include/TypeScript/MLIRLogic/MLIRTypeHelper.h @@ -3544,6 +3544,27 @@ class MLIRTypeHelper } } + // a tuple (`[number, string]`, its elements unnamed - not an object's fields) extends an array whose element + // each of its elements extends (`A extends unknown[]` inferred as a tuple, TSLANG 184) + if (auto srcTuple = dyn_cast(srcType)) + { + auto extArray = dyn_cast(extendType); + if (extArray && srcTuple.size() > 0 + && llvm::all_of(srcTuple.getFields(), [](mlir_ts::FieldInfo field) { return !field.id; })) + { + for (auto field : srcTuple.getFields()) + { + auto result = extendsType(location, field.type, extArray.getElementType(), typeParamsWithArgs); + if (result != ExtendsResult::True) + { + return result; + } + } + + return ExtendsResult::True; + } + } + // Special case when we have string type (widen from Literal Type) if (auto literalType = dyn_cast(extendType)) { diff --git a/tslang/lib/TypeScript/MLIRGenCast.cpp b/tslang/lib/TypeScript/MLIRGenCast.cpp index 33d50ef3c..606cf2377 100644 --- a/tslang/lib/TypeScript/MLIRGenCast.cpp +++ b/tslang/lib/TypeScript/MLIRGenCast.cpp @@ -3529,26 +3529,50 @@ namespace mlirgen return !(sameResults && srcInputs.size() == destInputs.size()); } - // The array a function type's rest parameter is (`(...args: A) => T` with A `number[]`), null where it has none - static mlir_ts::ArrayType restArrayOf(mlir_ts::FunctionType funcType) + // What a function type's rest parameter is, an array (`(...args: A) => T` with A `number[]`) or a tuple (A + // `[number, string]`), null where it has none + static mlir::Type restArrayOf(mlir_ts::FunctionType funcType) { - return funcType && funcType.isVarArg() && !funcType.isCVarArg() && funcType.getNumInputs() > 0 - ? dyn_cast(funcType.getInputs().back()) - : mlir_ts::ArrayType(); + if (!funcType || !funcType.isVarArg() || funcType.isCVarArg() || funcType.getNumInputs() == 0) + { + return mlir::Type(); + } + + auto rest = funcType.getInputs().back(); + return isa(rest) ? rest : mlir::Type(); + } + + // the type of the rest parameter's element at `index`: the array's element, the tuple's field (null past its end) + static mlir::Type restElementType(mlir::Type rest, size_t index) + { + if (auto arrayType = dyn_cast(rest)) + { + return arrayType.getElementType(); + } + + auto tupleType = cast(rest); + return index < tupleType.size() ? tupleType.getFieldInfo(index).type : mlir::Type(); } - // adaptableSignature for a function given as a type with a rest array (TSLANG 94): the parameters the function - // takes past the type's fixed ones are elements of the array. With the same parameters as those elements there - // is still an adapter to make: it reads them out of the array. `fixedCount` is the number of fixed ones. + // adaptableSignature for a function given as a type with a rest array or tuple (TSLANG 94, 184): the parameters + // the function takes past the type's fixed ones are elements of it. With the same parameters as those elements + // there is still an adapter to make: it reads them out of it. `fixedCount` is the number of fixed ones. static bool adaptableToRestArray(mlir::ArrayRef srcInputs, mlir::TypeRange srcResults, mlir::ArrayRef destInputs, mlir::TypeRange destResults, - mlir_ts::ArrayType restArray, bool &dropResult, size_t &fixedCount) + mlir::Type restArray, bool &dropResult, size_t &fixedCount) { fixedCount = destInputs.size() - 1; SmallVector destExpanded(destInputs.drop_back()); for (auto index = fixedCount; index < srcInputs.size(); index++) { - destExpanded.push_back(restArray.getElementType()); + auto elementType = restElementType(restArray, index - fixedCount); + if (!elementType) + { + dropResult = false; + return false; + } + + destExpanded.push_back(elementType); } if (adaptableSignature(srcInputs, srcResults, destExpanded, destResults, dropResult)) @@ -3560,10 +3584,10 @@ namespace mlirgen return llvm::equal(srcInputs, destExpanded) && srcResults == destResults; } - // The arguments an adapter gives a function from the type's fixed ones and its rest array `rest`: the fixed ones, - // then an element of the array for each parameter the function takes past them + // The arguments an adapter gives a function from the type's fixed ones and its rest array or tuple `rest`: the + // fixed ones, then an element of it for each parameter the function takes past them static void expandRestArguments(mlir::OpBuilder &builder, mlir::Location location, mlir::Type structIndexType, - mlir::ValueRange fixedArgs, mlir::Value rest, mlir_ts::ArrayType restArray, + mlir::ValueRange fixedArgs, mlir::Value rest, mlir::Type restArray, size_t fixedCount, size_t srcCount, SmallVectorImpl &expandedArgs) { for (auto index = size_t(0); index < std::min((size_t)fixedArgs.size(), fixedCount); index++) @@ -3573,11 +3597,18 @@ namespace mlirgen for (auto index = fixedCount; index < srcCount; index++) { - auto position = - builder.create(location, structIndexType, builder.getI32IntegerAttr((int)(index - fixedCount))); - auto elementRef = builder.create( - location, mlir_ts::RefType::get(restArray.getElementType()), rest, position); - expandedArgs.push_back(builder.create(location, restArray.getElementType(), elementRef)); + auto elementIndex = (int64_t)(index - fixedCount); + auto elementType = restElementType(restArray, elementIndex); + if (isa(restArray)) + { + expandedArgs.push_back(builder.create(location, elementType, rest, + builder.getDenseI64ArrayAttr({elementIndex}))); + continue; + } + + auto position = builder.create(location, structIndexType, builder.getI32IntegerAttr((int)elementIndex)); + auto elementRef = builder.create(location, mlir_ts::RefType::get(elementType), rest, position); + expandedArgs.push_back(builder.create(location, elementType, elementRef)); } } @@ -4213,8 +4244,7 @@ namespace mlirgen // `(...args: number[]) => number`, TSLANG 94) auto toRestArray = false; if (auto srcFuncType = mth.GetFunctionType(valueType), destFuncType = mth.GetFunctionType(type); - srcFuncType && destFuncType && !srcFuncType.isVarArg() && destFuncType.isVarArg() - && destFuncType.getNumInputs() > 0 && isa(destFuncType.getInputs().back())) + srcFuncType && destFuncType && !srcFuncType.isVarArg() && restArrayOf(destFuncType)) { toRestArray = true; } diff --git a/tslang/lib/TypeScript/MLIRGenFunctions.cpp b/tslang/lib/TypeScript/MLIRGenFunctions.cpp index 1e75090c1..8de299ae6 100644 --- a/tslang/lib/TypeScript/MLIRGenFunctions.cpp +++ b/tslang/lib/TypeScript/MLIRGenFunctions.cpp @@ -1447,9 +1447,98 @@ namespace mlirgen nf.createNumericLiteral(S("0"), TokenFlags::None))); }; + // -mm=own: the delegate of a yield* is exchanged into a local of next() for a call on it and back, as for its + // next() (mlirGenYieldStar): `{ let .yq: G | undefined = undefined; [.yq, .yd] = [.yd, .yq]; + // try { } finally { [.yq, .yd] = [.yd, .yq]; } }` + auto ownDelegate = genContext.yieldStarDelegate && compileOptions.memoryModel == MemoryModelOwn + && genContext.typeAliasMap.count(".YS_G"); + auto delegateLocal = [&]() { return nf.createIdentifier(stows(".yq" + std::string(genContext.yieldStarDelegate))); }; + auto withDelegateLocal = [&](NodeArray callStatements) { + auto delegateIdent = nf.createIdentifier(stows(std::string(genContext.yieldStarDelegate))); + auto localIdent = delegateLocal(); + auto exchange = [&]() { + NodeArray targets; + targets.push_back(localIdent); + targets.push_back(delegateIdent); + NodeArray values; + values.push_back(delegateIdent); + values.push_back(localIdent); + return nf.createExpressionStatement(nf.createBinaryExpression( + nf.createArrayLiteralExpression(targets, false), nf.createToken(SyntaxKind::EqualsToken), + nf.createArrayLiteralExpression(values, false))).as(); + }; + + NodeArray members; + members.push_back(nf.createTypeReferenceNode(nf.createIdentifier(S(".YS_G")).as()).as()); + members.push_back(nf.createToken(SyntaxKind::UndefinedKeyword).as()); + auto localDeclaration = nf.createVariableDeclaration(localIdent, undefined, nf.createUnionTypeNode(members).as(), + nf.createIdentifier(S(UNDEFINED_NAME))); + localDeclaration->internalFlags |= InternalFlags::StackLocal; + NodeArray localDeclarations; + localDeclarations.push_back(localDeclaration); + + NodeArray backStatements; + backStatements.push_back(exchange()); + + NodeArray delegateStatements; + delegateStatements.push_back( + nf.createVariableStatement(undefined, nf.createVariableDeclarationList(localDeclarations, NodeFlags::Let))); + delegateStatements.push_back(exchange()); + delegateStatements.push_back(nf.createTryStatement(nf.createBlock(callStatements, false), undefined, + nf.createBlock(backStatements, false))); + return nf.createBlock(delegateStatements, false).as(); + }; + NodeArray throwStatements; throwStatements.push_back(resetMode()); - if (genContext.yieldStarDelegate && genContext.yieldStarResult && genContext.yieldStarSkipNext) + if (genContext.yieldStarDelegate && genContext.yieldStarResult && genContext.yieldStarSkipNext && ownDelegate) + { + // -mm=own, the same in the local the delegate is exchanged into (TSLANG 184): + // { ...exchange...; try { if (.yq!.throw) { .yc = .yq!.throw!(this.thrown); .ys = true; } } finally { ... } } + // if (!.ys) throw this.thrown; + auto delegateThrow = [&]() { + return nf.createPropertyAccessExpression(nf.createNonNullExpression(delegateLocal()), nf.createIdentifier(S("throw"))); + }; + auto skipIdent = [&]() { return nf.createIdentifier(stows(std::string(genContext.yieldStarSkipNext))); }; + // what was thrown, exchanged out of the generator's field into a local first: given from the field, the + // delegate's throw() - which keeps what it is given - was taken for a call that may overwrite the field it + // borrows (`let .yt: any = 0; [.yt, this.thrown] = [this.thrown, .yt];`) + auto thrownLocal = [&]() { return nf.createIdentifier(stows(".yt" + std::string(genContext.yieldStarDelegate))); }; + NodeArray thrownDeclarations; + auto thrownDeclaration = nf.createVariableDeclaration( + thrownLocal(), undefined, nf.createToken(SyntaxKind::AnyKeyword).as(), + nf.createTypeAssertion(nf.createToken(SyntaxKind::AnyKeyword).as(), + nf.createNumericLiteral(S("0"), TokenFlags::None))); + thrownDeclaration->internalFlags |= InternalFlags::StackLocal; + thrownDeclarations.push_back(thrownDeclaration); + NodeArray thrownTargets; + thrownTargets.push_back(thrownLocal()); + thrownTargets.push_back(thisProp(GENERATOR_THROWN_NAME)); + NodeArray thrownValues; + thrownValues.push_back(thisProp(GENERATOR_THROWN_NAME)); + thrownValues.push_back(thrownLocal()); + + NodeArray arguments; + arguments.push_back(thrownLocal()); + NodeArray handStatements; + handStatements.push_back( + nf.createVariableStatement(undefined, nf.createVariableDeclarationList(thrownDeclarations, NodeFlags::Let))); + handStatements.push_back(nf.createExpressionStatement(nf.createBinaryExpression( + nf.createArrayLiteralExpression(thrownTargets, false), nf.createToken(SyntaxKind::EqualsToken), + nf.createArrayLiteralExpression(thrownValues, false)))); + handStatements.push_back(nf.createExpressionStatement(nf.createBinaryExpression( + nf.createIdentifier(stows(std::string(genContext.yieldStarResult))), nf.createToken(SyntaxKind::EqualsToken), + nf.createCallExpression(nf.createNonNullExpression(delegateThrow()), undefined, arguments)))); + handStatements.push_back(nf.createExpressionStatement( + nf.createBinaryExpression(skipIdent(), nf.createToken(SyntaxKind::EqualsToken), nf.createToken(SyntaxKind::TrueKeyword)))); + NodeArray callStatements; + callStatements.push_back(nf.createIfStatement(delegateThrow(), nf.createBlock(handStatements, false), undefined)); + throwStatements.push_back(withDelegateLocal(callStatements)); + throwStatements.push_back(nf.createIfStatement( + nf.createPrefixUnaryExpression(nf.createToken(SyntaxKind::ExclamationToken), skipIdent()), + nf.createThrowStatement(thisProp(GENERATOR_THROWN_NAME)), undefined)); + } + else if (genContext.yieldStarDelegate && genContext.yieldStarResult && genContext.yieldStarSkipNext) { // at the yield of a yield* whose delegate has throw(): handed to it, its result the loop's next step // (mlirGenYieldStar) - `if (.yd.throw) { .yc = .yd.throw!(this.thrown); .ys = true; } else throw this.thrown;` @@ -1480,50 +1569,16 @@ namespace mlirgen NodeArray returnStatements; returnStatements.push_back(resetMode()); // at the yield of a yield*: the delegate's return() first, with the same value (mlirGenYieldStar) - if (genContext.yieldStarDelegate && compileOptions.memoryModel == MemoryModelOwn && genContext.typeAliasMap.count(".YS_G")) + if (ownDelegate) { - // -mm=own: the delegate is exchanged into a local of next() for the call and back, as for its - // next() (mlirGenYieldStar): `{ let .yq: G | undefined = undefined; [.yq, .yd] = [.yd, .yq]; - // try { .yq!.return?.(this.thrown); } finally { [.yq, .yd] = [.yd, .yq]; } }` - auto delegateIdent = nf.createIdentifier(stows(std::string(genContext.yieldStarDelegate))); - auto localIdent = nf.createIdentifier(stows(".yq" + std::string(genContext.yieldStarDelegate))); - auto exchange = [&]() { - NodeArray targets; - targets.push_back(localIdent); - targets.push_back(delegateIdent); - NodeArray values; - values.push_back(delegateIdent); - values.push_back(localIdent); - return nf.createExpressionStatement(nf.createBinaryExpression( - nf.createArrayLiteralExpression(targets, false), nf.createToken(SyntaxKind::EqualsToken), - nf.createArrayLiteralExpression(values, false))).as(); - }; - - NodeArray members; - members.push_back(nf.createTypeReferenceNode(nf.createIdentifier(S(".YS_G")).as()).as()); - members.push_back(nf.createToken(SyntaxKind::UndefinedKeyword).as()); - auto localDeclaration = nf.createVariableDeclaration(localIdent, undefined, nf.createUnionTypeNode(members).as(), - nf.createIdentifier(S(UNDEFINED_NAME))); - localDeclaration->internalFlags |= InternalFlags::StackLocal; - NodeArray localDeclarations; - localDeclarations.push_back(localDeclaration); - + // -mm=own: in the local the delegate is exchanged into, `.yq!.return?.(this.thrown)` NodeArray arguments; arguments.push_back(thisProp(GENERATOR_THROWN_NAME)); NodeArray callStatements; callStatements.push_back(nf.createExpressionStatement(nf.createCallChain( - nf.createPropertyAccessExpression(nf.createNonNullExpression(localIdent), nf.createIdentifier(S("return"))), + nf.createPropertyAccessExpression(nf.createNonNullExpression(delegateLocal()), nf.createIdentifier(S("return"))), nf.createToken(SyntaxKind::QuestionDotToken), undefined, arguments))); - NodeArray backStatements; - backStatements.push_back(exchange()); - - NodeArray delegateStatements; - delegateStatements.push_back( - nf.createVariableStatement(undefined, nf.createVariableDeclarationList(localDeclarations, NodeFlags::Let))); - delegateStatements.push_back(exchange()); - delegateStatements.push_back(nf.createTryStatement(nf.createBlock(callStatements, false), undefined, - nf.createBlock(backStatements, false))); - returnStatements.push_back(nf.createBlock(delegateStatements, false)); + returnStatements.push_back(withDelegateLocal(callStatements)); } else if (genContext.yieldStarDelegate) { diff --git a/tslang/lib/TypeScript/MLIRGenGenerics.cpp b/tslang/lib/TypeScript/MLIRGenGenerics.cpp index 92baab2ad..314c12fa9 100644 --- a/tslang/lib/TypeScript/MLIRGenGenerics.cpp +++ b/tslang/lib/TypeScript/MLIRGenGenerics.cpp @@ -371,13 +371,28 @@ namespace mlirgen auto fixed = tempfuncType.size() - 1; inferTypeFuncType(location, tempfuncType.take_front(fixed), funcType.take_front(fixed), results, genContext); + // ...a tuple of them where their types differ (`(a: number, b: string) => ...`: A `[number, string]`, + // TSLANG 184), as tsc infers it - an array of their union would take either at each place + auto restTypes = funcType.drop_front(fixed); + auto asTuple = restTypes.size() > 1 && llvm::any_of(restTypes, [&](mlir::Type type) { return type != restTypes.front(); }); + if (asTuple) + { + SmallVector fields; + for (auto restType : restTypes) + { + fields.push_back({mlir::Attribute(), restType, false, mlir_ts::AccessLevel::Public}); + } + + inferType(location, tempfuncType.back(), getTupleType(fields), results, genContext); + } + struct ArrayInfo arrayInfo{}; - for (auto restType : funcType.drop_front(fixed)) + for (auto restType : restTypes) { accumulateArrayItemType(location, restType, arrayInfo); } - if (arrayInfo.accumulatedArrayElementType) + if (!asTuple && arrayInfo.accumulatedArrayElementType) { inferType(location, tempfuncType.back(), getArrayType(arrayInfo.accumulatedArrayElementType), results, genContext); @@ -1310,6 +1325,23 @@ namespace mlirgen } else { + // a rest parameter whose type parameter is a tuple already (inferred from a function given + // for `(...args: A) => T`, TSLANG 184) with as many elements as there are arguments: the + // arguments are cast to it at the call, not inferred again as an array of their union + if (auto namedGeneric = dyn_cast(paramType)) + { + auto found = genericTypeGenContext.typeParamsWithArgs.find(namedGeneric.getName().getValue()); + auto tupleType = found != genericTypeGenContext.typeParamsWithArgs.end() + ? dyn_cast_or_null(found->getValue().second) + : mlir_ts::TupleType(); + if (tupleType && tupleType.size() == callOpsCount - paramIndex) + { + paramInfo->processed = true; + processed++; + continue; + } + } + struct ArrayInfo arrayInfo{}; for (auto varArgIndex = paramIndex; varArgIndex < callOpsCount; varArgIndex++) { diff --git a/tslang/lib/TypeScript/MLIRGenImpl.h b/tslang/lib/TypeScript/MLIRGenImpl.h index 4ded56e2b..032bd87af 100644 --- a/tslang/lib/TypeScript/MLIRGenImpl.h +++ b/tslang/lib/TypeScript/MLIRGenImpl.h @@ -5395,6 +5395,23 @@ class MLIRGenImpl delegateGenContext.yieldStarDelegate = delegateName.c_str(); } + // ...and a throw() of it is handed to the delegate's throw(), when it has one (TSLANG 184, as 183 for + // the other models): the resume check puts its result in `.yc` and sets `.ys`, and the step's next() + // is then not called. Only for elements that own nothing (a number, a boolean), as the generator's + // return() under -mm=own: of strings or objects, the step's result would be one of two calls' - "a + // value is merged from several branches" - and the delegate's throw() is not called (it throws at the + // yield, as before) + auto skipName = ".ys" + site; + auto resultName = ".yc" + site; + auto skipIdent = nf.createIdentifier(stows(skipName)); + auto handsThrow = delegateGenContext.yieldStarDelegate && !mth.ownsHeapMemory(loc(yieldExpressionAST), elementType) && + (delegateInfo->findField(builder.getStringAttr("throw")) || delegateInfo->findMethod("throw")); + if (handsThrow) + { + delegateGenContext.yieldStarResult = resultName.c_str(); + delegateGenContext.yieldStarSkipNext = skipName.c_str(); + } + // one step, in a block of its own: the local is given back where the block ends, before the yield auto step = [&](const char *localName, bool declaresResult) { auto localIdent = nf.createIdentifier(stows(localName + site)); @@ -5430,8 +5447,19 @@ class MLIRGenImpl loopStatements.push_back(declare( _v_ident, undefined, nf.createPropertyAccessExpression(resultIdent, nf.createIdentifier(S("value"))), NodeFlags::Const, false)); - loopStatements.push_back(nf.createExpressionStatement(_yield_expr)); - loopStatements.push_back(step(".ym", false)); + if (handsThrow) + { + loopStatements.push_back(declare(skipIdent, undefined, nf.createToken(SyntaxKind::FalseKeyword), NodeFlags::Let, false)); + loopStatements.push_back(nf.createExpressionStatement(_yield_expr)); + loopStatements.push_back(nf.createIfStatement( + nf.createPrefixUnaryExpression(nf.createToken(SyntaxKind::ExclamationToken), skipIdent), step(".ym", false), + undefined)); + } + else + { + loopStatements.push_back(nf.createExpressionStatement(_yield_expr)); + loopStatements.push_back(step(".ym", false)); + } NodeArray statements; statements.push_back(declare(delegateIdent, delegateOrUndefined(), yieldExpressionAST->expression, NodeFlags::Let, false)); diff --git a/tslang/test/tester/CMakeLists.txt b/tslang/test/tester/CMakeLists.txt index 719f1299b..8cae8de14 100644 --- a/tslang/test/tester/CMakeLists.txt +++ b/tslang/test/tester/CMakeLists.txt @@ -1422,6 +1422,8 @@ tslang_add_test(NAME test-compile-00-generic-arrow-through-generic COMMAND test- tslang_add_test(NAME test-jit-00-generator-yield-star-throw COMMAND test-runner -jit "${PROJECT_SOURCE_DIR}/test/tester/tests/00generator_yield_star_throw.ts") tslang_add_test(NAME test-jit-rc-00-generator-yield-star-throw COMMAND test-runner -jit -mm=rc "${PROJECT_SOURCE_DIR}/test/tester/tests/00generator_yield_star_throw.ts") tslang_add_test(NAME test-compile-00-generator-yield-star-throw COMMAND test-runner "${PROJECT_SOURCE_DIR}/test/tester/tests/00generator_yield_star_throw.ts") +tslang_add_test(NAME test-jit-own-00-generator-yield-star-throw COMMAND test-runner -jit -mm=own "${PROJECT_SOURCE_DIR}/test/tester/tests/00generator_yield_star_throw.ts") +tslang_add_test(NAME test-compile-own-00-generator-yield-star-throw COMMAND test-runner -mm=own "${PROJECT_SOURCE_DIR}/test/tester/tests/00generator_yield_star_throw.ts") tslang_add_test(NAME test-jit-00-own-union-shape-field-borrow COMMAND test-runner -jit "${PROJECT_SOURCE_DIR}/test/tester/tests/00own_union_shape_field_borrow.ts") tslang_add_test(NAME test-jit-rc-00-own-union-shape-field-borrow COMMAND test-runner -jit -mm=rc "${PROJECT_SOURCE_DIR}/test/tester/tests/00own_union_shape_field_borrow.ts") tslang_add_test(NAME test-jit-own-00-own-union-shape-field-borrow COMMAND test-runner -jit -mm=own "${PROJECT_SOURCE_DIR}/test/tester/tests/00own_union_shape_field_borrow.ts") diff --git a/tslang/test/tester/tests/00generic_arrow_through_generic.ts b/tslang/test/tester/tests/00generic_arrow_through_generic.ts index 7de6943a1..4a44458ad 100644 --- a/tslang/test/tester/tests/00generic_arrow_through_generic.ts +++ b/tslang/test/tester/tests/00generic_arrow_through_generic.ts @@ -29,5 +29,10 @@ function main() { assert(call2((n: number) => n + 1, 4) == 5, "call2"); assert(kept == 1, "kept"); + // parameters of different types: A is the tuple of them (TSLANG 184) + assert(call2((a: number, b: string) => b + a, 1, "x") == "x1", "call2 tuple"); + assert(call2((a: string, b: number, c: boolean) => c ? a + b : a, "n", 7, true) == "n7", "call2 three"); + assert(call({ x: (a: number, b: string) => b + a }, 2, "y") == "y2", "call tuple"); + print("done."); } From 86226cc2f05048c4b8e9617c4268821a795ca40c Mon Sep 17 00:00:00 2001 From: ASDAlexander77 Date: Tue, 24 Nov 2026 14:58:31 +0000 Subject: [PATCH 2/2] wasm: run 00generator_yield_star_throw.ts under own again (throw() at a yield* is handed to the delegate there now) Co-Authored-By: Claude Opus 5.5 --- tslang/test/wasm/wasm_skips.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/tslang/test/wasm/wasm_skips.txt b/tslang/test/wasm/wasm_skips.txt index 542778c05..9eb1e83b4 100644 --- a/tslang/test/wasm/wasm_skips.txt +++ b/tslang/test/wasm/wasm_skips.txt @@ -18,4 +18,3 @@ json.ts none # (default library) builds a 100000-character st 00global_interface_initializer.ts own # asserts "a field read" (native own: the same assert) 00let_without_initializer_owns.ts own # copies an `any` holding an object, which -mm=own refuses at run time by design (native own: the same assert) 00generator_yield_in_finally_values.ts own # a string or an object returned through a finally that yields, and a yield* of a Generator, are errors under -mm=own yet (TSLANG 153) -00generator_yield_star_throw.ts own # throw() at a yield* is not handed to the delegate under -mm=own yet: thrown at the yield (TSLANG 183, done in 184)