diff --git a/ets2panda/parser/statementParser.cpp b/ets2panda/parser/statementParser.cpp index 86f766bedcc0252c8688b7a7fe7be0a5365f29d7..81e2951a86a6a82626ca328725dbf7ae47eeed54 100644 --- a/ets2panda/parser/statementParser.cpp +++ b/ets2panda/parser/statementParser.cpp @@ -167,6 +167,10 @@ ir::Statement *ParserImpl::ParseStatementBasedOnTokenType(StatementParsingFlags switch (lexer_->GetToken().Type()) { case lexer::TokenType::KEYW_EXPORT: return ParseExportDeclaration(flags); + case lexer::TokenType::KEYW_EXTENDS: + LogError(diagnostic::ERROR_ARKTS_NO_CONDITIONAL_TYPES); + lexer_->NextToken(); + return nullptr; case lexer::TokenType::KEYW_IMPORT: return ParseImportDeclaration(flags); case lexer::TokenType::KEYW_FUNCTION: diff --git a/ets2panda/test/ast/compiler/ets/conditional-type-alias.ets b/ets2panda/test/ast/compiler/ets/conditional-type-alias.ets new file mode 100644 index 0000000000000000000000000000000000000000..095f6a96801035f8cdcf40f85bda0babea4b5789 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/conditional-type-alias.ets @@ -0,0 +1,22 @@ +/* + * 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. + */ + +// (arkts-no-conditional-types) +type X = T extends number ? T : string + +/* @@? 17:15 Error TypeError: Conditional type aliases are not supported. Introduce a new type with constraints explicitly, or rewrite logic using Object! */ +/* @@? 17:23 Error TypeError: Type name 'number' used in the wrong context */ +/* @@? 17:32 Error TypeError: TypeError: Unresolved reference T */ +/* @@? 17:36 Error TypeError: Type name 'string' used in the wrong context */ diff --git a/ets2panda/util/diagnostic/semantic.yaml b/ets2panda/util/diagnostic/semantic.yaml index 568a3b73128a4625368f0bb392f21c0762ebe352..8285f973c362f9c063efe7cd827448ab2f7aba9c 100644 --- a/ets2panda/util/diagnostic/semantic.yaml +++ b/ets2panda/util/diagnostic/semantic.yaml @@ -1496,5 +1496,9 @@ semantic: message: "Class field '{}' defined by the parent class is not accessible in the child class via super." - name: INTERFACE_EXTENDS_CLASS - id: 373 + id: 378 message: "Interfaces cannot extend classes, only other interfaces." + +- name: ERROR_ARKTS_NO_CONDITIONAL_TYPES + id: 379 + message: "Conditional type aliases are not supported. Introduce a new type with constraints explicitly, or rewrite logic using Object!" \ No newline at end of file