diff --git a/tslang/include/TypeScript/MLIRLogic/MLIRTypeHelper.h b/tslang/include/TypeScript/MLIRLogic/MLIRTypeHelper.h index 7308f4d9..c961c989 100644 --- a/tslang/include/TypeScript/MLIRLogic/MLIRTypeHelper.h +++ b/tslang/include/TypeScript/MLIRLogic/MLIRTypeHelper.h @@ -2333,7 +2333,27 @@ class MLIRTypeHelper } return tupleType.getFieldInfo(index).type; - } + } + + if (auto objectStorageType = dyn_cast(srcType)) + { + auto index = objectStorageType.getIndex(fieldName); + if (index < 0) + { + return mlir::Type(); + } + + return objectStorageType.getFieldInfo(index).type; + } + + // a generator/boxed-object return type (e.g. `function*`'s BoxAsObject + // wrapper) is not itself a tuple - unwrap to its underlying storage type + // (TupleType/ConstTupleType/ObjectStorageType) so structural constraint + // matching (e.g. `TIter extends { next(): ... }`) can see its fields. + if (auto objectType = dyn_cast(srcType)) + { + return getFieldTypeByFieldName(objectType.getStorageType(), fieldName); + } if (auto srcInterfaceType = dyn_cast(srcType)) { @@ -2489,9 +2509,22 @@ class MLIRTypeHelper auto extIsVarArgs = getVarArgFromFuncRef(extendType); auto srcReturnType = getReturnTypeFromFuncRef(srcType); - auto extReturnType = getReturnTypeFromFuncRef(extendType); + auto extReturnType = getReturnTypeFromFuncRef(extendType); + + // when srcType's leading (bound `this`) param is being skipped, the + // constraint's own leading `this` placeholder (an OpaqueType standing + // in for "any this type", e.g. a method-shaped generic constraint like + // `{ next(): ... }`) must be skipped in lockstep - otherwise the two + // param lists go out of alignment by one and every real param after it + // is compared against the wrong slot (or a null past the end). + auto skipExtParams = skipSrcParams > 0 && !extParams.empty() && mlir::isa(extParams.front()) + ? 1 : 0; + if (skipExtParams) + { + extParams = extParams.drop_front(skipExtParams); + } - return extendsTypeFuncTypes(location, srcParams, extParams, extIsVarArgs, srcReturnType, extReturnType, typeParamsWithArgs, skipSrcParams); + return extendsTypeFuncTypes(location, srcParams, extParams, extIsVarArgs, srcReturnType, extReturnType, typeParamsWithArgs, skipSrcParams); } ExtendsResult extendsTypeFuncTypes(mlir::Location location, ArrayRef srcParams, ArrayRef extParams, bool extIsVarArgs,