diff --git a/ets2panda/checker/ets/object.cpp b/ets2panda/checker/ets/object.cpp index ce34a1924ac2dc50a43986af0cd206303170f074..1649138262b54c8c8462130c35a4ea3919216d61 100644 --- a/ets2panda/checker/ets/object.cpp +++ b/ets2panda/checker/ets/object.cpp @@ -187,6 +187,10 @@ bool ETSChecker::ComputeSuperType(ETSObjectType *type) void ETSChecker::ValidateImplementedInterface(ETSObjectType *type, Type *interface, std::unordered_set *extendsSet, const lexer::SourcePosition &pos) { + if (interface->IsETSObjectType() && interface->AsETSObjectType()->HasObjectFlag(ETSObjectFlags::CLASS)) { + LogError(diagnostic::INTERFACE_EXTENDS_CLASS, {}, pos); + return; + } if (!interface->IsETSObjectType() || !interface->AsETSObjectType()->HasObjectFlag(ETSObjectFlags::INTERFACE)) { LogError(diagnostic::NOT_INTERFACE, {}, pos); return; diff --git a/ets2panda/parser/ETSparser.cpp b/ets2panda/parser/ETSparser.cpp index 36001a7946a083e80444d63fcd2b0a9da50d1cb3..9a591d8e19727b8d723a76ada9a00722ac42e7cf 100644 --- a/ets2panda/parser/ETSparser.cpp +++ b/ets2panda/parser/ETSparser.cpp @@ -1191,6 +1191,10 @@ ir::ETSImportDeclaration *ETSParser::ParseImportPathBuildImport(ArenaVector(GetContext().GetProgram()), importFlags); importDeclaration->SetRange({startLoc, importPathStringLiteral->End()}); + if (Lexer()->GetToken().Ident().Is("assert")) { + LogError(diagnostic::ERROR_ARKTS_NO_IMPORT_ASSERTIONS); + return importDeclaration; + } ConsumeSemicolon(importDeclaration); return importDeclaration; } @@ -1494,6 +1498,10 @@ ir::AstNode *ETSParser::ParseImportDefaultSpecifier(ArenaVector * } } + if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_SUBSTITUTION) { + LogError(diagnostic::ERROR_ARKTS_NO_REQUIRE); + return nullptr; + } if (Lexer()->GetToken().KeywordType() != lexer::TokenType::KEYW_FROM) { LogExpectedToken(lexer::TokenType::KEYW_FROM); Lexer()->NextToken(); // eat 'from' diff --git a/ets2panda/test/ast/parser/ets/import_assertion.ets b/ets2panda/test/ast/parser/ets/import_assertion.ets new file mode 100644 index 0000000000000000000000000000000000000000..bbf4ed4a28bea17c89c9a37aa2acf3f6143bb3bc --- /dev/null +++ b/ets2panda/test/ast/parser/ets/import_assertion.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. + */ + +import * as Pt from "mod" /* @@ label1 */assert /* @@ label2 */{ type: /* @@ label3 */"json" } + + +/* @@@ label1 Error SyntaxError: Import assertion is not supported, please use the ordinary import syntax instead! */ +/* @@@ label1 Error TypeError: Unresolved reference assert */ +/* @@@ label2 Error SyntaxError: Unexpected token '{'. */ +/* @@@ label3 Error SyntaxError: Label must be followed by a loop statement. */ diff --git a/ets2panda/test/ast/parser/ets/import_require.ets b/ets2panda/test/ast/parser/ets/import_require.ets new file mode 100644 index 0000000000000000000000000000000000000000..ad8766f57b15aa3ff127e8aa45c4e8fd08d393da --- /dev/null +++ b/ets2panda/test/ast/parser/ets/import_require.ets @@ -0,0 +1,21 @@ +/* + * 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. + */ + +import m /* @@ label1 */= /* @@ label2 */require("mod") + +/* @@@ label1 Error SyntaxError: Importing by 'require' and 'import' assignment is not supported, use 'import * as ... from ...' form instead! */ +/* @@@ label1 Error SyntaxError: Unexpected token '='. */ +/* @@@ label2 Error SyntaxError: Unexpected token 'require'. */ +/* @@@ label2 Error TypeError: Unresolved reference require */ diff --git a/ets2panda/test/ast/parser/ets/interface_extends_class.ets b/ets2panda/test/ast/parser/ets/interface_extends_class.ets new file mode 100644 index 0000000000000000000000000000000000000000..6e88716f0c466a20fc1b95f31c4989e730b5f135 --- /dev/null +++ b/ets2panda/test/ast/parser/ets/interface_extends_class.ets @@ -0,0 +1,20 @@ +/* + * 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. + */ + +class A {} + +interface BInterface extends /* @@ label */A {} + +/* @@@ label Error TypeError: Interfaces cannot extend classes, only other interfaces. */ diff --git a/ets2panda/util/diagnostic/semantic.yaml b/ets2panda/util/diagnostic/semantic.yaml index 95946196dcd9c41687bd58f1e23189202269ff12..568a3b73128a4625368f0bb392f21c0762ebe352 100644 --- a/ets2panda/util/diagnostic/semantic.yaml +++ b/ets2panda/util/diagnostic/semantic.yaml @@ -1494,3 +1494,7 @@ semantic: - name: SUPER_NOT_ACCESSIBLE id: 377 message: "Class field '{}' defined by the parent class is not accessible in the child class via super." + +- name: INTERFACE_EXTENDS_CLASS + id: 373 + message: "Interfaces cannot extend classes, only other interfaces." diff --git a/ets2panda/util/diagnostic/syntax.yaml b/ets2panda/util/diagnostic/syntax.yaml index c6a4d4e840a101aa96537ea7ba4f7beb758cd1b5..524f1a311296371a716d0a660fab0577238e9c68 100644 --- a/ets2panda/util/diagnostic/syntax.yaml +++ b/ets2panda/util/diagnostic/syntax.yaml @@ -1243,3 +1243,11 @@ syntax: - name: ERROR_ARKTS_NO_AMBIENT_DECLS id: 308 message: "Ambient module declaration is not supported!" + +- name: ERROR_ARKTS_NO_REQUIRE + id: 309 + message: "Importing by 'require' and 'import' assignment is not supported, use 'import * as ... from ...' form instead!" + +- name: ERROR_ARKTS_NO_IMPORT_ASSERTIONS + id: 310 + message: "Import assertion is not supported, please use the ordinary import syntax instead!"