• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2024-2025 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "ast_verifier_test.h"
17 #include "ir/astNode.h"
18 #include "ir/expressions/callExpression.h"
19 #include "checker/ETSchecker.h"
20 #include "checker/types/signature.h"
21 #include "util/diagnosticEngine.h"
22 #include <gtest/gtest.h>
23 
24 using ark::es2panda::checker::SignatureFlags;
25 using ark::es2panda::compiler::ast_verifier::CheckAbstractMethod;
26 using ark::es2panda::ir::Identifier;
27 using ark::es2panda::ir::MemberExpression;
28 using ark::es2panda::ir::MemberExpressionKind;
29 using ark::es2panda::ir::SuperExpression;
30 
31 namespace {
32 
TEST_F(ASTVerifierTest,LabelsHaveReferences)33 TEST_F(ASTVerifierTest, LabelsHaveReferences)
34 {
35     ark::es2panda::util::DiagnosticEngine de;
36     ark::es2panda::checker::ETSChecker checker(de);
37 
38     char const *text = R"(
39         abstract class A {
40             abstract foo (): void
41             bar(): void {}
42         }
43 
44         class B extends A {
45             foo () {
46                 super.bar()
47             }
48         }
49     )";
50 
51     CONTEXT(ES2PANDA_STATE_CHECKED, text)
52     {
53         // Setup call to abstract method via super
54         GetAst()->IterateRecursively([&checker, this](ark::es2panda::ir::AstNode *child) {
55             if (child->IsCallExpression()) {
56                 auto *const call = child->AsCallExpression();
57                 auto *super = checker.AllocNode<SuperExpression>();
58                 auto *id = checker.AllocNode<Identifier>("foo", Allocator());
59 
60                 auto *callee =
61                     checker.AllocNode<MemberExpression>(super, id, MemberExpressionKind::PROPERTY_ACCESS, false, false);
62                 call->SetCallee(callee);
63 
64                 // For testing just copy signature from original callee and add abstract flag
65                 auto *const signature = call->Signature();
66                 signature->AddSignatureFlag(SignatureFlags::ABSTRACT);
67                 call->SetSignature(signature);
68             }
69         });
70 
71         EXPECT_TRUE(Verify<CheckAbstractMethod>(ExpectVerifierMessage {"CALL TO ABSTRACT METHOD VIA SUPER"}));
72     }
73 }
74 
75 }  // namespace
76