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 "etsExtensionFuncHelperType.h"
17
18 #include "etsFunctionType.h"
19
20 namespace ark::es2panda::checker {
21 /*
22 !NB etsExtensionFuncHelperType is to support function with receiver(extension function)
23 when we try to resolve a member expression like "a.b", there are different cases:
24 1. there is a method or prop whose name is "b" in class A
25 2. there is an instance extension of class A, function b(this:A) {}
26 3. both 1 and 2 existed
27 in order to figure out a representation for case 3, we need the etsExtensionFuncHelperType
28 */
29
ToString(std::stringstream & ss,bool precise) const30 void ETSExtensionFuncHelperType::ToString(std::stringstream &ss, bool precise) const
31 {
32 classMethodType_->ToString(ss, precise);
33 ss << " | ";
34 extensionFunctionType_->ToString(ss, precise);
35 }
36
AssignmentTarget(TypeRelation * relation,Type * source)37 void ETSExtensionFuncHelperType::AssignmentTarget(TypeRelation *relation, Type *source)
38 {
39 if (!source->IsETSFunctionType()) {
40 return;
41 }
42
43 if (relation->IsAssignableTo(source->AsETSFunctionType(), classMethodType_)) {
44 return;
45 }
46
47 if (relation->IsAssignableTo(source->AsETSFunctionType(), extensionFunctionType_)) {
48 return;
49 }
50 }
51 } // namespace ark::es2panda::checker
52