Skip to content

Commit 5adcced

Browse files
added test
1 parent b200154 commit 5adcced

File tree

3 files changed

+79
-0
lines changed

3 files changed

+79
-0
lines changed

tsc/lib/TypeScript/LowerToLLVM.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4648,6 +4648,27 @@ static void populateTypeScriptConversionPatterns(LLVMTypeConverter &converter, m
46484648
return llvmPtrType;
46494649
});
46504650

4651+
converter.addConversion([&](mlir_ts::ConstructFunctionType type) {
4652+
SmallVector<mlir::Type> convertedInputs;
4653+
for (auto subType : type.getInputs())
4654+
{
4655+
convertedInputs.push_back(converter.convertType(subType));
4656+
}
4657+
4658+
SmallVector<mlir::Type> convertedResults;
4659+
for (auto subType : type.getResults())
4660+
{
4661+
convertedResults.push_back(converter.convertType(subType));
4662+
}
4663+
4664+
auto funcType = mlir::FunctionType::get(type.getContext(), convertedInputs, convertedResults);
4665+
4666+
LLVMTypeConverter::SignatureConversion result(convertedInputs.size());
4667+
auto llvmFuncType = converter.convertFunctionSignature(funcType, false, result);
4668+
auto llvmPtrType = LLVM::LLVMPointerType::get(llvmFuncType);
4669+
return llvmPtrType;
4670+
});
4671+
46514672
converter.addConversion([&](mlir_ts::BoundFunctionType type) {
46524673
SmallVector<mlir::Type> convertedInputs;
46534674
for (auto subType : type.getInputs())

tsc/test/tester/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,7 @@ add_test(NAME test-compile-callWithSpread COMMAND test-runner "${PROJECT_SOURCE_
334334
add_test(NAME test-compile-newWithSpread COMMAND test-runner "${PROJECT_SOURCE_DIR}/test/tester/tests/newWithSpread.ts")
335335
add_test(NAME test-compile-typeGuardOfFormThisMember COMMAND test-runner "${PROJECT_SOURCE_DIR}/test/tester/tests/typeGuardOfFormThisMember.ts")
336336
add_test(NAME test-compile-typeGuardOfFormTypeOfBoolean COMMAND test-runner "${PROJECT_SOURCE_DIR}/test/tester/tests/typeGuardOfFormTypeOfBoolean.ts")
337+
add_test(NAME test-compile-thisTypeInClasses COMMAND test-runner "${PROJECT_SOURCE_DIR}/test/tester/tests/thisTypeInClasses.ts")
337338

338339
add_test(NAME test-jit-00-print COMMAND test-runner -jit "${PROJECT_SOURCE_DIR}/test/tester/tests/00print.ts")
339340
add_test(NAME test-jit-00-assert COMMAND test-runner -jit "${PROJECT_SOURCE_DIR}/test/tester/tests/00assert.ts")
@@ -588,3 +589,4 @@ add_test(NAME test-jit-callWithSpread COMMAND test-runner -jit "${PROJECT_SOURCE
588589
add_test(NAME test-jit-newWithSpread COMMAND test-runner -jit "${PROJECT_SOURCE_DIR}/test/tester/tests/newWithSpread.ts")
589590
add_test(NAME test-jit-typeGuardOfFormThisMember COMMAND test-runner -jit "${PROJECT_SOURCE_DIR}/test/tester/tests/typeGuardOfFormThisMember.ts")
590591
add_test(NAME test-jit-typeGuardOfFormTypeOfBoolean COMMAND test-runner -jit "${PROJECT_SOURCE_DIR}/test/tester/tests/typeGuardOfFormTypeOfBoolean.ts")
592+
add_test(NAME test-jit-thisTypeInClasses COMMAND test-runner -jit "${PROJECT_SOURCE_DIR}/test/tester/tests/thisTypeInClasses.ts")
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
class C1 {
2+
x: this;
3+
f(x: this): this { return undefined; }
4+
}
5+
6+
class C2 {
7+
[x: string]: this;
8+
}
9+
10+
interface Foo<T> {
11+
x: T;
12+
y: this;
13+
}
14+
15+
class Date {}
16+
17+
class C3 {
18+
a: this[];
19+
b: [this, this];
20+
c: this | Date;
21+
// TODO: intersection
22+
//d: this & Date;
23+
e: (((this)));
24+
f: (x: this) => this;
25+
g: new (x: this) => this;
26+
h: Foo<this>;
27+
i: Foo<this | (() => this)>;
28+
j: (x: any) => x is this;
29+
}
30+
31+
declare class C4 {
32+
x: this;
33+
f(x: this): this;
34+
}
35+
36+
class C5 {
37+
foo() {
38+
let f1 = (x: this): this => this;
39+
let f2 = (x: this) => this;
40+
let f3 = (x: this) => (y: this) => this;
41+
let f4 = (x: this) => {
42+
let g = (y: this) => {
43+
return () => this;
44+
}
45+
return g(this);
46+
}
47+
}
48+
bar() {
49+
let x1 = <this>undefined;
50+
let x2 = undefined as this;
51+
}
52+
}
53+
54+
function main() {
55+
print("done.");
56+
}

0 commit comments

Comments
 (0)