diff --git a/ets2panda/checker/ets/function.cpp b/ets2panda/checker/ets/function.cpp index 3bd487e0e0c49e4cbb19fb618c436ae6f6c307dd..de7b02378d9803479484e8d37ef553836b3bf63c 100644 --- a/ets2panda/checker/ets/function.cpp +++ b/ets2panda/checker/ets/function.cpp @@ -27,6 +27,7 @@ #include "checker/types/ets/etsObjectType.h" #include "checker/types/ets/etsPartialTypeParameter.h" #include "checker/types/gradualType.h" +#include "checker/types/typeError.h" #include "compiler/lowering/scopesInit/scopesInitPhase.h" #include "ir/base/catchClause.h" #include "ir/base/classDefinition.h" @@ -528,6 +529,7 @@ bool ETSChecker::ValidateSignatureRequiredParams(Signature *substitutedSig, // Note: If the signatures are from lambdas, then they have no `Function`. ir::ScriptFunction *const lambda = argument->AsArrowFunctionExpression()->Function(); auto targetParm = substitutedSig->GetSignatureInfo()->params[index]->Declaration()->Node(); + ERROR_SANITY_CHECK(this, targetParm->IsETSParameterExpression(), return false); if (CheckLambdaAssignable(targetParm->AsETSParameterExpression(), lambda)) { continue; } diff --git a/ets2panda/checker/ets/helpers.cpp b/ets2panda/checker/ets/helpers.cpp index 535a1adc4054046cf7763dad920e3ad694939845..be4b57afdab82ce7914cf4dc4a923446b932f901 100644 --- a/ets2panda/checker/ets/helpers.cpp +++ b/ets2panda/checker/ets/helpers.cpp @@ -1854,7 +1854,8 @@ Type *ETSChecker::ResolveReferencedType(varbinder::LocalVariable *refVar, const case ir::AstNodeType::CLASS_DECLARATION: case ir::AstNodeType::STRUCT_DECLARATION: case ir::AstNodeType::CLASS_DEFINITION: - if (refVar->Declaration()->Node()->AsClassDefinition()->IsNamespaceTransformed()) { + if (refVar->Declaration()->Node()->IsClassDefinition() && + refVar->Declaration()->Node()->AsClassDefinition()->IsNamespaceTransformed()) { LogError(diagnostic::NAMESPACE_AS_TYPE, {refVar->Name()}, name->Start()); return GlobalTypeError(); } diff --git a/ets2panda/test/ast/compiler/ets/resolve_class_declaration.ets b/ets2panda/test/ast/compiler/ets/resolve_class_declaration.ets new file mode 100644 index 0000000000000000000000000000000000000000..97180f8bebc508b8226952cec153081ad05e92cc --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/resolve_class_declaration.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 I { + b5 : number;r_2.ETSGLOBAL::hot_catc { + return; +} + +/* @@? 17:20 Error SyntaxError: Interface fields must have type annotation. */ +/* @@? 17:30 Error SyntaxError: Unexpected token, expected ','. */ +/* @@? 17:30 Error SyntaxError: Unexpected token, expected 'private' or identifier. */ +/* @@? 17:31 Error SyntaxError: Identifier expected. */ +/* @@? 17:31 Error SyntaxError: Unexpected token, expected ','. */ +/* @@? 17:31 Error SyntaxError: Unexpected token, expected 'private' or identifier. */ +/* @@? 17:41 Error SyntaxError: Interface fields must have type annotation. */ +/* @@? 18:5 Error SyntaxError: Invalid Type. */ diff --git a/ets2panda/test/ast/compiler/ets/signature_param.ets b/ets2panda/test/ast/compiler/ets/signature_param.ets new file mode 100644 index 0000000000000000000000000000000000000000..9c758d79536dcf8a7666d2b41a8b87d601229938 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/signature_param.ets @@ -0,0 +1,48 @@ +/* + * 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. + */ + +function foo1(f: () => void) { + try { + + } catch (e) { + arktest.assertTrue(false, "expected} +} + +class A {} + +function foo2(let f = ((x:A {} + +function foo3() { + foo2(() => {}}); + foo2(() => {}); +} + +/* @@? 20:35 Error SyntaxError: Newline is not allowed in strings */ +/* @@? 20:45 Error SyntaxError: Unexpected token, expected ',' or ')'. */ +/* @@? 22:1 Error SyntaxError: Illegal start of CLASS expression. */ +/* @@? 24:1 Error SyntaxError: Unexpected token, expected ')'. */ +/* @@? 24:1 Error SyntaxError: Unexpected token '{'. */ +/* @@? 24:1 Error SyntaxError: Unexpected token, expected ')'. */ +/* @@? 24:1 Error SyntaxError: Expected '{', got 'let'. */ +/* @@? 24:1 Error SyntaxError: Unexpected token, expected ',' or ')'. */ +/* @@? 24:1 Error SyntaxError: Parameter declaration should have an explicit type annotation. */ +/* @@? 24:1 Error SyntaxError: Unexpected token, expected an identifier. */ +/* @@? 24:1 Error SyntaxError: Nested functions are not allowed. */ +/* @@? 24:1 Error TypeError: Variable 'f' has already been declared. */ +/* @@? 24:1 Error TypeError: Unresolved reference x */ +/* @@? 26:1 Error SyntaxError: Nested functions are not allowed. */ +/* @@? 27:18 Error SyntaxError: Unexpected token, expected ',' or ')'. */ +/* @@? 27:18 Error SyntaxError: Unexpected token ')'. */ +/* @@? 28:21 Error TypeError: Unresolved reference foo2 */