diff --git a/checker/ets/function.cpp b/checker/ets/function.cpp index 709429598f7c0f214a080c9d762903db8782aa37..5508ca7622bb17c7b473a1b421e7c15dd7a50ea6 100644 --- a/checker/ets/function.cpp +++ b/checker/ets/function.cpp @@ -1829,28 +1829,23 @@ void ETSChecker::ReplaceIdentifierReferencesInProxyMethod( } } node->Iterate([this, &proxy_params, &merged_target_references](ir::AstNode *child_node) { - ReplaceIdentifierReferenceInProxyMethod(child_node, proxy_params, merged_target_references); - }); -} - -void ETSChecker::ReplaceIdentifierReferenceInProxyMethod( - ir::AstNode *node, ArenaVector &proxy_params, - std::unordered_map &merged_target_references) -{ - // If we see an identifier reference - if (node->IsIdentifier()) { - auto *ident_node = node->AsIdentifier(); - ASSERT(ident_node->Variable()); - - // Then check if that reference is present in the target references which we want to replace - auto found = merged_target_references.find(ident_node->Variable()); - if (found != merged_target_references.end()) { - // If it is present in the target references, replace it with the proper proxy parameter reference - ident_node->SetVariable(proxy_params[found->second]->AsETSParameterExpression()->Variable()); + if (child_node->IsMemberExpression() && child_node->AsMemberExpression()->Kind() == ir::MemberExpressionKind::PROPERTY_ACCESS) { + ReplaceIdentifierReferencesInProxyMethod(child_node->AsMemberExpression()->Object(), proxy_params, merged_target_references); + return; } - } - - ReplaceIdentifierReferencesInProxyMethod(node, proxy_params, merged_target_references); + if (child_node->IsIdentifier()) { + ir::Identifier *id = child_node->AsIdentifier(); + ASSERT(id->Variable()); + // Then check if that reference is present in the target references which we want to replace + auto found = merged_target_references.find(id->Variable()); + if (found != merged_target_references.end()) { + // If it is present in the target references, replace it with the proper proxy parameter reference + id->SetVariable(proxy_params[found->second]->AsETSParameterExpression()->Variable()); + } + return; + } + ReplaceIdentifierReferencesInProxyMethod(child_node, proxy_params, merged_target_references); + }); } binder::FunctionParamScope *ETSChecker::CreateProxyMethodParams(ir::ArrowFunctionExpression *lambda, diff --git a/test/compiler/ets/arrayParamInLambda-expected.txt b/test/compiler/ets/arrayParamInLambda-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..db36bc0ac5dd9bc541c1f6fc0f781496d879a975 --- /dev/null +++ b/test/compiler/ets/arrayParamInLambda-expected.txt @@ -0,0 +1,761 @@ +{ + "type": "Program", + "statements": [ + { + "type": "TSTypeAliasDeclaration", + "id": { + "type": "Identifier", + "name": "BenchmarkFunc", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 19 + } + } + }, + "typeAnnotation": { + "type": "ETSFunctionType", + "params": [], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "void", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 28 + }, + "end": { + "line": 1, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 28 + }, + "end": { + "line": 1, + "column": 33 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 28 + }, + "end": { + "line": 1, + "column": 33 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 22 + }, + "end": { + "line": 1, + "column": 33 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 33 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ETSGLOBAL", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "arrayParamInLambdaFunc", + "decorators": [], + "loc": { + "start": { + "line": 3, + "column": 10 + }, + "end": { + "line": 3, + "column": 32 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "arrayParamInLambdaFunc", + "decorators": [], + "loc": { + "start": { + "line": 3, + "column": 10 + }, + "end": { + "line": 3, + "column": 32 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "void", + "decorators": [], + "loc": { + "start": { + "line": 3, + "column": 36 + }, + "end": { + "line": 3, + "column": 40 + } + } + }, + "loc": { + "start": { + "line": 3, + "column": 36 + }, + "end": { + "line": 3, + "column": 42 + } + } + }, + "loc": { + "start": { + "line": 3, + "column": 36 + }, + "end": { + "line": 3, + "column": 42 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "arr", + "typeAnnotation": { + "type": "TSArrayType", + "elementType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "number", + "decorators": [], + "loc": { + "start": { + "line": 4, + "column": 16 + }, + "end": { + "line": 4, + "column": 22 + } + } + }, + "loc": { + "start": { + "line": 4, + "column": 16 + }, + "end": { + "line": 4, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 4, + "column": 16 + }, + "end": { + "line": 4, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 4, + "column": 25 + }, + "end": { + "line": 4, + "column": 26 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 4, + "column": 11 + }, + "end": { + "line": 4, + "column": 14 + } + } + }, + "init": { + "type": "ArrayExpression", + "elements": [ + { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 4, + "column": 28 + }, + "end": { + "line": 4, + "column": 29 + } + } + }, + { + "type": "NumberLiteral", + "value": 2, + "loc": { + "start": { + "line": 4, + "column": 31 + }, + "end": { + "line": 4, + "column": 32 + } + } + }, + { + "type": "NumberLiteral", + "value": 3, + "loc": { + "start": { + "line": 4, + "column": 34 + }, + "end": { + "line": 4, + "column": 35 + } + } + }, + { + "type": "NumberLiteral", + "value": 4, + "loc": { + "start": { + "line": 4, + "column": 37 + }, + "end": { + "line": 4, + "column": 38 + } + } + } + ], + "loc": { + "start": { + "line": 4, + "column": 27 + }, + "end": { + "line": 4, + "column": 39 + } + } + }, + "loc": { + "start": { + "line": 4, + "column": 11 + }, + "end": { + "line": 4, + "column": 39 + } + } + } + ], + "kind": "const", + "loc": { + "start": { + "line": 4, + "column": 5 + }, + "end": { + "line": 4, + "column": 40 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "ITERATE_FUNC", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "BenchmarkFunc", + "decorators": [], + "loc": { + "start": { + "line": 5, + "column": 25 + }, + "end": { + "line": 5, + "column": 38 + } + } + }, + "loc": { + "start": { + "line": 5, + "column": 25 + }, + "end": { + "line": 5, + "column": 40 + } + } + }, + "loc": { + "start": { + "line": 5, + "column": 25 + }, + "end": { + "line": 5, + "column": 40 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 5, + "column": 11 + }, + "end": { + "line": 5, + "column": 23 + } + } + }, + "init": { + "type": "ArrowFunctionExpression", + "function": { + "type": "ScriptFunction", + "id": null, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "length", + "decorators": [], + "loc": { + "start": { + "line": 6, + "column": 15 + }, + "end": { + "line": 6, + "column": 21 + } + } + }, + "init": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "arr", + "decorators": [], + "loc": { + "start": { + "line": 6, + "column": 24 + }, + "end": { + "line": 6, + "column": 27 + } + } + }, + "property": { + "type": "Identifier", + "name": "length", + "decorators": [], + "loc": { + "start": { + "line": 6, + "column": 28 + }, + "end": { + "line": 6, + "column": 34 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 6, + "column": 24 + }, + "end": { + "line": 6, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 6, + "column": 15 + }, + "end": { + "line": 6, + "column": 34 + } + } + } + ], + "kind": "const", + "loc": { + "start": { + "line": 6, + "column": 9 + }, + "end": { + "line": 6, + "column": 35 + } + } + } + ], + "loc": { + "start": { + "line": 5, + "column": 47 + }, + "end": { + "line": 7, + "column": 6 + } + } + }, + "loc": { + "start": { + "line": 5, + "column": 41 + }, + "end": { + "line": 7, + "column": 6 + } + } + }, + "loc": { + "start": { + "line": 5, + "column": 41 + }, + "end": { + "line": 7, + "column": 6 + } + } + }, + "loc": { + "start": { + "line": 5, + "column": 11 + }, + "end": { + "line": 7, + "column": 6 + } + } + } + ], + "kind": "const", + "loc": { + "start": { + "line": 5, + "column": 5 + }, + "end": { + "line": 7, + "column": 6 + } + } + } + ], + "loc": { + "start": { + "line": 3, + "column": 41 + }, + "end": { + "line": 8, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 3, + "column": 32 + }, + "end": { + "line": 8, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 3, + "column": 32 + }, + "end": { + "line": 8, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 3, + "column": 1 + }, + "end": { + "line": 8, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 8, + "column": 2 + } + } +} diff --git a/test/compiler/ets/arrayParamInLambda.ets b/test/compiler/ets/arrayParamInLambda.ets new file mode 100644 index 0000000000000000000000000000000000000000..7f6ef442700b19130bc3a57dccb52e3fe9ca49bb --- /dev/null +++ b/test/compiler/ets/arrayParamInLambda.ets @@ -0,0 +1,8 @@ +type BenchmarkFunc = () => void; + +function arrayParamInLambdaFunc(): void { + const arr: number[] = [1, 2, 3, 4]; + const ITERATE_FUNC: BenchmarkFunc = () => { + const length = arr.length; + } +} \ No newline at end of file