Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions tslang/lib/TypeScript/MLIRGenAccessCall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1892,6 +1892,11 @@ namespace mlirgen
return 3;
}

// an optional parameter (`count: int = 0`) takes what it holds as well as that: scored as
// optional<si32>, an int fitted only by conversion, and `new Array<int>(10)` went to
// `(...args: T[])` declared after `(count: int)`
paramType = mth.stripOptionalType(paramType);

auto literalType = dyn_cast<mlir_ts::LiteralType>(argType);
auto baseType = literalType ? literalType.getElementType() : argType;
// `number` is a C `double`, as f64 is
Expand Down
20 changes: 20 additions & 0 deletions tslang/test/tester/tests/00class_constructor_overloads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,27 @@ class B {
}
}

// an optional parameter fits as the type it holds: `(count: int = 0)` takes an int as well as the
// rest parameter's elements do, and declared first it wins (it was scored as optional<int>, by
// conversion, and `new C<int>(10)` went to `(...args: T[])`)
class C<T> {
n = 0;

constructor(count: int = 0) {
this.n = count;
}

constructor(...args: T[]) {
this.n = -args.length;
}
}

function main() {
const c1 = new C<int>(10);
const c3 = new C<int>(1, 2, 3);
assert(c1.n == 10);
assert(c3.n == -3);

const a0 = new A<int>();
const a1 = new A<int>(10);
const a2 = new A<int>([1, 2]);
Expand Down
Loading