diff --git a/ets2panda/parser/ETSparserTypes.cpp b/ets2panda/parser/ETSparserTypes.cpp index 3b0f7ea5c60e8a962119fdce247fe75a2dd3113c..de8a5133adcabd87623c4eb36170463cc196eb64 100644 --- a/ets2panda/parser/ETSparserTypes.cpp +++ b/ets2panda/parser/ETSparserTypes.cpp @@ -527,6 +527,13 @@ ir::TypeNode *ETSParser::ParseTypeAnnotationNoPreferParam(TypeAnnotationParsingO return nullptr; } + if (((*options) & TypeAnnotationParsingOptions::DISALLOW_UNION) == 0 && + Lexer()->TryEatTokenType(lexer::TokenType::PUNCTUATOR_BITWISE_AND)) { + LogError(diagnostic::INTERSECTION_TYPES); + Lexer()->TryEatTokenType(lexer::TokenType::LITERAL_IDENT); + return AllocBrokenType({Lexer()->GetToken().Start(), Lexer()->GetToken().End()}); + } + if (!needFurtherProcessing) { return typeAnnotation; } diff --git a/ets2panda/test/ast/compiler/ets/utility_type_can_not_found_etsobjecttype.ets b/ets2panda/test/ast/compiler/ets/utility_type_can_not_found_etsobjecttype.ets index f549a860b8ab50e6349d41dcc5729825bdb46024..b9f46988413f3bca9c3e785586e2921143383390 100644 --- a/ets2panda/test/ast/compiler/ets/utility_type_can_not_found_etsobjecttype.ets +++ b/ets2panda/test/ast/compiler/ets/utility_type_can_not_found_etsobjecttype.ets @@ -25,5 +25,5 @@ class X { } } -/* @@? 16:34 Error TypeError: Cannot find type 'any'. */ +/* @@? 16:34 Error SyntaxError: 'any' and 'unknown' types are not supported. Specify types explicitly. */ /* @@? 23:14 Error TypeError: Target type for class composite needs to be an object type, found 'T' */ \ No newline at end of file diff --git a/ets2panda/test/ast/parser/ets/constructor_type_inference_crash.ets b/ets2panda/test/ast/parser/ets/constructor_type_inference_crash.ets index d31d7c3e7a9b63085039b91a46b9988c1aaa4024..278b4d106f0dba2e8cf386378a4b82b39125731f 100644 --- a/ets2panda/test/ast/parser/ets/constructor_type_inference_crash.ets +++ b/ets2panda/test/ast/parser/ets/constructor_type_inference_crash.ets @@ -22,6 +22,6 @@ let c = new C(10, 'foo'); /* @@? 17:14 Error TypeError: Only abstract or native methods can't have body. */ /* @@? 19:3 Error TypeError: No matching call signature for constructor */ -/* @@? 19:19 Error TypeError: Cannot find type 'any'. */ -/* @@? 19:28 Error TypeError: Cannot find type 'any'. */ +/* @@? 19:19 Error SyntaxError: 'any' and 'unknown' types are not supported. Specify types explicitly. */ +/* @@? 19:28 Error SyntaxError: 'any' and 'unknown' types are not supported. Specify types explicitly. */ diff --git a/ets2panda/test/ast/parser/ets/intersection_types.ets b/ets2panda/test/ast/parser/ets/intersection_types.ets new file mode 100644 index 0000000000000000000000000000000000000000..8b7cdb919c87bc4a25acac934401a32628531162 --- /dev/null +++ b/ets2panda/test/ast/parser/ets/intersection_types.ets @@ -0,0 +1,28 @@ +/* + * 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://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + */ + +interface Identity { + id: number + name: string +} + +interface Contact { + email: string + phoneNumber: string +} + +type Employee = Identity & Contact + +/* @@? 26:28 Error SyntaxError: Intersection types are not supported, use inheritance instead! */ \ No newline at end of file diff --git a/ets2panda/test/ast/parser/ets/recursive_exported_structure.ets b/ets2panda/test/ast/parser/ets/recursive_exported_structure.ets index 90fd2ccf79feb2a813546efb8a3f8747385cac3b..a7c30be7f8806f4007c06f53ffc914594b7c00eb 100644 --- a/ets2panda/test/ast/parser/ets/recursive_exported_structure.ets +++ b/ets2panda/test/ast/parser/ets/recursive_exported_structure.ets @@ -93,10 +93,9 @@ export default _exported; /* @@? 41:23 Error TypeError: need to specify target type for class composite */ /* @@? 54:20 Error TypeError: No matching call signature for (...) */ /* @@? 54:31 Error TypeError: need to specify target type for class composite */ -/* @@? 61:64 Error SyntaxError: Unexpected token '&'. */ -/* @@? 61:66 Error SyntaxError: Unexpected token '{'. */ +/* @@? 61:66 Error SyntaxError: Intersection types are not supported, use inheritance instead! */ /* @@? 62:12 Error SyntaxError: Label must be followed by a loop statement. */ /* @@? 62:12 Error TypeError: Type name 'IndexableType' used in the wrong context */ -/* @@? 66:36 Error TypeError: Interfaces cannot extend classes, only other interfaces. */ +/* @@? 66:36 Error TypeError: Interface expected here. */ /* @@? 73:6 Error TypeError: Indexed signatures are not allowed. Use arrays instead! */ -/* @@? 76:16 Error TypeError: Cannot cast type 'ExportedStructure' to 'Record Double|Record Double>>' */ +/* @@? 85:1 Error TypeError: Indexed access is not supported for such expression type. */ diff --git a/ets2panda/test/ast/parser/ets/typenode_clone_brokentype.ets b/ets2panda/test/ast/parser/ets/typenode_clone_brokentype.ets index f955112a64a8c9d36e78da0b629073b7b607e670..2d27ad2f7e6c2b05373a912ffe8ec45587a42939 100644 --- a/ets2panda/test/ast/parser/ets/typenode_clone_brokentype.ets +++ b/ets2panda/test/ast/parser/ets/typenode_clone_brokentype.ets @@ -55,5 +55,5 @@ declare const broken2: AnotherBroken; /* @@? 32:12 Error SyntaxError: Label must be followed by a loop statement. */ /* @@? 32:12 Error TypeError: Object type doesn't have proper index access method. */ /* @@? 36:27 Error TypeError: Cannot find type 'UndefinedInterface'. */ -/* @@? 39:35 Error TypeError: Cannot find type 'any'. */ -/* @@? 40:38 Error TypeError: Cannot find type 'any'. */ \ No newline at end of file +/* @@? 39:35 Error SyntaxError: 'any' and 'unknown' types are not supported. Specify types explicitly. */ +/* @@? 40:38 Error SyntaxError: 'any' and 'unknown' types are not supported. Specify types explicitly. */ \ No newline at end of file diff --git a/ets2panda/util/diagnostic/syntax.yaml b/ets2panda/util/diagnostic/syntax.yaml index 6e77a84dfedf7564e99c2a38da49f4d57110205d..da1a051e042e8c71e3579a9bed56a6ca3213d0cc 100644 --- a/ets2panda/util/diagnostic/syntax.yaml +++ b/ets2panda/util/diagnostic/syntax.yaml @@ -57,6 +57,10 @@ syntax: id: 28 message: "Annotations are not allowed on this type of declaration." +- name: ANY_UNKNOWN_TYPES + id: 102460 + message: "'any' and 'unknown' types are not supported. Specify types explicitly." + - name: ASSIGN_TO_ARGS_INVALID id: 57 message: "Assigning to 'arguments' in strict mode is invalid." @@ -497,6 +501,10 @@ syntax: id: 180 message: "Interface member initialization is prohibited." +- name: INTERSECTION_TYPES + id: 145527 + message: "Intersection types are not supported, use inheritance instead!" + - name: INVALIDE_CHAR_CLASS id: 79 message: "Invalid character class." diff --git a/ets2panda/varbinder/ETSBinder.cpp b/ets2panda/varbinder/ETSBinder.cpp index d9cb8a738b58cf826eb18c5ba84b4faf0ce3071d..e6e90b20b617d7a5a5e8ab20de6d9123fec5e58e 100644 --- a/ets2panda/varbinder/ETSBinder.cpp +++ b/ets2panda/varbinder/ETSBinder.cpp @@ -62,6 +62,15 @@ static bool IsSpecialName(const util::StringView &name) name == compiler::Signatures::FIXED_ARRAY_TYPE_NAME; } +static bool IsAnyOrUnknown(ETSBinder *binder, const util::StringView &name, const lexer::SourcePosition &pos) +{ + if (name.Is("any") || name.Is("unknown")) { + binder->ThrowError(pos, diagnostic::ANY_UNKNOWN_TYPES); + return true; + } + return false; +} + bool ETSBinder::LookupInDebugInfoPlugin(ir::Identifier *ident) { auto *checker = GetContext()->GetChecker()->AsETSChecker(); @@ -101,7 +110,7 @@ void ETSBinder::LookupTypeReference(ir::Identifier *ident) return; } - if (ident->IsErrorPlaceHolder()) { + if (ident->IsErrorPlaceHolder() || IsAnyOrUnknown(this, name, ident->Start())) { CreateDummyVariable(this, ident); return; }