1 /*
2 * Copyright (c) 2021 - 2024 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 "checker/typeChecker/TypeChecker.h"
17
18 namespace ark::es2panda::checker {
19
VisitArrowFunctionExpression(ir::ArrowFunctionExpression * node)20 void ETSTypeChecker::VisitArrowFunctionExpression(ir::ArrowFunctionExpression *node)
21 {
22 Iterate(node);
23 if (!node->TsType()->IsETSObjectType()) {
24 LogTypeError({"Cannot infer arrow function type from context for type: '", node->TsType(),
25 "', consider adding type explicitly"},
26 node->Start());
27 }
28 }
29
RunTypeChecker(Checker * checker,ScriptExtension ext,ir::AstNode * node)30 bool RunTypeChecker(Checker *checker, ScriptExtension ext, ir::AstNode *node)
31 {
32 switch (ext) {
33 case ScriptExtension::ETS:
34 return ETSTypeChecker(checker).Check(node);
35 case ScriptExtension::JS:
36 return JSTypeChecker(checker).Check(node);
37 case ScriptExtension::TS:
38 return TSTypeChecker(checker).Check(node);
39 case ScriptExtension::AS:
40 return ASTypeChecker(checker).Check(node);
41 default:
42 UNREACHABLE();
43 }
44 }
45
46 } // namespace ark::es2panda::checker
47