diff --git a/ets2panda/ir/ts/tsThisType.cpp b/ets2panda/ir/ts/tsThisType.cpp index 1b49be750598aaeeaa48516938fc0b61b1dff07e..5c3da9bd3e679b040d820a24b8e4ba391c6369a9 100644 --- a/ets2panda/ir/ts/tsThisType.cpp +++ b/ets2panda/ir/ts/tsThisType.cpp @@ -70,7 +70,11 @@ checker::VerifiedType TSThisType::Check([[maybe_unused]] checker::ETSChecker *ch checker::Type *TSThisType::GetType([[maybe_unused]] checker::ETSChecker *checker) { - return checker->Context().ContainingClass(); + auto *containingClass = checker->Context().ContainingClass(); + if (containingClass == nullptr) { + return checker->GlobalTypeError(); + } + return containingClass; } TSThisType *TSThisType::Clone(ArenaAllocator *const allocator, AstNode *const parent) diff --git a/ets2panda/test/ast/compiler/ets/getType.ets b/ets2panda/test/ast/compiler/ets/getType.ets new file mode 100644 index 0000000000000000000000000000000000000000..aee120c32a1fefaf602b94ac1517d558c1505785 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/getType.ets @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http: * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +declare type type_tuple_union = [string, boolean, number] | (this.mnum === other.mnum && this.mden === other.mden +)[] + +/* @@? 15:62 Error SyntaxError: A 'this' type is available only as return type in a non-static method of a class or struct and extension functions. */ +/* @@? 15:66 Error SyntaxError: Unexpected token, expected ')'. */ +/* @@? 15:67 Error TypeError: Unresolved reference mnum */ +/* @@? 15:76 Error TypeError: Unresolved reference other */ +/* @@? 15:90 Error TypeError: Cannot reference 'this' in this context. */ +/* @@? 15:95 Error TypeError: Property 'mden' does not exist on type 'Error' */ +/* @@? 16:1 Error SyntaxError: Unexpected token ')'. */ +/* @@? 16:1 Error TypeError: Indexed access is not supported for such expression type. */ +/* @@? 16:3 Error SyntaxError: Unexpected token ']'. */ +/* @@? 27:67 Error SyntaxError: Unexpected token, expected ']'. */ \ No newline at end of file