From 978cb05286b8137cee4852373bc3b4214dbb00ed Mon Sep 17 00:00:00 2001 From: Vivien Voros Date: Tue, 16 Jan 2024 12:06:28 +0100 Subject: [PATCH 01/26] [ArkTS frontend] overriding methods with optional parameters Overriding a method with optional parameter causes error. Fixes internal issue #15203 Change-Id: If45a44317c73c535b22505f5d87708b00b27470e Signed-off-by: Vivien Voros --- ets2panda/checker/ets/function.cpp | 2 +- .../test/parser/ets/override-expected.txt | 2543 +++++++++++++++++ ets2panda/test/parser/ets/override.ets | 25 + ets2panda/test/runtime/ets/Override-3.ets | 42 + 4 files changed, 2611 insertions(+), 1 deletion(-) create mode 100644 ets2panda/test/parser/ets/override-expected.txt create mode 100644 ets2panda/test/parser/ets/override.ets create mode 100644 ets2panda/test/runtime/ets/Override-3.ets diff --git a/ets2panda/checker/ets/function.cpp b/ets2panda/checker/ets/function.cpp index 5c9d216477..e6f781ed57 100644 --- a/ets2panda/checker/ets/function.cpp +++ b/ets2panda/checker/ets/function.cpp @@ -1255,7 +1255,7 @@ void ETSChecker::CheckOverride(Signature *signature) iter = iter->SuperType(); } - if (!isOverriding && signature->Function()->IsOverride()) { + if (!isOverriding && signature->Function()->IsOverride() && !(signature->Function()->IsDefaultParamProxy())) { ThrowTypeError({"Method ", signature->Function()->Id()->Name(), signature, " in ", signature->Owner(), " not overriding any method"}, signature->Function()->Start()); diff --git a/ets2panda/test/parser/ets/override-expected.txt b/ets2panda/test/parser/ets/override-expected.txt new file mode 100644 index 0000000000..6fb7ad9495 --- /dev/null +++ b/ets2panda/test/parser/ets/override-expected.txt @@ -0,0 +1,2543 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "B", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 7 + }, + "end": { + "line": 16, + "column": 8 + } + } + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "params": [ + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 10 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 11 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 8 + }, + "end": { + "line": 16, + "column": 11 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 3 + }, + "end": { + "line": 17, + "column": 6 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 3 + }, + "end": { + "line": 17, + "column": 6 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "a", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 10 + }, + "end": { + "line": 17, + "column": 11 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 10 + }, + "end": { + "line": 17, + "column": 12 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 10 + }, + "end": { + "line": 17, + "column": 12 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 7 + }, + "end": { + "line": 17, + "column": 12 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 7 + }, + "end": { + "line": 17, + "column": 12 + } + } + }, + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "op", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 18 + }, + "end": { + "line": 17, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 18 + }, + "end": { + "line": 17, + "column": 20 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 18 + }, + "end": { + "line": 17, + "column": 20 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 13 + }, + "end": { + "line": 17, + "column": 20 + } + } + }, + "initializer": { + "type": "UndefinedLiteral", + "value": undefined, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 13 + }, + "end": { + "line": 17, + "column": 20 + } + } + } + ], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 22 + }, + "end": { + "line": 17, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 22 + }, + "end": { + "line": 17, + "column": 25 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 22 + }, + "end": { + "line": 17, + "column": 25 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "Identifier", + "name": "a", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 33 + }, + "end": { + "line": 17, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 26 + }, + "end": { + "line": 17, + "column": 34 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 24 + }, + "end": { + "line": 17, + "column": 36 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 6 + }, + "end": { + "line": 17, + "column": 36 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 6 + }, + "end": { + "line": 17, + "column": 36 + } + } + }, + "overloads": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "foo_proxy", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "foo_proxy", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "a", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "op", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "$proxy_mask$", + "typeAnnotation": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + } + ], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "IfStatement", + "test": { + "type": "BinaryExpression", + "operator": "==", + "left": { + "type": "BinaryExpression", + "operator": "&", + "left": { + "type": "BinaryExpression", + "operator": ">>", + "left": { + "type": "Identifier", + "name": "$proxy_mask$", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "right": { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "right": { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "right": { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "consequent": { + "type": "BlockStatement", + "statements": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "op", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "right": { + "type": "UndefinedLiteral", + "value": undefined, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "alternate": null, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + { + "type": "ReturnStatement", + "argument": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "ThisExpression", + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "property": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "arguments": [ + { + "type": "Identifier", + "name": "a", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + { + "type": "Identifier", + "name": "op", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + } + ], + "optional": false, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 3 + } + } + } + ], + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 3 + }, + "end": { + "line": 17, + "column": 36 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "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": 18, + "column": 2 + }, + "end": { + "line": 18, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 12 + }, + "end": { + "line": 18, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 18, + "column": 2 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 7 + }, + "end": { + "line": 19, + "column": 8 + } + } + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "params": [ + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 9 + }, + "end": { + "line": 19, + "column": 10 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 9 + }, + "end": { + "line": 19, + "column": 11 + } + } + } + ], + "loc": { + "start": { + "line": 19, + "column": 8 + }, + "end": { + "line": 19, + "column": 11 + } + } + }, + "superClass": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "B", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 20 + }, + "end": { + "line": 19, + "column": 21 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 22 + }, + "end": { + "line": 19, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 22 + }, + "end": { + "line": 19, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 22 + }, + "end": { + "line": 19, + "column": 24 + } + } + } + ], + "loc": { + "start": { + "line": 19, + "column": 21 + }, + "end": { + "line": 19, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 20 + }, + "end": { + "line": 19, + "column": 26 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 20 + }, + "end": { + "line": 19, + "column": 26 + } + } + }, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 12 + }, + "end": { + "line": 20, + "column": 15 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 12 + }, + "end": { + "line": 20, + "column": 15 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "a", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 19 + }, + "end": { + "line": 20, + "column": 20 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 19 + }, + "end": { + "line": 20, + "column": 21 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 19 + }, + "end": { + "line": 20, + "column": 21 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 16 + }, + "end": { + "line": 20, + "column": 21 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 16 + }, + "end": { + "line": 20, + "column": 21 + } + } + }, + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "op", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 27 + }, + "end": { + "line": 20, + "column": 28 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 27 + }, + "end": { + "line": 20, + "column": 29 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 27 + }, + "end": { + "line": 20, + "column": 29 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 22 + }, + "end": { + "line": 20, + "column": 29 + } + } + }, + "initializer": { + "type": "UndefinedLiteral", + "value": undefined, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 22 + }, + "end": { + "line": 20, + "column": 29 + } + } + } + ], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 31 + }, + "end": { + "line": 20, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 31 + }, + "end": { + "line": 20, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 31 + }, + "end": { + "line": 20, + "column": 34 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "Identifier", + "name": "a", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 42 + }, + "end": { + "line": 20, + "column": 43 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 35 + }, + "end": { + "line": 20, + "column": 43 + } + } + } + ], + "loc": { + "start": { + "line": 20, + "column": 33 + }, + "end": { + "line": 20, + "column": 45 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 15 + }, + "end": { + "line": 20, + "column": 45 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 15 + }, + "end": { + "line": 20, + "column": 45 + } + } + }, + "overloads": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "foo_proxy", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "foo_proxy", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "a", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "op", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "$proxy_mask$", + "typeAnnotation": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + } + ], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "IfStatement", + "test": { + "type": "BinaryExpression", + "operator": "==", + "left": { + "type": "BinaryExpression", + "operator": "&", + "left": { + "type": "BinaryExpression", + "operator": ">>", + "left": { + "type": "Identifier", + "name": "$proxy_mask$", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "right": { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "right": { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "right": { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "consequent": { + "type": "BlockStatement", + "statements": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "op", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "right": { + "type": "UndefinedLiteral", + "value": undefined, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "alternate": null, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + { + "type": "ReturnStatement", + "argument": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "ThisExpression", + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "property": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "arguments": [ + { + "type": "Identifier", + "name": "a", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + { + "type": "Identifier", + "name": "op", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + } + ], + "optional": false, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 3 + } + } + } + ], + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 3 + }, + "end": { + "line": 20, + "column": 45 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "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": 21, + "column": 2 + }, + "end": { + "line": 21, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 19, + "column": 25 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 1 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + { + "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": "main", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 10 + }, + "end": { + "line": 22, + "column": 14 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 10 + }, + "end": { + "line": 22, + "column": 14 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 22, + "column": 16 + }, + "end": { + "line": 24, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 14 + }, + "end": { + "line": 24, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 14 + }, + "end": { + "line": 24, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 1 + }, + "end": { + "line": 24, + "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": 26, + "column": 1 + } + } +} diff --git a/ets2panda/test/parser/ets/override.ets b/ets2panda/test/parser/ets/override.ets new file mode 100644 index 0000000000..90460dc700 --- /dev/null +++ b/ets2panda/test/parser/ets/override.ets @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 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. + */ + +class B { + foo(a: T, op?: T): T { return a } +} +class A extends B { + override foo(a: T, op?: T): T { return a } +} +function main(){ + +} + diff --git a/ets2panda/test/runtime/ets/Override-3.ets b/ets2panda/test/runtime/ets/Override-3.ets new file mode 100644 index 0000000000..f3294dc066 --- /dev/null +++ b/ets2panda/test/runtime/ets/Override-3.ets @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 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. + */ + +class B { + foo(a: int, op?: int): int { return a } +} +class A extends B { + override foo(a: int, op?: int): int { return a } +} + +class C { + foo(a: T, op?: T): T { return a } +} +class D extends C { + override foo(a: T, op?: T): T { return a } +} + +function main(){ + let a = new A(); + let b = new B(); + let c = new C(); + let d = new D(); + + assert(b.foo(5) == a.foo(5)); + assert(b.foo(6) != a.foo(5)); + assert(b.foo(5) != a.foo(6)); + assert(c.foo("x") == d.foo("x")); + assert(c.foo("x") != d.foo("y")); + assert(c.foo("y") != d.foo("x")); +} -- Gitee From 98a5cd203b22f49930c7e73467d44a85a6cd0021 Mon Sep 17 00:00:00 2001 From: Anna Antipina Date: Thu, 11 Jan 2024 18:12:52 +0300 Subject: [PATCH 02/26] Title: Implement string constructor for NullishType Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/I8VHWY Description: enable the ability to create 'new String(NullishType)' Test: ${ARK_SOURCE_DIR}/tests/tests-u-runner/runner.sh ${ARK_SOURCE_DIR} --ets-runtime --build-dir="${ARK_BUILD_DIR}" --heap-verifier="fail_on_verification:pre:into:before_g1_concurrent:post" --timeout=30 --force-generate --test-file string_from_nullish.ets Signed-off-by: Anna Antipina --- ets2panda/compiler/core/ETSGen.h | 56 ++++++++++++++++++- ets2panda/compiler/scripts/signatures.yaml | 12 ++++ .../test/runtime/ets/string_from_nullish.ets | 38 +++++++++++++ 3 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 ets2panda/test/runtime/ets/string_from_nullish.ets diff --git a/ets2panda/compiler/core/ETSGen.h b/ets2panda/compiler/core/ETSGen.h index 456d8c01f5..b1c5907351 100644 --- a/ets2panda/compiler/core/ETSGen.h +++ b/ets2panda/compiler/core/ETSGen.h @@ -983,13 +983,67 @@ private: } } + template + bool ResolveStringFromNullishBuiltin(const ir::AstNode *node, checker::Signature *signature, + const ArenaVector &arguments) + { + if (signature->InternalName() != Signatures::BUILTIN_STRING_FROM_NULLISH_CTOR) { + return false; + } + auto argExpr = arguments[0]; + if (argExpr->IsExpression()) { + if (argExpr->AsExpression()->IsNullLiteral()) { + LoadAccumulatorString(node, "null"); + return true; + } + if (argExpr->AsExpression()->IsUndefinedLiteral()) { + LoadAccumulatorString(node, "undefined"); + return true; + } + } + + Label *isNull = AllocLabel(); + Label *end = AllocLabel(); +#ifdef PANDA_WITH_ETS + Label *isUndefined = AllocLabel(); +#endif + COMPILE_ARG(0); + LoadAccumulator(node, arg0); + if (argExpr->TsType()->IsNullish()) { + BranchIfNull(node, isNull); +#ifdef PANDA_WITH_ETS + Sa().Emit(node); + BranchIfTrue(node, isUndefined); +#endif + } + LoadAccumulator(node, arg0); + CastToString(node); + StoreAccumulator(node, arg0); + Ra().Emit(node, Signatures::BUILTIN_STRING_FROM_STRING_CTOR, arg0, dummyReg_); + JumpTo(node, end); + if (argExpr->TsType()->IsNullish()) { + SetLabel(node, isNull); + LoadAccumulatorString(node, "null"); +#ifdef PANDA_WITH_ETS + JumpTo(node, end); + SetLabel(node, isUndefined); + LoadAccumulatorString(node, "undefined"); +#endif + } + SetLabel(node, end); + return true; + } + template void CallImpl(const ir::AstNode *node, checker::Signature *signature, const ArenaVector &arguments) { RegScope rs(this); - const auto name = signature->InternalName(); + if (ResolveStringFromNullishBuiltin(node, signature, arguments)) { + return; + } + const auto name = signature->InternalName(); switch (arguments.size()) { case 0U: { Ra().Emit(node, name, dummyReg_, dummyReg_); diff --git a/ets2panda/compiler/scripts/signatures.yaml b/ets2panda/compiler/scripts/signatures.yaml index 37f0738757..c079795062 100644 --- a/ets2panda/compiler/scripts/signatures.yaml +++ b/ets2panda/compiler/scripts/signatures.yaml @@ -304,6 +304,18 @@ signatures: return_type: PRIMITIVE_VOID ref: BUILTIN_OBJECT_CTOR + - callee: BUILTIN_STRING + method_name: $CTOR + params: [BUILTIN_STRING] + return_type: PRIMITIVE_VOID + ref: BUILTIN_STRING_FROM_STRING_CTOR + + - callee: BUILTIN_STRING + method_name: $CTOR + params: [BUILTIN_OBJECT] + return_type: PRIMITIVE_VOID + ref: BUILTIN_STRING_FROM_NULLISH_CTOR + - callee: BUILTIN_OBJECT method_name: toString params: [] diff --git a/ets2panda/test/runtime/ets/string_from_nullish.ets b/ets2panda/test/runtime/ets/string_from_nullish.ets new file mode 100644 index 0000000000..b2aae3aa50 --- /dev/null +++ b/ets2panda/test/runtime/ets/string_from_nullish.ets @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2023-2024 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 main(): int { + let z: NullishType = new Number(1); + let z1 = undefined; + let z2 = null; + let z3: Object = new String("0"); + let z4: Object = new Number(1); + let x = new String(z) + let x1 = new String(z1) + let x2 = new String(z2) + let x3 = new String(z3) + let x4 = new String(z4) + let x5 = new String(null) + let x6 = new String(undefined) + let actual: String[] = [new String(z), new String(z1), new String(z2), new String(z3), new String(z4), new String(null), new String(undefined)] + let expected: String[] = ["1", "undefined", "null", "0", "1", "null", "undefined"] + for (let i = 0; i < expected.length; i++) { + if (actual[i] != expected[i]) { + console.log("Failed: actual is \"" + actual[i] + "\" expected is \"" + expected[i] + "\"") + return 1; + } + } + return 0; +} -- Gitee From b5005eee4adebbb712998eeea50c0d2962f71e18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferenc=20Horv=C3=A1th?= Date: Wed, 17 Jan 2024 16:22:37 +0100 Subject: [PATCH 03/26] Fix the instantiation of tuple types MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes internal issue #15207 Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/I8XAME Testing: All required pre-merge tests passed. Results are available in the ggwatcher. Signed-off-by: Ferenc Horváth Change-Id: I07666818f493ea8f61f75b04bb95cdbc47a68e32 --- ets2panda/checker/types/ets/etsTupleType.cpp | 3 +- .../compiler/ets/nullableTuple-expected.txt | 797 ++++++++++++++++++ ets2panda/test/compiler/ets/nullableTuple.ets | 24 + 3 files changed, 823 insertions(+), 1 deletion(-) create mode 100644 ets2panda/test/compiler/ets/nullableTuple-expected.txt create mode 100644 ets2panda/test/compiler/ets/nullableTuple.ets diff --git a/ets2panda/checker/types/ets/etsTupleType.cpp b/ets2panda/checker/types/ets/etsTupleType.cpp index 99afd7bf64..aaaf104a04 100644 --- a/ets2panda/checker/types/ets/etsTupleType.cpp +++ b/ets2panda/checker/types/ets/etsTupleType.cpp @@ -185,7 +185,8 @@ void ETSTupleType::Cast(TypeRelation *const relation, Type *const target) Type *ETSTupleType::Instantiate([[maybe_unused]] ArenaAllocator *allocator, [[maybe_unused]] TypeRelation *relation, [[maybe_unused]] GlobalTypesHolder *globalTypes) { - return this; + return allocator->New(GetTupleTypesList(), + ElementType()->Instantiate(allocator, relation, globalTypes), GetSpreadType()); } } // namespace panda::es2panda::checker diff --git a/ets2panda/test/compiler/ets/nullableTuple-expected.txt b/ets2panda/test/compiler/ets/nullableTuple-expected.txt new file mode 100644 index 0000000000..6cd2174f4a --- /dev/null +++ b/ets2panda/test/compiler/ets/nullableTuple-expected.txt @@ -0,0 +1,797 @@ +{ + "type": "Program", + "statements": [ + { + "type": "TSTypeAliasDeclaration", + "id": { + "type": "Identifier", + "name": "TNumberStringPair", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 6 + }, + "end": { + "line": 16, + "column": 23 + } + } + }, + "typeAnnotation": { + "type": "ETSTuple", + "types": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "number", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 27 + }, + "end": { + "line": 16, + "column": 33 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 27 + }, + "end": { + "line": 16, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 27 + }, + "end": { + "line": 16, + "column": 34 + } + } + }, + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 35 + }, + "end": { + "line": 16, + "column": 41 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 35 + }, + "end": { + "line": 16, + "column": 42 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 35 + }, + "end": { + "line": 16, + "column": 42 + } + } + } + ], + "spreadType": null, + "loc": { + "start": { + "line": 16, + "column": 26 + }, + "end": { + "line": 16, + "column": 43 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 16, + "column": 43 + } + } + }, + { + "type": "TSTypeAliasDeclaration", + "id": { + "type": "Identifier", + "name": "TTupleUnion", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 6 + }, + "end": { + "line": 17, + "column": 17 + } + } + }, + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "TNumberStringPair", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 20 + }, + "end": { + "line": 17, + "column": 37 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 20 + }, + "end": { + "line": 17, + "column": 38 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 20 + }, + "end": { + "line": 17, + "column": 38 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 1 + }, + "end": { + "line": 17, + "column": 48 + } + } + }, + { + "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": "main", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 10 + }, + "end": { + "line": 19, + "column": 14 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 10 + }, + "end": { + "line": 19, + "column": 14 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "void", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 18 + }, + "end": { + "line": 19, + "column": 22 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 18 + }, + "end": { + "line": 19, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 18 + }, + "end": { + "line": 19, + "column": 24 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "x", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "TNumberStringPair", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 11 + }, + "end": { + "line": 20, + "column": 28 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 11 + }, + "end": { + "line": 20, + "column": 30 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 11 + }, + "end": { + "line": 20, + "column": 30 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 8 + }, + "end": { + "line": 20, + "column": 9 + } + } + }, + "init": { + "type": "ArrayExpression", + "elements": [ + { + "type": "NumberLiteral", + "value": 12, + "loc": { + "start": { + "line": 20, + "column": 32 + }, + "end": { + "line": 20, + "column": 36 + } + } + }, + { + "type": "StringLiteral", + "value": "Hello World", + "loc": { + "start": { + "line": 20, + "column": 38 + }, + "end": { + "line": 20, + "column": 51 + } + } + } + ], + "loc": { + "start": { + "line": 20, + "column": 31 + }, + "end": { + "line": 20, + "column": 52 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 8 + }, + "end": { + "line": 20, + "column": 52 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 20, + "column": 4 + }, + "end": { + "line": 20, + "column": 53 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "y", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "TTupleUnion", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 11 + }, + "end": { + "line": 21, + "column": 22 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 11 + }, + "end": { + "line": 21, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 11 + }, + "end": { + "line": 21, + "column": 24 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 8 + }, + "end": { + "line": 21, + "column": 9 + } + } + }, + "init": { + "type": "UndefinedLiteral", + "value": undefined, + "loc": { + "start": { + "line": 21, + "column": 25 + }, + "end": { + "line": 21, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 8 + }, + "end": { + "line": 21, + "column": 34 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 21, + "column": 4 + }, + "end": { + "line": 21, + "column": 35 + } + } + }, + { + "type": "AssertStatement", + "test": { + "type": "BinaryExpression", + "operator": "==", + "left": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "x", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 11 + }, + "end": { + "line": 23, + "column": 12 + } + } + }, + "property": { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 23, + "column": 13 + }, + "end": { + "line": 23, + "column": 14 + } + } + }, + "computed": true, + "optional": false, + "loc": { + "start": { + "line": 23, + "column": 11 + }, + "end": { + "line": 23, + "column": 15 + } + } + }, + "right": { + "type": "NumberLiteral", + "value": 12, + "loc": { + "start": { + "line": 23, + "column": 19 + }, + "end": { + "line": 23, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 11 + }, + "end": { + "line": 23, + "column": 23 + } + } + }, + "second": null, + "loc": { + "start": { + "line": 23, + "column": 4 + }, + "end": { + "line": 23, + "column": 24 + } + } + } + ], + "loc": { + "start": { + "line": 19, + "column": 23 + }, + "end": { + "line": 24, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 14 + }, + "end": { + "line": 24, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 14 + }, + "end": { + "line": 24, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 1 + }, + "end": { + "line": 24, + "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": 25, + "column": 1 + } + } +} diff --git a/ets2panda/test/compiler/ets/nullableTuple.ets b/ets2panda/test/compiler/ets/nullableTuple.ets new file mode 100644 index 0000000000..7891b82c56 --- /dev/null +++ b/ets2panda/test/compiler/ets/nullableTuple.ets @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2024 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. + */ + +type TNumberStringPair = [number, string]; +type TTupleUnion = TNumberStringPair|undefined; + +function main(): void { + let x: TNumberStringPair = [12.0, "Hello World"]; + let y: TTupleUnion = undefined; + + assert x[0] == 12.0; +} -- Gitee From 868588b3d981923d80f8a8db3221f61e86d8d6ca Mon Sep 17 00:00:00 2001 From: Martin Sajti Date: Fri, 5 Jan 2024 15:53:39 +0100 Subject: [PATCH 04/26] Get enum value, when used with '&' operator in binary expression Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/I8UVCM Internal issue: #15017 Test: build, new runtime test Signed-off-by: Martin Sajti --- ets2panda/checker/ets/arithmetic.cpp | 13 ++++++++ ets2panda/compiler/core/ETSGen.cpp | 7 ++++ ets2panda/ir/astNode.h | 2 +- ets2panda/ir/astNodeFlags.h | 1 + ets2panda/test/runtime/ets/Enum6.ets | 50 ++++++++++++++++++++++++++++ 5 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 ets2panda/test/runtime/ets/Enum6.ets diff --git a/ets2panda/checker/ets/arithmetic.cpp b/ets2panda/checker/ets/arithmetic.cpp index 66b26f3539..46b8207153 100644 --- a/ets2panda/checker/ets/arithmetic.cpp +++ b/ets2panda/checker/ets/arithmetic.cpp @@ -291,6 +291,19 @@ checker::Type *ETSChecker::CheckBinaryOperatorBitwise(ir::Expression *left, ir:: bool isEqualOp, checker::Type *const leftType, checker::Type *const rightType, Type *unboxedL, Type *unboxedR) { + // NOTE (mmartin): These need to be done for other binary expressions, but currently it's not defined precisely when + // to apply this conversion + + if (leftType->IsETSEnumType()) { + left->AddAstNodeFlags(ir::AstNodeFlags::ENUM_GET_VALUE); + unboxedL = GlobalIntType(); + } + + if (rightType->IsETSEnumType()) { + right->AddAstNodeFlags(ir::AstNodeFlags::ENUM_GET_VALUE); + unboxedR = GlobalIntType(); + } + if (leftType->IsETSUnionType() || rightType->IsETSUnionType()) { ThrowTypeError("Bad operand type, unions are not allowed in binary expressions except equality.", pos); } diff --git a/ets2panda/compiler/core/ETSGen.cpp b/ets2panda/compiler/core/ETSGen.cpp index 1949eabc51..e222381e66 100644 --- a/ets2panda/compiler/core/ETSGen.cpp +++ b/ets2panda/compiler/core/ETSGen.cpp @@ -982,6 +982,13 @@ void ETSGen::ApplyConversion(const ir::AstNode *node, const checker::Type *targe { auto ttctx = TargetTypeContext(this, targetType); + if (node->HasAstNodeFlags(ir::AstNodeFlags::ENUM_GET_VALUE)) { + Ra().Emit( + node, node->AsExpression()->TsType()->AsETSEnumType()->GetValueMethod().globalSignature->InternalName(), + dummyReg_, 0); + node->RemoveAstNodeFlags(ir::AstNodeFlags::ENUM_GET_VALUE); + } + if ((node->GetBoxingUnboxingFlags() & ir::BoxingUnboxingFlags::BOXING_FLAG) != 0U) { ApplyBoxingConversion(node); return; diff --git a/ets2panda/ir/astNode.h b/ets2panda/ir/astNode.h index f6eedfb88e..4b20f93db3 100644 --- a/ets2panda/ir/astNode.h +++ b/ets2panda/ir/astNode.h @@ -450,7 +450,7 @@ public: { \ return ((member_name)&flag) != 0U; \ } \ - void Remove##flag_type(flag_type flag) noexcept \ + void Remove##flag_type(flag_type flag) const noexcept \ { \ (member_name) &= ~flag; \ } diff --git a/ets2panda/ir/astNodeFlags.h b/ets2panda/ir/astNodeFlags.h index f6420bb131..fb74be021b 100644 --- a/ets2panda/ir/astNodeFlags.h +++ b/ets2panda/ir/astNodeFlags.h @@ -22,6 +22,7 @@ namespace panda::es2panda::ir { enum class AstNodeFlags { NO_OPTS = 0, CHECKCAST = 1U << 0U, + ENUM_GET_VALUE = 1U << 1U, }; enum class ModifierFlags : uint32_t { diff --git a/ets2panda/test/runtime/ets/Enum6.ets b/ets2panda/test/runtime/ets/Enum6.ets new file mode 100644 index 0000000000..39b8f0c5db --- /dev/null +++ b/ets2panda/test/runtime/ets/Enum6.ets @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2023 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. + */ + +enum Access { + READ = 1, + WRITE = 2, + READWRITE = 3 +} + +enum TestEnum { + A = 144, + B, + C = 795 +} + +function main(): void { + test_access_enum_bitwise(Access.WRITE); + assert (Access.WRITE & Access.READWRITE) == 2; + + test_test_enum_bitwise(TestEnum.C); + assert (TestEnum.B & TestEnum.A) == 144 + +} + +function test_access_enum_bitwise(enum_val: Access): void { + assert (enum_val & Access.READ) == 0 + assert (enum_val & Access.WRITE) == 2 + assert (enum_val | Access.READ) == 3 + assert (enum_val | Access.READWRITE) == 3 + assert (enum_val & Access.READWRITE) == 2 +} + +function test_test_enum_bitwise(enum_val: TestEnum): void { + assert (enum_val & TestEnum.A) == 16 + assert (enum_val | TestEnum.A) == 923 + assert (enum_val & TestEnum.B) == 17 + assert (enum_val | TestEnum.B) == 923 +} -- Gitee From e734e961b4851337573c79abce6b94fdfb3671cb Mon Sep 17 00:00:00 2001 From: Martin Sajti Date: Wed, 10 Jan 2024 14:13:19 +0100 Subject: [PATCH 05/26] Tuple instantiation and LUB for type parameters Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/I8VHL5 Internal issue: #15174, #15184 Test: build, new checker test, new runtime test Signed-off-by: Martin Sajti --- ets2panda/checker/ETSAnalyzer.cpp | 2 +- ets2panda/checker/types/ets/etsObjectType.cpp | 51 +- ets2panda/checker/types/ets/etsObjectType.h | 1 + ets2panda/checker/types/ets/etsTupleType.cpp | 17 + ets2panda/checker/types/ets/etsTupleType.h | 1 + ets2panda/ir/ets/etsTuple.cpp | 84 +- ets2panda/ir/ets/etsTuple.h | 6 +- ets2panda/ir/expressions/memberExpression.cpp | 7 - .../compiler/ets/tuple_types_19-expected.txt | 2271 +++++++++++++++++ .../test/compiler/ets/tuple_types_19.ets | 31 + .../test/runtime/ets/tuple_types_runtime.ets | 11 + 11 files changed, 2410 insertions(+), 72 deletions(-) create mode 100644 ets2panda/test/compiler/ets/tuple_types_19-expected.txt create mode 100644 ets2panda/test/compiler/ets/tuple_types_19.ets diff --git a/ets2panda/checker/ETSAnalyzer.cpp b/ets2panda/checker/ETSAnalyzer.cpp index 653bcf2c2e..77a8d79564 100644 --- a/ets2panda/checker/ETSAnalyzer.cpp +++ b/ets2panda/checker/ETSAnalyzer.cpp @@ -725,7 +725,7 @@ checker::Type *ETSAnalyzer::Check(ir::ArrayExpression *expr) const currentElement->Start()); } - const checker::CastingContext cast( + checker::AssignmentContext( checker->Relation(), currentElement, elementType, compareType, currentElement->Start(), {"Array initializer's type is not assignable to tuple type at index: ", idx}); diff --git a/ets2panda/checker/types/ets/etsObjectType.cpp b/ets2panda/checker/types/ets/etsObjectType.cpp index 4dfa0dba6f..17cbff5b6f 100644 --- a/ets2panda/checker/types/ets/etsObjectType.cpp +++ b/ets2panda/checker/types/ets/etsObjectType.cpp @@ -604,46 +604,57 @@ void ETSObjectType::Cast(TypeRelation *const relation, Type *const target) conversion::Forbidden(relation); } -void ETSObjectType::IsSupertypeOf(TypeRelation *relation, Type *source) +bool ETSObjectType::DefaultObjectTypeChecks(const ETSChecker *const etsChecker, TypeRelation *const relation, + Type *const source) { - relation->Result(false); - auto *const etsChecker = relation->GetChecker()->AsETSChecker(); - - if (source->IsETSUnionType()) { - bool res = std::all_of(source->AsETSUnionType()->ConstituentTypes().begin(), - source->AsETSUnionType()->ConstituentTypes().end(), [this, relation](Type *ct) { - relation->Result(false); - IsSupertypeOf(relation, ct); - return relation->IsTrue(); - }); - relation->Result(res); - return; - } - // 3.8.3 Subtyping among Array Types auto const *const base = GetConstOriginalBaseType(); if (base == etsChecker->GlobalETSObjectType() && source->IsETSArrayType()) { relation->Result(true); - return; + return true; + } + + if (source->IsETSTypeParameter()) { + IsSupertypeOf(relation, source->AsETSTypeParameter()->GetConstraintType()); + return true; } if (!source->IsETSObjectType() || !source->AsETSObjectType()->HasObjectFlag(ETSObjectFlags::CLASS | ETSObjectFlags::INTERFACE | ETSObjectFlags::NULL_TYPE)) { - return; + return true; } if ((!ContainsNull() && source->ContainsNull()) || (!ContainsUndefined() && source->ContainsUndefined())) { - return; + return true; } // All classes and interfaces are subtypes of Object if (base == etsChecker->GlobalETSObjectType() || base == etsChecker->GlobalETSNullishObjectType()) { relation->Result(true); - return; + return true; } IdenticalUptoNullability(relation, source); - if (relation->IsTrue()) { + return relation->IsTrue(); +} + +void ETSObjectType::IsSupertypeOf(TypeRelation *relation, Type *source) +{ + relation->Result(false); + auto *const etsChecker = relation->GetChecker()->AsETSChecker(); + + if (source->IsETSUnionType()) { + bool res = std::all_of(source->AsETSUnionType()->ConstituentTypes().begin(), + source->AsETSUnionType()->ConstituentTypes().end(), [this, relation](Type *ct) { + relation->Result(false); + IsSupertypeOf(relation, ct); + return relation->IsTrue(); + }); + relation->Result(res); + return; + } + + if (DefaultObjectTypeChecks(etsChecker, relation, source)) { return; } diff --git a/ets2panda/checker/types/ets/etsObjectType.h b/ets2panda/checker/types/ets/etsObjectType.h index 548bacce30..464754a587 100644 --- a/ets2panda/checker/types/ets/etsObjectType.h +++ b/ets2panda/checker/types/ets/etsObjectType.h @@ -482,6 +482,7 @@ public: Type *Substitute(TypeRelation *relation, const Substitution *substitution) override; void Cast(TypeRelation *relation, Type *target) override; bool CastNumericObject(TypeRelation *relation, Type *target); + bool DefaultObjectTypeChecks(const ETSChecker *etsChecker, TypeRelation *relation, Type *source); void IsSupertypeOf(TypeRelation *relation, Type *source) override; Type *AsSuper(Checker *checker, varbinder::Variable *sourceVar) override; diff --git a/ets2panda/checker/types/ets/etsTupleType.cpp b/ets2panda/checker/types/ets/etsTupleType.cpp index aaaf104a04..08e74f9828 100644 --- a/ets2panda/checker/types/ets/etsTupleType.cpp +++ b/ets2panda/checker/types/ets/etsTupleType.cpp @@ -14,7 +14,10 @@ */ #include "etsTupleType.h" + +#include "checker/ETSchecker.h" #include "checker/ets/conversion.h" +#include "ir/ets/etsTuple.h" namespace panda::es2panda::checker { void ETSTupleType::ToString(std::stringstream &ss) const @@ -129,6 +132,20 @@ void ETSTupleType::AssignmentTarget(TypeRelation *const relation, Type *const so relation->Result(true); } +Type *ETSTupleType::Substitute(TypeRelation *relation, const Substitution *substitution) +{ + auto *const checker = relation->GetChecker()->AsETSChecker(); + ArenaVector newTypeList(checker->Allocator()->Adapter()); + + for (auto *const tupleTypeListElement : GetTupleTypesList()) { + newTypeList.emplace_back(tupleTypeListElement->Substitute(relation, substitution)); + } + + auto *newSpreadType = spreadType_ == nullptr ? nullptr : spreadType_->Substitute(relation, substitution); + auto *newElementType = ir::ETSTuple::CalculateLUBForTuple(checker, newTypeList, newSpreadType); + return checker->Allocator()->New(std::move(newTypeList), newElementType, newSpreadType); +} + void ETSTupleType::Cast(TypeRelation *const relation, Type *const target) { // NOTE(mmartin): Might be not the correct casting rules, as these aren't defined yet diff --git a/ets2panda/checker/types/ets/etsTupleType.h b/ets2panda/checker/types/ets/etsTupleType.h index 7e84e5f87a..249dbe58cf 100644 --- a/ets2panda/checker/types/ets/etsTupleType.h +++ b/ets2panda/checker/types/ets/etsTupleType.h @@ -85,6 +85,7 @@ public: void Identical(TypeRelation *relation, Type *other) override; void AssignmentTarget(TypeRelation *relation, Type *source) override; bool AssignmentSource(TypeRelation *relation, Type *target) override; + Type *Substitute(TypeRelation *relation, const Substitution *substitution) override; void Cast(TypeRelation *relation, Type *target) override; Type *Instantiate(ArenaAllocator *allocator, TypeRelation *relation, GlobalTypesHolder *globalTypes) override; diff --git a/ets2panda/ir/ets/etsTuple.cpp b/ets2panda/ir/ets/etsTuple.cpp index dcb984b54b..929fce73a1 100644 --- a/ets2panda/ir/ets/etsTuple.cpp +++ b/ets2panda/ir/ets/etsTuple.cpp @@ -15,7 +15,6 @@ #include "etsTuple.h" -#include "checker/ETSchecker.h" #include "checker/types/ets/etsTupleType.h" #include "ir/astDump.h" @@ -79,7 +78,36 @@ checker::Type *ETSTuple::Check([[maybe_unused]] checker::ETSChecker *const check return GetType(checker); } -void ETSTuple::SetNullUndefinedFlags(std::pair &containsNullOrUndefined, const checker::Type *const type) +checker::Type *ETSTuple::GetType(checker::ETSChecker *const checker) +{ + if (TsType() != nullptr) { + return TsType(); + } + + ArenaVector typeList(checker->Allocator()->Adapter()); + + for (auto *const typeAnnotation : GetTupleTypeAnnotationsList()) { + auto *const checkedType = checker->GetTypeFromTypeAnnotation(typeAnnotation); + typeList.emplace_back(checkedType); + } + + if (HasSpreadType()) { + ASSERT(spreadType_->IsTSArrayType()); + auto *const arrayType = spreadType_->GetType(checker); + ASSERT(arrayType->IsETSArrayType()); + spreadType_->SetTsType(arrayType->AsETSArrayType()->ElementType()); + } + + auto *const spreadElementType = spreadType_ != nullptr ? spreadType_->TsType() : nullptr; + + auto *const tupleType = checker->Allocator()->New( + typeList, CalculateLUBForTuple(checker, typeList, spreadElementType), spreadElementType); + + SetTsType(tupleType); + return TsType(); +} + +static void SetNullUndefinedFlags(std::pair &containsNullOrUndefined, const checker::Type *const type) { if (type->HasTypeFlag(checker::TypeFlag::NULLISH)) { containsNullOrUndefined.first = true; @@ -101,7 +129,7 @@ checker::Type *ETSTuple::CalculateLUBForTuple(checker::ETSChecker *const checker bool allElementsAreSame = std::all_of(typeList.begin(), typeList.end(), - [this, &checker, &typeList, &containsNullOrUndefined](checker::Type *const element) { + [&checker, &typeList, &containsNullOrUndefined](checker::Type *const element) { SetNullUndefinedFlags(containsNullOrUndefined, element); return checker->Relation()->IsIdenticalTo(typeList[0], element); }); @@ -113,16 +141,13 @@ checker::Type *ETSTuple::CalculateLUBForTuple(checker::ETSChecker *const checker // If only one type present in the tuple, that will be the holder array type. If any two not identical types // present, primitives will be boxed, and LUB is calculated for all of them. - // That makes it possible to assign eg. `[int, int, ...int[]]` tuple type to `int[]` array type. Because a `short[]` - // array already isn't assignable to `int[]` array, that preserve that the `[int, short, ...int[]]` tuple type's - // element type will be calculated to `Object[]`, which is not assignable to `int[]` array either. + // That makes it possible to assign eg. `[int, int, ...int[]]` tuple type to `int[]` array type. Because a + // `short[]` array already isn't assignable to `int[]` array, that preserve that the `[int, short, ...int[]]` + // tuple type's element type will be calculated to `Object[]`, which is not assignable to `int[]` array either. if (allElementsAreSame) { return typeList[0]; } - auto *const savedRelationNode = checker->Relation()->GetNode(); - checker->Relation()->SetNode(this); - auto getBoxedTypeOrType = [&checker](checker::Type *const type) { auto *const boxedType = checker->PrimitiveTypeAsETSBuiltinType(type); return boxedType == nullptr ? type : boxedType; @@ -131,11 +156,19 @@ checker::Type *ETSTuple::CalculateLUBForTuple(checker::ETSChecker *const checker checker::Type *lubType = getBoxedTypeOrType(typeList[0]); for (std::size_t idx = 1; idx < typeList.size(); ++idx) { + if (typeList[idx]->IsETSTypeParameter()) { + lubType = typeList[idx]->AsETSTypeParameter()->GetConstraintType(); + continue; + } lubType = checker->FindLeastUpperBound(lubType, getBoxedTypeOrType(typeList[idx])); } if (spreadType != nullptr) { - lubType = checker->FindLeastUpperBound(lubType, getBoxedTypeOrType(spreadType)); + if (spreadType->IsETSTypeParameter()) { + lubType = spreadType->AsETSTypeParameter()->GetConstraintType(); + } else { + lubType = checker->FindLeastUpperBound(lubType, getBoxedTypeOrType(spreadType)); + } } const auto nullishUndefinedFlags = @@ -148,38 +181,7 @@ checker::Type *ETSTuple::CalculateLUBForTuple(checker::ETSChecker *const checker checker->GetGlobalTypesHolder()); } - checker->Relation()->SetNode(savedRelationNode); - return lubType; } -checker::Type *ETSTuple::GetType(checker::ETSChecker *const checker) -{ - if (TsType() != nullptr) { - return TsType(); - } - - ArenaVector typeList(checker->Allocator()->Adapter()); - - for (auto *const typeAnnotation : GetTupleTypeAnnotationsList()) { - auto *const checkedType = checker->GetTypeFromTypeAnnotation(typeAnnotation); - typeList.emplace_back(checkedType); - } - - if (HasSpreadType()) { - ASSERT(spreadType_->IsTSArrayType()); - auto *const arrayType = spreadType_->GetType(checker); - ASSERT(arrayType->IsETSArrayType()); - spreadType_->SetTsType(arrayType->AsETSArrayType()->ElementType()); - } - - auto *const spreadElementType = spreadType_ != nullptr ? spreadType_->TsType() : nullptr; - - auto *const tupleType = checker->Allocator()->New( - typeList, CalculateLUBForTuple(checker, typeList, spreadElementType), spreadElementType); - - SetTsType(tupleType); - return TsType(); -} - } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/ets/etsTuple.h b/ets2panda/ir/ets/etsTuple.h index ab4eff12f4..43379d9213 100644 --- a/ets2panda/ir/ets/etsTuple.h +++ b/ets2panda/ir/ets/etsTuple.h @@ -16,6 +16,7 @@ #ifndef ES2PANDA_IR_ETS_TUPLE_H #define ES2PANDA_IR_ETS_TUPLE_H +#include "checker/ETSchecker.h" #include "ir/typeNode.h" namespace panda::es2panda::ir { @@ -75,9 +76,8 @@ public: checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; checker::Type *GetType([[maybe_unused]] checker::ETSChecker *checker) override; - void SetNullUndefinedFlags(std::pair &containsNullOrUndefined, const checker::Type *type); - checker::Type *CalculateLUBForTuple(checker::ETSChecker *checker, ArenaVector &typeList, - checker::Type *spreadType); + static checker::Type *CalculateLUBForTuple(checker::ETSChecker *checker, ArenaVector &typeList, + checker::Type *spreadType); void Accept(ASTVisitorT *v) override { diff --git a/ets2panda/ir/expressions/memberExpression.cpp b/ets2panda/ir/expressions/memberExpression.cpp index 9f2c98d44f..c705d084eb 100644 --- a/ets2panda/ir/expressions/memberExpression.cpp +++ b/ets2panda/ir/expressions/memberExpression.cpp @@ -330,14 +330,7 @@ checker::Type *MemberExpression::CheckTupleAccessMethod(checker::ETSChecker *che // NOTE(mmartin): this can be replaced with the general type mapper, once implemented if ((GetBoxingUnboxingFlags() & ir::BoxingUnboxingFlags::UNBOXING_FLAG) != 0U) { - auto *const savedNode = checker->Relation()->GetNode(); - if (savedNode == nullptr) { - checker->Relation()->SetNode(this); - } - SetTupleConvertedType(checker->PrimitiveTypeAsETSBuiltinType(tupleTypeAtIdx)); - - checker->Relation()->SetNode(savedNode); } if (tupleTypeAtIdx->IsETSObjectType() && baseType->AsETSArrayType()->ElementType()->IsETSObjectType()) { diff --git a/ets2panda/test/compiler/ets/tuple_types_19-expected.txt b/ets2panda/test/compiler/ets/tuple_types_19-expected.txt new file mode 100644 index 0000000000..c1e89ef573 --- /dev/null +++ b/ets2panda/test/compiler/ets/tuple_types_19-expected.txt @@ -0,0 +1,2271 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "TuplePair", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 7 + }, + "end": { + "line": 16, + "column": 16 + } + } + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "params": [ + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "X", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 17 + }, + "end": { + "line": 16, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 17 + }, + "end": { + "line": 16, + "column": 19 + } + } + }, + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "Y", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 20 + }, + "end": { + "line": 16, + "column": 21 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 20 + }, + "end": { + "line": 16, + "column": 22 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 16 + }, + "end": { + "line": 16, + "column": 22 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "one", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 5 + }, + "end": { + "line": 17, + "column": 8 + } + } + }, + "accessibility": "public", + "static": false, + "readonly": false, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "ETSTuple", + "types": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "X", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 11 + }, + "end": { + "line": 17, + "column": 12 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 11 + }, + "end": { + "line": 17, + "column": 13 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 11 + }, + "end": { + "line": 17, + "column": 13 + } + } + }, + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Y", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 14 + }, + "end": { + "line": 17, + "column": 15 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 14 + }, + "end": { + "line": 17, + "column": 16 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 14 + }, + "end": { + "line": 17, + "column": 16 + } + } + } + ], + "spreadType": null, + "loc": { + "start": { + "line": 17, + "column": 10 + }, + "end": { + "line": 18, + "column": 11 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 5 + }, + "end": { + "line": 18, + "column": 11 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "provide", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 12 + }, + "end": { + "line": 18, + "column": 19 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "provide", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 12 + }, + "end": { + "line": 18, + "column": 19 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "returnType": { + "type": "ETSTuple", + "types": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "X", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 24 + }, + "end": { + "line": 18, + "column": 25 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 24 + }, + "end": { + "line": 18, + "column": 26 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 24 + }, + "end": { + "line": 18, + "column": 26 + } + } + }, + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Y", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 27 + }, + "end": { + "line": 18, + "column": 28 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 27 + }, + "end": { + "line": 18, + "column": 29 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 27 + }, + "end": { + "line": 18, + "column": 29 + } + } + } + ], + "spreadType": null, + "loc": { + "start": { + "line": 18, + "column": 23 + }, + "end": { + "line": 18, + "column": 31 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "MemberExpression", + "object": { + "type": "ThisExpression", + "loc": { + "start": { + "line": 18, + "column": 39 + }, + "end": { + "line": 18, + "column": 43 + } + } + }, + "property": { + "type": "Identifier", + "name": "one", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 44 + }, + "end": { + "line": 18, + "column": 47 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 18, + "column": 39 + }, + "end": { + "line": 18, + "column": 47 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 32 + }, + "end": { + "line": 18, + "column": 48 + } + } + } + ], + "loc": { + "start": { + "line": 18, + "column": 30 + }, + "end": { + "line": 18, + "column": 50 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 19 + }, + "end": { + "line": 18, + "column": 50 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 19 + }, + "end": { + "line": 18, + "column": 50 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 50 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "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": 19, + "column": 2 + }, + "end": { + "line": 19, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 23 + }, + "end": { + "line": 19, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 19, + "column": 2 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "TupleProvider", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 7 + }, + "end": { + "line": 21, + "column": 20 + } + } + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "params": [ + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "X", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 21 + }, + "end": { + "line": 21, + "column": 22 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 21 + }, + "end": { + "line": 21, + "column": 23 + } + } + } + ], + "loc": { + "start": { + "line": 21, + "column": 20 + }, + "end": { + "line": 21, + "column": 23 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "memb", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 5 + }, + "end": { + "line": 22, + "column": 9 + } + } + }, + "accessibility": "public", + "static": false, + "readonly": false, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "ETSTuple", + "types": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "X", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 12 + }, + "end": { + "line": 22, + "column": 13 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 12 + }, + "end": { + "line": 22, + "column": 14 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 12 + }, + "end": { + "line": 22, + "column": 14 + } + } + }, + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "X", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 15 + }, + "end": { + "line": 22, + "column": 16 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 15 + }, + "end": { + "line": 22, + "column": 17 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 15 + }, + "end": { + "line": 22, + "column": 17 + } + } + } + ], + "spreadType": null, + "loc": { + "start": { + "line": 22, + "column": 11 + }, + "end": { + "line": 22, + "column": 18 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 5 + }, + "end": { + "line": 22, + "column": 18 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "accessibility": "public", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "value", + "typeAnnotation": { + "type": "ETSTuple", + "types": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "X", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 25 + }, + "end": { + "line": 23, + "column": 26 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 25 + }, + "end": { + "line": 23, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 25 + }, + "end": { + "line": 23, + "column": 27 + } + } + }, + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "X", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 28 + }, + "end": { + "line": 23, + "column": 29 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 28 + }, + "end": { + "line": 23, + "column": 30 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 28 + }, + "end": { + "line": 23, + "column": 30 + } + } + } + ], + "spreadType": null, + "loc": { + "start": { + "line": 23, + "column": 24 + }, + "end": { + "line": 23, + "column": 31 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 17 + }, + "end": { + "line": 23, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 17 + }, + "end": { + "line": 23, + "column": 31 + } + } + } + ], + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "MemberExpression", + "object": { + "type": "ThisExpression", + "loc": { + "start": { + "line": 23, + "column": 34 + }, + "end": { + "line": 23, + "column": 38 + } + } + }, + "property": { + "type": "Identifier", + "name": "memb", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 39 + }, + "end": { + "line": 23, + "column": 43 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 23, + "column": 34 + }, + "end": { + "line": 23, + "column": 43 + } + } + }, + "right": { + "type": "Identifier", + "name": "value", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 46 + }, + "end": { + "line": 23, + "column": 51 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 34 + }, + "end": { + "line": 23, + "column": 51 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 34 + }, + "end": { + "line": 23, + "column": 52 + } + } + } + ], + "loc": { + "start": { + "line": 23, + "column": 32 + }, + "end": { + "line": 23, + "column": 53 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 16 + }, + "end": { + "line": 23, + "column": 53 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 16 + }, + "end": { + "line": 23, + "column": 53 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 5 + }, + "end": { + "line": 23, + "column": 53 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "publish", + "decorators": [], + "loc": { + "start": { + "line": 24, + "column": 12 + }, + "end": { + "line": 24, + "column": 19 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "publish", + "decorators": [], + "loc": { + "start": { + "line": 24, + "column": 12 + }, + "end": { + "line": 24, + "column": 19 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "returnType": { + "type": "ETSTuple", + "types": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "X", + "decorators": [], + "loc": { + "start": { + "line": 24, + "column": 24 + }, + "end": { + "line": 24, + "column": 25 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 24 + }, + "end": { + "line": 24, + "column": 26 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 24 + }, + "end": { + "line": 24, + "column": 26 + } + } + }, + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "X", + "decorators": [], + "loc": { + "start": { + "line": 24, + "column": 27 + }, + "end": { + "line": 24, + "column": 28 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 27 + }, + "end": { + "line": 24, + "column": 29 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 27 + }, + "end": { + "line": 24, + "column": 29 + } + } + } + ], + "spreadType": null, + "loc": { + "start": { + "line": 24, + "column": 23 + }, + "end": { + "line": 24, + "column": 31 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "MemberExpression", + "object": { + "type": "ThisExpression", + "loc": { + "start": { + "line": 24, + "column": 39 + }, + "end": { + "line": 24, + "column": 43 + } + } + }, + "property": { + "type": "Identifier", + "name": "memb", + "decorators": [], + "loc": { + "start": { + "line": 24, + "column": 44 + }, + "end": { + "line": 24, + "column": 48 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 24, + "column": 39 + }, + "end": { + "line": 24, + "column": 48 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 32 + }, + "end": { + "line": 24, + "column": 49 + } + } + } + ], + "loc": { + "start": { + "line": 24, + "column": 30 + }, + "end": { + "line": 24, + "column": 51 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 19 + }, + "end": { + "line": 24, + "column": 51 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 19 + }, + "end": { + "line": 24, + "column": 51 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 24, + "column": 5 + }, + "end": { + "line": 24, + "column": 51 + } + } + } + ], + "loc": { + "start": { + "line": 21, + "column": 24 + }, + "end": { + "line": 25, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 1 + }, + "end": { + "line": 25, + "column": 2 + } + } + }, + { + "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": "foo", + "decorators": [], + "loc": { + "start": { + "line": 27, + "column": 10 + }, + "end": { + "line": 27, + "column": 13 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 27, + "column": 10 + }, + "end": { + "line": 27, + "column": 13 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "number_tup", + "typeAnnotation": { + "type": "ETSTuple", + "types": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Double", + "decorators": [], + "loc": { + "start": { + "line": 28, + "column": 22 + }, + "end": { + "line": 28, + "column": 28 + } + } + }, + "loc": { + "start": { + "line": 28, + "column": 22 + }, + "end": { + "line": 28, + "column": 29 + } + } + }, + "loc": { + "start": { + "line": 28, + "column": 22 + }, + "end": { + "line": 28, + "column": 29 + } + } + }, + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Double", + "decorators": [], + "loc": { + "start": { + "line": 28, + "column": 30 + }, + "end": { + "line": 28, + "column": 36 + } + } + }, + "loc": { + "start": { + "line": 28, + "column": 30 + }, + "end": { + "line": 28, + "column": 37 + } + } + }, + "loc": { + "start": { + "line": 28, + "column": 30 + }, + "end": { + "line": 28, + "column": 37 + } + } + } + ], + "spreadType": null, + "loc": { + "start": { + "line": 28, + "column": 21 + }, + "end": { + "line": 28, + "column": 39 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 28, + "column": 9 + }, + "end": { + "line": 28, + "column": 19 + } + } + }, + "init": { + "type": "ArrayExpression", + "elements": [ + { + "type": "NumberLiteral", + "value": 42, + "loc": { + "start": { + "line": 28, + "column": 41 + }, + "end": { + "line": 28, + "column": 45 + } + } + }, + { + "type": "NumberLiteral", + "value": 43, + "loc": { + "start": { + "line": 28, + "column": 47 + }, + "end": { + "line": 28, + "column": 51 + } + } + } + ], + "loc": { + "start": { + "line": 28, + "column": 40 + }, + "end": { + "line": 28, + "column": 52 + } + } + }, + "loc": { + "start": { + "line": 28, + "column": 9 + }, + "end": { + "line": 28, + "column": 52 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 28, + "column": 5 + }, + "end": { + "line": 28, + "column": 53 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "tn", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "TupleProvider", + "decorators": [], + "loc": { + "start": { + "line": 29, + "column": 13 + }, + "end": { + "line": 29, + "column": 26 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "number", + "decorators": [], + "loc": { + "start": { + "line": 29, + "column": 27 + }, + "end": { + "line": 29, + "column": 33 + } + } + }, + "loc": { + "start": { + "line": 29, + "column": 27 + }, + "end": { + "line": 29, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 29, + "column": 27 + }, + "end": { + "line": 29, + "column": 34 + } + } + } + ], + "loc": { + "start": { + "line": 29, + "column": 26 + }, + "end": { + "line": 29, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 29, + "column": 13 + }, + "end": { + "line": 29, + "column": 36 + } + } + }, + "loc": { + "start": { + "line": 29, + "column": 13 + }, + "end": { + "line": 29, + "column": 36 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 29, + "column": 9 + }, + "end": { + "line": 29, + "column": 11 + } + } + }, + "init": { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "TupleProvider", + "decorators": [], + "loc": { + "start": { + "line": 29, + "column": 41 + }, + "end": { + "line": 29, + "column": 54 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "number", + "decorators": [], + "loc": { + "start": { + "line": 29, + "column": 55 + }, + "end": { + "line": 29, + "column": 61 + } + } + }, + "loc": { + "start": { + "line": 29, + "column": 55 + }, + "end": { + "line": 29, + "column": 62 + } + } + }, + "loc": { + "start": { + "line": 29, + "column": 55 + }, + "end": { + "line": 29, + "column": 62 + } + } + } + ], + "loc": { + "start": { + "line": 29, + "column": 54 + }, + "end": { + "line": 29, + "column": 62 + } + } + }, + "loc": { + "start": { + "line": 29, + "column": 41 + }, + "end": { + "line": 29, + "column": 63 + } + } + }, + "loc": { + "start": { + "line": 29, + "column": 41 + }, + "end": { + "line": 29, + "column": 63 + } + } + }, + "arguments": [ + { + "type": "Identifier", + "name": "number_tup", + "decorators": [], + "loc": { + "start": { + "line": 29, + "column": 63 + }, + "end": { + "line": 29, + "column": 73 + } + } + } + ], + "loc": { + "start": { + "line": 29, + "column": 37 + }, + "end": { + "line": 29, + "column": 75 + } + } + }, + "loc": { + "start": { + "line": 29, + "column": 9 + }, + "end": { + "line": 29, + "column": 75 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 29, + "column": 5 + }, + "end": { + "line": 29, + "column": 75 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "result", + "typeAnnotation": { + "type": "ETSTuple", + "types": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Number", + "decorators": [], + "loc": { + "start": { + "line": 30, + "column": 18 + }, + "end": { + "line": 30, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 30, + "column": 18 + }, + "end": { + "line": 30, + "column": 25 + } + } + }, + "loc": { + "start": { + "line": 30, + "column": 18 + }, + "end": { + "line": 30, + "column": 25 + } + } + }, + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Number", + "decorators": [], + "loc": { + "start": { + "line": 30, + "column": 26 + }, + "end": { + "line": 30, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 30, + "column": 26 + }, + "end": { + "line": 30, + "column": 33 + } + } + }, + "loc": { + "start": { + "line": 30, + "column": 26 + }, + "end": { + "line": 30, + "column": 33 + } + } + } + ], + "spreadType": null, + "loc": { + "start": { + "line": 30, + "column": 17 + }, + "end": { + "line": 30, + "column": 35 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 30, + "column": 9 + }, + "end": { + "line": 30, + "column": 15 + } + } + }, + "init": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "tn", + "decorators": [], + "loc": { + "start": { + "line": 30, + "column": 36 + }, + "end": { + "line": 30, + "column": 38 + } + } + }, + "property": { + "type": "Identifier", + "name": "publish", + "decorators": [], + "loc": { + "start": { + "line": 30, + "column": 39 + }, + "end": { + "line": 30, + "column": 46 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 30, + "column": 36 + }, + "end": { + "line": 30, + "column": 46 + } + } + }, + "arguments": [], + "optional": false, + "loc": { + "start": { + "line": 30, + "column": 36 + }, + "end": { + "line": 30, + "column": 48 + } + } + }, + "loc": { + "start": { + "line": 30, + "column": 9 + }, + "end": { + "line": 30, + "column": 48 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 30, + "column": 5 + }, + "end": { + "line": 30, + "column": 49 + } + } + } + ], + "loc": { + "start": { + "line": 27, + "column": 16 + }, + "end": { + "line": 31, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 27, + "column": 13 + }, + "end": { + "line": 31, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 27, + "column": 13 + }, + "end": { + "line": 31, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 27, + "column": 1 + }, + "end": { + "line": 31, + "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": 32, + "column": 1 + } + } +} diff --git a/ets2panda/test/compiler/ets/tuple_types_19.ets b/ets2panda/test/compiler/ets/tuple_types_19.ets new file mode 100644 index 0000000000..cb744db81f --- /dev/null +++ b/ets2panda/test/compiler/ets/tuple_types_19.ets @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2023 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. + */ + +class TuplePair { + one: [X, Y] + public provide(): [X, Y] { return this.one; } +} + +class TupleProvider { + memb: [X, X]; + constructor(value: [X, X]) { this.memb = value;} + public publish(): [X, X] { return this.memb; } +} + +function foo() { + let number_tup: [Double, Double] = [42.0, 43.0]; + let tn: TupleProvider = new TupleProvider(number_tup); + let result: [Number, Number] = tn.publish(); +} diff --git a/ets2panda/test/runtime/ets/tuple_types_runtime.ets b/ets2panda/test/runtime/ets/tuple_types_runtime.ets index 5f57797cab..046ad690bb 100644 --- a/ets2panda/test/runtime/ets/tuple_types_runtime.ets +++ b/ets2panda/test/runtime/ets/tuple_types_runtime.ets @@ -28,6 +28,12 @@ class B extends A { } } +class TupleProvider { + memb: [X, X]; + constructor(value: [X, X]) { this.memb = value;} + public publish(): [X, X] { return this.memb; } +} + function main(): void { const tup_1: [string, number] = ["a", 12]; @@ -126,4 +132,9 @@ function main(): void { assert(a_b_tup[0].foo() == 1); assert(a_b_tup[1].foo() == 2); assert(a_b_tup[2].foo() == 2); + + let number_tup: [Double, Double] = [42.0, 43.0]; + let tn: TupleProvider = new TupleProvider(number_tup); + let result: [Number, Number] = tn.publish(); + assert result[0] == 42.0; } -- Gitee From 28a3b6b8ce1b507c2bbfe40a7b27cf5ff1abc700 Mon Sep 17 00:00:00 2001 From: Soma Simon Date: Tue, 16 Jan 2024 11:32:09 +0100 Subject: [PATCH 06/26] [ArkTS frontend] Fix cannot reference 'this' in this context Save context at proxy methods to fix the problem with this expression. Create a better check if a proxy method has return type. Fixes internal issue #14623 Change-Id: I03f41a1e90a6bde387ab504ce886694a69f8a40f Signed-off-by: Soma Simon --- ets2panda/checker/ETSAnalyzer.cpp | 1 + ets2panda/parser/ETSparser.cpp | 2 +- ..._implicitly_typed_return_void-expected.txt | 4 +- .../test/parser/ets/proxy_method-expected.txt | 1440 +++++++++++++++++ ets2panda/test/parser/ets/proxy_method.ets | 24 + .../test/runtime/ets/InferProxymethodType.ets | 37 + 6 files changed, 1505 insertions(+), 3 deletions(-) create mode 100644 ets2panda/test/parser/ets/proxy_method-expected.txt create mode 100644 ets2panda/test/parser/ets/proxy_method.ets create mode 100644 ets2panda/test/runtime/ets/InferProxymethodType.ets diff --git a/ets2panda/checker/ETSAnalyzer.cpp b/ets2panda/checker/ETSAnalyzer.cpp index 77a8d79564..f2d00c77db 100644 --- a/ets2panda/checker/ETSAnalyzer.cpp +++ b/ets2panda/checker/ETSAnalyzer.cpp @@ -1145,6 +1145,7 @@ checker::Type *ETSAnalyzer::Check(ir::CallExpression *expr) const } if (expr->Signature()->HasSignatureFlag(checker::SignatureFlags::NEED_RETURN_TYPE)) { + checker::SavedCheckerContext savedCtx(checker, checker->Context().Status(), expr->Signature()->Owner()); expr->Signature()->OwnerVar()->Declaration()->Node()->Check(checker); returnType = expr->Signature()->ReturnType(); // NOTE(vpukhov): #14902 substituted signature is not updated diff --git a/ets2panda/parser/ETSparser.cpp b/ets2panda/parser/ETSparser.cpp index b6d884410d..8bacd3eba6 100644 --- a/ets2panda/parser/ETSparser.cpp +++ b/ets2panda/parser/ETSparser.cpp @@ -2299,7 +2299,7 @@ ir::MethodDefinition *ETSParser::CreateProxyMethodDefinition(ir::MethodDefinitio } proxyMethod += ' '; - if (returnType != "void") { + if ((function->AsScriptFunction()->Flags() & ir::ScriptFunctionFlags::HAS_RETURN) != 0) { proxyMethod += "return "; } diff --git a/ets2panda/test/parser/ets/default_parameter_implicitly_typed_return_void-expected.txt b/ets2panda/test/parser/ets/default_parameter_implicitly_typed_return_void-expected.txt index 1e35125767..bb716f90ae 100644 --- a/ets2panda/test/parser/ets/default_parameter_implicitly_typed_return_void-expected.txt +++ b/ets2panda/test/parser/ets/default_parameter_implicitly_typed_return_void-expected.txt @@ -1100,8 +1100,8 @@ } }, { - "type": "ReturnStatement", - "argument": { + "type": "ExpressionStatement", + "expression": { "type": "CallExpression", "callee": { "type": "Identifier", diff --git a/ets2panda/test/parser/ets/proxy_method-expected.txt b/ets2panda/test/parser/ets/proxy_method-expected.txt new file mode 100644 index 0000000000..fa34056abf --- /dev/null +++ b/ets2panda/test/parser/ets/proxy_method-expected.txt @@ -0,0 +1,1440 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 7 + }, + "end": { + "line": 16, + "column": 8 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "met", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 5 + }, + "end": { + "line": 17, + "column": 8 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "met", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 5 + }, + "end": { + "line": 17, + "column": 8 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "s", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 12 + }, + "end": { + "line": 17, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 12 + }, + "end": { + "line": 17, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 12 + }, + "end": { + "line": 17, + "column": 19 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 9 + }, + "end": { + "line": 17, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 9 + }, + "end": { + "line": 17, + "column": 19 + } + } + }, + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "q", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 24 + }, + "end": { + "line": 17, + "column": 30 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 24 + }, + "end": { + "line": 17, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 24 + }, + "end": { + "line": 17, + "column": 31 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 20 + }, + "end": { + "line": 17, + "column": 31 + } + } + }, + "initializer": { + "type": "UndefinedLiteral", + "value": undefined, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 20 + }, + "end": { + "line": 17, + "column": 31 + } + } + } + ], + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "console", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 9 + }, + "end": { + "line": 18, + "column": 16 + } + } + }, + "property": { + "type": "Identifier", + "name": "log", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 17 + }, + "end": { + "line": 18, + "column": 20 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 18, + "column": 9 + }, + "end": { + "line": 18, + "column": 20 + } + } + }, + "arguments": [ + { + "type": "BinaryExpression", + "operator": "+", + "left": { + "type": "StringLiteral", + "value": "met ", + "loc": { + "start": { + "line": 18, + "column": 21 + }, + "end": { + "line": 18, + "column": 27 + } + } + }, + "right": { + "type": "Identifier", + "name": "s", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 30 + }, + "end": { + "line": 18, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 21 + }, + "end": { + "line": 18, + "column": 31 + } + } + } + ], + "optional": false, + "loc": { + "start": { + "line": 18, + "column": 9 + }, + "end": { + "line": 18, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 9 + }, + "end": { + "line": 18, + "column": 32 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 31 + }, + "end": { + "line": 19, + "column": 6 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 8 + }, + "end": { + "line": 19, + "column": 6 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 8 + }, + "end": { + "line": 19, + "column": 6 + } + } + }, + "overloads": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "met_proxy", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "met_proxy", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "s", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "q", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "$proxy_mask$", + "typeAnnotation": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + } + ], + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "IfStatement", + "test": { + "type": "BinaryExpression", + "operator": "==", + "left": { + "type": "BinaryExpression", + "operator": "&", + "left": { + "type": "BinaryExpression", + "operator": ">>", + "left": { + "type": "Identifier", + "name": "$proxy_mask$", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "right": { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "right": { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "right": { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "consequent": { + "type": "BlockStatement", + "statements": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "q", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "right": { + "type": "UndefinedLiteral", + "value": undefined, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "alternate": null, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "ThisExpression", + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "property": { + "type": "Identifier", + "name": "met", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "arguments": [ + { + "type": "Identifier", + "name": "s", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + { + "type": "Identifier", + "name": "q", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + } + ], + "optional": false, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 3 + } + } + } + ], + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 5 + }, + "end": { + "line": 19, + "column": 6 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "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": 20, + "column": 2 + }, + "end": { + "line": 20, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 20, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 20, + "column": 2 + } + } + }, + { + "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": "main", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 10 + }, + "end": { + "line": 22, + "column": 14 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 10 + }, + "end": { + "line": 22, + "column": 14 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 9 + }, + "end": { + "line": 23, + "column": 10 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 9 + }, + "end": { + "line": 23, + "column": 11 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 9 + }, + "end": { + "line": 23, + "column": 11 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 23, + "column": 5 + }, + "end": { + "line": 23, + "column": 13 + } + } + }, + "property": { + "type": "Identifier", + "name": "met", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 13 + }, + "end": { + "line": 23, + "column": 16 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 23, + "column": 5 + }, + "end": { + "line": 23, + "column": 16 + } + } + }, + "arguments": [ + { + "type": "StringLiteral", + "value": "S", + "loc": { + "start": { + "line": 23, + "column": 17 + }, + "end": { + "line": 23, + "column": 20 + } + } + } + ], + "optional": false, + "loc": { + "start": { + "line": 23, + "column": 5 + }, + "end": { + "line": 23, + "column": 21 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 5 + }, + "end": { + "line": 23, + "column": 21 + } + } + } + ], + "loc": { + "start": { + "line": 22, + "column": 17 + }, + "end": { + "line": 24, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 14 + }, + "end": { + "line": 24, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 14 + }, + "end": { + "line": 24, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 1 + }, + "end": { + "line": 24, + "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": 25, + "column": 1 + } + } +} diff --git a/ets2panda/test/parser/ets/proxy_method.ets b/ets2panda/test/parser/ets/proxy_method.ets new file mode 100644 index 0000000000..d058f71495 --- /dev/null +++ b/ets2panda/test/parser/ets/proxy_method.ets @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2024 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. + */ + +class A { + met(s: string, q?: string){ + console.log("met " + s) + } +} + +function main() { + new A().met('S') +} diff --git a/ets2panda/test/runtime/ets/InferProxymethodType.ets b/ets2panda/test/runtime/ets/InferProxymethodType.ets new file mode 100644 index 0000000000..334bb0f6ec --- /dev/null +++ b/ets2panda/test/runtime/ets/InferProxymethodType.ets @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 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. + */ + + class A { + met(s: string, q?: string){ + return true; + } + + mat2(){ + return this.met("cat","a"); + } +} + +function main() { + let newA = new A(); + let a1 = new A().met('S'); + let a2 = new A().met('S',"a"); + let a3 = newA.met('S', 'a'); + let b = new A().mat2(); + + assert a1; + assert a2; + assert a3; + assert b; +} -- Gitee From fbd6f86f5e9bc074aa67725af6d366e3718cec72 Mon Sep 17 00:00:00 2001 From: ozerovnikita Date: Thu, 21 Dec 2023 19:28:37 +0300 Subject: [PATCH 07/26] fix CTE in assignment non-functional non-functional variable to a functional type Description: replaced ThrowError() call that returns Unresolved reference with ThrowTypeError() call with error description Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/I8S702 Signed-off-by: ozerovnikita --- ets2panda/checker/ets/helpers.cpp | 3 +- ...l_variable_to_functional_type-expected.txt | 894 ++++++++++++++++++ ...functional_variable_to_functional_type.ets | 26 + ...variable_to_functional_type_1-expected.txt | 449 +++++++++ ...nctional_variable_to_functional_type_1.ets | 21 + 5 files changed, 1392 insertions(+), 1 deletion(-) create mode 100644 ets2panda/test/parser/ets/assignment_non-functional_variable_to_functional_type-expected.txt create mode 100644 ets2panda/test/parser/ets/assignment_non-functional_variable_to_functional_type.ets create mode 100644 ets2panda/test/parser/ets/assignment_non-functional_variable_to_functional_type_1-expected.txt create mode 100644 ets2panda/test/parser/ets/assignment_non-functional_variable_to_functional_type_1.ets diff --git a/ets2panda/checker/ets/helpers.cpp b/ets2panda/checker/ets/helpers.cpp index e720f7b96f..77aa904632 100644 --- a/ets2panda/checker/ets/helpers.cpp +++ b/ets2panda/checker/ets/helpers.cpp @@ -586,7 +586,8 @@ void ETSChecker::ValidateAssignmentIdentifier(ir::Identifier *const ident, varbi if (targetType->IsETSObjectType() && targetType->AsETSObjectType()->HasObjectFlag(ETSObjectFlags::FUNCTIONAL)) { if (!type->IsETSFunctionType() && !(type->IsETSObjectType() && type->AsETSObjectType()->HasObjectFlag(ETSObjectFlags::FUNCTIONAL))) { - ThrowError(ident); + ThrowTypeError({"Assigning a non-functional variable \"", ident->Name(), "\" to a functional type"}, + ident->Start()); } return; diff --git a/ets2panda/test/parser/ets/assignment_non-functional_variable_to_functional_type-expected.txt b/ets2panda/test/parser/ets/assignment_non-functional_variable_to_functional_type-expected.txt new file mode 100644 index 0000000000..6ca5ac47b0 --- /dev/null +++ b/ets2panda/test/parser/ets/assignment_non-functional_variable_to_functional_type-expected.txt @@ -0,0 +1,894 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "__Observable__", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 16 + }, + "end": { + "line": 16, + "column": 30 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "__memo_state_observable_handler__", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 12 + }, + "end": { + "line": 17, + "column": 45 + } + } + }, + "accessibility": "public", + "static": false, + "readonly": false, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "ETSFunctionType", + "params": [], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Observable", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 53 + }, + "end": { + "line": 17, + "column": 63 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 53 + }, + "end": { + "line": 17, + "column": 64 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 53 + }, + "end": { + "line": 17, + "column": 64 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 47 + }, + "end": { + "line": 17, + "column": 64 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 12 + }, + "end": { + "line": 17, + "column": 64 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "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": 18, + "column": 2 + }, + "end": { + "line": 18, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 31 + }, + "end": { + "line": 18, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 10 + }, + "end": { + "line": 18, + "column": 2 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "Observable", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 7 + }, + "end": { + "line": 20, + "column": 17 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "installOn", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 12 + }, + "end": { + "line": 21, + "column": 21 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "installOn", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 12 + }, + "end": { + "line": 21, + "column": 21 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "value", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Object", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 29 + }, + "end": { + "line": 21, + "column": 35 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 29 + }, + "end": { + "line": 21, + "column": 36 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 29 + }, + "end": { + "line": 21, + "column": 36 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 22 + }, + "end": { + "line": 21, + "column": 36 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 22 + }, + "end": { + "line": 21, + "column": 36 + } + } + }, + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "observable", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Observable", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 49 + }, + "end": { + "line": 21, + "column": 59 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 49 + }, + "end": { + "line": 21, + "column": 60 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 49 + }, + "end": { + "line": 21, + "column": 60 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 37 + }, + "end": { + "line": 21, + "column": 60 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 37 + }, + "end": { + "line": 21, + "column": 60 + } + } + } + ], + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "MemberExpression", + "object": { + "type": "TSAsExpression", + "expression": { + "type": "Identifier", + "name": "value", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 10 + }, + "end": { + "line": 23, + "column": 15 + } + } + }, + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "__Observable__", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 19 + }, + "end": { + "line": 23, + "column": 33 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 19 + }, + "end": { + "line": 23, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 19 + }, + "end": { + "line": 23, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 9 + }, + "end": { + "line": 23, + "column": 34 + } + } + }, + "property": { + "type": "Identifier", + "name": "__memo_state_observable_handler__", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 35 + }, + "end": { + "line": 23, + "column": 68 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 23, + "column": 9 + }, + "end": { + "line": 23, + "column": 68 + } + } + }, + "right": { + "type": "Identifier", + "name": "observable", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 71 + }, + "end": { + "line": 23, + "column": 81 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 9 + }, + "end": { + "line": 23, + "column": 81 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 9 + }, + "end": { + "line": 23, + "column": 81 + } + } + } + ], + "loc": { + "start": { + "line": 22, + "column": 5 + }, + "end": { + "line": 24, + "column": 6 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 21 + }, + "end": { + "line": 24, + "column": 6 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 21 + }, + "end": { + "line": 24, + "column": 6 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 5 + }, + "end": { + "line": 24, + "column": 6 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "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": 26, + "column": 2 + }, + "end": { + "line": 26, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 20, + "column": 18 + }, + "end": { + "line": 26, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 1 + }, + "end": { + "line": 26, + "column": 2 + } + } + }, + { + "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 + } + } + } + ], + "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": 27, + "column": 1 + } + } +} +TypeError: Assigning a non-functional variable "observable" to a functional type [assignment_non-functional_variable_to_functional_type.ets:23:71] diff --git a/ets2panda/test/parser/ets/assignment_non-functional_variable_to_functional_type.ets b/ets2panda/test/parser/ets/assignment_non-functional_variable_to_functional_type.ets new file mode 100644 index 0000000000..4288ab1f6b --- /dev/null +++ b/ets2panda/test/parser/ets/assignment_non-functional_variable_to_functional_type.ets @@ -0,0 +1,26 @@ +/** + * Copyright (c) 2023 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. + */ + +abstract class __Observable__ { + public __memo_state_observable_handler__: () => Observable|undefined; +} + +class Observable { + static installOn(value: Object, observable: Observable|undefined) + { + (value as __Observable__).__memo_state_observable_handler__ = observable + } + +} diff --git a/ets2panda/test/parser/ets/assignment_non-functional_variable_to_functional_type_1-expected.txt b/ets2panda/test/parser/ets/assignment_non-functional_variable_to_functional_type_1-expected.txt new file mode 100644 index 0000000000..366185c853 --- /dev/null +++ b/ets2panda/test/parser/ets/assignment_non-functional_variable_to_functional_type_1-expected.txt @@ -0,0 +1,449 @@ +{ + "type": "Program", + "statements": [ + { + "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": "main", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 10 + }, + "end": { + "line": 16, + "column": 14 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 10 + }, + "end": { + "line": 16, + "column": 14 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "a", + "typeAnnotation": { + "type": "ETSFunctionType", + "params": [], + "returnType": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 18, + "column": 18 + }, + "end": { + "line": 18, + "column": 21 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 12 + }, + "end": { + "line": 18, + "column": 21 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 9 + }, + "end": { + "line": 18, + "column": 10 + } + } + }, + "init": null, + "loc": { + "start": { + "line": 18, + "column": 9 + }, + "end": { + "line": 18, + "column": 10 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 10 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "b", + "typeAnnotation": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 19, + "column": 12 + }, + "end": { + "line": 19, + "column": 15 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 9 + }, + "end": { + "line": 19, + "column": 10 + } + } + }, + "init": { + "type": "NumberLiteral", + "value": 5, + "loc": { + "start": { + "line": 19, + "column": 18 + }, + "end": { + "line": 19, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 9 + }, + "end": { + "line": 19, + "column": 19 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 19, + "column": 5 + }, + "end": { + "line": 19, + "column": 19 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "a", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 5 + }, + "end": { + "line": 20, + "column": 6 + } + } + }, + "right": { + "type": "Identifier", + "name": "b", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 9 + }, + "end": { + "line": 20, + "column": 10 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 5 + }, + "end": { + "line": 20, + "column": 10 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 5 + }, + "end": { + "line": 20, + "column": 10 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 1 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 14 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 14 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 21, + "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": 22, + "column": 1 + } + } +} +TypeError: Assigning a non-functional variable "b" to a functional type [assignment_non-functional_variable_to_functional_type_1.ets:20:9] diff --git a/ets2panda/test/parser/ets/assignment_non-functional_variable_to_functional_type_1.ets b/ets2panda/test/parser/ets/assignment_non-functional_variable_to_functional_type_1.ets new file mode 100644 index 0000000000..fec2befa80 --- /dev/null +++ b/ets2panda/test/parser/ets/assignment_non-functional_variable_to_functional_type_1.ets @@ -0,0 +1,21 @@ +/** + * Copyright (c) 2023 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 main() +{ + let a: () => int + let b: int = 5 + a = b +} -- Gitee From 91f8339b07c7b2a760c369a50c63256f886f01d9 Mon Sep 17 00:00:00 2001 From: Molokanov Yaroslav Date: Thu, 28 Dec 2023 14:18:41 +0300 Subject: [PATCH 08/26] ValidateSignature method fix for CodeCheck Reducing ValidateSignature method cyclomatic complexity and size Signed-off-by: Molokanov Yaroslav --- ets2panda/checker/ETSchecker.h | 5 + ets2panda/checker/ets/function.cpp | 163 +++++++++++++++++------------ 2 files changed, 99 insertions(+), 69 deletions(-) diff --git a/ets2panda/checker/ETSchecker.h b/ets2panda/checker/ETSchecker.h index 60b5410d3c..44cd7dfbda 100644 --- a/ets2panda/checker/ETSchecker.h +++ b/ets2panda/checker/ETSchecker.h @@ -313,6 +313,11 @@ public: Signature *ValidateSignature(Signature *signature, const ir::TSTypeParameterInstantiation *typeArguments, const ArenaVector &arguments, const lexer::SourcePosition &pos, TypeRelationFlag initialFlags, const std::vector &argTypeInferenceRequired); + bool ValidateSignatureRequiredParams(Signature *substitutedSig, const ArenaVector &arguments, + TypeRelationFlag flags, const std::vector &argTypeInferenceRequired, + bool throwError); + bool ValidateSignatureRestParams(Signature *substitutedSig, const ArenaVector &arguments, + TypeRelationFlag flags, bool throwError); Signature *ValidateSignatures(ArenaVector &signatures, const ir::TSTypeParameterInstantiation *typeArguments, const ArenaVector &arguments, const lexer::SourcePosition &pos, diff --git a/ets2panda/checker/ets/function.cpp b/ets2panda/checker/ets/function.cpp index e6f781ed57..7dfecd77be 100644 --- a/ets2panda/checker/ets/function.cpp +++ b/ets2panda/checker/ets/function.cpp @@ -182,38 +182,14 @@ Signature *ETSChecker::ValidateParameterlessConstructor(Signature *signature, co return signature; } -Signature *ETSChecker::ValidateSignature(Signature *signature, const ir::TSTypeParameterInstantiation *typeArguments, - const ArenaVector &arguments, - const lexer::SourcePosition &pos, TypeRelationFlag flags, - const std::vector &argTypeInferenceRequired) +bool ETSChecker::ValidateSignatureRequiredParams(Signature *substitutedSig, + const ArenaVector &arguments, TypeRelationFlag flags, + const std::vector &argTypeInferenceRequired, bool throwError) { - if (signature->Function()->IsDefaultParamProxy() && ((flags & TypeRelationFlag::CHECK_PROXY) == 0)) { - return nullptr; - } - - Signature *substitutedSig = MaybeSubstituteTypeParameters(this, signature, typeArguments, arguments, pos, flags); - if (substitutedSig == nullptr) { - return nullptr; - } - - auto const hasRestParameter = substitutedSig->RestVar() != nullptr; std::size_t const argumentCount = arguments.size(); std::size_t const parameterCount = substitutedSig->MinArgCount(); - auto const throwError = (flags & TypeRelationFlag::NO_THROW) == 0; - - if (!signature->Function()->IsDefaultParamProxy()) { - if (argumentCount < parameterCount || (argumentCount > parameterCount && !hasRestParameter)) { - if (throwError) { - ThrowTypeError({"Expected ", parameterCount, " arguments, got ", argumentCount, "."}, pos); - } - return nullptr; - } - } - - // Check all required formal parameter(s) first - auto const count = std::min(parameterCount, argumentCount); - std::size_t index = 0U; - for (; index < count; ++index) { + auto count = std::min(parameterCount, argumentCount); + for (std::size_t index = 0; index < count; ++index) { auto &argument = arguments[index]; if (argument->IsObjectExpression()) { @@ -221,7 +197,7 @@ Signature *ETSChecker::ValidateSignature(Signature *signature, const ir::TSTypeP // No chance to check the argument at this point continue; } - return nullptr; + return false; } if (argument->IsMemberExpression()) { @@ -231,7 +207,7 @@ Signature *ETSChecker::ValidateSignature(Signature *signature, const ir::TSTypeP if (throwError) { ThrowTypeError("Spread argument cannot be passed for ordinary parameter.", argument->Start()); } - return nullptr; + return false; } if (argTypeInferenceRequired[index]) { @@ -241,7 +217,7 @@ Signature *ETSChecker::ValidateSignature(Signature *signature, const ir::TSTypeP if (CheckLambdaAssignable(substitutedSig->Function()->Params()[index], lambda)) { continue; } - return nullptr; + return false; } if (argument->IsArrayExpression()) { @@ -251,50 +227,99 @@ Signature *ETSChecker::ValidateSignature(Signature *signature, const ir::TSTypeP auto *const argumentType = argument->Check(this); - if (auto const invocationCtx = checker::InvocationContext( - Relation(), argument, argumentType, substitutedSig->Params()[index]->TsType(), argument->Start(), - {INVALID_CALL_ARGUMENT_1, index, INVALID_CALL_ARGUMENT_2}, flags); - !invocationCtx.IsInvocable()) { - return nullptr; + auto const invocationCtx = checker::InvocationContext( + Relation(), argument, argumentType, substitutedSig->Params()[index]->TsType(), argument->Start(), + {INVALID_CALL_ARGUMENT_1, index, INVALID_CALL_ARGUMENT_2}, flags); + if (!invocationCtx.IsInvocable()) { + return false; } } - // Check rest parameter(s) if any exists - if (hasRestParameter && index < argumentCount) { - auto const restCount = argumentCount - index; - - for (; index < argumentCount; ++index) { - auto &argument = arguments[index]; - - if (argument->IsSpreadElement()) { - if (restCount > 1U) { - if (throwError) { - ThrowTypeError("Spread argument for the rest parameter can be only one.", argument->Start()); - } - return nullptr; - } + return true; +} - auto *const restArgument = argument->AsSpreadElement()->Argument(); - auto *const argumentType = restArgument->Check(this); +bool ETSChecker::ValidateSignatureRestParams(Signature *substitutedSig, const ArenaVector &arguments, + TypeRelationFlag flags, bool throwError) +{ + std::size_t const argumentCount = arguments.size(); + std::size_t const parameterCount = substitutedSig->MinArgCount(); + auto count = std::min(parameterCount, argumentCount); + auto const restCount = argumentCount - count; - if (auto const invocationCtx = checker::InvocationContext( - Relation(), restArgument, argumentType, substitutedSig->RestVar()->TsType(), argument->Start(), - {INVALID_CALL_ARGUMENT_1, index, INVALID_CALL_ARGUMENT_3}, flags); - !invocationCtx.IsInvocable()) { - return nullptr; - } - } else { - auto *const argumentType = argument->Check(this); - - if (auto const invocationCtx = checker::InvocationContext( - Relation(), argument, argumentType, - substitutedSig->RestVar()->TsType()->AsETSArrayType()->ElementType(), argument->Start(), - {INVALID_CALL_ARGUMENT_1, index, INVALID_CALL_ARGUMENT_3}, flags); - !invocationCtx.IsInvocable()) { - return nullptr; - } + for (std::size_t index = count; index < argumentCount; ++index) { + auto &argument = arguments[index]; + + if (!argument->IsSpreadElement()) { + auto const invocationCtx = checker::InvocationContext( + Relation(), argument, argument->Check(this), + substitutedSig->RestVar()->TsType()->AsETSArrayType()->ElementType(), argument->Start(), + {INVALID_CALL_ARGUMENT_1, index, INVALID_CALL_ARGUMENT_3}, flags); + if (!invocationCtx.IsInvocable()) { + return false; } + continue; } + + if (restCount > 1U) { + if (throwError) { + ThrowTypeError("Spread argument for the rest parameter can be only one.", argument->Start()); + } + return false; + } + + auto *const restArgument = argument->AsSpreadElement()->Argument(); + + auto const invocationCtx = checker::InvocationContext( + Relation(), restArgument, restArgument->Check(this), substitutedSig->RestVar()->TsType(), argument->Start(), + {INVALID_CALL_ARGUMENT_1, index, INVALID_CALL_ARGUMENT_3}, flags); + if (!invocationCtx.IsInvocable()) { + return false; + } + } + + return true; +} + +Signature *ETSChecker::ValidateSignature(Signature *signature, const ir::TSTypeParameterInstantiation *typeArguments, + const ArenaVector &arguments, + const lexer::SourcePosition &pos, TypeRelationFlag flags, + const std::vector &argTypeInferenceRequired) +{ + if (signature->Function()->IsDefaultParamProxy() && ((flags & TypeRelationFlag::CHECK_PROXY) == 0)) { + return nullptr; + } + + Signature *substitutedSig = MaybeSubstituteTypeParameters(this, signature, typeArguments, arguments, pos, flags); + if (substitutedSig == nullptr) { + return nullptr; + } + + auto const hasRestParameter = substitutedSig->RestVar() != nullptr; + std::size_t const argumentCount = arguments.size(); + std::size_t const parameterCount = substitutedSig->MinArgCount(); + auto const throwError = (flags & TypeRelationFlag::NO_THROW) == 0; + + if (!signature->Function()->IsDefaultParamProxy()) { + if (argumentCount < parameterCount || (argumentCount > parameterCount && !hasRestParameter)) { + if (throwError) { + ThrowTypeError({"Expected ", parameterCount, " arguments, got ", argumentCount, "."}, pos); + } + return nullptr; + } + } + + auto count = std::min(parameterCount, argumentCount); + // Check all required formal parameter(s) first + if (!ValidateSignatureRequiredParams(substitutedSig, arguments, flags, argTypeInferenceRequired, throwError)) { + return nullptr; + } + + // Check rest parameter(s) if any exists + if (!hasRestParameter || count >= argumentCount) { + return substitutedSig; + } + if (!ValidateSignatureRestParams(substitutedSig, arguments, flags, throwError)) { + return nullptr; } return substitutedSig; -- Gitee From f58a4cbadba8d3d0baa2c1d8365cb6f228600537 Mon Sep 17 00:00:00 2001 From: Martin Sajti Date: Fri, 19 Jan 2024 15:46:57 +0100 Subject: [PATCH 09/26] Fix getter/setter instantiation for generic classes Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/I8XLK2 Internal issue: #15308 Test: build, new checker test Signed-off-by: Martin Sajti --- ets2panda/checker/types/ets/etsObjectType.cpp | 3 +- .../generic_class_getter_setter-expected.txt | 1064 +++++++++++++++++ .../ets/generic_class_getter_setter.ets | 23 + 3 files changed, 1089 insertions(+), 1 deletion(-) create mode 100644 ets2panda/test/compiler/ets/generic_class_getter_setter-expected.txt create mode 100644 ets2panda/test/compiler/ets/generic_class_getter_setter.ets diff --git a/ets2panda/checker/types/ets/etsObjectType.cpp b/ets2panda/checker/types/ets/etsObjectType.cpp index 17cbff5b6f..ab6f4fb3f5 100644 --- a/ets2panda/checker/types/ets/etsObjectType.cpp +++ b/ets2panda/checker/types/ets/etsObjectType.cpp @@ -780,7 +780,8 @@ static varbinder::LocalVariable *CopyPropertyWithTypeArguments(varbinder::LocalV const Substitution *substitution) { auto *const checker = relation->GetChecker()->AsETSChecker(); - auto *const copiedPropType = checker->GetTypeOfVariable(prop)->Substitute(relation, substitution); + auto *const varType = ETSChecker::IsVariableGetterSetter(prop) ? prop->TsType() : checker->GetTypeOfVariable(prop); + auto *const copiedPropType = varType->Substitute(relation, substitution); auto *const copiedProp = prop->Copy(checker->Allocator(), prop->Declaration()); copiedPropType->SetVariable(copiedProp); copiedProp->SetTsType(copiedPropType); diff --git a/ets2panda/test/compiler/ets/generic_class_getter_setter-expected.txt b/ets2panda/test/compiler/ets/generic_class_getter_setter-expected.txt new file mode 100644 index 0000000000..aa42a01485 --- /dev/null +++ b/ets2panda/test/compiler/ets/generic_class_getter_setter-expected.txt @@ -0,0 +1,1064 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 7 + }, + "end": { + "line": 16, + "column": 8 + } + } + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "params": [ + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 10 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 11 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 8 + }, + "end": { + "line": 16, + "column": 11 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "memb", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "get", + "accessibility": "public", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "memb", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "number", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 17 + }, + "end": { + "line": 17, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 17 + }, + "end": { + "line": 17, + "column": 25 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 17 + }, + "end": { + "line": 17, + "column": 25 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 17, + "column": 33 + }, + "end": { + "line": 17, + "column": 36 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 26 + }, + "end": { + "line": 17, + "column": 37 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 24 + }, + "end": { + "line": 17, + "column": 39 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 13 + }, + "end": { + "line": 17, + "column": 39 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 13 + }, + "end": { + "line": 17, + "column": 39 + } + } + }, + "overloads": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "memb", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "set", + "accessibility": "public", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "memb", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "a0", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "number", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 18 + }, + "end": { + "line": 18, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 18 + }, + "end": { + "line": 18, + "column": 25 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 18 + }, + "end": { + "line": 18, + "column": 25 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 14 + }, + "end": { + "line": 18, + "column": 25 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 14 + }, + "end": { + "line": 18, + "column": 25 + } + } + } + ], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "void", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 27 + }, + "end": { + "line": 18, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 27 + }, + "end": { + "line": 18, + "column": 33 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 27 + }, + "end": { + "line": 18, + "column": 33 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 18, + "column": 32 + }, + "end": { + "line": 18, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 13 + }, + "end": { + "line": 18, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 13 + }, + "end": { + "line": 18, + "column": 34 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 13 + }, + "end": { + "line": 18, + "column": 34 + } + } + } + ], + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 13 + }, + "end": { + "line": 17, + "column": 39 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "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": 19, + "column": 2 + }, + "end": { + "line": 19, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 12 + }, + "end": { + "line": 19, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 19, + "column": 2 + } + } + }, + { + "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": "main", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 10 + }, + "end": { + "line": 21, + "column": 14 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 10 + }, + "end": { + "line": 21, + "column": 14 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "void", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 18 + }, + "end": { + "line": 21, + "column": 22 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 18 + }, + "end": { + "line": 21, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 18 + }, + "end": { + "line": 21, + "column": 24 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "memb", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "number", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 15 + }, + "end": { + "line": 22, + "column": 21 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 15 + }, + "end": { + "line": 22, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 15 + }, + "end": { + "line": 22, + "column": 23 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 9 + }, + "end": { + "line": 22, + "column": 13 + } + } + }, + "init": { + "type": "MemberExpression", + "object": { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 28 + }, + "end": { + "line": 22, + "column": 29 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Object", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 30 + }, + "end": { + "line": 22, + "column": 36 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 30 + }, + "end": { + "line": 22, + "column": 37 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 30 + }, + "end": { + "line": 22, + "column": 37 + } + } + } + ], + "loc": { + "start": { + "line": 22, + "column": 29 + }, + "end": { + "line": 22, + "column": 37 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 28 + }, + "end": { + "line": 22, + "column": 38 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 28 + }, + "end": { + "line": 22, + "column": 38 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 22, + "column": 24 + }, + "end": { + "line": 22, + "column": 40 + } + } + }, + "property": { + "type": "Identifier", + "name": "memb", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 40 + }, + "end": { + "line": 22, + "column": 44 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 22, + "column": 24 + }, + "end": { + "line": 22, + "column": 44 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 9 + }, + "end": { + "line": 22, + "column": 44 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 22, + "column": 5 + }, + "end": { + "line": 22, + "column": 45 + } + } + } + ], + "loc": { + "start": { + "line": 21, + "column": 23 + }, + "end": { + "line": 23, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 14 + }, + "end": { + "line": 23, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 14 + }, + "end": { + "line": 23, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 1 + }, + "end": { + "line": 23, + "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": 24, + "column": 1 + } + } +} diff --git a/ets2panda/test/compiler/ets/generic_class_getter_setter.ets b/ets2panda/test/compiler/ets/generic_class_getter_setter.ets new file mode 100644 index 0000000000..3ee99d0898 --- /dev/null +++ b/ets2panda/test/compiler/ets/generic_class_getter_setter.ets @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 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. + */ + +class A { + get memb(): number { return 1.0; } + set memb(a0: number): void {} +} + +function main(): void { + let memb: number = new A().memb; +} -- Gitee From e4e3b9b1fc494c927508ea7f4fb717674426bdfb Mon Sep 17 00:00:00 2001 From: zhao-xinyuan8 Date: Thu, 11 Jan 2024 03:39:39 +0000 Subject: [PATCH 10/26] Fix new array creation workaround logic Remove new array creation workaround logic for ETS_ARRAY and GENERIC types. Remove errorneous case launch_expression.ets Signed-off-by: zhao-xinyuan8 --- ets2panda/checker/ETSAnalyzer.cpp | 2 - .../ets/launch_expression-expected.txt | 1265 +++++++++-------- .../test/compiler/ets/launch_expression.ets | 3 +- 3 files changed, 641 insertions(+), 629 deletions(-) diff --git a/ets2panda/checker/ETSAnalyzer.cpp b/ets2panda/checker/ETSAnalyzer.cpp index f2d00c77db..885e81d208 100644 --- a/ets2panda/checker/ETSAnalyzer.cpp +++ b/ets2panda/checker/ETSAnalyzer.cpp @@ -506,9 +506,7 @@ checker::Type *ETSAnalyzer::Check(ir::ETSNewArrayInstanceExpression *expr) const checker->ValidateArrayIndex(expr->dimension_, true); if (!elementType->HasTypeFlag(TypeFlag::ETS_PRIMITIVE) && !elementType->IsNullish() && - !elementType->HasTypeFlag(TypeFlag::GENERIC) && !elementType->HasTypeFlag(TypeFlag::ETS_ARRAY) && elementType->ToAssemblerName().str() != "Ball") { - // Check only valid for ETS_PRIMITIVE and IsNullish, GENERIC and ETS_ARRAY are workaround checks for stdlib // Ball is workaround for koala ui lib if (elementType->IsETSObjectType()) { auto *calleeObj = elementType->AsETSObjectType(); diff --git a/ets2panda/test/compiler/ets/launch_expression-expected.txt b/ets2panda/test/compiler/ets/launch_expression-expected.txt index ef4e77e942..e0578ae161 100644 --- a/ets2panda/test/compiler/ets/launch_expression-expected.txt +++ b/ets2panda/test/compiler/ets/launch_expression-expected.txt @@ -1,6 +1,131 @@ { "type": "Program", "statements": [ + { + "type": "TSTypeAliasDeclaration", + "id": { + "type": "Identifier", + "name": "P", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 6 + }, + "end": { + "line": 20, + "column": 7 + } + } + }, + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Promise", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 10 + }, + "end": { + "line": 20, + "column": 17 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 18 + }, + "end": { + "line": 20, + "column": 21 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 18 + }, + "end": { + "line": 20, + "column": 22 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 18 + }, + "end": { + "line": 20, + "column": 22 + } + } + } + ], + "loc": { + "start": { + "line": 20, + "column": 17 + }, + "end": { + "line": 20, + "column": 22 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 10 + }, + "end": { + "line": 20, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 10 + }, + "end": { + "line": 20, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 1 + }, + "end": { + "line": 21, + "column": 9 + } + } + }, { "type": "ClassDeclaration", "definition": { @@ -627,11 +752,11 @@ "decorators": [], "loc": { "start": { - "line": 20, + "line": 21, "column": 10 }, "end": { - "line": 20, + "line": 21, "column": 19 } } @@ -651,11 +776,11 @@ "decorators": [], "loc": { "start": { - "line": 20, + "line": 21, "column": 10 }, "end": { - "line": 20, + "line": 21, "column": 19 } } @@ -673,11 +798,11 @@ "type": "ETSPrimitiveType", "loc": { "start": { - "line": 20, + "line": 21, "column": 28 }, "end": { - "line": 20, + "line": 21, "column": 31 } } @@ -685,22 +810,22 @@ "decorators": [], "loc": { "start": { - "line": 20, + "line": 21, "column": 20 }, "end": { - "line": 20, + "line": 21, "column": 31 } } }, "loc": { "start": { - "line": 20, + "line": 21, "column": 20 }, "end": { - "line": 20, + "line": 21, "column": 31 } } @@ -714,11 +839,11 @@ "type": "ETSPrimitiveType", "loc": { "start": { - "line": 20, + "line": 21, "column": 41 }, "end": { - "line": 20, + "line": 21, "column": 44 } } @@ -726,22 +851,22 @@ "decorators": [], "loc": { "start": { - "line": 20, + "line": 21, "column": 33 }, "end": { - "line": 20, + "line": 21, "column": 44 } } }, "loc": { "start": { - "line": 20, + "line": 21, "column": 33 }, "end": { - "line": 20, + "line": 21, "column": 44 } } @@ -757,33 +882,33 @@ "decorators": [], "loc": { "start": { - "line": 20, + "line": 21, "column": 47 }, "end": { - "line": 20, + "line": 21, "column": 51 } } }, "loc": { "start": { - "line": 20, + "line": 21, "column": 47 }, "end": { - "line": 20, + "line": 21, "column": 53 } } }, "loc": { "start": { - "line": 20, + "line": 21, "column": 47 }, "end": { - "line": 20, + "line": 21, "column": 53 } } @@ -802,11 +927,11 @@ "decorators": [], "loc": { "start": { - "line": 21, + "line": 22, "column": 9 }, "end": { - "line": 21, + "line": 22, "column": 15 } } @@ -817,22 +942,22 @@ "decorators": [], "loc": { "start": { - "line": 21, + "line": 22, "column": 19 }, "end": { - "line": 21, + "line": 22, "column": 25 } } }, "loc": { "start": { - "line": 21, + "line": 22, "column": 9 }, "end": { - "line": 21, + "line": 22, "column": 25 } } @@ -845,11 +970,11 @@ "argument": null, "loc": { "start": { - "line": 22, + "line": 23, "column": 9 }, "end": { - "line": 22, + "line": 23, "column": 16 } } @@ -857,11 +982,11 @@ ], "loc": { "start": { - "line": 21, + "line": 22, "column": 27 }, "end": { - "line": 23, + "line": 24, "column": 6 } } @@ -869,11 +994,11 @@ "alternate": null, "loc": { "start": { - "line": 21, + "line": 22, "column": 5 }, "end": { - "line": 23, + "line": 24, "column": 6 } } @@ -890,11 +1015,11 @@ "decorators": [], "loc": { "start": { - "line": 24, + "line": 25, "column": 5 }, "end": { - "line": 24, + "line": 25, "column": 12 } } @@ -905,11 +1030,11 @@ "decorators": [], "loc": { "start": { - "line": 24, + "line": 25, "column": 13 }, "end": { - "line": 24, + "line": 25, "column": 20 } } @@ -918,11 +1043,11 @@ "optional": false, "loc": { "start": { - "line": 24, + "line": 25, "column": 5 }, "end": { - "line": 24, + "line": 25, "column": 20 } } @@ -942,11 +1067,11 @@ "value": "Values of type int are not equal: ", "loc": { "start": { - "line": 24, + "line": 25, "column": 21 }, "end": { - "line": 24, + "line": 25, "column": 57 } } @@ -957,22 +1082,22 @@ "decorators": [], "loc": { "start": { - "line": 24, + "line": 25, "column": 60 }, "end": { - "line": 24, + "line": 25, "column": 66 } } }, "loc": { "start": { - "line": 24, + "line": 25, "column": 21 }, "end": { - "line": 24, + "line": 25, "column": 66 } } @@ -982,22 +1107,22 @@ "value": " != ", "loc": { "start": { - "line": 24, + "line": 25, "column": 69 }, "end": { - "line": 24, + "line": 25, "column": 75 } } }, "loc": { "start": { - "line": 24, + "line": 25, "column": 21 }, "end": { - "line": 24, + "line": 25, "column": 75 } } @@ -1008,22 +1133,22 @@ "decorators": [], "loc": { "start": { - "line": 24, + "line": 25, "column": 78 }, "end": { - "line": 24, + "line": 25, "column": 84 } } }, "loc": { "start": { - "line": 24, + "line": 25, "column": 21 }, "end": { - "line": 24, + "line": 25, "column": 84 } } @@ -1032,22 +1157,22 @@ "optional": false, "loc": { "start": { - "line": 24, + "line": 25, "column": 5 }, "end": { - "line": 24, + "line": 25, "column": 85 } } }, "loc": { "start": { - "line": 24, + "line": 25, "column": 5 }, "end": { - "line": 24, + "line": 25, "column": 86 } } @@ -1066,33 +1191,33 @@ "decorators": [], "loc": { "start": { - "line": 25, + "line": 26, "column": 15 }, "end": { - "line": 25, + "line": 26, "column": 20 } } }, "loc": { "start": { - "line": 25, + "line": 26, "column": 15 }, "end": { - "line": 25, + "line": 26, "column": 21 } } }, "loc": { "start": { - "line": 25, + "line": 26, "column": 15 }, "end": { - "line": 25, + "line": 26, "column": 21 } } @@ -1100,22 +1225,22 @@ "arguments": [], "loc": { "start": { - "line": 25, + "line": 26, "column": 11 }, "end": { - "line": 25, + "line": 26, "column": 23 } } }, "loc": { "start": { - "line": 25, + "line": 26, "column": 5 }, "end": { - "line": 25, + "line": 26, "column": 23 } } @@ -1123,33 +1248,33 @@ ], "loc": { "start": { - "line": 20, + "line": 21, "column": 52 }, "end": { - "line": 26, + "line": 27, "column": 2 } } }, "loc": { "start": { - "line": 20, + "line": 21, "column": 19 }, "end": { - "line": 26, + "line": 27, "column": 2 } } }, "loc": { "start": { - "line": 20, + "line": 21, "column": 19 }, "end": { - "line": 26, + "line": 27, "column": 2 } } @@ -1158,11 +1283,11 @@ "decorators": [], "loc": { "start": { - "line": 20, + "line": 21, "column": 1 }, "end": { - "line": 26, + "line": 27, "column": 2 } } @@ -1175,11 +1300,11 @@ "decorators": [], "loc": { "start": { - "line": 27, + "line": 28, "column": 10 }, "end": { - "line": 27, + "line": 28, "column": 14 } } @@ -1199,11 +1324,11 @@ "decorators": [], "loc": { "start": { - "line": 27, + "line": 28, "column": 10 }, "end": { - "line": 27, + "line": 28, "column": 14 } } @@ -1221,11 +1346,11 @@ "type": "ETSPrimitiveType", "loc": { "start": { - "line": 27, + "line": 28, "column": 18 }, "end": { - "line": 27, + "line": 28, "column": 21 } } @@ -1233,22 +1358,22 @@ "decorators": [], "loc": { "start": { - "line": 27, + "line": 28, "column": 15 }, "end": { - "line": 27, + "line": 28, "column": 21 } } }, "loc": { "start": { - "line": 27, + "line": 28, "column": 15 }, "end": { - "line": 27, + "line": 28, "column": 21 } } @@ -1264,33 +1389,33 @@ "decorators": [], "loc": { "start": { - "line": 27, + "line": 28, "column": 25 }, "end": { - "line": 27, + "line": 28, "column": 28 } } }, "loc": { "start": { - "line": 27, + "line": 28, "column": 25 }, "end": { - "line": 27, + "line": 28, "column": 30 } } }, "loc": { "start": { - "line": 27, + "line": 28, "column": 25 }, "end": { - "line": 27, + "line": 28, "column": 30 } } @@ -1312,11 +1437,11 @@ "decorators": [], "loc": { "start": { - "line": 28, + "line": 29, "column": 9 }, "end": { - "line": 28, + "line": 29, "column": 10 } } @@ -1326,22 +1451,22 @@ "value": 0, "loc": { "start": { - "line": 28, + "line": 29, "column": 14 }, "end": { - "line": 28, + "line": 29, "column": 15 } } }, "loc": { "start": { - "line": 28, + "line": 29, "column": 9 }, "end": { - "line": 28, + "line": 29, "column": 15 } } @@ -1355,11 +1480,11 @@ "decorators": [], "loc": { "start": { - "line": 28, + "line": 29, "column": 19 }, "end": { - "line": 28, + "line": 29, "column": 20 } } @@ -1370,33 +1495,33 @@ "decorators": [], "loc": { "start": { - "line": 28, + "line": 29, "column": 23 }, "end": { - "line": 28, + "line": 29, "column": 28 } } }, "loc": { "start": { - "line": 28, + "line": 29, "column": 19 }, "end": { - "line": 28, + "line": 29, "column": 28 } } }, "loc": { "start": { - "line": 28, + "line": 29, "column": 9 }, "end": { - "line": 28, + "line": 29, "column": 28 } } @@ -1414,11 +1539,11 @@ "decorators": [], "loc": { "start": { - "line": 29, + "line": 30, "column": 16 }, "end": { - "line": 29, + "line": 30, "column": 17 } } @@ -1429,11 +1554,11 @@ "decorators": [], "loc": { "start": { - "line": 29, + "line": 30, "column": 18 }, "end": { - "line": 29, + "line": 30, "column": 19 } } @@ -1442,22 +1567,22 @@ "optional": false, "loc": { "start": { - "line": 29, + "line": 30, "column": 16 }, "end": { - "line": 29, + "line": 30, "column": 20 } } }, "loc": { "start": { - "line": 29, + "line": 30, "column": 9 }, "end": { - "line": 29, + "line": 30, "column": 21 } } @@ -1465,11 +1590,11 @@ ], "loc": { "start": { - "line": 28, + "line": 29, "column": 30 }, "end": { - "line": 30, + "line": 31, "column": 6 } } @@ -1477,11 +1602,11 @@ "alternate": null, "loc": { "start": { - "line": 28, + "line": 29, "column": 5 }, "end": { - "line": 30, + "line": 31, "column": 6 } } @@ -1502,116 +1627,60 @@ "type": "ETSTypeReferencePart", "name": { "type": "Identifier", - "name": "Promise", + "name": "P", "decorators": [], "loc": { "start": { - "line": 31, + "line": 32, "column": 12 }, "end": { - "line": 31, - "column": 19 - } - } - }, - "typeParams": { - "type": "TSTypeParameterInstantiation", - "params": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Int", - "decorators": [], - "loc": { - "start": { - "line": 31, - "column": 20 - }, - "end": { - "line": 31, - "column": 23 - } - } - }, - "loc": { - "start": { - "line": 31, - "column": 20 - }, - "end": { - "line": 31, - "column": 24 - } - } - }, - "loc": { - "start": { - "line": 31, - "column": 20 - }, - "end": { - "line": 31, - "column": 24 - } - } - } - ], - "loc": { - "start": { - "line": 31, - "column": 19 - }, - "end": { - "line": 31, - "column": 24 + "line": 32, + "column": 13 } } }, "loc": { "start": { - "line": 31, + "line": 32, "column": 12 }, "end": { - "line": 31, - "column": 25 + "line": 32, + "column": 14 } } }, "loc": { "start": { - "line": 31, + "line": 32, "column": 12 }, "end": { - "line": 31, - "column": 25 + "line": 32, + "column": 14 } } }, "loc": { "start": { - "line": 31, - "column": 27 + "line": 32, + "column": 16 }, "end": { - "line": 31, - "column": 28 + "line": 32, + "column": 17 } } }, "decorators": [], "loc": { "start": { - "line": 31, + "line": 32, "column": 9 }, "end": { - "line": 31, + "line": 32, "column": 10 } } @@ -1624,94 +1693,38 @@ "type": "ETSTypeReferencePart", "name": { "type": "Identifier", - "name": "Promise", + "name": "P", "decorators": [], "loc": { "start": { - "line": 31, - "column": 33 - }, - "end": { - "line": 31, - "column": 40 - } - } - }, - "typeParams": { - "type": "TSTypeParameterInstantiation", - "params": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Int", - "decorators": [], - "loc": { - "start": { - "line": 31, - "column": 41 - }, - "end": { - "line": 31, - "column": 44 - } - } - }, - "loc": { - "start": { - "line": 31, - "column": 41 - }, - "end": { - "line": 31, - "column": 45 - } - } - }, - "loc": { - "start": { - "line": 31, - "column": 41 - }, - "end": { - "line": 31, - "column": 45 - } - } - } - ], - "loc": { - "start": { - "line": 31, - "column": 40 + "line": 32, + "column": 22 }, "end": { - "line": 31, - "column": 45 + "line": 32, + "column": 23 } } }, "loc": { "start": { - "line": 31, - "column": 33 + "line": 32, + "column": 22 }, "end": { - "line": 31, - "column": 46 + "line": 32, + "column": 24 } } }, "loc": { "start": { - "line": 31, - "column": 33 + "line": 32, + "column": 22 }, "end": { - "line": 31, - "column": 46 + "line": 32, + "column": 24 } } }, @@ -1721,34 +1734,34 @@ "decorators": [], "loc": { "start": { - "line": 31, - "column": 46 + "line": 32, + "column": 24 }, "end": { - "line": 31, - "column": 51 + "line": 32, + "column": 29 } } }, "loc": { "start": { - "line": 31, - "column": 29 + "line": 32, + "column": 18 }, "end": { - "line": 31, - "column": 52 + "line": 32, + "column": 30 } } }, "loc": { "start": { - "line": 31, + "line": 32, "column": 9 }, "end": { - "line": 31, - "column": 52 + "line": 32, + "column": 30 } } } @@ -1756,12 +1769,12 @@ "kind": "let", "loc": { "start": { - "line": 31, + "line": 32, "column": 5 }, "end": { - "line": 31, - "column": 52 + "line": 32, + "column": 30 } } }, @@ -1778,11 +1791,11 @@ "decorators": [], "loc": { "start": { - "line": 32, + "line": 33, "column": 14 }, "end": { - "line": 32, + "line": 33, "column": 15 } } @@ -1792,22 +1805,22 @@ "value": 0, "loc": { "start": { - "line": 32, + "line": 33, "column": 18 }, "end": { - "line": 32, + "line": 33, "column": 19 } } }, "loc": { "start": { - "line": 32, + "line": 33, "column": 14 }, "end": { - "line": 32, + "line": 33, "column": 19 } } @@ -1816,11 +1829,11 @@ "kind": "let", "loc": { "start": { - "line": 32, + "line": 33, "column": 10 }, "end": { - "line": 32, + "line": 33, "column": 19 } } @@ -1834,11 +1847,11 @@ "decorators": [], "loc": { "start": { - "line": 32, + "line": 33, "column": 21 }, "end": { - "line": 32, + "line": 33, "column": 22 } } @@ -1849,22 +1862,22 @@ "decorators": [], "loc": { "start": { - "line": 32, + "line": 33, "column": 25 }, "end": { - "line": 32, + "line": 33, "column": 30 } } }, "loc": { "start": { - "line": 32, + "line": 33, "column": 21 }, "end": { - "line": 32, + "line": 33, "column": 30 } } @@ -1879,22 +1892,22 @@ "decorators": [], "loc": { "start": { - "line": 32, + "line": 33, "column": 34 }, "end": { - "line": 32, + "line": 33, "column": 35 } } }, "loc": { "start": { - "line": 32, + "line": 33, "column": 32 }, "end": { - "line": 32, + "line": 33, "column": 35 } } @@ -1915,11 +1928,11 @@ "decorators": [], "loc": { "start": { - "line": 33, + "line": 34, "column": 9 }, "end": { - "line": 33, + "line": 34, "column": 10 } } @@ -1930,11 +1943,11 @@ "decorators": [], "loc": { "start": { - "line": 33, + "line": 34, "column": 11 }, "end": { - "line": 33, + "line": 34, "column": 12 } } @@ -1943,11 +1956,11 @@ "optional": false, "loc": { "start": { - "line": 33, + "line": 34, "column": 9 }, "end": { - "line": 33, + "line": 34, "column": 13 } } @@ -1962,11 +1975,11 @@ "decorators": [], "loc": { "start": { - "line": 33, + "line": 34, "column": 23 }, "end": { - "line": 33, + "line": 34, "column": 27 } } @@ -1984,11 +1997,11 @@ "decorators": [], "loc": { "start": { - "line": 33, + "line": 34, "column": 28 }, "end": { - "line": 33, + "line": 34, "column": 29 } } @@ -1998,22 +2011,22 @@ "value": 1, "loc": { "start": { - "line": 33, + "line": 34, "column": 30 }, "end": { - "line": 33, + "line": 34, "column": 31 } } }, "loc": { "start": { - "line": 33, + "line": 34, "column": 28 }, "end": { - "line": 33, + "line": 34, "column": 31 } } @@ -2024,22 +2037,22 @@ "decorators": [], "loc": { "start": { - "line": 33, + "line": 34, "column": 32 }, "end": { - "line": 33, + "line": 34, "column": 33 } } }, "loc": { "start": { - "line": 33, + "line": 34, "column": 28 }, "end": { - "line": 33, + "line": 34, "column": 33 } } @@ -2048,44 +2061,44 @@ "optional": false, "loc": { "start": { - "line": 33, + "line": 34, "column": 23 }, "end": { - "line": 33, + "line": 34, "column": 34 } } }, "loc": { "start": { - "line": 33, + "line": 34, "column": 16 }, "end": { - "line": 33, + "line": 34, "column": 34 } } }, "loc": { "start": { - "line": 33, + "line": 34, "column": 9 }, "end": { - "line": 33, + "line": 34, "column": 34 } } }, "loc": { "start": { - "line": 33, + "line": 34, "column": 9 }, "end": { - "line": 33, + "line": 34, "column": 35 } } @@ -2093,22 +2106,22 @@ ], "loc": { "start": { - "line": 32, + "line": 33, "column": 37 }, "end": { - "line": 34, + "line": 35, "column": 6 } } }, "loc": { "start": { - "line": 32, + "line": 33, "column": 5 }, "end": { - "line": 34, + "line": 35, "column": 6 } } @@ -2124,11 +2137,11 @@ "decorators": [], "loc": { "start": { - "line": 35, + "line": 36, "column": 9 }, "end": { - "line": 35, + "line": 36, "column": 15 } } @@ -2138,22 +2151,22 @@ "value": 0, "loc": { "start": { - "line": 35, + "line": 36, "column": 18 }, "end": { - "line": 35, + "line": 36, "column": 19 } } }, "loc": { "start": { - "line": 35, + "line": 36, "column": 9 }, "end": { - "line": 35, + "line": 36, "column": 19 } } @@ -2162,11 +2175,11 @@ "kind": "let", "loc": { "start": { - "line": 35, + "line": 36, "column": 5 }, "end": { - "line": 35, + "line": 36, "column": 19 } } @@ -2184,11 +2197,11 @@ "decorators": [], "loc": { "start": { - "line": 36, + "line": 37, "column": 14 }, "end": { - "line": 36, + "line": 37, "column": 15 } } @@ -2198,22 +2211,22 @@ "value": 0, "loc": { "start": { - "line": 36, + "line": 37, "column": 18 }, "end": { - "line": 36, + "line": 37, "column": 19 } } }, "loc": { "start": { - "line": 36, + "line": 37, "column": 14 }, "end": { - "line": 36, + "line": 37, "column": 19 } } @@ -2222,11 +2235,11 @@ "kind": "let", "loc": { "start": { - "line": 36, + "line": 37, "column": 10 }, "end": { - "line": 36, + "line": 37, "column": 19 } } @@ -2240,11 +2253,11 @@ "decorators": [], "loc": { "start": { - "line": 36, + "line": 37, "column": 21 }, "end": { - "line": 36, + "line": 37, "column": 22 } } @@ -2255,22 +2268,22 @@ "decorators": [], "loc": { "start": { - "line": 36, + "line": 37, "column": 25 }, "end": { - "line": 36, + "line": 37, "column": 30 } } }, "loc": { "start": { - "line": 36, + "line": 37, "column": 21 }, "end": { - "line": 36, + "line": 37, "column": 30 } } @@ -2285,22 +2298,22 @@ "decorators": [], "loc": { "start": { - "line": 36, + "line": 37, "column": 34 }, "end": { - "line": 36, + "line": 37, "column": 35 } } }, "loc": { "start": { - "line": 36, + "line": 37, "column": 32 }, "end": { - "line": 36, + "line": 37, "column": 35 } } @@ -2319,11 +2332,11 @@ "decorators": [], "loc": { "start": { - "line": 37, + "line": 38, "column": 9 }, "end": { - "line": 37, + "line": 38, "column": 15 } } @@ -2337,11 +2350,11 @@ "decorators": [], "loc": { "start": { - "line": 37, + "line": 38, "column": 18 }, "end": { - "line": 37, + "line": 38, "column": 24 } } @@ -2361,11 +2374,11 @@ "decorators": [], "loc": { "start": { - "line": 37, + "line": 38, "column": 27 }, "end": { - "line": 37, + "line": 38, "column": 28 } } @@ -2376,11 +2389,11 @@ "decorators": [], "loc": { "start": { - "line": 37, + "line": 38, "column": 29 }, "end": { - "line": 37, + "line": 38, "column": 30 } } @@ -2389,11 +2402,11 @@ "optional": false, "loc": { "start": { - "line": 37, + "line": 38, "column": 27 }, "end": { - "line": 37, + "line": 38, "column": 31 } } @@ -2404,11 +2417,11 @@ "decorators": [], "loc": { "start": { - "line": 37, + "line": 38, "column": 32 }, "end": { - "line": 37, + "line": 38, "column": 47 } } @@ -2417,11 +2430,11 @@ "optional": false, "loc": { "start": { - "line": 37, + "line": 38, "column": 27 }, "end": { - "line": 37, + "line": 38, "column": 47 } } @@ -2430,11 +2443,11 @@ "optional": false, "loc": { "start": { - "line": 37, + "line": 38, "column": 27 }, "end": { - "line": 37, + "line": 38, "column": 49 } } @@ -2447,11 +2460,11 @@ "decorators": [], "loc": { "start": { - "line": 37, + "line": 38, "column": 52 }, "end": { - "line": 37, + "line": 38, "column": 53 } } @@ -2462,11 +2475,11 @@ "decorators": [], "loc": { "start": { - "line": 37, + "line": 38, "column": 54 }, "end": { - "line": 37, + "line": 38, "column": 55 } } @@ -2475,55 +2488,55 @@ "optional": false, "loc": { "start": { - "line": 37, + "line": 38, "column": 52 }, "end": { - "line": 37, + "line": 38, "column": 56 } } }, "loc": { "start": { - "line": 37, + "line": 38, "column": 27 }, "end": { - "line": 37, + "line": 38, "column": 56 } } }, "loc": { "start": { - "line": 37, + "line": 38, "column": 18 }, "end": { - "line": 37, + "line": 38, "column": 56 } } }, "loc": { "start": { - "line": 37, + "line": 38, "column": 9 }, "end": { - "line": 37, + "line": 38, "column": 56 } } }, "loc": { "start": { - "line": 37, + "line": 38, "column": 9 }, "end": { - "line": 37, + "line": 38, "column": 57 } } @@ -2531,22 +2544,22 @@ ], "loc": { "start": { - "line": 36, + "line": 37, "column": 37 }, "end": { - "line": 38, + "line": 39, "column": 6 } } }, "loc": { "start": { - "line": 36, + "line": 37, "column": 5 }, "end": { - "line": 38, + "line": 39, "column": 6 } } @@ -2559,22 +2572,22 @@ "decorators": [], "loc": { "start": { - "line": 39, + "line": 40, "column": 12 }, "end": { - "line": 39, + "line": 40, "column": 18 } } }, "loc": { "start": { - "line": 39, + "line": 40, "column": 5 }, "end": { - "line": 39, + "line": 40, "column": 19 } } @@ -2582,33 +2595,33 @@ ], "loc": { "start": { - "line": 27, + "line": 28, "column": 29 }, "end": { - "line": 40, + "line": 41, "column": 2 } } }, "loc": { "start": { - "line": 27, + "line": 28, "column": 14 }, "end": { - "line": 40, + "line": 41, "column": 2 } } }, "loc": { "start": { - "line": 27, + "line": 28, "column": 14 }, "end": { - "line": 40, + "line": 41, "column": 2 } } @@ -2617,11 +2630,11 @@ "decorators": [], "loc": { "start": { - "line": 27, + "line": 28, "column": 1 }, "end": { - "line": 40, + "line": 41, "column": 2 } } @@ -2634,11 +2647,11 @@ "decorators": [], "loc": { "start": { - "line": 41, + "line": 42, "column": 10 }, "end": { - "line": 41, + "line": 42, "column": 18 } } @@ -2658,11 +2671,11 @@ "decorators": [], "loc": { "start": { - "line": 41, + "line": 42, "column": 10 }, "end": { - "line": 41, + "line": 42, "column": 18 } } @@ -2680,11 +2693,11 @@ "type": "ETSPrimitiveType", "loc": { "start": { - "line": 41, + "line": 42, "column": 22 }, "end": { - "line": 41, + "line": 42, "column": 25 } } @@ -2692,22 +2705,22 @@ "decorators": [], "loc": { "start": { - "line": 41, + "line": 42, "column": 19 }, "end": { - "line": 41, + "line": 42, "column": 25 } } }, "loc": { "start": { - "line": 41, + "line": 42, "column": 19 }, "end": { - "line": 41, + "line": 42, "column": 25 } } @@ -2717,11 +2730,11 @@ "type": "ETSPrimitiveType", "loc": { "start": { - "line": 41, + "line": 42, "column": 29 }, "end": { - "line": 41, + "line": 42, "column": 32 } } @@ -2743,11 +2756,11 @@ "decorators": [], "loc": { "start": { - "line": 42, + "line": 43, "column": 9 }, "end": { - "line": 42, + "line": 43, "column": 10 } } @@ -2757,22 +2770,22 @@ "value": 0, "loc": { "start": { - "line": 42, + "line": 43, "column": 14 }, "end": { - "line": 42, + "line": 43, "column": 15 } } }, "loc": { "start": { - "line": 42, + "line": 43, "column": 9 }, "end": { - "line": 42, + "line": 43, "column": 15 } } @@ -2786,11 +2799,11 @@ "decorators": [], "loc": { "start": { - "line": 42, + "line": 43, "column": 19 }, "end": { - "line": 42, + "line": 43, "column": 20 } } @@ -2801,33 +2814,33 @@ "decorators": [], "loc": { "start": { - "line": 42, + "line": 43, "column": 23 }, "end": { - "line": 42, + "line": 43, "column": 28 } } }, "loc": { "start": { - "line": 42, + "line": 43, "column": 19 }, "end": { - "line": 42, + "line": 43, "column": 28 } } }, "loc": { "start": { - "line": 42, + "line": 43, "column": 9 }, "end": { - "line": 42, + "line": 43, "column": 28 } } @@ -2845,11 +2858,11 @@ "decorators": [], "loc": { "start": { - "line": 43, + "line": 44, "column": 16 }, "end": { - "line": 43, + "line": 44, "column": 17 } } @@ -2860,11 +2873,11 @@ "decorators": [], "loc": { "start": { - "line": 43, + "line": 44, "column": 18 }, "end": { - "line": 43, + "line": 44, "column": 19 } } @@ -2873,22 +2886,22 @@ "optional": false, "loc": { "start": { - "line": 43, + "line": 44, "column": 16 }, "end": { - "line": 43, + "line": 44, "column": 20 } } }, "loc": { "start": { - "line": 43, + "line": 44, "column": 9 }, "end": { - "line": 43, + "line": 44, "column": 21 } } @@ -2896,11 +2909,11 @@ ], "loc": { "start": { - "line": 42, + "line": 43, "column": 30 }, "end": { - "line": 44, + "line": 45, "column": 6 } } @@ -2908,11 +2921,11 @@ "alternate": null, "loc": { "start": { - "line": 42, + "line": 43, "column": 5 }, "end": { - "line": 44, + "line": 45, "column": 6 } } @@ -2928,11 +2941,11 @@ "decorators": [], "loc": { "start": { - "line": 45, + "line": 46, "column": 9 }, "end": { - "line": 45, + "line": 46, "column": 15 } } @@ -2942,22 +2955,22 @@ "value": 0, "loc": { "start": { - "line": 45, + "line": 46, "column": 18 }, "end": { - "line": 45, + "line": 46, "column": 19 } } }, "loc": { "start": { - "line": 45, + "line": 46, "column": 9 }, "end": { - "line": 45, + "line": 46, "column": 19 } } @@ -2966,11 +2979,11 @@ "kind": "let", "loc": { "start": { - "line": 45, + "line": 46, "column": 5 }, "end": { - "line": 45, + "line": 46, "column": 19 } } @@ -2988,11 +3001,11 @@ "decorators": [], "loc": { "start": { - "line": 46, + "line": 47, "column": 14 }, "end": { - "line": 46, + "line": 47, "column": 15 } } @@ -3002,22 +3015,22 @@ "value": 0, "loc": { "start": { - "line": 46, + "line": 47, "column": 18 }, "end": { - "line": 46, + "line": 47, "column": 19 } } }, "loc": { "start": { - "line": 46, + "line": 47, "column": 14 }, "end": { - "line": 46, + "line": 47, "column": 19 } } @@ -3026,11 +3039,11 @@ "kind": "let", "loc": { "start": { - "line": 46, + "line": 47, "column": 10 }, "end": { - "line": 46, + "line": 47, "column": 19 } } @@ -3044,11 +3057,11 @@ "decorators": [], "loc": { "start": { - "line": 46, + "line": 47, "column": 21 }, "end": { - "line": 46, + "line": 47, "column": 22 } } @@ -3059,22 +3072,22 @@ "decorators": [], "loc": { "start": { - "line": 46, + "line": 47, "column": 25 }, "end": { - "line": 46, + "line": 47, "column": 30 } } }, "loc": { "start": { - "line": 46, + "line": 47, "column": 21 }, "end": { - "line": 46, + "line": 47, "column": 30 } } @@ -3089,22 +3102,22 @@ "decorators": [], "loc": { "start": { - "line": 46, + "line": 47, "column": 34 }, "end": { - "line": 46, + "line": 47, "column": 35 } } }, "loc": { "start": { - "line": 46, + "line": 47, "column": 32 }, "end": { - "line": 46, + "line": 47, "column": 35 } } @@ -3123,11 +3136,11 @@ "decorators": [], "loc": { "start": { - "line": 47, + "line": 48, "column": 9 }, "end": { - "line": 47, + "line": 48, "column": 15 } } @@ -3141,11 +3154,11 @@ "decorators": [], "loc": { "start": { - "line": 47, + "line": 48, "column": 18 }, "end": { - "line": 47, + "line": 48, "column": 24 } } @@ -3161,11 +3174,11 @@ "decorators": [], "loc": { "start": { - "line": 47, + "line": 48, "column": 27 }, "end": { - "line": 47, + "line": 48, "column": 35 } } @@ -3183,11 +3196,11 @@ "decorators": [], "loc": { "start": { - "line": 47, + "line": 48, "column": 36 }, "end": { - "line": 47, + "line": 48, "column": 37 } } @@ -3197,22 +3210,22 @@ "value": 1, "loc": { "start": { - "line": 47, + "line": 48, "column": 38 }, "end": { - "line": 47, + "line": 48, "column": 39 } } }, "loc": { "start": { - "line": 47, + "line": 48, "column": 36 }, "end": { - "line": 47, + "line": 48, "column": 39 } } @@ -3223,22 +3236,22 @@ "decorators": [], "loc": { "start": { - "line": 47, + "line": 48, "column": 40 }, "end": { - "line": 47, + "line": 48, "column": 41 } } }, "loc": { "start": { - "line": 47, + "line": 48, "column": 36 }, "end": { - "line": 47, + "line": 48, "column": 41 } } @@ -3247,11 +3260,11 @@ "optional": false, "loc": { "start": { - "line": 47, + "line": 48, "column": 27 }, "end": { - "line": 47, + "line": 48, "column": 42 } } @@ -3264,11 +3277,11 @@ "decorators": [], "loc": { "start": { - "line": 47, + "line": 48, "column": 45 }, "end": { - "line": 47, + "line": 48, "column": 46 } } @@ -3279,11 +3292,11 @@ "decorators": [], "loc": { "start": { - "line": 47, + "line": 48, "column": 47 }, "end": { - "line": 47, + "line": 48, "column": 48 } } @@ -3292,55 +3305,55 @@ "optional": false, "loc": { "start": { - "line": 47, + "line": 48, "column": 45 }, "end": { - "line": 47, + "line": 48, "column": 49 } } }, "loc": { "start": { - "line": 47, + "line": 48, "column": 27 }, "end": { - "line": 47, + "line": 48, "column": 49 } } }, "loc": { "start": { - "line": 47, + "line": 48, "column": 18 }, "end": { - "line": 47, + "line": 48, "column": 49 } } }, "loc": { "start": { - "line": 47, + "line": 48, "column": 9 }, "end": { - "line": 47, + "line": 48, "column": 49 } } }, "loc": { "start": { - "line": 47, + "line": 48, "column": 9 }, "end": { - "line": 47, + "line": 48, "column": 50 } } @@ -3348,22 +3361,22 @@ ], "loc": { "start": { - "line": 46, + "line": 47, "column": 37 }, "end": { - "line": 48, + "line": 49, "column": 6 } } }, "loc": { "start": { - "line": 46, + "line": 47, "column": 5 }, "end": { - "line": 48, + "line": 49, "column": 6 } } @@ -3376,22 +3389,22 @@ "decorators": [], "loc": { "start": { - "line": 49, + "line": 50, "column": 12 }, "end": { - "line": 49, + "line": 50, "column": 18 } } }, "loc": { "start": { - "line": 49, + "line": 50, "column": 5 }, "end": { - "line": 49, + "line": 50, "column": 19 } } @@ -3399,33 +3412,33 @@ ], "loc": { "start": { - "line": 41, + "line": 42, "column": 33 }, "end": { - "line": 50, + "line": 51, "column": 2 } } }, "loc": { "start": { - "line": 41, + "line": 42, "column": 18 }, "end": { - "line": 50, + "line": 51, "column": 2 } } }, "loc": { "start": { - "line": 41, + "line": 42, "column": 18 }, "end": { - "line": 50, + "line": 51, "column": 2 } } @@ -3434,11 +3447,11 @@ "decorators": [], "loc": { "start": { - "line": 41, + "line": 42, "column": 1 }, "end": { - "line": 50, + "line": 51, "column": 2 } } @@ -3451,11 +3464,11 @@ "decorators": [], "loc": { "start": { - "line": 51, + "line": 52, "column": 17 }, "end": { - "line": 51, + "line": 52, "column": 21 } } @@ -3475,11 +3488,11 @@ "decorators": [], "loc": { "start": { - "line": 51, + "line": 52, "column": 17 }, "end": { - "line": 51, + "line": 52, "column": 21 } } @@ -3492,11 +3505,11 @@ "type": "ETSPrimitiveType", "loc": { "start": { - "line": 51, + "line": 52, "column": 25 }, "end": { - "line": 51, + "line": 52, "column": 28 } } @@ -3517,11 +3530,11 @@ "decorators": [], "loc": { "start": { - "line": 52, + "line": 53, "column": 5 }, "end": { - "line": 52, + "line": 53, "column": 6 } } @@ -3531,11 +3544,11 @@ "value": 0, "loc": { "start": { - "line": 52, + "line": 53, "column": 7 }, "end": { - "line": 52, + "line": 53, "column": 8 } } @@ -3544,11 +3557,11 @@ "optional": false, "loc": { "start": { - "line": 52, + "line": 53, "column": 5 }, "end": { - "line": 52, + "line": 53, "column": 9 } } @@ -3558,33 +3571,33 @@ "value": 2, "loc": { "start": { - "line": 52, + "line": 53, "column": 12 }, "end": { - "line": 52, + "line": 53, "column": 13 } } }, "loc": { "start": { - "line": 52, + "line": 53, "column": 5 }, "end": { - "line": 52, + "line": 53, "column": 13 } } }, "loc": { "start": { - "line": 52, + "line": 53, "column": 5 }, "end": { - "line": 52, + "line": 53, "column": 14 } } @@ -3602,11 +3615,11 @@ "decorators": [], "loc": { "start": { - "line": 53, + "line": 54, "column": 5 }, "end": { - "line": 53, + "line": 54, "column": 6 } } @@ -3616,11 +3629,11 @@ "value": 0, "loc": { "start": { - "line": 53, + "line": 54, "column": 7 }, "end": { - "line": 53, + "line": 54, "column": 8 } } @@ -3629,11 +3642,11 @@ "optional": false, "loc": { "start": { - "line": 53, + "line": 54, "column": 5 }, "end": { - "line": 53, + "line": 54, "column": 9 } } @@ -3643,33 +3656,33 @@ "value": 6, "loc": { "start": { - "line": 53, + "line": 54, "column": 12 }, "end": { - "line": 53, + "line": 54, "column": 13 } } }, "loc": { "start": { - "line": 53, + "line": 54, "column": 5 }, "end": { - "line": 53, + "line": 54, "column": 13 } } }, "loc": { "start": { - "line": 53, + "line": 54, "column": 5 }, "end": { - "line": 53, + "line": 54, "column": 14 } } @@ -3687,11 +3700,11 @@ "decorators": [], "loc": { "start": { - "line": 54, + "line": 55, "column": 5 }, "end": { - "line": 54, + "line": 55, "column": 6 } } @@ -3701,11 +3714,11 @@ "value": 1, "loc": { "start": { - "line": 54, + "line": 55, "column": 7 }, "end": { - "line": 54, + "line": 55, "column": 8 } } @@ -3714,11 +3727,11 @@ "optional": false, "loc": { "start": { - "line": 54, + "line": 55, "column": 5 }, "end": { - "line": 54, + "line": 55, "column": 9 } } @@ -3728,33 +3741,33 @@ "value": 2, "loc": { "start": { - "line": 54, + "line": 55, "column": 12 }, "end": { - "line": 54, + "line": 55, "column": 13 } } }, "loc": { "start": { - "line": 54, + "line": 55, "column": 5 }, "end": { - "line": 54, + "line": 55, "column": 13 } } }, "loc": { "start": { - "line": 54, + "line": 55, "column": 5 }, "end": { - "line": 54, + "line": 55, "column": 14 } } @@ -3772,11 +3785,11 @@ "decorators": [], "loc": { "start": { - "line": 55, + "line": 56, "column": 5 }, "end": { - "line": 55, + "line": 56, "column": 6 } } @@ -3786,11 +3799,11 @@ "value": 1, "loc": { "start": { - "line": 55, + "line": 56, "column": 7 }, "end": { - "line": 55, + "line": 56, "column": 8 } } @@ -3799,11 +3812,11 @@ "optional": false, "loc": { "start": { - "line": 55, + "line": 56, "column": 5 }, "end": { - "line": 55, + "line": 56, "column": 9 } } @@ -3813,33 +3826,33 @@ "value": 7, "loc": { "start": { - "line": 55, + "line": 56, "column": 12 }, "end": { - "line": 55, + "line": 56, "column": 13 } } }, "loc": { "start": { - "line": 55, + "line": 56, "column": 5 }, "end": { - "line": 55, + "line": 56, "column": 13 } } }, "loc": { "start": { - "line": 55, + "line": 56, "column": 5 }, "end": { - "line": 55, + "line": 56, "column": 14 } } @@ -3855,11 +3868,11 @@ "decorators": [], "loc": { "start": { - "line": 56, + "line": 57, "column": 9 }, "end": { - "line": 56, + "line": 57, "column": 19 } } @@ -3872,11 +3885,11 @@ "decorators": [], "loc": { "start": { - "line": 56, + "line": 57, "column": 22 }, "end": { - "line": 56, + "line": 57, "column": 30 } } @@ -3888,11 +3901,11 @@ "decorators": [], "loc": { "start": { - "line": 56, + "line": 57, "column": 31 }, "end": { - "line": 56, + "line": 57, "column": 32 } } @@ -3901,22 +3914,22 @@ "optional": false, "loc": { "start": { - "line": 56, + "line": 57, "column": 22 }, "end": { - "line": 56, + "line": 57, "column": 33 } } }, "loc": { "start": { - "line": 56, + "line": 57, "column": 9 }, "end": { - "line": 56, + "line": 57, "column": 33 } } @@ -3925,11 +3938,11 @@ "kind": "let", "loc": { "start": { - "line": 56, + "line": 57, "column": 5 }, "end": { - "line": 56, + "line": 57, "column": 34 } } @@ -3945,11 +3958,11 @@ "decorators": [], "loc": { "start": { - "line": 57, + "line": 58, "column": 9 }, "end": { - "line": 57, + "line": 58, "column": 10 } } @@ -3964,11 +3977,11 @@ "decorators": [], "loc": { "start": { - "line": 57, + "line": 58, "column": 20 }, "end": { - "line": 57, + "line": 58, "column": 24 } } @@ -3980,11 +3993,11 @@ "decorators": [], "loc": { "start": { - "line": 57, + "line": 58, "column": 25 }, "end": { - "line": 57, + "line": 58, "column": 26 } } @@ -3993,33 +4006,33 @@ "optional": false, "loc": { "start": { - "line": 57, + "line": 58, "column": 20 }, "end": { - "line": 57, + "line": 58, "column": 27 } } }, "loc": { "start": { - "line": 57, + "line": 58, "column": 13 }, "end": { - "line": 57, + "line": 58, "column": 27 } } }, "loc": { "start": { - "line": 57, + "line": 58, "column": 9 }, "end": { - "line": 57, + "line": 58, "column": 27 } } @@ -4028,11 +4041,11 @@ "kind": "let", "loc": { "start": { - "line": 57, + "line": 58, "column": 5 }, "end": { - "line": 57, + "line": 58, "column": 28 } } @@ -4048,11 +4061,11 @@ "decorators": [], "loc": { "start": { - "line": 58, + "line": 59, "column": 9 }, "end": { - "line": 58, + "line": 59, "column": 18 } } @@ -4067,11 +4080,11 @@ "decorators": [], "loc": { "start": { - "line": 58, + "line": 59, "column": 21 }, "end": { - "line": 58, + "line": 59, "column": 22 } } @@ -4082,11 +4095,11 @@ "decorators": [], "loc": { "start": { - "line": 58, + "line": 59, "column": 23 }, "end": { - "line": 58, + "line": 59, "column": 38 } } @@ -4095,11 +4108,11 @@ "optional": false, "loc": { "start": { - "line": 58, + "line": 59, "column": 21 }, "end": { - "line": 58, + "line": 59, "column": 38 } } @@ -4108,22 +4121,22 @@ "optional": false, "loc": { "start": { - "line": 58, + "line": 59, "column": 21 }, "end": { - "line": 58, + "line": 59, "column": 40 } } }, "loc": { "start": { - "line": 58, + "line": 59, "column": 9 }, "end": { - "line": 58, + "line": 59, "column": 40 } } @@ -4132,11 +4145,11 @@ "kind": "let", "loc": { "start": { - "line": 58, + "line": 59, "column": 5 }, "end": { - "line": 58, + "line": 59, "column": 41 } } @@ -4151,11 +4164,11 @@ "decorators": [], "loc": { "start": { - "line": 59, + "line": 60, "column": 5 }, "end": { - "line": 59, + "line": 60, "column": 14 } } @@ -4169,11 +4182,11 @@ "decorators": [], "loc": { "start": { - "line": 59, + "line": 60, "column": 15 }, "end": { - "line": 59, + "line": 60, "column": 24 } } @@ -4182,22 +4195,22 @@ "type": "ETSPrimitiveType", "loc": { "start": { - "line": 59, + "line": 60, "column": 28 }, "end": { - "line": 59, + "line": 60, "column": 31 } } }, "loc": { "start": { - "line": 59, + "line": 60, "column": 15 }, "end": { - "line": 59, + "line": 60, "column": 24 } } @@ -4208,11 +4221,11 @@ "decorators": [], "loc": { "start": { - "line": 59, + "line": 60, "column": 33 }, "end": { - "line": 59, + "line": 60, "column": 43 } } @@ -4221,22 +4234,22 @@ "optional": false, "loc": { "start": { - "line": 59, + "line": 60, "column": 5 }, "end": { - "line": 59, + "line": 60, "column": 44 } } }, "loc": { "start": { - "line": 59, + "line": 60, "column": 5 }, "end": { - "line": 59, + "line": 60, "column": 45 } } @@ -4248,22 +4261,22 @@ "value": 0, "loc": { "start": { - "line": 60, + "line": 61, "column": 12 }, "end": { - "line": 60, + "line": 61, "column": 13 } } }, "loc": { "start": { - "line": 60, + "line": 61, "column": 5 }, "end": { - "line": 60, + "line": 61, "column": 14 } } @@ -4271,33 +4284,33 @@ ], "loc": { "start": { - "line": 51, + "line": 52, "column": 29 }, "end": { - "line": 61, + "line": 62, "column": 2 } } }, "loc": { "start": { - "line": 51, + "line": 52, "column": 21 }, "end": { - "line": 61, + "line": 62, "column": 2 } } }, "loc": { "start": { - "line": 51, + "line": 52, "column": 21 }, "end": { - "line": 61, + "line": 62, "column": 2 } } @@ -4306,11 +4319,11 @@ "decorators": [], "loc": { "start": { - "line": 51, + "line": 52, "column": 8 }, "end": { - "line": 61, + "line": 62, "column": 2 } } @@ -4345,7 +4358,7 @@ "column": 1 }, "end": { - "line": 62, + "line": 63, "column": 1 } } diff --git a/ets2panda/test/compiler/ets/launch_expression.ets b/ets2panda/test/compiler/ets/launch_expression.ets index 011deb2dee..362b63db11 100644 --- a/ets2panda/test/compiler/ets/launch_expression.ets +++ b/ets2panda/test/compiler/ets/launch_expression.ets @@ -17,6 +17,7 @@ let count = 2 let n = 9 let a: int[] = new int[count]; let v: int[] = new int[count]; +type P = Promise | null function assert_eq(value1: int, value2: int): void { if (value1 == value2) { return; @@ -28,7 +29,7 @@ function ufib(n: int) : Int { if (n >= 0 && n < count) { return v[n]; } - let p: Promise[] = new Promise[count] + let p: P[] = new P[count] for (let i = 0; i < count; ++i) { p[i] = launch ufib(n-1-i); } -- Gitee From 6f3401fa06b4b564a983b0ef553efb146afc90ce Mon Sep 17 00:00:00 2001 From: Martin Sajti Date: Fri, 22 Dec 2023 17:17:05 +0100 Subject: [PATCH 11/26] Class getter and setter generation Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/I8QPT7 Internal issue: #15142 Test: build, new checker tests Change-Id: Icd1d5db370c2503933ef3a8b944ecaf1a70ada8a Signed-off-by: Gergo Torok Signed-off-by: Martin Sajti --- ets2panda/checker/ETSchecker.h | 7 ++ ets2panda/checker/ets/helpers.cpp | 89 +++++++++++++++++++ ets2panda/checker/ets/object.cpp | 62 ++++++++++++- .../ets/interfacePropertyDeclarations.cpp | 11 ++- .../test/runtime/ets/classGetterSetter.ets | 33 +++++++ ets2panda/varbinder/variableFlags.h | 1 + 6 files changed, 196 insertions(+), 7 deletions(-) create mode 100644 ets2panda/test/runtime/ets/classGetterSetter.ets diff --git a/ets2panda/checker/ETSchecker.h b/ets2panda/checker/ETSchecker.h index 44cd7dfbda..e565e924bd 100644 --- a/ets2panda/checker/ETSchecker.h +++ b/ets2panda/checker/ETSchecker.h @@ -177,6 +177,7 @@ public: varbinder::Variable *ResolveInstanceExtension(const ir::MemberExpression *memberExpr); void CheckImplicitSuper(ETSObjectType *classType, Signature *ctorSig); void CheckValidInheritance(ETSObjectType *classType, ir::ClassDefinition *classDef); + void TransformProperties(ETSObjectType *classType); void CheckGetterSetterProperties(ETSObjectType *classType); void AddElementsToModuleObject(ETSObjectType *moduleObj, const util::StringView &str); Type *FindLeastUpperBound(Type *source, Type *target); @@ -547,6 +548,12 @@ public: void ModifyPreferredType(ir::ArrayExpression *arrayExpr, Type *newPreferredType); Type *SelectGlobalIntegerTypeForNumeric(Type *type); + void GenerateGetterSetterBody(ETSChecker *checker, ArenaVector &stmts, + ArenaVector ¶ms, ir::ClassProperty *field, + varbinder::FunctionParamScope *paramScope, bool isSetter); + static ir::MethodDefinition *GenerateDefaultGetterSetter(ir::ClassProperty *field, varbinder::ClassScope *scope, + bool isSetter, ETSChecker *checker); + // Exception ETSObjectType *CheckExceptionOrErrorType(checker::Type *type, lexer::SourcePosition pos); diff --git a/ets2panda/checker/ets/helpers.cpp b/ets2panda/checker/ets/helpers.cpp index 77aa904632..5c1b3fd187 100644 --- a/ets2panda/checker/ets/helpers.cpp +++ b/ets2panda/checker/ets/helpers.cpp @@ -2633,6 +2633,95 @@ std::string GenerateImplicitInstantiateArg(varbinder::LocalVariable *instantiate return implicitInstantiateArgument; } +void ETSChecker::GenerateGetterSetterBody(ETSChecker *checker, ArenaVector &stmts, + ArenaVector ¶ms, ir::ClassProperty *const field, + varbinder::FunctionParamScope *paramScope, bool isSetter) +{ + if (!isSetter) { + stmts.push_back(checker->Allocator()->New(field->Key())); + return; + } + + auto *paramIdent = field->Key()->AsIdentifier()->Clone(checker->Allocator()); + paramIdent->SetTsTypeAnnotation(field->TypeAnnotation()->Clone(checker->Allocator())); + paramIdent->TypeAnnotation()->SetParent(paramIdent); + + auto *paramExpression = checker->AllocNode(paramIdent, nullptr); + paramExpression->SetRange(paramIdent->Range()); + auto *const paramVar = std::get<2>(paramScope->AddParamDecl(checker->Allocator(), paramExpression)); + + paramIdent->SetVariable(paramVar); + paramExpression->SetVariable(paramVar); + + params.push_back(paramExpression); + + auto *assignmentExpression = checker->AllocNode( + field->Key(), paramExpression, lexer::TokenType::PUNCTUATOR_SUBSTITUTION); + + assignmentExpression->SetRange({field->Start(), field->End()}); + + stmts.push_back(checker->AllocNode(assignmentExpression)); + stmts.push_back(checker->Allocator()->New(nullptr)); +} + +ir::MethodDefinition *ETSChecker::GenerateDefaultGetterSetter(ir::ClassProperty *const field, + varbinder::ClassScope *classScope, bool isSetter, + ETSChecker *checker) +{ + auto *paramScope = checker->Allocator()->New(checker->Allocator(), classScope); + auto *functionScope = checker->Allocator()->New(checker->Allocator(), paramScope); + + functionScope->BindParamScope(paramScope); + paramScope->BindFunctionScope(functionScope); + + auto flags = ir::ModifierFlags::PUBLIC; + + ArenaVector params(checker->Allocator()->Adapter()); + ArenaVector stmts(checker->Allocator()->Adapter()); + checker->GenerateGetterSetterBody(checker, stmts, params, field, paramScope, isSetter); + + auto *body = checker->AllocNode(checker->Allocator(), std::move(stmts)); + auto funcFlags = isSetter ? ir::ScriptFunctionFlags::SETTER : ir::ScriptFunctionFlags::GETTER; + auto *const returnTypeAnn = isSetter ? nullptr : field->TypeAnnotation(); + auto *func = + checker->AllocNode(ir::FunctionSignature(nullptr, std::move(params), returnTypeAnn), body, + funcFlags, flags, true, Language(Language::Id::ETS)); + + func->SetRange(field->Range()); + func->SetScope(functionScope); + body->SetScope(functionScope); + + auto *methodIdent = field->Key()->AsIdentifier()->Clone(checker->Allocator()); + auto *decl = checker->Allocator()->New( + checker->Allocator(), field->Key()->AsIdentifier()->Name(), + field->Key()->AsIdentifier()->Variable()->Declaration()->Node()); + auto *var = functionScope->AddDecl(checker->Allocator(), decl, ScriptExtension::ETS); + + methodIdent->SetVariable(var); + + auto *funcExpr = checker->AllocNode(func); + funcExpr->SetRange(func->Range()); + func->AddFlag(ir::ScriptFunctionFlags::METHOD); + + auto *method = checker->AllocNode(ir::MethodDefinitionKind::METHOD, methodIdent, funcExpr, + flags, checker->Allocator(), false); + + method->Id()->SetMutator(); + method->SetRange(field->Range()); + method->Function()->SetIdent(method->Id()); + method->Function()->AddModifier(method->Modifiers()); + method->SetVariable(var); + + paramScope->BindNode(func); + functionScope->BindNode(func); + + checker->VarBinder()->AsETSBinder()->ResolveMethodDefinition(method); + functionScope->BindName(classScope->Node()->AsClassDefinition()->InternalName()); + method->Check(checker); + + return method; +} + bool ETSChecker::TryTransformingToStaticInvoke(ir::Identifier *const ident, const Type *resolvedType) { ASSERT(ident->Parent()->IsCallExpression()); diff --git a/ets2panda/checker/ets/object.cpp b/ets2panda/checker/ets/object.cpp index 6fbf90b9fc..f09789c926 100644 --- a/ets2panda/checker/ets/object.cpp +++ b/ets2panda/checker/ets/object.cpp @@ -719,6 +719,7 @@ void ETSChecker::ValidateOverriding(ETSObjectType *classType, const lexer::Sourc if (isGetterSetter && !functionOverridden) { for (auto *field : classType->Fields()) { if (field->Name() == (*it)->Name()) { + field->Declaration()->Node()->AddModifier(ir::ModifierFlags::SETTER); it = abstractsToBeImplemented.erase(it); functionOverridden = true; break; @@ -813,6 +814,7 @@ void ETSChecker::CheckClassDefinition(ir::ClassDefinition *classDef) } ValidateOverriding(classType, classDef->Start()); + TransformProperties(classType); CheckValidInheritance(classType, classDef); CheckConstFields(classType); CheckGetterSetterProperties(classType); @@ -1441,7 +1443,7 @@ void ETSChecker::CheckValidInheritance(ETSObjectType *classType, ir::ClassDefini continue; } - if (!IsSameDeclarationType(it, found)) { + if (!IsSameDeclarationType(it, found) && !it->HasFlag(varbinder::VariableFlags::GETTER_SETTER)) { const char *targetType {}; if (it->HasFlag(varbinder::VariableFlags::PROPERTY)) { @@ -1468,6 +1470,64 @@ void ETSChecker::CheckValidInheritance(ETSObjectType *classType, ir::ClassDefini } } +void ETSChecker::TransformProperties(ETSObjectType *classType) +{ + auto propertyList = classType->Fields(); + auto *const classDef = classType->GetDeclNode()->AsClassDefinition(); + + for (auto *const field : propertyList) { + ASSERT(field->Declaration()->Node()->IsClassProperty()); + auto *const classProp = field->Declaration()->Node()->AsClassProperty(); + + if ((field->Declaration()->Node()->Modifiers() & ir::ModifierFlags::SETTER) == 0U) { + continue; + } + + field->AddFlag(varbinder::VariableFlags::GETTER_SETTER); + + auto *const scope = this->Scope(); + ASSERT(scope->IsClassScope()); + + ir::MethodDefinition *getter = GenerateDefaultGetterSetter(classProp, scope->AsClassScope(), false, this); + classDef->Body().push_back(getter); + classType->AddProperty(getter->Variable()->AsLocalVariable()); + + auto *const methodScope = scope->AsClassScope()->InstanceMethodScope(); + auto name = getter->Key()->AsIdentifier()->Name(); + + auto *const decl = Allocator()->New(Allocator(), name, getter); + auto *const var = methodScope->AddDecl(Allocator(), decl, ScriptExtension::ETS); + var->AddFlag(varbinder::VariableFlags::METHOD); + + if (var == nullptr) { + auto *const prevDecl = methodScope->FindDecl(name); + ASSERT(prevDecl->IsFunctionDecl()); + prevDecl->Node()->AsMethodDefinition()->AddOverload(getter); + + if (!classProp->IsReadonly()) { + ir::MethodDefinition *const setter = + GenerateDefaultGetterSetter(classProp, scope->AsClassScope(), true, this); + + classType->AddProperty(setter->Variable()->AsLocalVariable()); + prevDecl->Node()->AsMethodDefinition()->AddOverload(setter); + } + + getter->Function()->Id()->SetVariable( + methodScope->FindLocal(name, varbinder::ResolveBindingOptions::BINDINGS)); + continue; + } + + if (!classProp->IsReadonly()) { + ir::MethodDefinition *const setter = + GenerateDefaultGetterSetter(classProp, scope->AsClassScope(), true, this); + + classType->AddProperty(setter->Variable()->AsLocalVariable()); + getter->AddOverload(setter); + } + getter->Function()->Id()->SetVariable(var); + } +} + void ETSChecker::CheckGetterSetterProperties(ETSObjectType *classType) { auto const checkGetterSetter = [this](varbinder::LocalVariable *var, util::StringView name) { diff --git a/ets2panda/compiler/lowering/ets/interfacePropertyDeclarations.cpp b/ets2panda/compiler/lowering/ets/interfacePropertyDeclarations.cpp index 85ccf455cf..97b56809eb 100644 --- a/ets2panda/compiler/lowering/ets/interfacePropertyDeclarations.cpp +++ b/ets2panda/compiler/lowering/ets/interfacePropertyDeclarations.cpp @@ -49,14 +49,12 @@ static ir::MethodDefinition *GenerateGetterOrSetter(checker::ETSChecker *const c paramIdent->SetTsTypeAnnotation(field->TypeAnnotation()->Clone(checker->Allocator())); paramIdent->TypeAnnotation()->SetParent(paramIdent); - auto paramExpression = checker->AllocNode(paramIdent, nullptr); + auto *const paramExpression = checker->AllocNode(paramIdent, nullptr); paramExpression->SetRange(paramIdent->Range()); - const auto [_, __, param_var] = paramScope->AddParamDecl(checker->Allocator(), paramExpression); - (void)_; - (void)__; + auto *const paramVar = std::get<2>(paramScope->AddParamDecl(checker->Allocator(), paramExpression)); - paramIdent->SetVariable(param_var); - paramExpression->SetVariable(param_var); + paramIdent->SetVariable(paramVar); + paramExpression->SetVariable(paramVar); params.push_back(paramExpression); } @@ -122,6 +120,7 @@ static ir::Expression *UpdateInterfacePropertys(checker::ETSChecker *const check auto *decl = checker->Allocator()->New(checker->Allocator(), name, getter); auto var = methodScope->AddDecl(checker->Allocator(), decl, ScriptExtension::ETS); + var->AddFlag(varbinder::VariableFlags::METHOD); if (var == nullptr) { auto prevDecl = methodScope->FindDecl(name); diff --git a/ets2panda/test/runtime/ets/classGetterSetter.ets b/ets2panda/test/runtime/ets/classGetterSetter.ets new file mode 100644 index 0000000000..29b68b3979 --- /dev/null +++ b/ets2panda/test/runtime/ets/classGetterSetter.ets @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2023 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 inter { + get my_field (): int; + set my_field(param: int); +} + +class A implements inter { + my_field: int = 3; +} + +function main() { + let a0: A = new A(); + assert a0.my_field == 3; + + let a1: inter = new A(); + assert a1.my_field == 3; + a1.my_field = 5; + assert a1.my_field == 5; +} diff --git a/ets2panda/varbinder/variableFlags.h b/ets2panda/varbinder/variableFlags.h index 87e165e4ce..3c9fa9813a 100644 --- a/ets2panda/varbinder/variableFlags.h +++ b/ets2panda/varbinder/variableFlags.h @@ -152,6 +152,7 @@ enum class VariableFlags : uint64_t { BUILTIN_TYPE = 1ULL << 32ULL, BOXED = 1ULL << 33ULL, + GETTER_SETTER = 1ULL << 34ULL, HOIST_VAR = HOIST | VAR, CLASS_OR_INTERFACE = CLASS | INTERFACE, -- Gitee From 562cc4c8e01d6c992b36da354047985ad326facf Mon Sep 17 00:00:00 2001 From: Martin Sajti Date: Wed, 3 Jan 2024 14:58:32 +0100 Subject: [PATCH 12/26] Fix ETSObjectType::Identical for function types Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/I8TEO3 Internal issue: #15034 Test: build, new checker tests Signed-off-by: Martin Sajti --- ets2panda/checker/types/ets/etsObjectType.cpp | 2 +- ets2panda/checker/types/ets/etsTupleType.cpp | 4 + .../compiler/ets/tuple_types_16-expected.txt | 1523 +++++++++++++++++ .../test/compiler/ets/tuple_types_16.ets | 24 + 4 files changed, 1552 insertions(+), 1 deletion(-) create mode 100644 ets2panda/test/compiler/ets/tuple_types_16-expected.txt create mode 100644 ets2panda/test/compiler/ets/tuple_types_16.ets diff --git a/ets2panda/checker/types/ets/etsObjectType.cpp b/ets2panda/checker/types/ets/etsObjectType.cpp index ab6f4fb3f5..cb10fbfff5 100644 --- a/ets2panda/checker/types/ets/etsObjectType.cpp +++ b/ets2panda/checker/types/ets/etsObjectType.cpp @@ -321,7 +321,7 @@ void ETSObjectType::IdenticalUptoNullability(TypeRelation *relation, Type *other return; } - if (relation->IgnoreTypeParameters() || (this == other)) { + if ((relation->IgnoreTypeParameters() && !HasObjectFlag(ETSObjectFlags::FUNCTIONAL)) || (this == other)) { relation->Result(true); return; } diff --git a/ets2panda/checker/types/ets/etsTupleType.cpp b/ets2panda/checker/types/ets/etsTupleType.cpp index 08e74f9828..92f9feb317 100644 --- a/ets2panda/checker/types/ets/etsTupleType.cpp +++ b/ets2panda/checker/types/ets/etsTupleType.cpp @@ -23,8 +23,12 @@ namespace panda::es2panda::checker { void ETSTupleType::ToString(std::stringstream &ss) const { ss << "["; + for (const auto *const type : typeList_) { type->ToString(ss); + if (type != typeList_.back()) { + ss << ","; + } } if (spreadType_ != nullptr) { diff --git a/ets2panda/test/compiler/ets/tuple_types_16-expected.txt b/ets2panda/test/compiler/ets/tuple_types_16-expected.txt new file mode 100644 index 0000000000..ed97776aec --- /dev/null +++ b/ets2panda/test/compiler/ets/tuple_types_16-expected.txt @@ -0,0 +1,1523 @@ +{ + "type": "Program", + "statements": [ + { + "type": "TSTypeAliasDeclaration", + "id": { + "type": "Identifier", + "name": "Func1", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 6 + }, + "end": { + "line": 16, + "column": 11 + } + } + }, + "typeAnnotation": { + "type": "ETSFunctionType", + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "value", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "String", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 22 + }, + "end": { + "line": 16, + "column": 28 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 22 + }, + "end": { + "line": 16, + "column": 29 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 22 + }, + "end": { + "line": 16, + "column": 29 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 15 + }, + "end": { + "line": 16, + "column": 29 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 15 + }, + "end": { + "line": 16, + "column": 29 + } + } + } + ], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "void", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 33 + }, + "end": { + "line": 16, + "column": 37 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 33 + }, + "end": { + "line": 17, + "column": 5 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 33 + }, + "end": { + "line": 17, + "column": 5 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 14 + }, + "end": { + "line": 17, + "column": 5 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 17, + "column": 5 + } + } + }, + { + "type": "TSTypeAliasDeclaration", + "id": { + "type": "Identifier", + "name": "Func0", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 6 + }, + "end": { + "line": 17, + "column": 11 + } + } + }, + "typeAnnotation": { + "type": "ETSFunctionType", + "params": [], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "void", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 20 + }, + "end": { + "line": 17, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 20 + }, + "end": { + "line": 17, + "column": 25 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 20 + }, + "end": { + "line": 17, + "column": 25 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 14 + }, + "end": { + "line": 17, + "column": 25 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 1 + }, + "end": { + "line": 17, + "column": 25 + } + } + }, + { + "type": "TSTypeAliasDeclaration", + "id": { + "type": "Identifier", + "name": "FuncTuple2", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 6 + }, + "end": { + "line": 18, + "column": 16 + } + } + }, + "typeAnnotation": { + "type": "ETSTuple", + "types": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Func1", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 20 + }, + "end": { + "line": 18, + "column": 25 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 20 + }, + "end": { + "line": 18, + "column": 26 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 20 + }, + "end": { + "line": 18, + "column": 26 + } + } + }, + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Func1", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 27 + }, + "end": { + "line": 18, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 27 + }, + "end": { + "line": 18, + "column": 33 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 27 + }, + "end": { + "line": 18, + "column": 33 + } + } + } + ], + "spreadType": null, + "loc": { + "start": { + "line": 18, + "column": 19 + }, + "end": { + "line": 19, + "column": 5 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 1 + }, + "end": { + "line": 19, + "column": 5 + } + } + }, + { + "type": "TSTypeAliasDeclaration", + "id": { + "type": "Identifier", + "name": "FuncTuple3", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 6 + }, + "end": { + "line": 19, + "column": 16 + } + } + }, + "typeAnnotation": { + "type": "ETSTuple", + "types": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Func1", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 20 + }, + "end": { + "line": 19, + "column": 25 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 20 + }, + "end": { + "line": 19, + "column": 26 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 20 + }, + "end": { + "line": 19, + "column": 26 + } + } + }, + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Func1", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 27 + }, + "end": { + "line": 19, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 27 + }, + "end": { + "line": 19, + "column": 33 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 27 + }, + "end": { + "line": 19, + "column": 33 + } + } + }, + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Func0", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 34 + }, + "end": { + "line": 19, + "column": 39 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 34 + }, + "end": { + "line": 19, + "column": 40 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 34 + }, + "end": { + "line": 19, + "column": 40 + } + } + } + ], + "spreadType": null, + "loc": { + "start": { + "line": 19, + "column": 19 + }, + "end": { + "line": 21, + "column": 9 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 1 + }, + "end": { + "line": 21, + "column": 9 + } + } + }, + { + "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": "main", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 10 + }, + "end": { + "line": 21, + "column": 14 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 10 + }, + "end": { + "line": 21, + "column": 14 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "void", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 18 + }, + "end": { + "line": 21, + "column": 22 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 18 + }, + "end": { + "line": 21, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 18 + }, + "end": { + "line": 21, + "column": 24 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "t2", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "FuncTuple2", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 11 + }, + "end": { + "line": 22, + "column": 21 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 11 + }, + "end": { + "line": 22, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 11 + }, + "end": { + "line": 22, + "column": 23 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 7 + }, + "end": { + "line": 22, + "column": 9 + } + } + }, + "init": { + "type": "ArrayExpression", + "elements": [ + { + "type": "ArrowFunctionExpression", + "function": { + "type": "ScriptFunction", + "id": null, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "value", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "String", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 33 + }, + "end": { + "line": 22, + "column": 39 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 33 + }, + "end": { + "line": 22, + "column": 40 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 33 + }, + "end": { + "line": 22, + "column": 40 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 26 + }, + "end": { + "line": 22, + "column": 40 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 26 + }, + "end": { + "line": 22, + "column": 40 + } + } + } + ], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 22, + "column": 44 + }, + "end": { + "line": 22, + "column": 46 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 25 + }, + "end": { + "line": 22, + "column": 46 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 25 + }, + "end": { + "line": 22, + "column": 46 + } + } + }, + { + "type": "ArrowFunctionExpression", + "function": { + "type": "ScriptFunction", + "id": null, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "value", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "String", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 56 + }, + "end": { + "line": 22, + "column": 62 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 56 + }, + "end": { + "line": 22, + "column": 63 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 56 + }, + "end": { + "line": 22, + "column": 63 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 49 + }, + "end": { + "line": 22, + "column": 63 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 49 + }, + "end": { + "line": 22, + "column": 63 + } + } + } + ], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 22, + "column": 67 + }, + "end": { + "line": 22, + "column": 69 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 48 + }, + "end": { + "line": 22, + "column": 69 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 48 + }, + "end": { + "line": 22, + "column": 69 + } + } + } + ], + "loc": { + "start": { + "line": 22, + "column": 24 + }, + "end": { + "line": 22, + "column": 70 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 7 + }, + "end": { + "line": 22, + "column": 70 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 22, + "column": 3 + }, + "end": { + "line": 22, + "column": 70 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "t3", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "FuncTuple3", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 11 + }, + "end": { + "line": 23, + "column": 21 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 11 + }, + "end": { + "line": 23, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 11 + }, + "end": { + "line": 23, + "column": 23 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 7 + }, + "end": { + "line": 23, + "column": 9 + } + } + }, + "init": { + "type": "ArrayExpression", + "elements": [ + { + "type": "ArrowFunctionExpression", + "function": { + "type": "ScriptFunction", + "id": null, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "value", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "String", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 33 + }, + "end": { + "line": 23, + "column": 39 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 33 + }, + "end": { + "line": 23, + "column": 40 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 33 + }, + "end": { + "line": 23, + "column": 40 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 26 + }, + "end": { + "line": 23, + "column": 40 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 26 + }, + "end": { + "line": 23, + "column": 40 + } + } + } + ], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 23, + "column": 44 + }, + "end": { + "line": 23, + "column": 46 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 25 + }, + "end": { + "line": 23, + "column": 46 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 25 + }, + "end": { + "line": 23, + "column": 46 + } + } + }, + { + "type": "ArrowFunctionExpression", + "function": { + "type": "ScriptFunction", + "id": null, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "value", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "String", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 56 + }, + "end": { + "line": 23, + "column": 62 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 56 + }, + "end": { + "line": 23, + "column": 63 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 56 + }, + "end": { + "line": 23, + "column": 63 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 49 + }, + "end": { + "line": 23, + "column": 63 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 49 + }, + "end": { + "line": 23, + "column": 63 + } + } + } + ], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 23, + "column": 67 + }, + "end": { + "line": 23, + "column": 69 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 48 + }, + "end": { + "line": 23, + "column": 69 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 48 + }, + "end": { + "line": 23, + "column": 69 + } + } + }, + { + "type": "ArrowFunctionExpression", + "function": { + "type": "ScriptFunction", + "id": null, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 23, + "column": 77 + }, + "end": { + "line": 23, + "column": 79 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 71 + }, + "end": { + "line": 23, + "column": 79 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 71 + }, + "end": { + "line": 23, + "column": 79 + } + } + } + ], + "loc": { + "start": { + "line": 23, + "column": 24 + }, + "end": { + "line": 23, + "column": 80 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 7 + }, + "end": { + "line": 23, + "column": 80 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 23, + "column": 3 + }, + "end": { + "line": 23, + "column": 80 + } + } + } + ], + "loc": { + "start": { + "line": 21, + "column": 23 + }, + "end": { + "line": 24, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 14 + }, + "end": { + "line": 24, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 14 + }, + "end": { + "line": 24, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 1 + }, + "end": { + "line": 24, + "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": 25, + "column": 1 + } + } +} diff --git a/ets2panda/test/compiler/ets/tuple_types_16.ets b/ets2panda/test/compiler/ets/tuple_types_16.ets new file mode 100644 index 0000000000..d0069f32aa --- /dev/null +++ b/ets2panda/test/compiler/ets/tuple_types_16.ets @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2023 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. + */ + +type Func1 = (value: String) => void +type Func0 = () => void; +type FuncTuple2 = [Func1, Func1] +type FuncTuple3 = [Func1, Func1, Func0] + +function main(): void { + let t2: FuncTuple2 = [(value: String) => {}, (value: String) => {}] + let t3: FuncTuple3 = [(value: String) => {}, (value: String) => {}, () => {}] +} -- Gitee From 53774b7d97be49e504ff1ffa35a5447e1475d340 Mon Sep 17 00:00:00 2001 From: Istvan Romai Date: Thu, 18 Jan 2024 08:50:07 +0100 Subject: [PATCH 13/26] [ArkTS frontend] Missing toString() method for arrays Added .toString() handling to arrays Fixes internal issue: #14766 Change-Id: Idc271497e2795456d840ad0a8c7416a99b10169c Signed-off-by: Istvan Romai --- ets2panda/checker/ETSAnalyzer.cpp | 22 ++++++++++++++++------ ets2panda/checker/ETSAnalyzer.h | 1 + ets2panda/compiler/core/ETSGen.cpp | 3 ++- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/ets2panda/checker/ETSAnalyzer.cpp b/ets2panda/checker/ETSAnalyzer.cpp index 885e81d208..ad052f8e19 100644 --- a/ets2panda/checker/ETSAnalyzer.cpp +++ b/ets2panda/checker/ETSAnalyzer.cpp @@ -1254,6 +1254,15 @@ checker::Type *ETSAnalyzer::Check([[maybe_unused]] ir::ImportExpression *expr) c UNREACHABLE(); } +checker::Type *ETSAnalyzer::SetAndAdjustType(ETSChecker *checker, ir::MemberExpression *expr, + ETSObjectType *objectType) const +{ + expr->SetObjectType(objectType); + auto [resType, resVar] = expr->ResolveObjectMember(checker); + expr->SetPropVar(resVar); + return expr->AdjustType(checker, resType); +} + checker::Type *ETSAnalyzer::Check(ir::MemberExpression *expr) const { ETSChecker *checker = GetETSChecker(); @@ -1284,15 +1293,16 @@ checker::Type *ETSAnalyzer::Check(ir::MemberExpression *expr) const return expr->AdjustType(checker, expr->CheckComputed(checker, baseType)); } - if (baseType->IsETSArrayType() && expr->Property()->AsIdentifier()->Name().Is("length")) { - return expr->AdjustType(checker, checker->GlobalIntType()); + if (baseType->IsETSArrayType()) { + if (expr->Property()->AsIdentifier()->Name().Is("length")) { + return expr->AdjustType(checker, checker->GlobalIntType()); + } + + return SetAndAdjustType(checker, expr, checker->GlobalETSObjectType()); } if (baseType->IsETSObjectType()) { - expr->SetObjectType(baseType->AsETSObjectType()); - auto [resType, resVar] = expr->ResolveObjectMember(checker); - expr->SetPropVar(resVar); - return expr->AdjustType(checker, resType); + return SetAndAdjustType(checker, expr, baseType->AsETSObjectType()); } if (baseType->IsETSEnumType() || baseType->IsETSStringEnumType()) { diff --git a/ets2panda/checker/ETSAnalyzer.h b/ets2panda/checker/ETSAnalyzer.h index db1f0439fb..c284a6db26 100644 --- a/ets2panda/checker/ETSAnalyzer.h +++ b/ets2panda/checker/ETSAnalyzer.h @@ -44,6 +44,7 @@ private: bool isFunctionalInterface, bool isUnionTypeWithFunctionalInterface) const; checker::Type *GetReturnType(ir::CallExpression *expr, checker::Type *calleeType) const; checker::Type *GetFunctionReturnType(ir::ReturnStatement *st, ir::ScriptFunction *containingFunc) const; + checker::Type *SetAndAdjustType(ETSChecker *checker, ir::MemberExpression *expr, ETSObjectType *objectType) const; }; } // namespace panda::es2panda::checker diff --git a/ets2panda/compiler/core/ETSGen.cpp b/ets2panda/compiler/core/ETSGen.cpp index e222381e66..3b1b3792a2 100644 --- a/ets2panda/compiler/core/ETSGen.cpp +++ b/ets2panda/compiler/core/ETSGen.cpp @@ -2387,7 +2387,8 @@ void ETSGen::StringBuilderAppend(const ir::AstNode *node, VReg builder) signature = Signatures::BUILTIN_STRING_BUILDER_APPEND_BUILTIN_STRING; } - if ((GetAccumulatorType()->IsETSObjectType() || GetAccumulatorType()->IsETSTypeParameter()) && + if ((GetAccumulatorType()->IsETSObjectType() || GetAccumulatorType()->IsETSTypeParameter() || + GetAccumulatorType()->IsETSArrayType()) && !GetAccumulatorType()->IsETSStringType()) { if (Checker()->MayHaveNullValue(GetAccumulatorType())) { Label *ifnull = AllocLabel(); -- Gitee From 19a16925ecd5066fe1aa91d5bce6529bfa2ab629 Mon Sep 17 00:00:00 2001 From: Anna Antipina Date: Tue, 23 Jan 2024 18:04:28 +0300 Subject: [PATCH 14/26] Title: Fix update expression compiling Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/I8YE1Q Description: Fix boxing-unboxing flags in Update expression compiling Test: ${ARK_SOURCE_DIR}/tests/tests-u-runner/runner.sh ${ARK_SOURCE_DIR} --ets-runtime --build-dir="${ARK_BUILD_DIR}" --heap-verifier="fail_on_verification:pre:into:before_g1_concurrent:post" --timeout=30 --force-generate --test-file UpdateExpression.ets Signed-off-by: Anna Antipina - --- ets2panda/compiler/core/ETSCompiler.cpp | 9 ++++----- ets2panda/test/runtime/ets/UpdateExpression.ets | 6 ++++++ 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/ets2panda/compiler/core/ETSCompiler.cpp b/ets2panda/compiler/core/ETSCompiler.cpp index c95eceb6d3..fd2476ce94 100644 --- a/ets2panda/compiler/core/ETSCompiler.cpp +++ b/ets2panda/compiler/core/ETSCompiler.cpp @@ -1189,8 +1189,11 @@ void ETSCompiler::Compile(const ir::UpdateExpression *expr) const const auto argumentUnboxingFlags = static_cast(expr->Argument()->GetBoxingUnboxingFlags() & ir::BoxingUnboxingFlags::UNBOXING_FLAG); + // workaround so argument_ does not get auto unboxed by lref.GetValue() + expr->Argument()->SetBoxingUnboxingFlags(ir::BoxingUnboxingFlags::NONE); + lref.GetValue(); + if (expr->IsPrefix()) { - lref.GetValue(); expr->Argument()->SetBoxingUnboxingFlags(argumentUnboxingFlags); etsg->ApplyConversion(expr->Argument(), nullptr); @@ -1209,10 +1212,6 @@ void ETSCompiler::Compile(const ir::UpdateExpression *expr) const return; } - // workaround so argument_ does not get auto unboxed by lref.GetValue() - expr->Argument()->SetBoxingUnboxingFlags(ir::BoxingUnboxingFlags::NONE); - lref.GetValue(); - compiler::RegScope rs(etsg); compiler::VReg originalValueReg = etsg->AllocReg(); etsg->StoreAccumulator(expr->Argument(), originalValueReg); diff --git a/ets2panda/test/runtime/ets/UpdateExpression.ets b/ets2panda/test/runtime/ets/UpdateExpression.ets index 4cb626c2c2..ef41ddc581 100644 --- a/ets2panda/test/runtime/ets/UpdateExpression.ets +++ b/ets2panda/test/runtime/ets/UpdateExpression.ets @@ -92,4 +92,10 @@ function main(): void { assert ++s as int == -32768; assert --s as int == 32767; } + + { + let b: Int[] = [1, 2] + assert ++b[1] == 3 + assert --b[1] == 2 + } } -- Gitee From 975751ad7be68fde877ec413a668e4e1c315cee7 Mon Sep 17 00:00:00 2001 From: Robert Sipka Date: Wed, 17 Jan 2024 14:27:46 +0100 Subject: [PATCH 15/26] [ArkTs] Remove some redundant code parts around source handling Remove redundant parsedSources_ vector Rename sourceFilePath_ to sourceFile_ Remove unused fileName_ member Remove redundant absoluteName_ member Signed-off-by: Robert Sipka --- ets2panda/compiler/core/ETSemitter.cpp | 4 +-- ets2panda/compiler/core/emitter.cpp | 2 +- ets2panda/parser/ETSparser.cpp | 16 +++++------ ets2panda/parser/ETSparser.h | 3 +-- ets2panda/parser/program/program.h | 37 +++++++------------------- ets2panda/varbinder/ETSBinder.cpp | 2 +- 6 files changed, 21 insertions(+), 43 deletions(-) diff --git a/ets2panda/compiler/core/ETSemitter.cpp b/ets2panda/compiler/core/ETSemitter.cpp index 04faea2890..116c3a7432 100644 --- a/ets2panda/compiler/core/ETSemitter.cpp +++ b/ets2panda/compiler/core/ETSemitter.cpp @@ -412,7 +412,7 @@ void ETSEmitter::GenInterfaceRecord(const ir::TSInterfaceDeclaration *interfaceD } interfaceRecord.metadata->SetAccessFlags(accessFlags); - interfaceRecord.sourceFile = Context()->VarBinder()->Program()->AbsoluteName().Mutf8(); + interfaceRecord.sourceFile = Context()->VarBinder()->Program()->SourceFile().GetAbsolutePath().Mutf8(); interfaceRecord.metadata->SetAttributeValue(Signatures::EXTENDS_ATTRIBUTE, Signatures::BUILTIN_OBJECT); for (auto *it : baseType->Interfaces()) { @@ -456,7 +456,7 @@ void ETSEmitter::GenClassRecord(const ir::ClassDefinition *classDef, bool extern } classRecord.metadata->SetAccessFlags(accessFlags); - classRecord.sourceFile = Context()->VarBinder()->Program()->AbsoluteName().Mutf8(); + classRecord.sourceFile = Context()->VarBinder()->Program()->SourceFile().GetAbsolutePath().Mutf8(); auto *baseType = classDef->TsType()->AsETSObjectType(); if (baseType->SuperType() != nullptr) { diff --git a/ets2panda/compiler/core/emitter.cpp b/ets2panda/compiler/core/emitter.cpp index 6242436e0b..bfc94a084d 100644 --- a/ets2panda/compiler/core/emitter.cpp +++ b/ets2panda/compiler/core/emitter.cpp @@ -257,7 +257,7 @@ void FunctionEmitter::GenFunctionCatchTables(pandasm::Function *func) void FunctionEmitter::GenSourceFileDebugInfo(pandasm::Function *func) { - func->sourceFile = std::string {cg_->VarBinder()->Program()->AbsoluteName()}; + func->sourceFile = std::string {cg_->VarBinder()->Program()->SourceFile().GetAbsolutePath()}; if (!cg_->IsDebug()) { return; diff --git a/ets2panda/parser/ETSparser.cpp b/ets2panda/parser/ETSparser.cpp index 8bacd3eba6..7d587b6939 100644 --- a/ets2panda/parser/ETSparser.cpp +++ b/ets2panda/parser/ETSparser.cpp @@ -190,7 +190,6 @@ void ETSParser::ParseETSGlobalScript(lexer::SourcePosition startLoc, ArenaVector for (const auto &item : items) { auto resolved = ResolveImportPath(item); resolvedParsedSources_.emplace(item, resolved); - parsedSources_.push_back(resolved); } }; // clang-format on @@ -288,7 +287,7 @@ static bool IsCompitableExtension(const std::string &extension) return extension == ".ets" || extension == ".ts"; } -void ETSParser::CollectDefaultSources() +std::vector ETSParser::CollectDefaultSources() { std::vector paths; std::vector stdlib = {"std/core", "std/math", "std/containers", @@ -319,9 +318,9 @@ void ETSParser::CollectDefaultSources() std::string filePath = path + "/" + entry->d_name; if (fileName == "Object.ets") { - parsedSources_.emplace(parsedSources_.begin(), filePath); + paths.emplace(paths.begin(), filePath); } else { - parsedSources_.emplace_back(filePath); + paths.emplace_back(filePath); } } @@ -340,13 +339,14 @@ void ETSParser::CollectDefaultSources() baseName.append(entry.path().string().substr(pos, entry.path().string().size())); if (entry.path().filename().string() == "Object.ets") { - parsedSources_.emplace(parsedSources_.begin(), baseName); + paths.emplace(paths.begin(), baseName); } else { - parsedSources_.emplace_back(baseName); + paths.emplace_back(baseName); } } } #endif + return paths; } ETSParser::ImportData ETSParser::GetImportData(const std::string &path) @@ -598,9 +598,7 @@ void ETSParser::ParseDefaultSources() ParseImportDeclarations(statements); GetContext().Status() &= ~ParserStatus::IN_DEFAULT_IMPORTS; - CollectDefaultSources(); - - ParseSources(parsedSources_, true); + ParseSources(CollectDefaultSources(), true); } void ETSParser::ParseSource(const SourceFile &sourceFile) diff --git a/ets2panda/parser/ETSparser.h b/ets2panda/parser/ETSparser.h index ca5fefcf6d..69b26abe93 100644 --- a/ets2panda/parser/ETSparser.h +++ b/ets2panda/parser/ETSparser.h @@ -124,7 +124,7 @@ private: static int NFTWCallBack(const char *fpath, const struct stat * /*unused*/, int tflag, struct FTW * /*unused*/); #endif void ParseTopLevelDeclaration(ArenaVector &statements); - void CollectDefaultSources(); + std::vector CollectDefaultSources(); void CollectUserSourcesFromIndex(const std::string &path, const std::string &resolvedPath, std::vector &userPaths); std::string ResolveImportPath(const std::string &path); @@ -382,7 +382,6 @@ public: private: parser::Program *globalProgram_; - std::vector parsedSources_; std::vector insertingNodes_ {}; std::unordered_map resolvedParsedSources_; }; diff --git a/ets2panda/parser/program/program.h b/ets2panda/parser/program/program.h index b1a29f3b1f..a289ac73b6 100644 --- a/ets2panda/parser/program/program.h +++ b/ets2panda/parser/program/program.h @@ -94,24 +94,19 @@ public: return sourceCode_; } - util::StringView SourceFilePath() const + const util::StringView &SourceFilePath() const { - return sourceFilePath_.GetPath(); + return sourceFile_.GetPath(); } - util::StringView SourceFileFolder() const + const util::Path &SourceFile() const { - return sourceFileFolder_; + return sourceFile_; } - util::StringView FileName() const - { - return fileName_; - } - - util::StringView AbsoluteName() const + util::StringView SourceFileFolder() const { - return absoluteName_; + return sourceFileFolder_; } util::StringView ResolvedFilePath() const @@ -163,17 +158,15 @@ public: const util::StringView &sourceFileFolder) { sourceCode_ = sourceCode; - sourceFilePath_ = util::Path(sourceFilePath, Allocator()); + sourceFile_ = util::Path(sourceFilePath, Allocator()); sourceFileFolder_ = sourceFileFolder; - absoluteName_ = util::UString(os::GetAbsolutePath(sourceFilePath.Utf8()), Allocator()).View(); } void SetSource(const panda::es2panda::SourceFile &sourceFile) { sourceCode_ = util::UString(sourceFile.source, Allocator()).View(); - sourceFilePath_ = util::Path(sourceFile.filePath, Allocator()); + sourceFile_ = util::Path(sourceFile.filePath, Allocator()); sourceFileFolder_ = util::UString(sourceFile.fileFolder, Allocator()).View(); - absoluteName_ = sourceFilePath_.GetAbsolutePath(); resolvedFilePath_ = util::UString(sourceFile.resolvedPath, Allocator()).View(); } @@ -187,16 +180,6 @@ public: packageName_ = packageName; } - void SetFileName(util::StringView fileName) - { - fileName_ = util::UString(fileName, Allocator()).View(); - } - - void SetAbsoluteName(util::StringView absouleName) - { - absoluteName_ = util::UString(absouleName, Allocator()).View(); - } - const bool &IsEntryPoint() const { return entryPoint_; @@ -225,11 +208,9 @@ private: ir::BlockStatement *ast_ {}; ir::ClassDefinition *globalClass_ {}; util::StringView sourceCode_ {}; - util::Path sourceFilePath_ {}; + util::Path sourceFile_ {}; util::StringView sourceFileFolder_ {}; util::StringView packageName_ {}; - util::StringView fileName_ {}; - util::StringView absoluteName_ {}; util::StringView resolvedFilePath_ {}; ExternalSource externalSources_; ScriptKind kind_ {}; diff --git a/ets2panda/varbinder/ETSBinder.cpp b/ets2panda/varbinder/ETSBinder.cpp index 3df41bd5eb..06d08f3553 100644 --- a/ets2panda/varbinder/ETSBinder.cpp +++ b/ets2panda/varbinder/ETSBinder.cpp @@ -1036,7 +1036,7 @@ void ETSBinder::BuildETSNewClassInstanceExpression(ir::ETSNewClassInstanceExpres void ETSBinder::BuildImportDeclaration(ir::ETSImportDeclaration *decl) { - if (decl->Source()->Str() == Program()->AbsoluteName()) { + if (decl->Source()->Str() == Program()->SourceFile().GetAbsolutePath()) { return; } -- Gitee From 0a97353cf49085ce99cf282f5c5ceb0153605325 Mon Sep 17 00:00:00 2001 From: peterseres Date: Tue, 19 Dec 2023 16:09:13 +0100 Subject: [PATCH 16/26] Change-Id: Ib692ef522d53042e347e9ba79d11f7a82a57f709 Title: Add new ninja target Description: es2panda-pre-test to run parser, runtime, ets-cts, function test cases clang-tidy and clang format. This commit contain the Python script. Fixes internal issue #13849 Testing: This commit and issue doesn't contains test cases because it's a Python script and a little modification in cmake. Signed-off-by: Peter Seres --- ets2panda/scripts/es2panda_pre_test.py | 184 +++++++++++++++++++++++++ 1 file changed, 184 insertions(+) create mode 100644 ets2panda/scripts/es2panda_pre_test.py diff --git a/ets2panda/scripts/es2panda_pre_test.py b/ets2panda/scripts/es2panda_pre_test.py new file mode 100644 index 0000000000..217f955c94 --- /dev/null +++ b/ets2panda/scripts/es2panda_pre_test.py @@ -0,0 +1,184 @@ +# +# Copyright (c) 2022-2023 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. +# +import re +import argparse +import subprocess +import time + +from enum import Enum + + +class TestTypes(Enum): + NORMAL = 0 + CLANGTIDY = 1 + CLANGFORMAT = 2 + + +def print_summary(log_lines, searched_words, end_word=""): + was_any_log = False + should_print = False + + for line in log_lines: + for word in searched_words: + if any(word in line for word in searched_words): + should_print = True + was_any_log = True + + if end_word and end_word in line: + should_print=False + + if should_print: + print(line.strip()) + + if not was_any_log: + print("Problem occourd: ", was_any_log) + + print(f"\n") + + +def print_progress_to_console(line, test_type, pattern_progress_bar, pattern_clang_tidy, pattern_clang_format): + match test_type: + case TestTypes.NORMAL: + match = pattern_progress_bar.search(line) + if match: + print(line, end='') + case TestTypes.CLANGTIDY: + match = re.match(pattern_clang_tidy, line) + if match: + print(f"[{match.group(1)}/{match.group(2)}] {match.group(3)}") + case TestTypes.CLANGFORMAT: + match = re.match(pattern_clang_format, line) + if match: + print(f"[{match.group(1)}/{match.group(2)}] Clang-format: {match.group(3)} \n") + + +def test_process_runner(runtime_process, test_type): + pattern_progress_bar = re.compile(r'\b(\d{1,3}%)\|(.+?)\| (\d+)/(\d+) \[\d{2}:\d{2}<\d{2}:\d{2},\s*\d+\.\d+it/s\]$') + pattern_clang_tidy = re.compile(r"^\[(\d+)\/(\d+)\]\s+Done\s+clang-tidy:\s+.*?\/es2panda\/(.+\.cpp)$") + pattern_clang_format = re.compile(r"\[(\d+)/(\d+)\]\s+Running clang-format: (.+)") + + should_print = False + log_lines = [] + + for line in runtime_process.stdout: + log_lines.append(line) + print_progress_to_console(line, test_type, pattern_progress_bar, pattern_clang_tidy, pattern_clang_format) + + return log_lines + + +def command_runner(command_to_run, test_type): + try: + process = subprocess.Popen(command_to_run, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True) + process_log = test_process_runner(process, test_type) + + except subprocess.CalledProcessError as e: + process_log = str(e) + print("An error occurred during processing:", process_log) + + except Exception as e: + process_log = str(e) + print("An error occurred during processing:", process_log) + + return process_log + +def print_summary_to_file(log, file_name, word_for_success, word_for_fail, test_name): + has_to_write_out_the_log = False + + for line in log: + if word_for_fail in line: + has_to_write_out_the_log = True + elif word_for_success in line: + print(line) + + if has_to_write_out_the_log: + with open(file_name, "w") as file: + for line in log: + file.write(line) + + print(f"{test_name} is faild. Please check the log file: {file_name}") + + +def main(): + parser = argparse.ArgumentParser(description="Program description.") + parser.add_argument("--working-dir", required=False, help="Path to the working dir") + parser.add_argument("--build-root", required=False, help="Path to the working dir") + + args = parser.parse_args() + print(f"Argumentum: Working dir: {args.working_dir}") + print(f"Argumentum: Build root: {args.build_root}") + + command_helper = ["python3", f"{args.working_dir}/tests/tests-u-runner/main.py", "--build-dir", f"{args.build_root}", + "--processes", "all", "--show-progress", "--force-generate" + ] + + # Run Parser tests + parser_test_run_command = command_helper + ["--parser" ] + + parser_log = command_runner(parser_test_run_command, TestTypes.NORMAL) + + # Run Runtime tests + runtime_test_run_command = command_helper + ["--ets-runtime", "--timeout", "60"] + + runtime_log = command_runner(runtime_test_run_command, TestTypes.NORMAL) + + # Functional tests + functional_test_run_command = command_helper + ["--ets-func-tests"] + + functional_log = command_runner(functional_test_run_command, TestTypes.NORMAL) + + # Run Ets-cts test + ets_cts_test_run_command = command_helper + ["--ets-cts"] + + ets_cts_log = command_runner(ets_cts_test_run_command, TestTypes.NORMAL) + + # Run Clang-format + clang_format_run_command = ["ninja", "-C", f"{args.build_root}", "code-style-check"] + + clang_format_log = command_runner(clang_format_run_command, TestTypes.CLANGFORMAT) + + # Run Clang-tidy + clang_tidy_run_command = [f"{args.working_dir}/scripts/clang-tidy/clang_tidy_check.py", "--filename-filter=ets2panda", + f"{args.working_dir}", f"{args.build_root}" + ] + + clang_tidy_log = command_runner(clang_tidy_run_command,TestTypes.CLANGTIDY) + + print("\n\nTest results: \n") + + print(f"\nParser test results:") + print_summary(parser_log, ["New failures at", "Summary("]) + + print(f"\nRuntime test results:") + print_summary(runtime_log, ["New failures at", "Summary("]) + + print(f"\nFunctional test results:") + print_summary(functional_log, ["Summary("]) + + print(f"\nEts-cts test results:") + print_summary(ets_cts_log, ["New failures at", "Summary("]) + + print(f"\nClang-format results:") + print_summary_to_file(clang_format_log, "clang-format.log", "Clang-format was passed successfully!", "Failed:", "Clang-format") + + print(f"\nClang-tidy results:") + print_summary(clang_tidy_log,["Clang-tidy was passed successfully!", "Failed:"], "Done clang-tidy:") + + +if __name__ == "__main__": + start_time = time.perf_counter() + main() + end_time = time.perf_counter() + print("Runtime: ", (end_time - start_time)/60, " minute" ) -- Gitee From d5c1dddebeca26cbbd0812b429444149d69c7cf8 Mon Sep 17 00:00:00 2001 From: Soma Simon Date: Fri, 19 Jan 2024 11:24:35 +0100 Subject: [PATCH 17/26] [ArkTS frontend] Fix call static interface method with type alias Fix condition when creating the searchflag, to find the property Fixed internal issue #14507 Change-Id: Iba1ae4c08e48752f182c21bbb9c3fcc2425bf69d Signed-off-by: Soma Simon --- ets2panda/checker/ets/object.cpp | 6 ++- .../ets/call_static_with_type_alias.ets | 52 +++++++++++++++++++ 2 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 ets2panda/test/runtime/ets/call_static_with_type_alias.ets diff --git a/ets2panda/checker/ets/object.cpp b/ets2panda/checker/ets/object.cpp index f09789c926..8c06deccbc 100644 --- a/ets2panda/checker/ets/object.cpp +++ b/ets2panda/checker/ets/object.cpp @@ -1250,8 +1250,10 @@ PropertySearchFlags ETSChecker::GetSearchFlags(const ir::MemberExpression *const { auto searchFlag = GetInitialSearchFlags(memberExpr); searchFlag |= PropertySearchFlags::SEARCH_IN_BASE | PropertySearchFlags::SEARCH_IN_INTERFACES; - - if (targetRef != nullptr && targetRef->HasFlag(varbinder::VariableFlags::CLASS_OR_INTERFACE)) { + if (targetRef != nullptr && + (targetRef->HasFlag(varbinder::VariableFlags::CLASS_OR_INTERFACE) || + (targetRef->HasFlag(varbinder::VariableFlags::TYPE_ALIAS) && + targetRef->TsType()->Variable()->HasFlag(varbinder::VariableFlags::CLASS_OR_INTERFACE)))) { searchFlag &= ~(PropertySearchFlags::SEARCH_INSTANCE); } else if (memberExpr->Object()->IsThisExpression() || (memberExpr->Object()->IsIdentifier() && memberExpr->ObjType()->GetDeclNode() != nullptr && diff --git a/ets2panda/test/runtime/ets/call_static_with_type_alias.ets b/ets2panda/test/runtime/ets/call_static_with_type_alias.ets new file mode 100644 index 0000000000..0a86ff562a --- /dev/null +++ b/ets2panda/test/runtime/ets/call_static_with_type_alias.ets @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2024 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 { + static inc(p: number): number { + return p + 1; + } +} + +class C1 { + static inc2(p: number): number { + return p + 2; + } +} + +class C2 implements I { +} + +type TI = I; +type TTI = TI; + +type TC1 = C1; +type TTC1 = TC1; + +type TC2 = C2; +type TTC2 = TC2; + +function main(): void { + assert I.inc(20) == 21; + assert TI.inc(20) == 21; + assert TTI.inc(20) == 21; + + assert C1.inc2(20) == 22; + assert TC1.inc2(20) == 22; + assert TTC1.inc2(20) == 22; + + assert C2.inc(20) == 21; + assert TC2.inc(20) == 21; + assert TTC2.inc(20) == 21; +} -- Gitee From b7e112196d0ba70cb830f716e70ab852ca85520d Mon Sep 17 00:00:00 2001 From: aleksisch Date: Fri, 12 Jan 2024 14:52:45 +0300 Subject: [PATCH 18/26] make field & register traverse deterministic Signed-off-by: aleksisch --- ets2panda/checker/types/ets/etsObjectType.cpp | 7 ++-- ets2panda/checker/types/ets/etsObjectType.h | 2 +- ets2panda/compiler/core/envScope.cpp | 2 +- ets2panda/compiler/core/regScope.cpp | 4 +- .../lowering/scopesInit/savedBindingsCtx.cpp | 2 +- ets2panda/parser/ETSparser.cpp | 39 ++++++++++++------- ets2panda/parser/ETSparser.h | 1 + ets2panda/varbinder/scope.h | 7 ++++ 8 files changed, 42 insertions(+), 22 deletions(-) diff --git a/ets2panda/checker/types/ets/etsObjectType.cpp b/ets2panda/checker/types/ets/etsObjectType.cpp index cb10fbfff5..2a7695b053 100644 --- a/ets2panda/checker/types/ets/etsObjectType.cpp +++ b/ets2panda/checker/types/ets/etsObjectType.cpp @@ -272,12 +272,11 @@ std::vector ETSObjectType::ForeignProperties() return foreignProps; } -std::unordered_map ETSObjectType::CollectAllProperties() const +ArenaMap ETSObjectType::CollectAllProperties() const { - std::unordered_map propMap; + ArenaMap propMap(allocator_->Adapter()); EnsurePropertiesInstantiated(); - propMap.reserve(properties_.size()); - Iterate([&propMap](const varbinder::LocalVariable *var) { propMap.insert({var->Name(), var}); }); + Iterate([&propMap](const varbinder::LocalVariable *var) { propMap.emplace(var->Name(), var); }); return propMap; } diff --git a/ets2panda/checker/types/ets/etsObjectType.h b/ets2panda/checker/types/ets/etsObjectType.h index 464754a587..ff6cca7a94 100644 --- a/ets2panda/checker/types/ets/etsObjectType.h +++ b/ets2panda/checker/types/ets/etsObjectType.h @@ -545,7 +545,7 @@ private: propertiesInstantiated_ = true; } } - std::unordered_map CollectAllProperties() const; + ArenaMap CollectAllProperties() const; void IdenticalUptoNullability(TypeRelation *relation, Type *other); bool CastWideningNarrowing(TypeRelation *relation, Type *target, TypeFlag unboxFlags, TypeFlag wideningFlags, TypeFlag narrowingFlags); diff --git a/ets2panda/compiler/core/envScope.cpp b/ets2panda/compiler/core/envScope.cpp index 7adc372f8f..cb870fdce8 100644 --- a/ets2panda/compiler/core/envScope.cpp +++ b/ets2panda/compiler/core/envScope.cpp @@ -60,7 +60,7 @@ void LoopEnvScope::CopyBindings(PandaGen *pg, varbinder::VariableScope *scope, v ASSERT(scope->NeedLexEnv()); - for (const auto &[_, variable] : scope_->Bindings()) { + for (const auto &[_, variable] : scope_->OrderedBindings(pg_->Allocator())) { (void)_; if (!variable->HasFlag(flag)) { continue; diff --git a/ets2panda/compiler/core/regScope.cpp b/ets2panda/compiler/core/regScope.cpp index 6109ffd80f..9f7a6d7e41 100644 --- a/ets2panda/compiler/core/regScope.cpp +++ b/ets2panda/compiler/core/regScope.cpp @@ -52,7 +52,7 @@ LocalRegScope::LocalRegScope(CodeGen *cg, varbinder::Scope *scope) : RegScope(cg prevScope_ = cg_->scope_; cg_->scope_ = scope; - for (const auto &[_, var] : scope->Bindings()) { + for (const auto &[_, var] : scope->OrderedBindings(cg_->Allocator())) { (void)_; if (!var->LexicalBound() && var->IsLocalVariable()) { var->AsLocalVariable()->BindVReg(cg_->AllocReg()); @@ -99,7 +99,7 @@ void FunctionRegScope::InitializeParams(const StoreParamCb &cb) paramReg++; } - for (const auto it : funcScope->Bindings()) { + for (const auto it : funcScope->OrderedBindings(cg_->Allocator())) { auto *const var = std::get<1>(it); if (var->Declaration()->IsParameterDecl() || var->Declaration()->IsTypeAliasDecl()) { continue; diff --git a/ets2panda/compiler/lowering/scopesInit/savedBindingsCtx.cpp b/ets2panda/compiler/lowering/scopesInit/savedBindingsCtx.cpp index 72bab547bd..c8197d78c2 100644 --- a/ets2panda/compiler/lowering/scopesInit/savedBindingsCtx.cpp +++ b/ets2panda/compiler/lowering/scopesInit/savedBindingsCtx.cpp @@ -26,7 +26,7 @@ void ImportDeclarationContext::BindImportDecl(ir::ImportDeclaration *importDecl) { varbinder::ModuleScope::ImportDeclList declList(Allocator()->Adapter()); - for (const auto &[name, variable] : VarBinder()->GetScope()->Bindings()) { + for (const auto &[name, variable] : VarBinder()->GetScope()->OrderedBindings(Allocator())) { if (SavedBindings().find(name) != SavedBindings().end()) { continue; } diff --git a/ets2panda/parser/ETSparser.cpp b/ets2panda/parser/ETSparser.cpp index 7d587b6939..0634e8bdfa 100644 --- a/ets2panda/parser/ETSparser.cpp +++ b/ets2panda/parser/ETSparser.cpp @@ -287,12 +287,9 @@ static bool IsCompitableExtension(const std::string &extension) return extension == ".ets" || extension == ".ts"; } -std::vector ETSParser::CollectDefaultSources() +std::vector ETSParser::UnixApiDefaultSources([[maybe_unused]] const std::vector &stdlib) { std::vector paths; - std::vector stdlib = {"std/core", "std/math", "std/containers", - "std/time", "std/interop/js", "escompat"}; - #ifdef USE_UNIX_SYSCALL for (auto const &path : stdlib) { auto resolvedPath = ResolveImportPath(path); @@ -303,6 +300,7 @@ std::vector ETSParser::CollectDefaultSources() } struct dirent *entry; + std::set orderedFiles; while ((entry = readdir(dir)) != nullptr) { if (entry->d_type != DT_REG) { continue; @@ -310,7 +308,6 @@ std::vector ETSParser::CollectDefaultSources() std::string fileName = entry->d_name; std::string::size_type pos = fileName.find_last_of('.'); - if (pos == std::string::npos || !IsCompitableExtension(fileName.substr(pos))) { continue; } @@ -320,14 +317,27 @@ std::vector ETSParser::CollectDefaultSources() if (fileName == "Object.ets") { paths.emplace(paths.begin(), filePath); } else { - paths.emplace_back(filePath); + orderedFiles.emplace(filePath); } } - + paths.insert(paths.end(), orderedFiles.begin(), orderedFiles.end()); closedir(dir); } +#endif + return paths; +} + +std::vector ETSParser::CollectDefaultSources() +{ + std::vector stdlib = {"std/core", "std/math", "std/containers", + "std/time", "std/interop/js", "escompat"}; + +#ifdef USE_UNIX_SYSCALL + return UnixApiDefaultSources(stdlib); #else + std::vector paths; for (auto const &path : stdlib) { + std::set orderedFiles; for (auto const &entry : fs::directory_iterator(ResolveImportPath(path))) { if (!fs::is_regular_file(entry) || !IsCompitableExtension(entry.path().extension().string())) { continue; @@ -341,12 +351,13 @@ std::vector ETSParser::CollectDefaultSources() if (entry.path().filename().string() == "Object.ets") { paths.emplace(paths.begin(), baseName); } else { - paths.emplace_back(baseName); + orderedFiles.emplace(baseName); } } + paths.insert(paths.end(), orderedFiles.begin(), orderedFiles.end()); } -#endif return paths; +#endif } ETSParser::ImportData ETSParser::GetImportData(const std::string &path) @@ -464,7 +475,7 @@ void ETSParser::CollectUserSourcesFromIndex([[maybe_unused]] const std::string & #ifdef USE_UNIX_SYSCALL DIR *dir = opendir(resolvedPath.c_str()); bool isIndex = false; - std::vector tmpPaths; + std::set tmpPaths; if (dir == nullptr) { ThrowSyntaxError({"Cannot open folder: ", resolvedPath}); @@ -489,9 +500,9 @@ void ETSParser::CollectUserSourcesFromIndex([[maybe_unused]] const std::string & isIndex = true; break; } else if (fileName == "Object.ets") { - tmpPaths.emplace(userPaths.begin(), filePath); + userPaths.emplace(userPaths.begin(), filePath); } else { - tmpPaths.emplace_back(filePath); + tmpPaths.insert(filePath); } } @@ -531,6 +542,7 @@ std::tuple, bool> ETSParser::CollectUserSources(const s } else if (fs::exists(resolvedPath + "/index.ts")) { userPaths.emplace_back(path + "/index.ts"); } else { + std::set orderedFiles; for (auto const &entry : fs::directory_iterator(resolvedPath)) { if (!fs::is_regular_file(entry) || !IsCompitableExtension(entry.path().extension().string())) { continue; @@ -540,8 +552,9 @@ std::tuple, bool> ETSParser::CollectUserSources(const s std::size_t pos = entry.path().string().find_last_of(panda::os::file::File::GetPathDelim()); baseName.append(entry.path().string().substr(pos, entry.path().string().size())); - userPaths.emplace_back(baseName); + orderedFiles.emplace(baseName); } + userPaths.insert(userPaths.begin(), orderedFiles.begin(), orderedFiles.end()); } #endif return {userPaths, false}; diff --git a/ets2panda/parser/ETSparser.h b/ets2panda/parser/ETSparser.h index 69b26abe93..f23f3442dc 100644 --- a/ets2panda/parser/ETSparser.h +++ b/ets2panda/parser/ETSparser.h @@ -124,6 +124,7 @@ private: static int NFTWCallBack(const char *fpath, const struct stat * /*unused*/, int tflag, struct FTW * /*unused*/); #endif void ParseTopLevelDeclaration(ArenaVector &statements); + std::vector UnixApiDefaultSources(const std::vector &stdlib); std::vector CollectDefaultSources(); void CollectUserSourcesFromIndex(const std::string &path, const std::string &resolvedPath, std::vector &userPaths); diff --git a/ets2panda/varbinder/scope.h b/ets2panda/varbinder/scope.h index b53625d68e..f1030ca408 100644 --- a/ets2panda/varbinder/scope.h +++ b/ets2panda/varbinder/scope.h @@ -245,6 +245,13 @@ public: return bindings_; } + ArenaMap OrderedBindings(ArenaAllocator *allocator) const + { + ArenaMap result(allocator->Adapter()); + result.insert(bindings_.begin(), bindings_.end()); + return result; + } + virtual Variable *AddBinding(ArenaAllocator *allocator, Variable *currentVariable, Decl *newDecl, [[maybe_unused]] ScriptExtension extension) = 0; -- Gitee From e9aa18752e6ed7e869af243ad2f616d5bb463ea8 Mon Sep 17 00:00:00 2001 From: Vivien Voros Date: Thu, 11 Jan 2024 10:49:37 +0100 Subject: [PATCH 19/26] 'type' is hard keyword Change 'type' to soft keyword. Fixes internal issue #13941 Change-Id: Ia3a52c904e2ccc12b0c37448aa1f5eddf59a93e4 Signed-off-by: Vivien Voros --- ets2panda/lexer/scripts/keywords.yaml | 3 +- ets2panda/lexer/token/token.cpp | 1 + ets2panda/parser/ETSparser.cpp | 15 +- ets2panda/parser/ETSparser.h | 1 + .../parser/ets/user_defined_22-expected.txt | 830 ++++++++++++++++++ ets2panda/test/parser/ets/user_defined_22.ets | 22 + .../parser/ets/user_defined_23-expected.txt | 1 + ets2panda/test/parser/ets/user_defined_23.ets | 18 + .../parser/ets/user_defined_24-expected.txt | 1 + ets2panda/test/parser/ets/user_defined_24.ets | 18 + .../parser/ets/user_defined_25-expected.txt | 1 + ets2panda/test/parser/ets/user_defined_25.ets | 18 + 12 files changed, 923 insertions(+), 6 deletions(-) create mode 100644 ets2panda/test/parser/ets/user_defined_22-expected.txt create mode 100644 ets2panda/test/parser/ets/user_defined_22.ets create mode 100644 ets2panda/test/parser/ets/user_defined_23-expected.txt create mode 100644 ets2panda/test/parser/ets/user_defined_23.ets create mode 100644 ets2panda/test/parser/ets/user_defined_24-expected.txt create mode 100644 ets2panda/test/parser/ets/user_defined_24.ets create mode 100644 ets2panda/test/parser/ets/user_defined_25-expected.txt create mode 100644 ets2panda/test/parser/ets/user_defined_25.ets diff --git a/ets2panda/lexer/scripts/keywords.yaml b/ets2panda/lexer/scripts/keywords.yaml index e437a74c86..d6f8a5540f 100644 --- a/ets2panda/lexer/scripts/keywords.yaml +++ b/ets2panda/lexer/scripts/keywords.yaml @@ -430,8 +430,7 @@ keywords: - name: 'type' token: KEYW_TYPE - keyword: [ets] - keyword_like: [js, ts] + keyword_like: [ets, js, ts] - name: 'typeof' token: KEYW_TYPEOF diff --git a/ets2panda/lexer/token/token.cpp b/ets2panda/lexer/token/token.cpp index cf4e3e3033..1135f0f0a3 100644 --- a/ets2panda/lexer/token/token.cpp +++ b/ets2panda/lexer/token/token.cpp @@ -107,6 +107,7 @@ bool Token::IsDefinableTypeName() const case TokenType::KEYW_INT: case TokenType::KEYW_CHAR: case TokenType::KEYW_LONG: + case TokenType::KEYW_TYPE: return true; default: return false; diff --git a/ets2panda/parser/ETSparser.cpp b/ets2panda/parser/ETSparser.cpp index 0634e8bdfa..b91b25f816 100644 --- a/ets2panda/parser/ETSparser.cpp +++ b/ets2panda/parser/ETSparser.cpp @@ -741,6 +741,11 @@ void ETSParser::ParseTopLevelNextTokenDefault(ArenaVector &stat return; } + if (IsTypeKeyword()) { + ParseTopLevelType(statements, defaultExport, currentPos, &ETSParser::ParseTypeAliasDeclaration); + return; + } + if (initFunction != nullptr) { if (auto *const statement = ParseTopLevelStatement(); statement != nullptr) { statement->SetParent(initFunction->Body()); @@ -809,10 +814,6 @@ lexer::SourcePosition ETSParser::ParseTopLevelNextTokenResolution(ArenaVectorGetToken().KeywordType() == lexer::TokenType::KEYW_STRUCT); } +bool ETSParser::IsTypeKeyword() const +{ + return (Lexer()->GetToken().Type() == lexer::TokenType::LITERAL_IDENT && + Lexer()->GetToken().KeywordType() == lexer::TokenType::KEYW_TYPE); +} + void ETSParser::ValidateInstanceOfExpression(ir::Expression *expr) { ValidateGroupedExpression(expr); diff --git a/ets2panda/parser/ETSparser.h b/ets2panda/parser/ETSparser.h index f23f3442dc..4b4afef511 100644 --- a/ets2panda/parser/ETSparser.h +++ b/ets2panda/parser/ETSparser.h @@ -325,6 +325,7 @@ private: } bool IsStructKeyword() const; + bool IsTypeKeyword() const; // NOLINTNEXTLINE(google-default-arguments) ir::Expression *ParseExpression(ExpressionParseFlags flags = ExpressionParseFlags::NO_OPTS) override; diff --git a/ets2panda/test/parser/ets/user_defined_22-expected.txt b/ets2panda/test/parser/ets/user_defined_22-expected.txt new file mode 100644 index 0000000000..6b33f24143 --- /dev/null +++ b/ets2panda/test/parser/ets/user_defined_22-expected.txt @@ -0,0 +1,830 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 7 + }, + "end": { + "line": 16, + "column": 8 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "type", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 3 + }, + "end": { + "line": 17, + "column": 7 + } + } + }, + "value": { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 17, + "column": 18 + }, + "end": { + "line": 17, + "column": 19 + } + } + }, + "accessibility": "public", + "static": false, + "readonly": false, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "number", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 9 + }, + "end": { + "line": 17, + "column": 15 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 9 + }, + "end": { + "line": 17, + "column": 17 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 9 + }, + "end": { + "line": 17, + "column": 17 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 3 + }, + "end": { + "line": 17, + "column": 19 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "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": 18, + "column": 2 + }, + "end": { + "line": 18, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 18, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 18, + "column": 2 + } + } + }, + { + "type": "TSTypeAliasDeclaration", + "id": { + "type": "Identifier", + "name": "B", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 6 + }, + "end": { + "line": 19, + "column": 7 + } + } + }, + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 10 + }, + "end": { + "line": 19, + "column": 16 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 10 + }, + "end": { + "line": 20, + "column": 4 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 10 + }, + "end": { + "line": 20, + "column": 4 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 1 + }, + "end": { + "line": 20, + "column": 4 + } + } + }, + { + "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": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "a", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 5 + }, + "end": { + "line": 20, + "column": 6 + } + } + }, + "right": { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 13 + }, + "end": { + "line": 20, + "column": 14 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 13 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 13 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 20, + "column": 9 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 5 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 1 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "a", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 1 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "property": { + "type": "Identifier", + "name": "type", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 3 + }, + "end": { + "line": 21, + "column": 7 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 21, + "column": 1 + }, + "end": { + "line": 21, + "column": 7 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 1 + }, + "end": { + "line": 21, + "column": 7 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "b", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 5 + }, + "end": { + "line": 22, + "column": 6 + } + } + }, + "right": { + "type": "StringLiteral", + "value": "", + "loc": { + "start": { + "line": 22, + "column": 12 + }, + "end": { + "line": 22, + "column": 14 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 5 + }, + "end": { + "line": 22, + "column": 14 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 1 + }, + "end": { + "line": 22, + "column": 14 + } + } + } + ], + "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": "ClassProperty", + "key": { + "type": "Identifier", + "name": "a", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 5 + }, + "end": { + "line": 20, + "column": 6 + } + } + }, + "value": { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 13 + }, + "end": { + "line": 20, + "column": 14 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 13 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 13 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 20, + "column": 9 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "accessibility": "public", + "static": true, + "readonly": false, + "declare": false, + "optional": false, + "computed": false, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 5 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "b", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 5 + }, + "end": { + "line": 22, + "column": 6 + } + } + }, + "accessibility": "public", + "static": true, + "readonly": false, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "B", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 8 + }, + "end": { + "line": 22, + "column": 9 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 8 + }, + "end": { + "line": 22, + "column": 11 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 8 + }, + "end": { + "line": 22, + "column": 11 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 5 + }, + "end": { + "line": 22, + "column": 11 + } + } + } + ], + "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": 23, + "column": 1 + } + } +} diff --git a/ets2panda/test/parser/ets/user_defined_22.ets b/ets2panda/test/parser/ets/user_defined_22.ets new file mode 100644 index 0000000000..75ace1622e --- /dev/null +++ b/ets2panda/test/parser/ets/user_defined_22.ets @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2024 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. + */ + +class A { + type: number = 0 +} +type B = string +let a = new A +a.type +let b: B = "" diff --git a/ets2panda/test/parser/ets/user_defined_23-expected.txt b/ets2panda/test/parser/ets/user_defined_23-expected.txt new file mode 100644 index 0000000000..6fb05ccbb5 --- /dev/null +++ b/ets2panda/test/parser/ets/user_defined_23-expected.txt @@ -0,0 +1 @@ +SyntaxError: Cannot be used as user-defined type. [user_defined_23.ets:16:7] diff --git a/ets2panda/test/parser/ets/user_defined_23.ets b/ets2panda/test/parser/ets/user_defined_23.ets new file mode 100644 index 0000000000..43577e643e --- /dev/null +++ b/ets2panda/test/parser/ets/user_defined_23.ets @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2024 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. + */ + +class type { + type: number = 0 +} diff --git a/ets2panda/test/parser/ets/user_defined_24-expected.txt b/ets2panda/test/parser/ets/user_defined_24-expected.txt new file mode 100644 index 0000000000..458482bb15 --- /dev/null +++ b/ets2panda/test/parser/ets/user_defined_24-expected.txt @@ -0,0 +1 @@ +SyntaxError: Cannot be used as user-defined type. [user_defined_24.ets:16:8] diff --git a/ets2panda/test/parser/ets/user_defined_24.ets b/ets2panda/test/parser/ets/user_defined_24.ets new file mode 100644 index 0000000000..c52cb720a5 --- /dev/null +++ b/ets2panda/test/parser/ets/user_defined_24.ets @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2024 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. + */ + +struct type { + type: number = 0 +} diff --git a/ets2panda/test/parser/ets/user_defined_25-expected.txt b/ets2panda/test/parser/ets/user_defined_25-expected.txt new file mode 100644 index 0000000000..105c5ae761 --- /dev/null +++ b/ets2panda/test/parser/ets/user_defined_25-expected.txt @@ -0,0 +1 @@ +SyntaxError: Cannot be used as user-defined type. [user_defined_25.ets:16:11] diff --git a/ets2panda/test/parser/ets/user_defined_25.ets b/ets2panda/test/parser/ets/user_defined_25.ets new file mode 100644 index 0000000000..db7c0eb73b --- /dev/null +++ b/ets2panda/test/parser/ets/user_defined_25.ets @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2024 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 type { + type: number = 0 +} -- Gitee From 436d424eeeea339f04c6e63316cac09219ed9a43 Mon Sep 17 00:00:00 2001 From: Tatiana Date: Mon, 29 Jan 2024 14:44:43 +0300 Subject: [PATCH 20/26] Turn on ForLoopCorrectlyInitialized check in AST Verifier Fix internal issue #15239 Signed-off-by: Tatiana --- ets2panda/util/options.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/ets2panda/util/options.cpp b/ets2panda/util/options.cpp index db863804e2..7961ee7c14 100644 --- a/ets2panda/util/options.cpp +++ b/ets2panda/util/options.cpp @@ -181,8 +181,22 @@ bool Options::Parse(int argc, const char **argv) panda::PandArg genStdLib("gen-stdlib", false, "Gen standard library"); panda::PandArg plugins("plugins", "", "Plugins"); panda::PandArg skipPhases("skip-phases", "", "Phases to skip"); - panda::PandArg verifierWarnings("verifier-warnings", "", "Show warnings form verifier"); - panda::PandArg verifierErrors("verifier-errors", "", "Show warnings form verifier"); + panda::PandArg verifierWarnings( + "verifier-warnings", "", + "Print errors and continue compilation if AST tree is incorrect. " + "Possible values: " + "NodeHasParentForAll,EveryChildHasValidParentForAll,VariableHasScopeForAll,NodeHasTypeForAll," + "IdentifierHasVariableForAll,ArithmeticOperationValidForAll,SequenceExpressionHasLastTypeForAll," + "ForLoopCorrectlyInitializedForAll,VariableHasEnclosingScopeForAll,ModifierAccessValidForAll," + "ImportExportAccessValid"); + panda::PandArg verifierErrors( + "verifier-errors", "ForLoopCorrectlyInitializedForAll", + "Print errors and stop compilation if AST tree is incorrect. " + "Possible values: " + "NodeHasParentForAll,EveryChildHasValidParentForAll,VariableHasScopeForAll,NodeHasTypeForAll," + "IdentifierHasVariableForAll,ArithmeticOperationValidForAll,SequenceExpressionHasLastTypeForAll," + "ForLoopCorrectlyInitializedForAll,VariableHasEnclosingScopeForAll,ModifierAccessValidForAll," + "ImportExportAccessValid"); panda::PandArg dumpBeforePhases("dump-before-phases", "", "Generate program dump before running phases in the list"); panda::PandArg dumpEtsSrcBeforePhases( -- Gitee From 3e62735ef84cab75748bac78a07d2a77eb29bb21 Mon Sep 17 00:00:00 2001 From: Otto Eotvos Date: Fri, 19 Jan 2024 13:03:55 +0100 Subject: [PATCH 21/26] [ArkTS] Rework assignment related error messages Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/I8L5TI Testing: All required pre-merge tests have passed. Results are available in the ggwatcher. Description: Error messages have been rewritten to show the types, which cannot be assigned to each other. Also some modification to the toString of Objects. Fixes internal issue #14547 Change-Id: Ib3d826662e07c3f973a441b4db725ac1b643637b Signed-off-by: Soma Simon Signed-off-by: Otto Eotvos --- ets2panda/checker/ETSAnalyzer.cpp | 84 +- ets2panda/checker/ETSAnalyzer.h | 2 + ets2panda/checker/ETSchecker.h | 1 + ets2panda/checker/ets/function.cpp | 27 +- ets2panda/checker/ets/helpers.cpp | 42 +- ets2panda/checker/ets/typeRelationContext.cpp | 5 +- ets2panda/checker/ets/typeRelationContext.h | 2 + ets2panda/checker/types/ets/etsArrayType.cpp | 5 + ets2panda/checker/types/ets/etsObjectType.cpp | 30 +- ets2panda/checker/types/ets/etsObjectType.h | 2 +- ets2panda/checker/types/ets/etsTupleType.cpp | 9 +- .../compiler/ets/FunctionType1-expected.txt | 2 +- .../compiler/ets/FunctionType3-expected.txt | 2 +- ...rsion_Double-to-Int_typeerror-expected.txt | 2 +- ...le-to-Int_w_try_stmt_typerror-expected.txt | 2 +- ...rsion_Int-to-Double_typeerror-expected.txt | 2 +- ...ntext_Int-to-Double_typeerror-expected.txt | 2 +- .../ets/etsObjectToString0-expected.txt | 584 ++++++++++++ .../test/compiler/ets/etsObjectToString0.ets | 21 + .../ets/etsObjectToString1-expected.txt | 640 +++++++++++++ .../test/compiler/ets/etsObjectToString1.ets | 21 + .../ets/etsObjectToString2-expected.txt | 668 +++++++++++++ .../test/compiler/ets/etsObjectToString2.ets | 21 + .../ets/etsObjectToString3-expected.txt | 890 ++++++++++++++++++ .../test/compiler/ets/etsObjectToString3.ets | 21 + .../ets/etsObjectToString4-expected.txt | 468 +++++++++ .../test/compiler/ets/etsObjectToString4.ets | 18 + .../ets/etsObjectToString5-expected.txt | 848 +++++++++++++++++ .../test/compiler/ets/etsObjectToString5.ets | 20 + .../ets/generic_function_call_2-expected.txt | 2 +- ...cs_primitive_type_param_neg_1-expected.txt | 2 +- .../ets/identifierReference10-expected.txt | 2 +- .../ets/identifierReference2-expected.txt | 2 +- .../ets/identifierReference3-expected.txt | 2 +- .../inferTypeOfArrayNegative3-expected.txt | 2 +- ...utBlockStatementDifferentType-expected.txt | 2 +- ...tementDifferentTypeInfunction-expected.txt | 2 +- .../compiler/ets/lambdaFunction3-expected.txt | 2 +- .../compiler/ets/lambdaFunction5-expected.txt | 2 +- ...ullableTypeParamToNonNullable-expected.txt | 2 +- ...ctLiteralPrimitiveContextType-expected.txt | 2 +- .../objectLiteralWrongValueType-expected.txt | 2 +- .../switchStatementWrongBoxing-expected.txt | 2 +- .../ets/tuple_types_10_neg-expected.txt | 2 +- .../ets/tuple_types_11_neg-expected.txt | 2 +- .../ets/tuple_types_6_neg-expected.txt | 2 +- .../ets/tuple_types_9_neg-expected.txt | 2 +- .../compiler/ets/union_types_4-expected.txt | 2 +- .../async_func_return_type_bad-expected.txt | 2 +- ...ic_class_ctor_decl_import_bad-expected.txt | 2 +- ...class_field_decl_import_bad_1-expected.txt | 2 +- ...class_field_decl_import_bad_2-expected.txt | 2 +- ...lass_method_decl_import_bad_1-expected.txt | 2 +- ...lass_method_decl_import_bad_2-expected.txt | 2 +- .../dynamic_func_decl_import_bad-expected.txt | 2 +- ets2panda/test/parser/ets/enum8-expected.txt | 2 +- ...unction_implicit_return_type2-expected.txt | 2 +- ...unction_implicit_return_type3-expected.txt | 2 +- ...unction_implicit_return_type6-expected.txt | 2 +- ...unction_implicit_return_type7-expected.txt | 2 +- .../ets/n_arrayHoldingNullValue-expected.txt | 2 +- ...ableFromFunctionToNonNullable-expected.txt | 2 +- ...ableFromMethodToNullableParam-expected.txt | 2 +- ...n_assignNullableToNonNullable-expected.txt | 2 +- ...ignNullableToNonNullableArray-expected.txt | 2 +- ...ullableToNonNullableTypeAlias-expected.txt | 2 +- ...callFunctionWithNullableParam-expected.txt | 2 +- ...erfaceMethodWithNullableParam-expected.txt | 2 +- ...n_callMethodWithNullableParam-expected.txt | 2 +- .../ets/n_returnNullFromFunction-expected.txt | 2 +- .../ets/n_returnNullFromMethod-expected.txt | 2 +- .../n_returnNullableFromFunction-expected.txt | 2 +- .../n_returnNullableFromMethod-expected.txt | 2 +- .../test/parser/ets/null_invalid-expected.txt | 2 +- .../test/parser/ets/switch_enum2-expected.txt | 2 +- ...eadonly_member_different_enum-expected.txt | 2 +- ...donly_member_different_enum_2-expected.txt | 2 +- .../test/unit/public/es2panda_public_test.cpp | 2 +- 78 files changed, 4421 insertions(+), 118 deletions(-) create mode 100644 ets2panda/test/compiler/ets/etsObjectToString0-expected.txt create mode 100644 ets2panda/test/compiler/ets/etsObjectToString0.ets create mode 100644 ets2panda/test/compiler/ets/etsObjectToString1-expected.txt create mode 100644 ets2panda/test/compiler/ets/etsObjectToString1.ets create mode 100644 ets2panda/test/compiler/ets/etsObjectToString2-expected.txt create mode 100644 ets2panda/test/compiler/ets/etsObjectToString2.ets create mode 100644 ets2panda/test/compiler/ets/etsObjectToString3-expected.txt create mode 100644 ets2panda/test/compiler/ets/etsObjectToString3.ets create mode 100644 ets2panda/test/compiler/ets/etsObjectToString4-expected.txt create mode 100644 ets2panda/test/compiler/ets/etsObjectToString4.ets create mode 100644 ets2panda/test/compiler/ets/etsObjectToString5-expected.txt create mode 100644 ets2panda/test/compiler/ets/etsObjectToString5.ets diff --git a/ets2panda/checker/ETSAnalyzer.cpp b/ets2panda/checker/ETSAnalyzer.cpp index ad052f8e19..810934b8e5 100644 --- a/ets2panda/checker/ETSAnalyzer.cpp +++ b/ets2panda/checker/ETSAnalyzer.cpp @@ -821,18 +821,30 @@ checker::Type *ETSAnalyzer::Check(ir::AssignmentExpression *expr) const checker->ThrowTypeError("Setting the length of an array is not permitted", expr->Left()->Start()); } - if (expr->Left()->IsIdentifier()) { - expr->target_ = expr->Left()->AsIdentifier()->Variable(); - } else { - expr->target_ = expr->Left()->AsMemberExpression()->PropVar(); - } + expr->target_ = expr->Left()->IsIdentifier() ? expr->Left()->AsIdentifier()->Variable() + : expr->Left()->AsMemberExpression()->PropVar(); if (expr->target_ != nullptr) { checker->ValidateUnaryOperatorOperand(expr->target_); } + auto [sourceType, relationNode] = CheckAssignmentExprOperatorType(expr); + const checker::Type *targetType = checker->TryGettingFunctionTypeFromInvokeFunction(leftType); + const checker::Type *rightType = checker->TryGettingFunctionTypeFromInvokeFunction(sourceType); + + checker::AssignmentContext(checker->Relation(), relationNode, sourceType, leftType, expr->Right()->Start(), + {"Type '", rightType, "' cannot be assigned to type '", targetType, "'"}); + + expr->SetTsType(expr->Left()->TsType()); + return expr->TsType(); +} + +std::tuple ETSAnalyzer::CheckAssignmentExprOperatorType(ir::AssignmentExpression *expr) const +{ + ETSChecker *checker = GetETSChecker(); checker::Type *sourceType {}; ir::Expression *relationNode = expr->Right(); + auto *leftType = expr->Left()->Check(checker); switch (expr->OperatorType()) { case lexer::TokenType::PUNCTUATOR_MULTIPLY_EQUAL: case lexer::TokenType::PUNCTUATOR_EXPONENTIATION_EQUAL: @@ -873,11 +885,7 @@ checker::Type *ETSAnalyzer::Check(ir::AssignmentExpression *expr) const } } - checker::AssignmentContext(checker->Relation(), relationNode, sourceType, leftType, expr->Right()->Start(), - {"Initializers type is not assignable to the target type"}); - - expr->SetTsType(expr->Left()->TsType()); - return expr->TsType(); + return {sourceType, relationNode}; } checker::Type *ETSAnalyzer::Check(ir::AwaitExpression *expr) const @@ -1347,7 +1355,9 @@ checker::Type *ETSAnalyzer::Check(ir::ObjectExpression *expr) const checker->ThrowTypeError({"need to specify target type for class composite"}, expr->Start()); } if (!expr->PreferredType()->IsETSObjectType()) { - checker->ThrowTypeError({"target type for class composite needs to be an object type"}, expr->Start()); + checker->ThrowTypeError( + {"Target type for class composite needs to be an object type, found '", expr->PreferredType(), "'"}, + expr->Start()); } if (expr->PreferredType()->IsETSDynamicType()) { @@ -1381,6 +1391,17 @@ checker::Type *ETSAnalyzer::Check(ir::ObjectExpression *expr) const checker->ThrowTypeError({"type ", objType->Name(), " has no parameterless constructor"}, expr->Start()); } + CheckObjectExprProps(expr); + + expr->SetTsType(objType); + return objType; +} + +void ETSAnalyzer::CheckObjectExprProps(const ir::ObjectExpression *expr) const +{ + ETSChecker *checker = GetETSChecker(); + checker::ETSObjectType *objType = expr->PreferredType()->AsETSObjectType(); + for (ir::Expression *propExpr : expr->Properties()) { ASSERT(propExpr->IsProperty()); ir::Property *prop = propExpr->AsProperty(); @@ -1413,12 +1434,13 @@ checker::Type *ETSAnalyzer::Check(ir::ObjectExpression *expr) const value->AsObjectExpression()->SetPreferredType(propType); } value->SetTsType(value->Check(checker)); - checker::AssignmentContext(checker->Relation(), value, value->TsType(), propType, value->Start(), - {"value type is not assignable to the property type"}); - } - expr->SetTsType(objType); - return objType; + const checker::Type *targetType = checker->TryGettingFunctionTypeFromInvokeFunction(propType); + + checker::AssignmentContext( + checker->Relation(), value, value->TsType(), propType, value->Start(), + {"Type '", value->TsType(), "' is not compatible with type '", targetType, "' at property '", pname, "'"}); + } } checker::Type *ETSAnalyzer::Check([[maybe_unused]] ir::OmittedExpression *expr) const @@ -2146,9 +2168,13 @@ void CheckReturnType(ETSChecker *checker, checker::Type *funcReturnType, checker stArgument->Start()); } } else { - checker::AssignmentContext(checker->Relation(), stArgument, argumentType, funcReturnType, stArgument->Start(), - {"Return statement type is not compatible with the enclosing method's return type."}, - checker::TypeRelationFlag::DIRECT_RETURN); + const Type *targetType = checker->TryGettingFunctionTypeFromInvokeFunction(funcReturnType); + const Type *sourceType = checker->TryGettingFunctionTypeFromInvokeFunction(argumentType); + + checker::AssignmentContext( + checker->Relation(), stArgument, argumentType, funcReturnType, stArgument->Start(), + {"Type '", sourceType, "' is not compatible with the enclosing method's return type '", targetType, "'"}, + checker::TypeRelationFlag::DIRECT_RETURN); } } @@ -2176,10 +2202,13 @@ void InferReturnType(ETSChecker *checker, ir::ScriptFunction *containingFunc, ch auto arrowFunc = stArgument->AsArrowFunctionExpression(); auto typeAnnotation = arrowFunc->CreateTypeAnnotation(checker); funcReturnType = typeAnnotation->GetType(checker); - checker::AssignmentContext(checker->Relation(), arrowFunc, arrowFunc->TsType(), funcReturnType, - stArgument->Start(), - {"Return statement type is not compatible with the enclosing method's return type."}, - checker::TypeRelationFlag::DIRECT_RETURN); + const Type *sourceType = checker->TryGettingFunctionTypeFromInvokeFunction(arrowFunc->TsType()); + const Type *targetType = checker->TryGettingFunctionTypeFromInvokeFunction(funcReturnType); + + checker::AssignmentContext( + checker->Relation(), arrowFunc, arrowFunc->TsType(), funcReturnType, stArgument->Start(), + {"Type '", sourceType, "' is not compatible with the enclosing method's return type '", targetType, "'"}, + checker::TypeRelationFlag::DIRECT_RETURN); } containingFunc->Signature()->SetReturnType(funcReturnType); @@ -2362,16 +2391,17 @@ checker::Type *ETSAnalyzer::Check(ir::SwitchStatement *st) const } else { checker::AssignmentContext( checker->Relation(), st->discriminant_, caseType, unboxedDiscType, it->Test()->Start(), - {"Switch case type ", caseType, " is not comparable to discriminant type ", comparedExprType}, + {"Switch case type '", caseType, "' is not comparable to discriminant type '", comparedExprType, + "'"}, (comparedExprType->IsETSObjectType() ? checker::TypeRelationFlag::NO_WIDENING : checker::TypeRelationFlag::NO_UNBOXING) | checker::TypeRelationFlag::NO_BOXING); } if (!validCaseType) { - checker->ThrowTypeError( - {"Switch case type ", caseType, " is not comparable to discriminant type ", comparedExprType}, - it->Test()->Start()); + checker->ThrowTypeError({"Switch case type '", caseType, "' is not comparable to discriminant type '", + comparedExprType, "'"}, + it->Test()->Start()); } } diff --git a/ets2panda/checker/ETSAnalyzer.h b/ets2panda/checker/ETSAnalyzer.h index c284a6db26..0e4e717fac 100644 --- a/ets2panda/checker/ETSAnalyzer.h +++ b/ets2panda/checker/ETSAnalyzer.h @@ -36,6 +36,8 @@ public: #undef DECLARE_ETSANALYZER_CHECK_METHOD checker::Type *PreferredType(ir::ObjectExpression *expr) const; checker::Type *GetPreferredType(ir::ArrayExpression *expr) const; + void CheckObjectExprProps(const ir::ObjectExpression *expr) const; + std::tuple CheckAssignmentExprOperatorType(ir::AssignmentExpression *expr) const; private: ETSChecker *GetETSChecker() const; diff --git a/ets2panda/checker/ETSchecker.h b/ets2panda/checker/ETSchecker.h index e565e924bd..e909286f93 100644 --- a/ets2panda/checker/ETSchecker.h +++ b/ets2panda/checker/ETSchecker.h @@ -547,6 +547,7 @@ public: void ValidateTupleMinElementSize(ir::ArrayExpression *arrayExpr, ETSTupleType *tuple); void ModifyPreferredType(ir::ArrayExpression *arrayExpr, Type *newPreferredType); Type *SelectGlobalIntegerTypeForNumeric(Type *type); + const Type *TryGettingFunctionTypeFromInvokeFunction(const Type *type) const; void GenerateGetterSetterBody(ETSChecker *checker, ArenaVector &stmts, ArenaVector ¶ms, ir::ClassProperty *field, diff --git a/ets2panda/checker/ets/function.cpp b/ets2panda/checker/ets/function.cpp index 7dfecd77be..e6476c47e5 100644 --- a/ets2panda/checker/ets/function.cpp +++ b/ets2panda/checker/ets/function.cpp @@ -162,11 +162,6 @@ bool ETSChecker::EnhanceSubstitutionForObject(const ArenaVector &typePar return true; } -// NOLINTBEGIN(modernize-avoid-c-arrays) -static constexpr char const INVALID_CALL_ARGUMENT_1[] = "Call argument at index "; -static constexpr char const INVALID_CALL_ARGUMENT_2[] = " is not compatible with the signature's type at that index."; -static constexpr char const INVALID_CALL_ARGUMENT_3[] = " is not compatible with the signature's rest parameter type."; -// NOLINTEND(modernize-avoid-c-arrays) Signature *ETSChecker::ValidateParameterlessConstructor(Signature *signature, const lexer::SourcePosition &pos, TypeRelationFlag flags) { @@ -226,10 +221,11 @@ bool ETSChecker::ValidateSignatureRequiredParams(Signature *substitutedSig, } auto *const argumentType = argument->Check(this); + const Type *targetType = TryGettingFunctionTypeFromInvokeFunction(substitutedSig->Params()[index]->TsType()); auto const invocationCtx = checker::InvocationContext( Relation(), argument, argumentType, substitutedSig->Params()[index]->TsType(), argument->Start(), - {INVALID_CALL_ARGUMENT_1, index, INVALID_CALL_ARGUMENT_2}, flags); + {"Type '", argumentType, "' is not compatible with type '", targetType, "' at index ", index + 1}, flags); if (!invocationCtx.IsInvocable()) { return false; } @@ -250,10 +246,16 @@ bool ETSChecker::ValidateSignatureRestParams(Signature *substitutedSig, const Ar auto &argument = arguments[index]; if (!argument->IsSpreadElement()) { + auto *const argumentType = argument->Check(this); + const Type *targetType = TryGettingFunctionTypeFromInvokeFunction( + substitutedSig->RestVar()->TsType()->AsETSArrayType()->ElementType()); + const Type *sourceType = TryGettingFunctionTypeFromInvokeFunction(argumentType); auto const invocationCtx = checker::InvocationContext( - Relation(), argument, argument->Check(this), + Relation(), argument, argumentType, substitutedSig->RestVar()->TsType()->AsETSArrayType()->ElementType(), argument->Start(), - {INVALID_CALL_ARGUMENT_1, index, INVALID_CALL_ARGUMENT_3}, flags); + {"Type '", sourceType, "' is not compatible with rest parameter type '", targetType, "' at index ", + index + 1}, + flags); if (!invocationCtx.IsInvocable()) { return false; } @@ -268,10 +270,15 @@ bool ETSChecker::ValidateSignatureRestParams(Signature *substitutedSig, const Ar } auto *const restArgument = argument->AsSpreadElement()->Argument(); + auto *const argumentType = restArgument->Check(this); + const Type *targetType = TryGettingFunctionTypeFromInvokeFunction(substitutedSig->RestVar()->TsType()); + const Type *sourceType = TryGettingFunctionTypeFromInvokeFunction(argumentType); auto const invocationCtx = checker::InvocationContext( - Relation(), restArgument, restArgument->Check(this), substitutedSig->RestVar()->TsType(), argument->Start(), - {INVALID_CALL_ARGUMENT_1, index, INVALID_CALL_ARGUMENT_3}, flags); + Relation(), restArgument, argumentType, substitutedSig->RestVar()->TsType(), argument->Start(), + {"Type '", sourceType, "' is not compatible with rest parameter type '", targetType, "' at index ", + index + 1}, + flags); if (!invocationCtx.IsInvocable()) { return false; } diff --git a/ets2panda/checker/ets/helpers.cpp b/ets2panda/checker/ets/helpers.cpp index 5c1b3fd187..41e52fafab 100644 --- a/ets2panda/checker/ets/helpers.cpp +++ b/ets2panda/checker/ets/helpers.cpp @@ -1011,9 +1011,11 @@ void ETSChecker::ResolveReturnStatement(checker::Type *funcReturnType, checker:: containingFunc->Signature()->SetReturnType(funcReturnType); containingFunc->Signature()->AddSignatureFlag(checker::SignatureFlags::INFERRED_RETURN_TYPE); } else if (!Relation()->IsAssignableTo(argumentType, funcReturnType)) { - ThrowTypeError( - "Return statement type is not compatible with previous method's return statement " - "type(s).", + const Type *targetType = TryGettingFunctionTypeFromInvokeFunction(funcReturnType); + const Type *sourceType = TryGettingFunctionTypeFromInvokeFunction(argumentType); + + Relation()->RaiseError( + {"Function cannot have different primitive return types, found '", targetType, "', '", sourceType, "'"}, st->Argument()->Start()); } } else { @@ -1130,8 +1132,11 @@ checker::Type *ETSChecker::CheckVariableDeclaration(ir::Identifier *ident, ir::T } if (annotationType != nullptr) { + const Type *targetType = TryGettingFunctionTypeFromInvokeFunction(annotationType); + const Type *sourceType = TryGettingFunctionTypeFromInvokeFunction(initType); + AssignmentContext(Relation(), init, initType, annotationType, init->Start(), - {"Initializers type is not assignable to the target type"}); + {"Type '", sourceType, "' cannot be assigned to type '", targetType, "'"}); if (isConst && initType->HasTypeFlag(TypeFlag::ETS_PRIMITIVE) && annotationType->HasTypeFlag(TypeFlag::ETS_PRIMITIVE)) { bindingVar->SetTsType(init->TsType()); @@ -1158,11 +1163,8 @@ checker::Type *ETSChecker::CheckVariableDeclaration(ir::Identifier *ident, ir::T init->Start()); } - if (initType->IsNullish() || isConst) { - bindingVar->SetTsType(initType); - } else { - bindingVar->SetTsType(GetNonConstantTypeFromPrimitiveType(initType)); - } + (initType->IsNullish() || isConst) ? bindingVar->SetTsType(initType) + : bindingVar->SetTsType(GetNonConstantTypeFromPrimitiveType(initType)); return bindingVar->TsType(); } @@ -2541,10 +2543,13 @@ bool ETSChecker::TypeInference(Signature *signature, const ArenaVectorIsETSFunctionType()); InferTypesForLambda(lambda, typeAnn->AsETSFunctionType()); Type *const argType = arrowFuncExpr->Check(this); + const Type *targetType = TryGettingFunctionTypeFromInvokeFunction(signature->Params()[index]->TsType()); + const std::initializer_list msg = { + "Type '", argType, "' is not compatible with type '", targetType, "' at index ", index + 1}; - checker::InvocationContext invokationCtx( - Relation(), arguments[index], argType, signature->Params()[index]->TsType(), arrowFuncExpr->Start(), - {"Call argument at index ", index, " is not compatible with the signature's type at that index"}, flags); + checker::InvocationContext invokationCtx(Relation(), arguments[index], argType, + signature->Params()[index]->TsType(), arrowFuncExpr->Start(), msg, + flags); invocable &= invokationCtx.IsInvocable(); } @@ -2722,6 +2727,19 @@ ir::MethodDefinition *ETSChecker::GenerateDefaultGetterSetter(ir::ClassProperty return method; } +const Type *ETSChecker::TryGettingFunctionTypeFromInvokeFunction(const Type *type) const +{ + if (type->IsETSObjectType() && type->AsETSObjectType()->HasObjectFlag(ETSObjectFlags::FUNCTIONAL)) { + auto const propInvoke = type->AsETSObjectType()->GetProperty(util::StringView("invoke"), + PropertySearchFlags::SEARCH_INSTANCE_METHOD); + ASSERT(propInvoke != nullptr); + + return propInvoke->TsType(); + } + + return type; +} + bool ETSChecker::TryTransformingToStaticInvoke(ir::Identifier *const ident, const Type *resolvedType) { ASSERT(ident->Parent()->IsCallExpression()); diff --git a/ets2panda/checker/ets/typeRelationContext.cpp b/ets2panda/checker/ets/typeRelationContext.cpp index e28b250c73..b74e3dcbc3 100644 --- a/ets2panda/checker/ets/typeRelationContext.cpp +++ b/ets2panda/checker/ets/typeRelationContext.cpp @@ -32,9 +32,12 @@ void AssignmentContext::ValidateArrayTypeInitializerByElement(TypeRelation *rela for (uint32_t index = 0; index < node->Elements().size(); index++) { ir::Expression *currentArrayElem = node->Elements()[index]; + auto *const currentArrayElementType = currentArrayElem->Check(relation->GetChecker()->AsETSChecker()); + AssignmentContext(relation, currentArrayElem, currentArrayElem->Check(relation->GetChecker()->AsETSChecker()), target->ElementType(), currentArrayElem->Start(), - {"Array element at index ", index, " is not compatible with the target array element type."}); + {"Array element at index ", index, " with type '", currentArrayElementType, + "' is not compatible with the target array element type '", target->ElementType(), "'"}); } } diff --git a/ets2panda/checker/ets/typeRelationContext.h b/ets2panda/checker/ets/typeRelationContext.h index 155aa6ae64..b4a9b19a73 100644 --- a/ets2panda/checker/ets/typeRelationContext.h +++ b/ets2panda/checker/ets/typeRelationContext.h @@ -47,6 +47,8 @@ public: flags_ |= flags; relation->SetNode(node); + // NOTE (oeotvos) The narrowing flag will be applied here. It means, that the result of "let tmp: int = 1.5" + // will be 1, which could cause problems. if (source->HasTypeFlag(TypeFlag::CONSTANT)) { flags_ |= TypeRelationFlag::NARROWING; } diff --git a/ets2panda/checker/types/ets/etsArrayType.cpp b/ets2panda/checker/types/ets/etsArrayType.cpp index 91989dc86e..9b0e9403aa 100644 --- a/ets2panda/checker/types/ets/etsArrayType.cpp +++ b/ets2panda/checker/types/ets/etsArrayType.cpp @@ -25,6 +25,11 @@ void ETSArrayType::ToString(std::stringstream &ss) const { element_->ToString(ss); ss << "[]"; + + if (IsNullish()) { + ss << lexer::TokenToString(lexer::TokenType::PUNCTUATOR_BITWISE_OR) + << lexer::TokenToString(lexer::TokenType::LITERAL_NULL); + } } void ETSArrayType::ToAssemblerType(std::stringstream &ss) const diff --git a/ets2panda/checker/types/ets/etsObjectType.cpp b/ets2panda/checker/types/ets/etsObjectType.cpp index 2a7695b053..9e82f59c79 100644 --- a/ets2panda/checker/types/ets/etsObjectType.cpp +++ b/ets2panda/checker/types/ets/etsObjectType.cpp @@ -283,26 +283,40 @@ ArenaMap ETSObjectType::Coll void ETSObjectType::ToString(std::stringstream &ss) const { - ss << name_; + if (HasObjectFlag(ETSObjectFlags::FUNCTIONAL)) { + if (IsNullish() && this != GetConstOriginalBaseType() && !name_.Is("NullType") && !IsETSNullLike() && + !name_.Empty()) { + ss << lexer::TokenToString(lexer::TokenType::PUNCTUATOR_LEFT_PARENTHESIS); + } + GetFunctionalInterfaceInvokeType()->ToString(ss); + } else { + ss << name_; + } if (!typeArguments_.empty()) { - auto const typeArgumentsSize = typeArguments_.size(); ss << compiler::Signatures::GENERIC_BEGIN; - typeArguments_[0]->ToString(ss); - for (std::size_t i = 1U; i < typeArgumentsSize; ++i) { - ss << ','; - typeArguments_[i]->ToString(ss); + for (auto arg = typeArguments_.cbegin(); arg != typeArguments_.cend(); ++arg) { + (*arg)->ToString(ss); + + if (next(arg) != typeArguments_.cend()) { + ss << lexer::TokenToString(lexer::TokenType::PUNCTUATOR_COMMA); + } } ss << compiler::Signatures::GENERIC_END; } if (IsNullish() && this != GetConstOriginalBaseType() && !name_.Is("NullType") && !IsETSNullLike() && !name_.Empty()) { + if (HasObjectFlag(ETSObjectFlags::FUNCTIONAL)) { + ss << lexer::TokenToString(lexer::TokenType::PUNCTUATOR_RIGHT_PARENTHESIS); + } if (ContainsNull()) { - ss << "|null"; + ss << lexer::TokenToString(lexer::TokenType::PUNCTUATOR_BITWISE_OR) + << lexer::TokenToString(lexer::TokenType::LITERAL_NULL); } if (ContainsUndefined()) { - ss << "|undefined"; + ss << lexer::TokenToString(lexer::TokenType::PUNCTUATOR_BITWISE_OR) + << lexer::TokenToString(lexer::TokenType::KEYW_UNDEFINED); } } } diff --git a/ets2panda/checker/types/ets/etsObjectType.h b/ets2panda/checker/types/ets/etsObjectType.h index ff6cca7a94..c59e37eb67 100644 --- a/ets2panda/checker/types/ets/etsObjectType.h +++ b/ets2panda/checker/types/ets/etsObjectType.h @@ -389,7 +389,7 @@ public: return (flags_ & flag) != 0; } - ETSFunctionType *GetFunctionalInterfaceInvokeType() + ETSFunctionType *GetFunctionalInterfaceInvokeType() const { ASSERT(HasObjectFlag(ETSObjectFlags::FUNCTIONAL)); auto *invoke = GetOwnProperty("invoke"); diff --git a/ets2panda/checker/types/ets/etsTupleType.cpp b/ets2panda/checker/types/ets/etsTupleType.cpp index 92f9feb317..1f79e6f997 100644 --- a/ets2panda/checker/types/ets/etsTupleType.cpp +++ b/ets2panda/checker/types/ets/etsTupleType.cpp @@ -24,10 +24,11 @@ void ETSTupleType::ToString(std::stringstream &ss) const { ss << "["; - for (const auto *const type : typeList_) { - type->ToString(ss); - if (type != typeList_.back()) { - ss << ","; + for (auto it = typeList_.begin(); it != typeList_.end(); it++) { + (*it)->ToString(ss); + + if (std::next(it) != typeList_.end()) { + ss << ", "; } } diff --git a/ets2panda/test/compiler/ets/FunctionType1-expected.txt b/ets2panda/test/compiler/ets/FunctionType1-expected.txt index 067f017468..eb64020f40 100644 --- a/ets2panda/test/compiler/ets/FunctionType1-expected.txt +++ b/ets2panda/test/compiler/ets/FunctionType1-expected.txt @@ -1001,4 +1001,4 @@ } } } -TypeError: Initializers type is not assignable to the target type [FunctionType1.ets:24:12] +TypeError: Type '(a: int, b: int) => int' cannot be assigned to type '(a: int, b: int) => void' [FunctionType1.ets:24:12] diff --git a/ets2panda/test/compiler/ets/FunctionType3-expected.txt b/ets2panda/test/compiler/ets/FunctionType3-expected.txt index 9f4f79c857..bbb4c6e27b 100644 --- a/ets2panda/test/compiler/ets/FunctionType3-expected.txt +++ b/ets2panda/test/compiler/ets/FunctionType3-expected.txt @@ -809,4 +809,4 @@ } } } -TypeError: Call argument at index 1 is not compatible with the signature's type at that index. [FunctionType3.ets:23:16] +TypeError: Type 'string' is not compatible with type 'int' at index 2 [FunctionType3.ets:23:16] diff --git a/ets2panda/test/compiler/ets/conversion_Double-to-Int_typeerror-expected.txt b/ets2panda/test/compiler/ets/conversion_Double-to-Int_typeerror-expected.txt index b96e1faf4d..b4bf32c633 100644 --- a/ets2panda/test/compiler/ets/conversion_Double-to-Int_typeerror-expected.txt +++ b/ets2panda/test/compiler/ets/conversion_Double-to-Int_typeerror-expected.txt @@ -456,4 +456,4 @@ } } } -TypeError: Initializers type is not assignable to the target type [conversion_Double-to-Int_typeerror.ets:17:17] +TypeError: Type 'Double' cannot be assigned to type 'Int' [conversion_Double-to-Int_typeerror.ets:17:17] diff --git a/ets2panda/test/compiler/ets/conversion_Double-to-Int_w_try_stmt_typerror-expected.txt b/ets2panda/test/compiler/ets/conversion_Double-to-Int_w_try_stmt_typerror-expected.txt index 96c8b5fd3c..34209cbf2a 100644 --- a/ets2panda/test/compiler/ets/conversion_Double-to-Int_w_try_stmt_typerror-expected.txt +++ b/ets2panda/test/compiler/ets/conversion_Double-to-Int_w_try_stmt_typerror-expected.txt @@ -718,4 +718,4 @@ } } } -TypeError: Return statement type is not compatible with the enclosing method's return type. [conversion_Double-to-Int_w_try_stmt_typerror.ets:17:18] +TypeError: Type 'Double' is not compatible with the enclosing method's return type 'Int' [conversion_Double-to-Int_w_try_stmt_typerror.ets:17:18] diff --git a/ets2panda/test/compiler/ets/conversion_Int-to-Double_typeerror-expected.txt b/ets2panda/test/compiler/ets/conversion_Int-to-Double_typeerror-expected.txt index 18cfe0261d..af949c2706 100644 --- a/ets2panda/test/compiler/ets/conversion_Int-to-Double_typeerror-expected.txt +++ b/ets2panda/test/compiler/ets/conversion_Int-to-Double_typeerror-expected.txt @@ -456,4 +456,4 @@ } } } -TypeError: Initializers type is not assignable to the target type [conversion_Int-to-Double_typeerror.ets:17:20] +TypeError: Type 'Int' cannot be assigned to type 'Double' [conversion_Int-to-Double_typeerror.ets:17:20] diff --git a/ets2panda/test/compiler/ets/conversion_call-context_Int-to-Double_typeerror-expected.txt b/ets2panda/test/compiler/ets/conversion_call-context_Int-to-Double_typeerror-expected.txt index a4f0dff3f5..b811e85e80 100644 --- a/ets2panda/test/compiler/ets/conversion_call-context_Int-to-Double_typeerror-expected.txt +++ b/ets2panda/test/compiler/ets/conversion_call-context_Int-to-Double_typeerror-expected.txt @@ -679,4 +679,4 @@ } } } -TypeError: Call argument at index 0 is not compatible with the signature's type at that index. [conversion_call-context_Int-to-Double_typeerror.ets:20:7] +TypeError: Type 'Int' is not compatible with type 'Double' at index 1 [conversion_call-context_Int-to-Double_typeerror.ets:20:7] diff --git a/ets2panda/test/compiler/ets/etsObjectToString0-expected.txt b/ets2panda/test/compiler/ets/etsObjectToString0-expected.txt new file mode 100644 index 0000000000..0f8108b11a --- /dev/null +++ b/ets2panda/test/compiler/ets/etsObjectToString0-expected.txt @@ -0,0 +1,584 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 7 + }, + "end": { + "line": 16, + "column": 8 + } + } + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "params": [ + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 10 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 11 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 8 + }, + "end": { + "line": 16, + "column": 11 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "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": 16, + "column": 13 + }, + "end": { + "line": 16, + "column": 13 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 11 + }, + "end": { + "line": 16, + "column": 13 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 16, + "column": 13 + } + } + }, + { + "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": "test", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 10 + }, + "end": { + "line": 18, + "column": 14 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "test", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 10 + }, + "end": { + "line": 18, + "column": 14 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "returnType": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 18, + "column": 18 + }, + "end": { + "line": 18, + "column": 21 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "a", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 12 + }, + "end": { + "line": 19, + "column": 13 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 19, + "column": 14 + }, + "end": { + "line": 19, + "column": 17 + } + } + } + ], + "loc": { + "start": { + "line": 19, + "column": 13 + }, + "end": { + "line": 19, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 12 + }, + "end": { + "line": 19, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 12 + }, + "end": { + "line": 19, + "column": 19 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 9 + }, + "end": { + "line": 19, + "column": 10 + } + } + }, + "init": null, + "loc": { + "start": { + "line": 19, + "column": 9 + }, + "end": { + "line": 19, + "column": 10 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 19, + "column": 5 + }, + "end": { + "line": 19, + "column": 24 + } + } + }, + { + "type": "ReturnStatement", + "argument": { + "type": "Identifier", + "name": "a", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 12 + }, + "end": { + "line": 20, + "column": 13 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 5 + }, + "end": { + "line": 20, + "column": 14 + } + } + } + ], + "loc": { + "start": { + "line": 18, + "column": 21 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 14 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 14 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 1 + }, + "end": { + "line": 21, + "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": 22, + "column": 1 + } + } +} +TypeError: Type 'A|null' is not compatible with the enclosing method's return type 'int' [etsObjectToString0.ets:20:12] diff --git a/ets2panda/test/compiler/ets/etsObjectToString0.ets b/ets2panda/test/compiler/ets/etsObjectToString0.ets new file mode 100644 index 0000000000..8601ec1d89 --- /dev/null +++ b/ets2panda/test/compiler/ets/etsObjectToString0.ets @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2023 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. + */ + +class A{} + +function test(): int{ + let a: A|null; + return a; +} diff --git a/ets2panda/test/compiler/ets/etsObjectToString1-expected.txt b/ets2panda/test/compiler/ets/etsObjectToString1-expected.txt new file mode 100644 index 0000000000..da2b83b6cf --- /dev/null +++ b/ets2panda/test/compiler/ets/etsObjectToString1-expected.txt @@ -0,0 +1,640 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 7 + }, + "end": { + "line": 16, + "column": 8 + } + } + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "params": [ + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 10 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 11 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 8 + }, + "end": { + "line": 16, + "column": 11 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "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": 16, + "column": 13 + }, + "end": { + "line": 16, + "column": 13 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 11 + }, + "end": { + "line": 16, + "column": 13 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 16, + "column": 13 + } + } + }, + { + "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": "test0", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 10 + }, + "end": { + "line": 18, + "column": 15 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "test0", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 10 + }, + "end": { + "line": 18, + "column": 15 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 19 + }, + "end": { + "line": 18, + "column": 20 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 18, + "column": 21 + }, + "end": { + "line": 18, + "column": 24 + } + } + } + ], + "loc": { + "start": { + "line": 18, + "column": 20 + }, + "end": { + "line": 18, + "column": 25 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 19 + }, + "end": { + "line": 18, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 19 + }, + "end": { + "line": 18, + "column": 27 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "a", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 12 + }, + "end": { + "line": 19, + "column": 13 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 19, + "column": 14 + }, + "end": { + "line": 19, + "column": 17 + } + } + } + ], + "loc": { + "start": { + "line": 19, + "column": 13 + }, + "end": { + "line": 19, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 12 + }, + "end": { + "line": 19, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 12 + }, + "end": { + "line": 19, + "column": 19 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 9 + }, + "end": { + "line": 19, + "column": 10 + } + } + }, + "init": null, + "loc": { + "start": { + "line": 19, + "column": 9 + }, + "end": { + "line": 19, + "column": 10 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 19, + "column": 5 + }, + "end": { + "line": 19, + "column": 24 + } + } + }, + { + "type": "ReturnStatement", + "argument": { + "type": "Identifier", + "name": "a", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 12 + }, + "end": { + "line": 20, + "column": 13 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 5 + }, + "end": { + "line": 20, + "column": 14 + } + } + } + ], + "loc": { + "start": { + "line": 18, + "column": 26 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 15 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 15 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 1 + }, + "end": { + "line": 21, + "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": 22, + "column": 1 + } + } +} +TypeError: Type 'A|null' is not compatible with the enclosing method's return type 'A' [etsObjectToString1.ets:20:12] diff --git a/ets2panda/test/compiler/ets/etsObjectToString1.ets b/ets2panda/test/compiler/ets/etsObjectToString1.ets new file mode 100644 index 0000000000..f6d7434f8c --- /dev/null +++ b/ets2panda/test/compiler/ets/etsObjectToString1.ets @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2023 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. + */ + +class A{} + +function test0(): A { + let a: A|null; + return a; +} diff --git a/ets2panda/test/compiler/ets/etsObjectToString2-expected.txt b/ets2panda/test/compiler/ets/etsObjectToString2-expected.txt new file mode 100644 index 0000000000..34fb46d94a --- /dev/null +++ b/ets2panda/test/compiler/ets/etsObjectToString2-expected.txt @@ -0,0 +1,668 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 7 + }, + "end": { + "line": 16, + "column": 8 + } + } + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "params": [ + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 10 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 11 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 8 + }, + "end": { + "line": 16, + "column": 11 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "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": 16, + "column": 13 + }, + "end": { + "line": 16, + "column": 13 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 11 + }, + "end": { + "line": 16, + "column": 13 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 16, + "column": 13 + } + } + }, + { + "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": "test1", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 10 + }, + "end": { + "line": 18, + "column": 15 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "test1", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 10 + }, + "end": { + "line": 18, + "column": 15 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 19 + }, + "end": { + "line": 18, + "column": 20 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "String", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 21 + }, + "end": { + "line": 18, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 21 + }, + "end": { + "line": 18, + "column": 28 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 21 + }, + "end": { + "line": 18, + "column": 28 + } + } + } + ], + "loc": { + "start": { + "line": 18, + "column": 20 + }, + "end": { + "line": 18, + "column": 28 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 19 + }, + "end": { + "line": 18, + "column": 29 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 19 + }, + "end": { + "line": 18, + "column": 29 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "a", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 12 + }, + "end": { + "line": 19, + "column": 13 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 19, + "column": 14 + }, + "end": { + "line": 19, + "column": 17 + } + } + } + ], + "loc": { + "start": { + "line": 19, + "column": 13 + }, + "end": { + "line": 19, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 12 + }, + "end": { + "line": 19, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 12 + }, + "end": { + "line": 19, + "column": 19 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 9 + }, + "end": { + "line": 19, + "column": 10 + } + } + }, + "init": null, + "loc": { + "start": { + "line": 19, + "column": 9 + }, + "end": { + "line": 19, + "column": 10 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 19, + "column": 5 + }, + "end": { + "line": 19, + "column": 24 + } + } + }, + { + "type": "ReturnStatement", + "argument": { + "type": "Identifier", + "name": "a", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 12 + }, + "end": { + "line": 20, + "column": 13 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 5 + }, + "end": { + "line": 20, + "column": 14 + } + } + } + ], + "loc": { + "start": { + "line": 18, + "column": 34 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 15 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 15 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 1 + }, + "end": { + "line": 21, + "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": 22, + "column": 1 + } + } +} +TypeError: Type 'A|null' is not compatible with the enclosing method's return type 'A|null' [etsObjectToString2.ets:20:12] diff --git a/ets2panda/test/compiler/ets/etsObjectToString2.ets b/ets2panda/test/compiler/ets/etsObjectToString2.ets new file mode 100644 index 0000000000..07125b85a1 --- /dev/null +++ b/ets2panda/test/compiler/ets/etsObjectToString2.ets @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2023 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. + */ + +class A{} + +function test1(): A|null { + let a: A|null; + return a; +} diff --git a/ets2panda/test/compiler/ets/etsObjectToString3-expected.txt b/ets2panda/test/compiler/ets/etsObjectToString3-expected.txt new file mode 100644 index 0000000000..b3fdc5aa26 --- /dev/null +++ b/ets2panda/test/compiler/ets/etsObjectToString3-expected.txt @@ -0,0 +1,890 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 7 + }, + "end": { + "line": 16, + "column": 8 + } + } + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "params": [ + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 10 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 11 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 8 + }, + "end": { + "line": 16, + "column": 11 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "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": 16, + "column": 13 + }, + "end": { + "line": 16, + "column": 13 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 11 + }, + "end": { + "line": 16, + "column": 13 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 16, + "column": 13 + } + } + }, + { + "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": "ClassProperty", + "key": { + "type": "Identifier", + "name": "z", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 6 + } + } + }, + "value": { + "type": "ArrowFunctionExpression", + "function": { + "type": "ScriptFunction", + "id": null, + "generator": false, + "async": false, + "expression": false, + "params": [], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 21 + }, + "end": { + "line": 18, + "column": 22 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 23 + }, + "end": { + "line": 18, + "column": 26 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 23 + }, + "end": { + "line": 18, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 23 + }, + "end": { + "line": 18, + "column": 27 + } + } + } + ], + "loc": { + "start": { + "line": 18, + "column": 22 + }, + "end": { + "line": 18, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 21 + }, + "end": { + "line": 18, + "column": 30 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 21 + }, + "end": { + "line": 18, + "column": 30 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "b", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 13 + }, + "end": { + "line": 19, + "column": 14 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 15 + }, + "end": { + "line": 19, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 15 + }, + "end": { + "line": 19, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 15 + }, + "end": { + "line": 19, + "column": 19 + } + } + } + ], + "loc": { + "start": { + "line": 19, + "column": 14 + }, + "end": { + "line": 19, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 13 + }, + "end": { + "line": 19, + "column": 21 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 13 + }, + "end": { + "line": 19, + "column": 21 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 9 + }, + "end": { + "line": 19, + "column": 10 + } + } + }, + "init": { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 26 + }, + "end": { + "line": 19, + "column": 27 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 28 + }, + "end": { + "line": 19, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 28 + }, + "end": { + "line": 19, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 28 + }, + "end": { + "line": 19, + "column": 32 + } + } + } + ], + "loc": { + "start": { + "line": 19, + "column": 27 + }, + "end": { + "line": 19, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 26 + }, + "end": { + "line": 19, + "column": 33 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 26 + }, + "end": { + "line": 19, + "column": 33 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 19, + "column": 22 + }, + "end": { + "line": 19, + "column": 35 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 9 + }, + "end": { + "line": 19, + "column": 35 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 19, + "column": 5 + }, + "end": { + "line": 19, + "column": 35 + } + } + }, + { + "type": "ReturnStatement", + "argument": { + "type": "Identifier", + "name": "b", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 12 + }, + "end": { + "line": 20, + "column": 13 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 5 + }, + "end": { + "line": 20, + "column": 14 + } + } + } + ], + "loc": { + "start": { + "line": 18, + "column": 31 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 17 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 17 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "accessibility": "public", + "static": true, + "readonly": false, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 8 + }, + "end": { + "line": 18, + "column": 9 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 10 + }, + "end": { + "line": 18, + "column": 13 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 10 + }, + "end": { + "line": 18, + "column": 14 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 10 + }, + "end": { + "line": 18, + "column": 14 + } + } + } + ], + "loc": { + "start": { + "line": 18, + "column": 9 + }, + "end": { + "line": 18, + "column": 14 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 8 + }, + "end": { + "line": 18, + "column": 16 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 8 + }, + "end": { + "line": 18, + "column": 16 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 21, + "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": 22, + "column": 1 + } + } +} +TypeError: Type '() => A' cannot be assigned to type 'A' [etsObjectToString3.ets:18:17] diff --git a/ets2panda/test/compiler/ets/etsObjectToString3.ets b/ets2panda/test/compiler/ets/etsObjectToString3.ets new file mode 100644 index 0000000000..afd5cff9f1 --- /dev/null +++ b/ets2panda/test/compiler/ets/etsObjectToString3.ets @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2023 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. + */ + +class A{} + +let z: A = (): A => { + let b : A = new A(); + return b; +} diff --git a/ets2panda/test/compiler/ets/etsObjectToString4-expected.txt b/ets2panda/test/compiler/ets/etsObjectToString4-expected.txt new file mode 100644 index 0000000000..a92c603283 --- /dev/null +++ b/ets2panda/test/compiler/ets/etsObjectToString4-expected.txt @@ -0,0 +1,468 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 7 + }, + "end": { + "line": 16, + "column": 8 + } + } + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "params": [ + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 10 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 11 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 8 + }, + "end": { + "line": 16, + "column": 11 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "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": 16, + "column": 13 + }, + "end": { + "line": 16, + "column": 13 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 11 + }, + "end": { + "line": 16, + "column": 13 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 16, + "column": 13 + } + } + }, + { + "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": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "f", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 6 + } + } + }, + "right": { + "type": "NumberLiteral", + "value": 5, + "loc": { + "start": { + "line": 18, + "column": 29 + }, + "end": { + "line": 18, + "column": 30 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 30 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 1 + }, + "end": { + "line": 18, + "column": 31 + } + } + } + ], + "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": "ClassProperty", + "key": { + "type": "Identifier", + "name": "f", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 6 + } + } + }, + "value": { + "type": "NumberLiteral", + "value": 5, + "loc": { + "start": { + "line": 18, + "column": 29 + }, + "end": { + "line": 18, + "column": 30 + } + } + }, + "accessibility": "public", + "static": true, + "readonly": false, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "ETSFunctionType", + "params": [], + "returnType": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 18, + "column": 15 + }, + "end": { + "line": 18, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 8 + }, + "end": { + "line": 18, + "column": 18 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 30 + } + } + } + ], + "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": 19, + "column": 1 + } + } +} +TypeError: Type 'int' cannot be assigned to type '() => int' [etsObjectToString4.ets:18:29] diff --git a/ets2panda/test/compiler/ets/etsObjectToString4.ets b/ets2panda/test/compiler/ets/etsObjectToString4.ets new file mode 100644 index 0000000000..f957ea6d94 --- /dev/null +++ b/ets2panda/test/compiler/ets/etsObjectToString4.ets @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2023 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. + */ + +class A{} + +let f: (() => int) | null = 5; diff --git a/ets2panda/test/compiler/ets/etsObjectToString5-expected.txt b/ets2panda/test/compiler/ets/etsObjectToString5-expected.txt new file mode 100644 index 0000000000..c96da27d61 --- /dev/null +++ b/ets2panda/test/compiler/ets/etsObjectToString5-expected.txt @@ -0,0 +1,848 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 7 + }, + "end": { + "line": 16, + "column": 8 + } + } + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "params": [ + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 10 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 11 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 8 + }, + "end": { + "line": 16, + "column": 11 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "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": 16, + "column": 13 + }, + "end": { + "line": 16, + "column": 13 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 11 + }, + "end": { + "line": 16, + "column": 13 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 16, + "column": 13 + } + } + }, + { + "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": "ClassProperty", + "key": { + "type": "Identifier", + "name": "g", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 6 + } + } + }, + "value": { + "type": "ArrowFunctionExpression", + "function": { + "type": "ScriptFunction", + "id": null, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "y", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 45 + }, + "end": { + "line": 18, + "column": 46 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "String", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 47 + }, + "end": { + "line": 18, + "column": 53 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 47 + }, + "end": { + "line": 18, + "column": 54 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 47 + }, + "end": { + "line": 18, + "column": 54 + } + } + } + ], + "loc": { + "start": { + "line": 18, + "column": 46 + }, + "end": { + "line": 18, + "column": 54 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 45 + }, + "end": { + "line": 18, + "column": 55 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 45 + }, + "end": { + "line": 18, + "column": 55 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 43 + }, + "end": { + "line": 18, + "column": 55 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 43 + }, + "end": { + "line": 18, + "column": 55 + } + } + } + ], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 57 + }, + "end": { + "line": 18, + "column": 58 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "String", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 59 + }, + "end": { + "line": 18, + "column": 65 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 59 + }, + "end": { + "line": 18, + "column": 66 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 59 + }, + "end": { + "line": 18, + "column": 66 + } + } + } + ], + "loc": { + "start": { + "line": 18, + "column": 58 + }, + "end": { + "line": 18, + "column": 66 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 57 + }, + "end": { + "line": 18, + "column": 67 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 57 + }, + "end": { + "line": 18, + "column": 67 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "Identifier", + "name": "y", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 12 + }, + "end": { + "line": 19, + "column": 13 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 5 + }, + "end": { + "line": 19, + "column": 14 + } + } + } + ], + "loc": { + "start": { + "line": 18, + "column": 75 + }, + "end": { + "line": 20, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 42 + }, + "end": { + "line": 20, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 42 + }, + "end": { + "line": 20, + "column": 2 + } + } + }, + "accessibility": "public", + "static": true, + "readonly": false, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "ETSFunctionType", + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "y", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 11 + }, + "end": { + "line": 18, + "column": 12 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 18, + "column": 13 + }, + "end": { + "line": 18, + "column": 16 + } + } + } + ], + "loc": { + "start": { + "line": 18, + "column": 12 + }, + "end": { + "line": 18, + "column": 17 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 11 + }, + "end": { + "line": 18, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 11 + }, + "end": { + "line": 18, + "column": 18 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 9 + }, + "end": { + "line": 18, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 9 + }, + "end": { + "line": 18, + "column": 18 + } + } + } + ], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 22 + }, + "end": { + "line": 18, + "column": 23 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 18, + "column": 24 + }, + "end": { + "line": 18, + "column": 27 + } + } + } + ], + "loc": { + "start": { + "line": 18, + "column": 23 + }, + "end": { + "line": 18, + "column": 28 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 22 + }, + "end": { + "line": 18, + "column": 29 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 22 + }, + "end": { + "line": 18, + "column": 29 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 7 + }, + "end": { + "line": 18, + "column": 29 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 20, + "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": 21, + "column": 1 + } + } +} +TypeError: Type '(y: A) => A|null' cannot be assigned to type '(y: A) => A|null' [etsObjectToString5.ets:18:42] diff --git a/ets2panda/test/compiler/ets/etsObjectToString5.ets b/ets2panda/test/compiler/ets/etsObjectToString5.ets new file mode 100644 index 0000000000..c4535d9f0f --- /dev/null +++ b/ets2panda/test/compiler/ets/etsObjectToString5.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2023 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. + */ + +class A{} + +let g:((y:A) => A|null)|null = (y:A): A|null => { + return y; +} diff --git a/ets2panda/test/compiler/ets/generic_function_call_2-expected.txt b/ets2panda/test/compiler/ets/generic_function_call_2-expected.txt index d7f2b19147..40b5c23fb5 100644 --- a/ets2panda/test/compiler/ets/generic_function_call_2-expected.txt +++ b/ets2panda/test/compiler/ets/generic_function_call_2-expected.txt @@ -982,4 +982,4 @@ } } } -TypeError: Call argument at index 0 is not compatible with the signature's type at that index. [generic_function_call_2.ets:24:9] +TypeError: Type 'B' is not compatible with type 'A' at index 1 [generic_function_call_2.ets:24:9] diff --git a/ets2panda/test/compiler/ets/generics_primitive_type_param_neg_1-expected.txt b/ets2panda/test/compiler/ets/generics_primitive_type_param_neg_1-expected.txt index 981fbdf9d5..6fac876a48 100644 --- a/ets2panda/test/compiler/ets/generics_primitive_type_param_neg_1-expected.txt +++ b/ets2panda/test/compiler/ets/generics_primitive_type_param_neg_1-expected.txt @@ -902,4 +902,4 @@ } } } -TypeError: Switch case type Int is not comparable to discriminant type int [generics_primitive_type_param_neg_1.ets:25:14] +TypeError: Switch case type 'Int' is not comparable to discriminant type 'int' [generics_primitive_type_param_neg_1.ets:25:14] diff --git a/ets2panda/test/compiler/ets/identifierReference10-expected.txt b/ets2panda/test/compiler/ets/identifierReference10-expected.txt index c956b38949..ac3b7839e9 100644 --- a/ets2panda/test/compiler/ets/identifierReference10-expected.txt +++ b/ets2panda/test/compiler/ets/identifierReference10-expected.txt @@ -870,4 +870,4 @@ } } } -TypeError: Initializers type is not assignable to the target type [identifierReference10.ets:24:16] +TypeError: Type 'string' cannot be assigned to type 'int' [identifierReference10.ets:24:16] diff --git a/ets2panda/test/compiler/ets/identifierReference2-expected.txt b/ets2panda/test/compiler/ets/identifierReference2-expected.txt index 4f28a2426c..c0fb2875ea 100644 --- a/ets2panda/test/compiler/ets/identifierReference2-expected.txt +++ b/ets2panda/test/compiler/ets/identifierReference2-expected.txt @@ -398,4 +398,4 @@ } } } -TypeError: Initializers type is not assignable to the target type [identifierReference2.ets:16:34] +TypeError: Type '(v: double, u: double) => double' cannot be assigned to type '(a: int, b: int) => void' [identifierReference2.ets:16:34] diff --git a/ets2panda/test/compiler/ets/identifierReference3-expected.txt b/ets2panda/test/compiler/ets/identifierReference3-expected.txt index 6e49f3f604..f5c375d18a 100644 --- a/ets2panda/test/compiler/ets/identifierReference3-expected.txt +++ b/ets2panda/test/compiler/ets/identifierReference3-expected.txt @@ -586,4 +586,4 @@ } } } -TypeError: Initializers type is not assignable to the target type [identifierReference3.ets:20:9] +TypeError: Type 'string' cannot be assigned to type 'int' [identifierReference3.ets:20:9] diff --git a/ets2panda/test/compiler/ets/inferTypeOfArrayNegative3-expected.txt b/ets2panda/test/compiler/ets/inferTypeOfArrayNegative3-expected.txt index 6b9887c244..50c685879a 100644 --- a/ets2panda/test/compiler/ets/inferTypeOfArrayNegative3-expected.txt +++ b/ets2panda/test/compiler/ets/inferTypeOfArrayNegative3-expected.txt @@ -429,4 +429,4 @@ } } } -TypeError: Initializers type is not assignable to the target type [inferTypeOfArrayNegative3.ets:17:8] +TypeError: Type 'string' cannot be assigned to type 'double' [inferTypeOfArrayNegative3.ets:17:8] diff --git a/ets2panda/test/compiler/ets/lambdaExpressionWithoutBlockStatementDifferentType-expected.txt b/ets2panda/test/compiler/ets/lambdaExpressionWithoutBlockStatementDifferentType-expected.txt index 358b42f55c..a17df28bb3 100644 --- a/ets2panda/test/compiler/ets/lambdaExpressionWithoutBlockStatementDifferentType-expected.txt +++ b/ets2panda/test/compiler/ets/lambdaExpressionWithoutBlockStatementDifferentType-expected.txt @@ -515,4 +515,4 @@ } } } -TypeError: Initializers type is not assignable to the target type [lambdaExpressionWithoutBlockStatementDifferentType.ets:17:28] +TypeError: Type '() => String' cannot be assigned to type '() => int' [lambdaExpressionWithoutBlockStatementDifferentType.ets:17:28] diff --git a/ets2panda/test/compiler/ets/lambdaExpressionWithoutBlockStatementDifferentTypeInfunction-expected.txt b/ets2panda/test/compiler/ets/lambdaExpressionWithoutBlockStatementDifferentTypeInfunction-expected.txt index 8d7e876115..c35a6a6a7b 100644 --- a/ets2panda/test/compiler/ets/lambdaExpressionWithoutBlockStatementDifferentTypeInfunction-expected.txt +++ b/ets2panda/test/compiler/ets/lambdaExpressionWithoutBlockStatementDifferentTypeInfunction-expected.txt @@ -666,4 +666,4 @@ } } } -TypeError: Return statement type is not compatible with the enclosing method's return type. [lambdaExpressionWithoutBlockStatementDifferentTypeInfunction.ets:21:39] +TypeError: Type 'String' is not compatible with the enclosing method's return type 'int' [lambdaExpressionWithoutBlockStatementDifferentTypeInfunction.ets:21:39] diff --git a/ets2panda/test/compiler/ets/lambdaFunction3-expected.txt b/ets2panda/test/compiler/ets/lambdaFunction3-expected.txt index 4fbb638c04..22b2a3c2f2 100644 --- a/ets2panda/test/compiler/ets/lambdaFunction3-expected.txt +++ b/ets2panda/test/compiler/ets/lambdaFunction3-expected.txt @@ -642,4 +642,4 @@ } } } -TypeError: Initializers type is not assignable to the target type [lambdaFunction3.ets:18:39] +TypeError: Type '(b: int) => void' cannot be assigned to type '(b: String) => void' [lambdaFunction3.ets:18:39] diff --git a/ets2panda/test/compiler/ets/lambdaFunction5-expected.txt b/ets2panda/test/compiler/ets/lambdaFunction5-expected.txt index 131a90f02e..5737ced2b4 100644 --- a/ets2panda/test/compiler/ets/lambdaFunction5-expected.txt +++ b/ets2panda/test/compiler/ets/lambdaFunction5-expected.txt @@ -1705,4 +1705,4 @@ } } } -TypeError: Call argument at index 1 is not compatible with the signature's type at that index. [lambdaFunction5.ets:35:17] +TypeError: Type 'string' is not compatible with type 'int' at index 2 [lambdaFunction5.ets:35:17] diff --git a/ets2panda/test/compiler/ets/n_assignGenericWithNullableTypeParamToNonNullable-expected.txt b/ets2panda/test/compiler/ets/n_assignGenericWithNullableTypeParamToNonNullable-expected.txt index a2cc17f306..218cfffdcb 100644 --- a/ets2panda/test/compiler/ets/n_assignGenericWithNullableTypeParamToNonNullable-expected.txt +++ b/ets2panda/test/compiler/ets/n_assignGenericWithNullableTypeParamToNonNullable-expected.txt @@ -1012,4 +1012,4 @@ } } } -TypeError: Initializers type is not assignable to the target type [n_assignGenericWithNullableTypeParamToNonNullable.ets:21:19] +TypeError: Type 'A' cannot be assigned to type 'A' [n_assignGenericWithNullableTypeParamToNonNullable.ets:21:19] diff --git a/ets2panda/test/compiler/ets/objectLiteralPrimitiveContextType-expected.txt b/ets2panda/test/compiler/ets/objectLiteralPrimitiveContextType-expected.txt index 15dc9ad6b1..d4c28c364b 100644 --- a/ets2panda/test/compiler/ets/objectLiteralPrimitiveContextType-expected.txt +++ b/ets2panda/test/compiler/ets/objectLiteralPrimitiveContextType-expected.txt @@ -257,4 +257,4 @@ } } } -TypeError: target type for class composite needs to be an object type [objectLiteralPrimitiveContextType.ets:16:14] +TypeError: Target type for class composite needs to be an object type, found 'int' [objectLiteralPrimitiveContextType.ets:16:14] diff --git a/ets2panda/test/compiler/ets/objectLiteralWrongValueType-expected.txt b/ets2panda/test/compiler/ets/objectLiteralWrongValueType-expected.txt index b391dd7761..ba7bf8cb40 100644 --- a/ets2panda/test/compiler/ets/objectLiteralWrongValueType-expected.txt +++ b/ets2panda/test/compiler/ets/objectLiteralWrongValueType-expected.txt @@ -518,4 +518,4 @@ } } } -TypeError: value type is not assignable to the property type [objectLiteralWrongValueType.ets:21:8] +TypeError: Type 'string' is not compatible with type 'int' at property 'f' [objectLiteralWrongValueType.ets:21:8] diff --git a/ets2panda/test/compiler/ets/switchStatementWrongBoxing-expected.txt b/ets2panda/test/compiler/ets/switchStatementWrongBoxing-expected.txt index 8ffd0b9a5d..f893cf2cf9 100644 --- a/ets2panda/test/compiler/ets/switchStatementWrongBoxing-expected.txt +++ b/ets2panda/test/compiler/ets/switchStatementWrongBoxing-expected.txt @@ -696,4 +696,4 @@ } } } -TypeError: Switch case type byte is not comparable to discriminant type Int [switchStatementWrongBoxing.ets:21:18] +TypeError: Switch case type 'byte' is not comparable to discriminant type 'Int' [switchStatementWrongBoxing.ets:21:18] diff --git a/ets2panda/test/compiler/ets/tuple_types_10_neg-expected.txt b/ets2panda/test/compiler/ets/tuple_types_10_neg-expected.txt index d72397b081..7f3a1736aa 100644 --- a/ets2panda/test/compiler/ets/tuple_types_10_neg-expected.txt +++ b/ets2panda/test/compiler/ets/tuple_types_10_neg-expected.txt @@ -670,4 +670,4 @@ } } } -TypeError: Initializers type is not assignable to the target type [tuple_types_10_neg.ets:19:39] +TypeError: Type '[double, double]' cannot be assigned to type '[double, double, double]' [tuple_types_10_neg.ets:19:39] diff --git a/ets2panda/test/compiler/ets/tuple_types_11_neg-expected.txt b/ets2panda/test/compiler/ets/tuple_types_11_neg-expected.txt index 669daa1144..999b175e3a 100644 --- a/ets2panda/test/compiler/ets/tuple_types_11_neg-expected.txt +++ b/ets2panda/test/compiler/ets/tuple_types_11_neg-expected.txt @@ -684,4 +684,4 @@ } } } -TypeError: Initializers type is not assignable to the target type [tuple_types_11_neg.ets:19:31] +TypeError: Type '[double, double, double]' cannot be assigned to type '[double, double]' [tuple_types_11_neg.ets:19:31] diff --git a/ets2panda/test/compiler/ets/tuple_types_6_neg-expected.txt b/ets2panda/test/compiler/ets/tuple_types_6_neg-expected.txt index b54e946549..01342b3043 100644 --- a/ets2panda/test/compiler/ets/tuple_types_6_neg-expected.txt +++ b/ets2panda/test/compiler/ets/tuple_types_6_neg-expected.txt @@ -533,4 +533,4 @@ } } } -TypeError: Initializers type is not assignable to the target type [tuple_types_6_neg.ets:19:23] +TypeError: Type '[double]' cannot be assigned to type '[Double]' [tuple_types_6_neg.ets:19:23] diff --git a/ets2panda/test/compiler/ets/tuple_types_9_neg-expected.txt b/ets2panda/test/compiler/ets/tuple_types_9_neg-expected.txt index b3ff7ada9a..959d61e101 100644 --- a/ets2panda/test/compiler/ets/tuple_types_9_neg-expected.txt +++ b/ets2panda/test/compiler/ets/tuple_types_9_neg-expected.txt @@ -737,4 +737,4 @@ } } } -TypeError: Initializers type is not assignable to the target type [tuple_types_9_neg.ets:19:36] +TypeError: Type '[double, String, ...Int[]]' cannot be assigned to type '[double, String, Int]' [tuple_types_9_neg.ets:19:36] diff --git a/ets2panda/test/compiler/ets/union_types_4-expected.txt b/ets2panda/test/compiler/ets/union_types_4-expected.txt index 3ae46f4f24..bdf5420f32 100644 --- a/ets2panda/test/compiler/ets/union_types_4-expected.txt +++ b/ets2panda/test/compiler/ets/union_types_4-expected.txt @@ -1555,4 +1555,4 @@ } } } -TypeError: Initializers type is not assignable to the target type [union_types_4.ets:30:9] +TypeError: Type 'B' cannot be assigned to type 'String|Short|A' [union_types_4.ets:30:9] diff --git a/ets2panda/test/parser/ets/async_func_return_type_bad-expected.txt b/ets2panda/test/parser/ets/async_func_return_type_bad-expected.txt index f10a8253c6..1ddada0928 100644 --- a/ets2panda/test/parser/ets/async_func_return_type_bad-expected.txt +++ b/ets2panda/test/parser/ets/async_func_return_type_bad-expected.txt @@ -342,4 +342,4 @@ } } } -TypeError: Return statement type is not compatible with the enclosing method's return type. [async_func_return_type_bad.ets:17:12] +TypeError: Type 'string' is not compatible with the enclosing method's return type 'Promise | Int' [async_func_return_type_bad.ets:17:12] diff --git a/ets2panda/test/parser/ets/dynamic_import_tests/dynamic_class_ctor_decl_import_bad-expected.txt b/ets2panda/test/parser/ets/dynamic_import_tests/dynamic_class_ctor_decl_import_bad-expected.txt index fa2438b241..f644e4d39a 100644 --- a/ets2panda/test/parser/ets/dynamic_import_tests/dynamic_class_ctor_decl_import_bad-expected.txt +++ b/ets2panda/test/parser/ets/dynamic_import_tests/dynamic_class_ctor_decl_import_bad-expected.txt @@ -1 +1 @@ -TypeError: Call argument at index 0 is not compatible with the signature's type at that index. [dynamic_class_ctor_decl_import_bad.ets:23:19] +TypeError: Type 'string' is not compatible with type 'double' at index 1 [dynamic_class_ctor_decl_import_bad.ets:23:19] diff --git a/ets2panda/test/parser/ets/dynamic_import_tests/dynamic_class_field_decl_import_bad_1-expected.txt b/ets2panda/test/parser/ets/dynamic_import_tests/dynamic_class_field_decl_import_bad_1-expected.txt index 1a691d4d82..d7211e1b8f 100644 --- a/ets2panda/test/parser/ets/dynamic_import_tests/dynamic_class_field_decl_import_bad_1-expected.txt +++ b/ets2panda/test/parser/ets/dynamic_import_tests/dynamic_class_field_decl_import_bad_1-expected.txt @@ -1 +1 @@ -TypeError: Initializers type is not assignable to the target type [dynamic_class_field_decl_import_bad_1.ets:23:12] +TypeError: Type 'int' cannot be assigned to type 'String' [dynamic_class_field_decl_import_bad_1.ets:23:12] diff --git a/ets2panda/test/parser/ets/dynamic_import_tests/dynamic_class_field_decl_import_bad_2-expected.txt b/ets2panda/test/parser/ets/dynamic_import_tests/dynamic_class_field_decl_import_bad_2-expected.txt index 88718c571e..cd3b95281f 100644 --- a/ets2panda/test/parser/ets/dynamic_import_tests/dynamic_class_field_decl_import_bad_2-expected.txt +++ b/ets2panda/test/parser/ets/dynamic_import_tests/dynamic_class_field_decl_import_bad_2-expected.txt @@ -1 +1 @@ -TypeError: Initializers type is not assignable to the target type [dynamic_class_field_decl_import_bad_2.ets:23:21] +TypeError: Type 'double' cannot be assigned to type 'String' [dynamic_class_field_decl_import_bad_2.ets:23:21] diff --git a/ets2panda/test/parser/ets/dynamic_import_tests/dynamic_class_method_decl_import_bad_1-expected.txt b/ets2panda/test/parser/ets/dynamic_import_tests/dynamic_class_method_decl_import_bad_1-expected.txt index 6eac80975c..68bb0527ce 100644 --- a/ets2panda/test/parser/ets/dynamic_import_tests/dynamic_class_method_decl_import_bad_1-expected.txt +++ b/ets2panda/test/parser/ets/dynamic_import_tests/dynamic_class_method_decl_import_bad_1-expected.txt @@ -1 +1 @@ -TypeError: Call argument at index 0 is not compatible with the signature's type at that index. [dynamic_class_method_decl_import_bad_1.ets:23:11] +TypeError: Type 'string' is not compatible with type 'double' at index 1 [dynamic_class_method_decl_import_bad_1.ets:23:11] diff --git a/ets2panda/test/parser/ets/dynamic_import_tests/dynamic_class_method_decl_import_bad_2-expected.txt b/ets2panda/test/parser/ets/dynamic_import_tests/dynamic_class_method_decl_import_bad_2-expected.txt index 9b52cc0ef3..5c8704ac8c 100644 --- a/ets2panda/test/parser/ets/dynamic_import_tests/dynamic_class_method_decl_import_bad_2-expected.txt +++ b/ets2panda/test/parser/ets/dynamic_import_tests/dynamic_class_method_decl_import_bad_2-expected.txt @@ -1 +1 @@ -TypeError: Initializers type is not assignable to the target type [dynamic_class_method_decl_import_bad_2.ets:23:21] +TypeError: Type 'double' cannot be assigned to type 'String' [dynamic_class_method_decl_import_bad_2.ets:23:21] diff --git a/ets2panda/test/parser/ets/dynamic_import_tests/dynamic_func_decl_import_bad-expected.txt b/ets2panda/test/parser/ets/dynamic_import_tests/dynamic_func_decl_import_bad-expected.txt index 3e84372b58..b835f137b0 100644 --- a/ets2panda/test/parser/ets/dynamic_import_tests/dynamic_func_decl_import_bad-expected.txt +++ b/ets2panda/test/parser/ets/dynamic_import_tests/dynamic_func_decl_import_bad-expected.txt @@ -1 +1 @@ -TypeError: Call argument at index 0 is not compatible with the signature's type at that index. [dynamic_func_decl_import_bad.ets:23:9] +TypeError: Type 'string' is not compatible with type 'A' at index 1 [dynamic_func_decl_import_bad.ets:23:9] diff --git a/ets2panda/test/parser/ets/enum8-expected.txt b/ets2panda/test/parser/ets/enum8-expected.txt index 67d246372e..150b136c75 100644 --- a/ets2panda/test/parser/ets/enum8-expected.txt +++ b/ets2panda/test/parser/ets/enum8-expected.txt @@ -563,4 +563,4 @@ } } } -TypeError: Initializers type is not assignable to the target type [enum8.ets:20:20] +TypeError: Type 'Color2' cannot be assigned to type 'Color' [enum8.ets:20:20] diff --git a/ets2panda/test/parser/ets/function_implicit_return_type2-expected.txt b/ets2panda/test/parser/ets/function_implicit_return_type2-expected.txt index 86dadbaca5..b9803f021f 100644 --- a/ets2panda/test/parser/ets/function_implicit_return_type2-expected.txt +++ b/ets2panda/test/parser/ets/function_implicit_return_type2-expected.txt @@ -316,4 +316,4 @@ } } } -TypeError: Initializers type is not assignable to the target type [function_implicit_return_type2.ets:17:27] +TypeError: Type '() => void' cannot be assigned to type '(i: int) => int' [function_implicit_return_type2.ets:17:27] diff --git a/ets2panda/test/parser/ets/function_implicit_return_type3-expected.txt b/ets2panda/test/parser/ets/function_implicit_return_type3-expected.txt index 41e4545d59..86af963d88 100644 --- a/ets2panda/test/parser/ets/function_implicit_return_type3-expected.txt +++ b/ets2panda/test/parser/ets/function_implicit_return_type3-expected.txt @@ -465,4 +465,4 @@ } } } -TypeError: Initializers type is not assignable to the target type [function_implicit_return_type3.ets:18:27] +TypeError: Type '(i: int) => void' cannot be assigned to type '(i: int) => int' [function_implicit_return_type3.ets:18:27] diff --git a/ets2panda/test/parser/ets/function_implicit_return_type6-expected.txt b/ets2panda/test/parser/ets/function_implicit_return_type6-expected.txt index c942bc192d..924369f75a 100644 --- a/ets2panda/test/parser/ets/function_implicit_return_type6-expected.txt +++ b/ets2panda/test/parser/ets/function_implicit_return_type6-expected.txt @@ -442,4 +442,4 @@ } } } -TypeError: Initializers type is not assignable to the target type [function_implicit_return_type6.ets:20:16] +TypeError: Type 'void' cannot be assigned to type 'int' [function_implicit_return_type6.ets:20:16] diff --git a/ets2panda/test/parser/ets/function_implicit_return_type7-expected.txt b/ets2panda/test/parser/ets/function_implicit_return_type7-expected.txt index 478d07c0ed..dd9c583fa7 100644 --- a/ets2panda/test/parser/ets/function_implicit_return_type7-expected.txt +++ b/ets2panda/test/parser/ets/function_implicit_return_type7-expected.txt @@ -598,4 +598,4 @@ } } } -TypeError: Return statement type is not compatible with previous method's return statement type(s). [function_implicit_return_type7.ets:21:10] +TypeError: Function cannot have different primitive return types, found 'boolean', 'int' [function_implicit_return_type7.ets:21:10] diff --git a/ets2panda/test/parser/ets/n_arrayHoldingNullValue-expected.txt b/ets2panda/test/parser/ets/n_arrayHoldingNullValue-expected.txt index d90b7f2cba..10346aee63 100644 --- a/ets2panda/test/parser/ets/n_arrayHoldingNullValue-expected.txt +++ b/ets2panda/test/parser/ets/n_arrayHoldingNullValue-expected.txt @@ -455,4 +455,4 @@ } } } -TypeError: Initializers type is not assignable to the target type [n_arrayHoldingNullValue.ets:17:24] +TypeError: Type 'null' cannot be assigned to type 'float[]' [n_arrayHoldingNullValue.ets:17:24] diff --git a/ets2panda/test/parser/ets/n_assignNullableFromFunctionToNonNullable-expected.txt b/ets2panda/test/parser/ets/n_assignNullableFromFunctionToNonNullable-expected.txt index cf852cc4c9..57e9c0bfde 100644 --- a/ets2panda/test/parser/ets/n_assignNullableFromFunctionToNonNullable-expected.txt +++ b/ets2panda/test/parser/ets/n_assignNullableFromFunctionToNonNullable-expected.txt @@ -743,4 +743,4 @@ } } } -TypeError: Initializers type is not assignable to the target type [n_assignNullableFromFunctionToNonNullable.ets:23:22] +TypeError: Type 'A|null' cannot be assigned to type 'Object' [n_assignNullableFromFunctionToNonNullable.ets:23:22] diff --git a/ets2panda/test/parser/ets/n_assignNullableFromMethodToNullableParam-expected.txt b/ets2panda/test/parser/ets/n_assignNullableFromMethodToNullableParam-expected.txt index 2f57863379..5698d12fe6 100644 --- a/ets2panda/test/parser/ets/n_assignNullableFromMethodToNullableParam-expected.txt +++ b/ets2panda/test/parser/ets/n_assignNullableFromMethodToNullableParam-expected.txt @@ -913,4 +913,4 @@ } } } -TypeError: Initializers type is not assignable to the target type [n_assignNullableFromMethodToNullableParam.ets:24:22] +TypeError: Type 'A|null' cannot be assigned to type 'Object' [n_assignNullableFromMethodToNullableParam.ets:24:22] diff --git a/ets2panda/test/parser/ets/n_assignNullableToNonNullable-expected.txt b/ets2panda/test/parser/ets/n_assignNullableToNonNullable-expected.txt index c8a3c89c36..ff8820fa74 100644 --- a/ets2panda/test/parser/ets/n_assignNullableToNonNullable-expected.txt +++ b/ets2panda/test/parser/ets/n_assignNullableToNonNullable-expected.txt @@ -707,4 +707,4 @@ } } } -TypeError: Initializers type is not assignable to the target type [n_assignNullableToNonNullable.ets:22:9] +TypeError: Type 'A|null' cannot be assigned to type 'Object' [n_assignNullableToNonNullable.ets:22:9] diff --git a/ets2panda/test/parser/ets/n_assignNullableToNonNullableArray-expected.txt b/ets2panda/test/parser/ets/n_assignNullableToNonNullableArray-expected.txt index 9b424caf23..c5df8b7939 100644 --- a/ets2panda/test/parser/ets/n_assignNullableToNonNullableArray-expected.txt +++ b/ets2panda/test/parser/ets/n_assignNullableToNonNullableArray-expected.txt @@ -803,4 +803,4 @@ } } } -TypeError: Initializers type is not assignable to the target type [n_assignNullableToNonNullableArray.ets:22:10] +TypeError: Type 'A[]|null' cannot be assigned to type 'Object[]' [n_assignNullableToNonNullableArray.ets:22:10] diff --git a/ets2panda/test/parser/ets/n_assignNullableToNonNullableTypeAlias-expected.txt b/ets2panda/test/parser/ets/n_assignNullableToNonNullableTypeAlias-expected.txt index 2ac81c66dd..28ddeff4fb 100644 --- a/ets2panda/test/parser/ets/n_assignNullableToNonNullableTypeAlias-expected.txt +++ b/ets2panda/test/parser/ets/n_assignNullableToNonNullableTypeAlias-expected.txt @@ -776,4 +776,4 @@ } } } -TypeError: Initializers type is not assignable to the target type [n_assignNullableToNonNullableTypeAlias.ets:24:9] +TypeError: Type 'A|null' cannot be assigned to type 'Object' [n_assignNullableToNonNullableTypeAlias.ets:24:9] diff --git a/ets2panda/test/parser/ets/n_callFunctionWithNullableParam-expected.txt b/ets2panda/test/parser/ets/n_callFunctionWithNullableParam-expected.txt index 5dffc7d900..229bee6d94 100644 --- a/ets2panda/test/parser/ets/n_callFunctionWithNullableParam-expected.txt +++ b/ets2panda/test/parser/ets/n_callFunctionWithNullableParam-expected.txt @@ -828,4 +828,4 @@ } } } -TypeError: Call argument at index 0 is not compatible with the signature's type at that index. [n_callFunctionWithNullableParam.ets:23:9] +TypeError: Type 'A|null' is not compatible with type 'A' at index 1 [n_callFunctionWithNullableParam.ets:23:9] diff --git a/ets2panda/test/parser/ets/n_callInterfaceMethodWithNullableParam-expected.txt b/ets2panda/test/parser/ets/n_callInterfaceMethodWithNullableParam-expected.txt index 1aed437dc3..9e0b6dfba6 100644 --- a/ets2panda/test/parser/ets/n_callInterfaceMethodWithNullableParam-expected.txt +++ b/ets2panda/test/parser/ets/n_callInterfaceMethodWithNullableParam-expected.txt @@ -1149,4 +1149,4 @@ } } } -TypeError: Call argument at index 0 is not compatible with the signature's type at that index. [n_callInterfaceMethodWithNullableParam.ets:27:12] +TypeError: Type 'I|null' is not compatible with type 'I' at index 1 [n_callInterfaceMethodWithNullableParam.ets:27:12] diff --git a/ets2panda/test/parser/ets/n_callMethodWithNullableParam-expected.txt b/ets2panda/test/parser/ets/n_callMethodWithNullableParam-expected.txt index 66b6147871..d671817126 100644 --- a/ets2panda/test/parser/ets/n_callMethodWithNullableParam-expected.txt +++ b/ets2panda/test/parser/ets/n_callMethodWithNullableParam-expected.txt @@ -858,4 +858,4 @@ } } } -TypeError: Call argument at index 0 is not compatible with the signature's type at that index. [n_callMethodWithNullableParam.ets:23:12] +TypeError: Type 'A|null' is not compatible with type 'A' at index 1 [n_callMethodWithNullableParam.ets:23:12] diff --git a/ets2panda/test/parser/ets/n_returnNullFromFunction-expected.txt b/ets2panda/test/parser/ets/n_returnNullFromFunction-expected.txt index 8d0cbdb744..1153d45e32 100644 --- a/ets2panda/test/parser/ets/n_returnNullFromFunction-expected.txt +++ b/ets2panda/test/parser/ets/n_returnNullFromFunction-expected.txt @@ -451,4 +451,4 @@ } } } -TypeError: Return statement type is not compatible with the enclosing method's return type. [n_returnNullFromFunction.ets:19:12] +TypeError: Type 'null' is not compatible with the enclosing method's return type 'A' [n_returnNullFromFunction.ets:19:12] diff --git a/ets2panda/test/parser/ets/n_returnNullFromMethod-expected.txt b/ets2panda/test/parser/ets/n_returnNullFromMethod-expected.txt index 6475dcf314..62e4dded19 100644 --- a/ets2panda/test/parser/ets/n_returnNullFromMethod-expected.txt +++ b/ets2panda/test/parser/ets/n_returnNullFromMethod-expected.txt @@ -451,4 +451,4 @@ } } } -TypeError: Return statement type is not compatible with the enclosing method's return type. [n_returnNullFromMethod.ets:18:16] +TypeError: Type 'null' is not compatible with the enclosing method's return type 'A' [n_returnNullFromMethod.ets:18:16] diff --git a/ets2panda/test/parser/ets/n_returnNullableFromFunction-expected.txt b/ets2panda/test/parser/ets/n_returnNullableFromFunction-expected.txt index 7a4275b332..3c41b4b7af 100644 --- a/ets2panda/test/parser/ets/n_returnNullableFromFunction-expected.txt +++ b/ets2panda/test/parser/ets/n_returnNullableFromFunction-expected.txt @@ -592,4 +592,4 @@ } } } -TypeError: Return statement type is not compatible with the enclosing method's return type. [n_returnNullableFromFunction.ets:21:12] +TypeError: Type 'A|null' is not compatible with the enclosing method's return type 'A' [n_returnNullableFromFunction.ets:21:12] diff --git a/ets2panda/test/parser/ets/n_returnNullableFromMethod-expected.txt b/ets2panda/test/parser/ets/n_returnNullableFromMethod-expected.txt index df711d1502..3c9ac3ca46 100644 --- a/ets2panda/test/parser/ets/n_returnNullableFromMethod-expected.txt +++ b/ets2panda/test/parser/ets/n_returnNullableFromMethod-expected.txt @@ -592,4 +592,4 @@ } } } -TypeError: Return statement type is not compatible with the enclosing method's return type. [n_returnNullableFromMethod.ets:20:16] +TypeError: Type 'A|null' is not compatible with the enclosing method's return type 'A' [n_returnNullableFromMethod.ets:20:16] diff --git a/ets2panda/test/parser/ets/null_invalid-expected.txt b/ets2panda/test/parser/ets/null_invalid-expected.txt index 1c9ab91eee..4f1b9e0d7c 100644 --- a/ets2panda/test/parser/ets/null_invalid-expected.txt +++ b/ets2panda/test/parser/ets/null_invalid-expected.txt @@ -336,4 +336,4 @@ } } } -TypeError: Initializers type is not assignable to the target type [null_invalid.ets:17:18] +TypeError: Type 'Object|null' cannot be assigned to type 'Object' [null_invalid.ets:17:18] diff --git a/ets2panda/test/parser/ets/switch_enum2-expected.txt b/ets2panda/test/parser/ets/switch_enum2-expected.txt index 18f714c831..59ed0f5ca2 100644 --- a/ets2panda/test/parser/ets/switch_enum2-expected.txt +++ b/ets2panda/test/parser/ets/switch_enum2-expected.txt @@ -577,4 +577,4 @@ } } } -TypeError: Switch case type int is not comparable to discriminant type Color [switch_enum2.ets:20:14] +TypeError: Switch case type 'int' is not comparable to discriminant type 'Color' [switch_enum2.ets:20:14] diff --git a/ets2panda/test/parser/ets/switch_readonly_member_different_enum-expected.txt b/ets2panda/test/parser/ets/switch_readonly_member_different_enum-expected.txt index f34d7e3f92..8ce637786e 100644 --- a/ets2panda/test/parser/ets/switch_readonly_member_different_enum-expected.txt +++ b/ets2panda/test/parser/ets/switch_readonly_member_different_enum-expected.txt @@ -1293,4 +1293,4 @@ } } } -TypeError: Switch case type A is not comparable to discriminant type E [switch_readonly_member_different_enum.ets:35:14] +TypeError: Switch case type 'A' is not comparable to discriminant type 'E' [switch_readonly_member_different_enum.ets:35:14] diff --git a/ets2panda/test/parser/ets/switch_readonly_member_different_enum_2-expected.txt b/ets2panda/test/parser/ets/switch_readonly_member_different_enum_2-expected.txt index 3ef004f3ec..5891ffb6e1 100644 --- a/ets2panda/test/parser/ets/switch_readonly_member_different_enum_2-expected.txt +++ b/ets2panda/test/parser/ets/switch_readonly_member_different_enum_2-expected.txt @@ -1293,4 +1293,4 @@ } } } -TypeError: Switch case type A is not comparable to discriminant type E [switch_readonly_member_different_enum_2.ets:34:14] +TypeError: Switch case type 'A' is not comparable to discriminant type 'E' [switch_readonly_member_different_enum_2.ets:34:14] diff --git a/ets2panda/test/unit/public/es2panda_public_test.cpp b/ets2panda/test/unit/public/es2panda_public_test.cpp index fcdef1dd36..2987e79dc3 100644 --- a/ets2panda/test/unit/public/es2panda_public_test.cpp +++ b/ets2panda/test/unit/public/es2panda_public_test.cpp @@ -57,7 +57,7 @@ TEST_F(Es2PandaLibTest, TypeError) impl_->ProceedToState(ctx, ES2PANDA_STATE_ASM_GENERATED); ASSERT_EQ(impl_->ContextState(ctx), ES2PANDA_STATE_ERROR); ASSERT_EQ(std::string(impl_->ContextErrorMessage(ctx)), - "TypeError: Initializers type is not assignable to the target type[type-error.ets:1,32]"); + "TypeError: Type 'string' cannot be assigned to type 'int'[type-error.ets:1,32]"); impl_->DestroyContext(ctx); } -- Gitee From a904d51c44a53822972983edc79b016bb7668f80 Mon Sep 17 00:00:00 2001 From: Vadim Lomovtsev Date: Mon, 22 Jan 2024 16:34:28 +0300 Subject: [PATCH 22/26] project-wide: fix clang-tidy & CI code-check issues Signed-off-by: Vadim Lomovtsev --- ets2panda/checker/ets/helpers.cpp | 6 +- .../compiler/lowering/ets/expandBrackets.cpp | 2 +- .../ets/interfacePropertyDeclarations.cpp | 6 +- .../compiler/lowering/ets/opAssignment.cpp | 128 ++++++++++-------- .../compiler/lowering/ets/unionLowering.cpp | 2 +- ets2panda/ir/astNode.h | 3 +- ets2panda/ir/base/classProperty.cpp | 5 +- ets2panda/ir/base/classProperty.h | 3 +- ets2panda/ir/base/decorator.cpp | 3 +- ets2panda/ir/base/decorator.h | 3 +- ets2panda/ir/base/metaProperty.cpp | 1 - ets2panda/ir/base/metaProperty.h | 3 +- ets2panda/ir/base/methodDefinition.cpp | 5 +- ets2panda/ir/base/methodDefinition.h | 3 +- ets2panda/ir/base/property.cpp | 5 +- ets2panda/ir/base/property.h | 3 +- ets2panda/ir/base/spreadElement.cpp | 1 - ets2panda/ir/base/spreadElement.h | 3 +- ets2panda/ir/base/templateElement.cpp | 1 - ets2panda/ir/base/templateElement.h | 3 +- ets2panda/ir/base/tsIndexSignature.cpp | 5 +- ets2panda/ir/base/tsIndexSignature.h | 3 +- ets2panda/ir/base/tsPropertySignature.cpp | 5 +- ets2panda/ir/base/tsPropertySignature.h | 3 +- ets2panda/ir/ets/etsClassLiteral.cpp | 3 +- ets2panda/ir/ets/etsClassLiteral.h | 3 +- ets2panda/ir/ets/etsFunctionType.cpp | 12 +- ets2panda/ir/ets/etsFunctionType.h | 3 +- ets2panda/ir/ets/etsLaunchExpression.cpp | 3 +- ets2panda/ir/ets/etsLaunchExpression.h | 3 +- .../ir/ets/etsNewArrayInstanceExpression.cpp | 5 +- .../ir/ets/etsNewArrayInstanceExpression.h | 3 +- .../ir/ets/etsNewClassInstanceExpression.cpp | 1 - .../ir/ets/etsNewClassInstanceExpression.h | 3 +- .../etsNewMultiDimArrayInstanceExpression.cpp | 1 - .../etsNewMultiDimArrayInstanceExpression.h | 4 +- ets2panda/ir/ets/etsPackageDeclaration.cpp | 1 - ets2panda/ir/ets/etsPackageDeclaration.h | 3 +- ets2panda/ir/ets/etsParameterExpression.cpp | 8 +- ets2panda/ir/ets/etsParameterExpression.h | 3 +- ets2panda/ir/ets/etsPrimitiveType.cpp | 1 - ets2panda/ir/ets/etsPrimitiveType.h | 3 +- ets2panda/ir/ets/etsStructDeclaration.cpp | 1 - ets2panda/ir/ets/etsStructDeclaration.h | 3 +- ets2panda/ir/ets/etsTypeReference.cpp | 3 +- ets2panda/ir/ets/etsTypeReference.h | 3 +- ets2panda/ir/ets/etsTypeReferencePart.cpp | 7 +- ets2panda/ir/ets/etsTypeReferencePart.h | 3 +- ets2panda/ir/expressions/arrayExpression.cpp | 1 - ets2panda/ir/expressions/arrayExpression.h | 3 +- .../expressions/arrowFunctionExpression.cpp | 1 - .../ir/expressions/arrowFunctionExpression.h | 3 +- .../ir/expressions/assignmentExpression.cpp | 5 +- .../ir/expressions/assignmentExpression.h | 3 +- ets2panda/ir/expressions/awaitExpression.cpp | 3 +- ets2panda/ir/expressions/awaitExpression.h | 3 +- ets2panda/ir/expressions/binaryExpression.cpp | 5 +- ets2panda/ir/expressions/binaryExpression.h | 3 +- ets2panda/ir/expressions/blockExpression.cpp | 1 - ets2panda/ir/expressions/blockExpression.h | 3 +- ets2panda/ir/expressions/callExpression.cpp | 1 - ets2panda/ir/expressions/callExpression.h | 3 +- ets2panda/ir/expressions/chainExpression.cpp | 3 +- ets2panda/ir/expressions/chainExpression.h | 3 +- ets2panda/ir/expressions/classExpression.cpp | 3 +- ets2panda/ir/expressions/classExpression.h | 3 +- .../ir/expressions/conditionalExpression.cpp | 7 +- .../ir/expressions/conditionalExpression.h | 3 +- .../ir/expressions/functionExpression.cpp | 3 +- ets2panda/ir/expressions/functionExpression.h | 3 +- ets2panda/ir/expressions/identifier.cpp | 1 - ets2panda/ir/expressions/identifier.h | 3 +- ets2panda/ir/expressions/importExpression.cpp | 3 +- ets2panda/ir/expressions/importExpression.h | 3 +- .../ir/expressions/literals/bigIntLiteral.cpp | 1 - .../ir/expressions/literals/bigIntLiteral.h | 3 +- .../expressions/literals/booleanLiteral.cpp | 1 - .../ir/expressions/literals/booleanLiteral.h | 3 +- .../ir/expressions/literals/charLiteral.cpp | 1 - .../ir/expressions/literals/charLiteral.h | 3 +- .../ir/expressions/literals/nullLiteral.cpp | 1 - .../ir/expressions/literals/nullLiteral.h | 3 +- .../ir/expressions/literals/numberLiteral.cpp | 1 - .../ir/expressions/literals/numberLiteral.h | 3 +- .../ir/expressions/literals/regExpLiteral.cpp | 1 - .../ir/expressions/literals/regExpLiteral.h | 3 +- .../ir/expressions/literals/stringLiteral.cpp | 1 - .../ir/expressions/literals/stringLiteral.h | 3 +- ets2panda/ir/expressions/memberExpression.cpp | 5 +- ets2panda/ir/expressions/memberExpression.h | 3 +- ets2panda/ir/expressions/newExpression.cpp | 1 - ets2panda/ir/expressions/newExpression.h | 3 +- ets2panda/ir/expressions/objectExpression.cpp | 1 - ets2panda/ir/expressions/objectExpression.h | 3 +- .../ir/expressions/omittedExpression.cpp | 1 - ets2panda/ir/expressions/omittedExpression.h | 3 +- .../ir/expressions/sequenceExpression.cpp | 1 - ets2panda/ir/expressions/sequenceExpression.h | 3 +- ets2panda/ir/expressions/superExpression.cpp | 1 - ets2panda/ir/expressions/superExpression.h | 3 +- .../expressions/taggedTemplateExpression.cpp | 7 +- .../ir/expressions/taggedTemplateExpression.h | 3 +- ets2panda/ir/expressions/templateLiteral.cpp | 1 - ets2panda/ir/expressions/templateLiteral.h | 3 +- ets2panda/ir/expressions/thisExpression.cpp | 1 - ets2panda/ir/expressions/thisExpression.h | 3 +- ets2panda/ir/expressions/unaryExpression.cpp | 3 +- ets2panda/ir/expressions/unaryExpression.h | 3 +- ets2panda/ir/expressions/updateExpression.cpp | 3 +- ets2panda/ir/expressions/updateExpression.h | 3 +- ets2panda/ir/expressions/yieldExpression.cpp | 3 +- ets2panda/ir/expressions/yieldExpression.h | 3 +- ets2panda/ir/ts/tsArrayType.cpp | 3 +- ets2panda/ir/ts/tsArrayType.h | 3 +- .../ir/ts/tsTypeParameterInstantiation.cpp | 1 - .../ir/ts/tsTypeParameterInstantiation.h | 3 +- ets2panda/ir/typeNode.cpp | 1 - ets2panda/ir/typeNode.h | 3 +- 118 files changed, 184 insertions(+), 286 deletions(-) diff --git a/ets2panda/checker/ets/helpers.cpp b/ets2panda/checker/ets/helpers.cpp index 41e52fafab..0f1e672c72 100644 --- a/ets2panda/checker/ets/helpers.cpp +++ b/ets2panda/checker/ets/helpers.cpp @@ -2647,8 +2647,8 @@ void ETSChecker::GenerateGetterSetterBody(ETSChecker *checker, ArenaVectorKey()->AsIdentifier()->Clone(checker->Allocator()); - paramIdent->SetTsTypeAnnotation(field->TypeAnnotation()->Clone(checker->Allocator())); + auto *paramIdent = field->Key()->AsIdentifier()->Clone(checker->Allocator(), nullptr); + paramIdent->SetTsTypeAnnotation(field->TypeAnnotation()->Clone(checker->Allocator(), nullptr)); paramIdent->TypeAnnotation()->SetParent(paramIdent); auto *paramExpression = checker->AllocNode(paramIdent, nullptr); @@ -2696,7 +2696,7 @@ ir::MethodDefinition *ETSChecker::GenerateDefaultGetterSetter(ir::ClassProperty func->SetScope(functionScope); body->SetScope(functionScope); - auto *methodIdent = field->Key()->AsIdentifier()->Clone(checker->Allocator()); + auto *methodIdent = field->Key()->AsIdentifier()->Clone(checker->Allocator(), nullptr); auto *decl = checker->Allocator()->New( checker->Allocator(), field->Key()->AsIdentifier()->Name(), field->Key()->AsIdentifier()->Variable()->Declaration()->Node()); diff --git a/ets2panda/compiler/lowering/ets/expandBrackets.cpp b/ets2panda/compiler/lowering/ets/expandBrackets.cpp index d8936fe26a..f5915b3187 100644 --- a/ets2panda/compiler/lowering/ets/expandBrackets.cpp +++ b/ets2panda/compiler/lowering/ets/expandBrackets.cpp @@ -61,7 +61,7 @@ bool ExpandBracketsPhase::Perform(public_lib::Context *ctx, parser::Program *pro " throw new TypeError(\"Index fractional part should not be different from 0.0\");" "};" "(@@E5);", - parser::DEFAULT_SOURCE_FILE, ident, dimension, exprType, ident->Clone(allocator), newExpression); + parser::DEFAULT_SOURCE_FILE, ident, dimension, exprType, ident->Clone(allocator, nullptr), newExpression); sequenceExpr->SetParent(newExpression->Parent()); InitScopesPhaseETS::RunExternalNode(sequenceExpr, ctx->compilerContext->VarBinder()); checker->VarBinder()->AsETSBinder()->ResolveReferencesForScope(sequenceExpr, scope); diff --git a/ets2panda/compiler/lowering/ets/interfacePropertyDeclarations.cpp b/ets2panda/compiler/lowering/ets/interfacePropertyDeclarations.cpp index 97b56809eb..23ca287fa4 100644 --- a/ets2panda/compiler/lowering/ets/interfacePropertyDeclarations.cpp +++ b/ets2panda/compiler/lowering/ets/interfacePropertyDeclarations.cpp @@ -45,8 +45,8 @@ static ir::MethodDefinition *GenerateGetterOrSetter(checker::ETSChecker *const c ArenaVector params(checker->Allocator()->Adapter()); if (isSetter) { - auto paramIdent = field->Key()->AsIdentifier()->Clone(checker->Allocator()); - paramIdent->SetTsTypeAnnotation(field->TypeAnnotation()->Clone(checker->Allocator())); + auto paramIdent = field->Key()->AsIdentifier()->Clone(checker->Allocator(), nullptr); + paramIdent->SetTsTypeAnnotation(field->TypeAnnotation()->Clone(checker->Allocator(), nullptr)); paramIdent->TypeAnnotation()->SetParent(paramIdent); auto *const paramExpression = checker->AllocNode(paramIdent, nullptr); @@ -71,7 +71,7 @@ static ir::MethodDefinition *GenerateGetterOrSetter(checker::ETSChecker *const c func->SetScope(functionScope); - auto methodIdent = field->Key()->AsIdentifier()->Clone(checker->Allocator()); + auto methodIdent = field->Key()->AsIdentifier()->Clone(checker->Allocator(), nullptr); auto *decl = checker->Allocator()->New(field->Key()->AsIdentifier()->Name()); auto var = functionScope->AddDecl(checker->Allocator(), decl, ScriptExtension::ETS); diff --git a/ets2panda/compiler/lowering/ets/opAssignment.cpp b/ets2panda/compiler/lowering/ets/opAssignment.cpp index 9b4bfa606b..eb49fd0b2c 100644 --- a/ets2panda/compiler/lowering/ets/opAssignment.cpp +++ b/ets2panda/compiler/lowering/ets/opAssignment.cpp @@ -87,32 +87,51 @@ void AdjustBoxingUnboxingFlags(ir::Expression *newExpr, const ir::Expression *ol } } -ir::Expression *HandleOpAssignment(public_lib::Context *ctx, checker::ETSChecker *checker, parser::ETSParser *parser, - ir::AssignmentExpression *assignment) +static ir::Expression *CreateLoweringResult([[maybe_unused]] public_lib::Context *ctx, + ir::AssignmentExpression *assignment, ir::Expression *loweringResult) { - if (assignment->TsType() == nullptr) { // hasn't been through checker - return assignment; - } + // Adjust [un]boxing flag + ir::AssignmentExpression *newAssignment = nullptr; - const auto opEqual = assignment->OperatorType(); - ASSERT(opEqual != lexer::TokenType::PUNCTUATOR_SUBSTITUTION); - ASSERT(parser != nullptr); + if (loweringResult->IsAssignmentExpression()) { + newAssignment = loweringResult->AsAssignmentExpression(); + } else if (loweringResult->IsBlockExpression()) { + auto stmts = loweringResult->AsBlockExpression()->Statements(); + if (!stmts.empty() && stmts.back()->IsExpressionStatement() && + stmts.back()->AsExpressionStatement()->GetExpression()->IsAssignmentExpression()) { + newAssignment = stmts.back()->AsExpressionStatement()->GetExpression()->AsAssignmentExpression(); + } else { + UNREACHABLE(); + } + } else { + UNREACHABLE(); + } - auto *const allocator = checker->Allocator(); + // NOTE(gogabr): make sure that the checker never puts both a boxing and an unboxing flag on the same node. + // Then this code will become unnecessary. + AdjustBoxingUnboxingFlags(newAssignment, assignment); - auto *const left = assignment->Left(); - auto *const right = assignment->Right(); - auto *const scope = NearestScope(assignment); + return loweringResult; +} - std::string newAssignmentStatements {}; +ir::OpaqueTypeNode *CreateOpaqueTypeNode(public_lib::Context *ctx, checker::Type *lcType) +{ + auto checker = ctx->checker->AsETSChecker(); + // Create proxy TypeNode for left hand of assignment expression + if (auto *lcTypeAsPrimitive = checker->ETSBuiltinTypeAsPrimitiveType(lcType); lcTypeAsPrimitive != nullptr) { + lcType = lcTypeAsPrimitive; + } + return checker->AllocNode(lcType); +} - ir::Identifier *ident1; +std::tuple CreateTemporaryVar( + ir::Expression *left, ArenaAllocator *allocator) +{ + std::string newStatements {}; + ir::Identifier *ident1 = nullptr; ir::Identifier *ident2 = nullptr; ir::Expression *object = nullptr; ir::Expression *property = nullptr; - - checker::SavedCheckerContext scc {checker, checker::CheckerStatus::IGNORE_VISIBILITY}; - // Create temporary variable(s) if left hand of assignment is not defined by simple identifier[s] if (left->IsIdentifier()) { ident1 = left->AsIdentifier(); @@ -123,26 +142,23 @@ ir::Expression *HandleOpAssignment(public_lib::Context *ctx, checker::ETSChecker ident1 = object->AsIdentifier(); } else { ident1 = Gensym(allocator); - newAssignmentStatements = "let @@I1 = (@@E2); "; + newStatements = "let @@I1 = (@@E2); "; } if (property = memberExpression->Property(); property->IsIdentifier()) { ident2 = property->AsIdentifier(); } else { ident2 = Gensym(allocator); - newAssignmentStatements += "let @@I3 = (@@E4); "; + newStatements += "let @@I3 = (@@E4); "; } } else { UNREACHABLE(); } + return std::make_tuple(ident1, ident2, object, property, newStatements); +} - // Create proxy TypeNode for left hand of assignment expression - auto *lcType = left->TsType(); - if (auto *lcTypeAsPrimitive = checker->ETSBuiltinTypeAsPrimitiveType(lcType); lcTypeAsPrimitive != nullptr) { - lcType = lcTypeAsPrimitive; - } - auto *exprType = checker->AllocNode(lcType); - +std::tuple GenerateCodeStringForExpression(ir::Identifier *ident2, ir::Expression *left) +{ // Generate ArkTS code string for new lowered assignment expression: std::string leftHand = "@@I5"; std::string rightHand = "@@I7"; @@ -158,51 +174,42 @@ ir::Expression *HandleOpAssignment(public_lib::Context *ctx, checker::ETSChecker UNREACHABLE(); } } + return std::make_tuple(leftHand, rightHand); +} + +ir::Expression *HandleOpAssignment(public_lib::Context *ctx, checker::ETSChecker *checker, parser::ETSParser *parser, + ArenaAllocator *allocator, ir::AssignmentExpression *assignment) +{ + const auto opEqual = assignment->OperatorType(); + ASSERT(opEqual != lexer::TokenType::PUNCTUATOR_SUBSTITUTION); + + auto *const left = assignment->Left(); + auto *const right = assignment->Right(); + auto *const scope = NearestScope(assignment); + + checker::SavedCheckerContext scc {checker, checker::CheckerStatus::IGNORE_VISIBILITY}; + + // Create temporary variable(s) if left hand of assignment is not defined by simple identifier[s] + auto [ident1, ident2, object, property, newAssignmentStatements] = CreateTemporaryVar(left, allocator); + // Generate ArkTS code string for new lowered assignment expression: + auto [leftHand, rightHand] = GenerateCodeStringForExpression(ident2, left); newAssignmentStatements += leftHand + " = (" + rightHand + ' ' + std::string {lexer::TokenToString(OpEqualToOp(opEqual))} + " (@@E9)) as @@T10"; - // std::cout << "Lowering statements: " << new_assignment_statements << std::endl; - - // Parse ArkTS code string and create and process corresponding AST node(s) auto expressionCtx = varbinder::LexicalScope::Enter(checker->VarBinder(), scope); auto *loweringResult = parser->CreateFormattedExpression( newAssignmentStatements, parser::DEFAULT_SOURCE_FILE, ident1, object, ident2, property, - ident1->Clone(allocator), ident2 != nullptr ? ident2->Clone(allocator) : nullptr, ident1->Clone(allocator), - ident2 != nullptr ? ident2->Clone(allocator) : nullptr, right, exprType); + ident1->Clone(allocator, nullptr), ident2 != nullptr ? ident2->Clone(allocator, nullptr) : nullptr, + ident1->Clone(allocator, nullptr), ident2 != nullptr ? ident2->Clone(allocator, nullptr) : nullptr, right, + CreateOpaqueTypeNode(ctx, left->TsType())); loweringResult->SetParent(assignment->Parent()); InitScopesPhaseETS::RunExternalNode(loweringResult, ctx->compilerContext->VarBinder()); checker->VarBinder()->AsETSBinder()->ResolveReferencesForScope(loweringResult, scope); loweringResult->Check(checker); - // Adjust [un]boxing flag - ir::AssignmentExpression *newAssignment; - if (loweringResult->IsAssignmentExpression()) { - newAssignment = loweringResult->AsAssignmentExpression(); - } else if (loweringResult->IsBlockExpression() && !loweringResult->AsBlockExpression()->Statements().empty() && - loweringResult->AsBlockExpression()->Statements().back()->IsExpressionStatement() && - loweringResult->AsBlockExpression() - ->Statements() - .back() - ->AsExpressionStatement() - ->GetExpression() - ->IsAssignmentExpression()) { - newAssignment = loweringResult->AsBlockExpression() - ->Statements() - .back() - ->AsExpressionStatement() - ->GetExpression() - ->AsAssignmentExpression(); - } else { - UNREACHABLE(); - } - - // NOTE(gogabr): make sure that the checker never puts both a boxing and an unboxing flag on the same node. - // Then this code will become unnecessary. - AdjustBoxingUnboxingFlags(newAssignment, assignment); - - return loweringResult; + return CreateLoweringResult(ctx, assignment, loweringResult); } bool OpAssignmentLowering::Perform(public_lib::Context *ctx, parser::Program *program) @@ -217,12 +224,15 @@ bool OpAssignmentLowering::Perform(public_lib::Context *ctx, parser::Program *pr } auto *const parser = ctx->parser->AsETSParser(); + ASSERT(parser != nullptr); checker::ETSChecker *checker = ctx->checker->AsETSChecker(); program->Ast()->TransformChildrenRecursively([ctx, checker, parser](ir::AstNode *ast) -> ir::AstNode * { if (ast->IsAssignmentExpression() && ast->AsAssignmentExpression()->OperatorType() != lexer::TokenType::PUNCTUATOR_SUBSTITUTION) { - return HandleOpAssignment(ctx, checker, parser, ast->AsAssignmentExpression()); + if (ast->AsAssignmentExpression()->TsType() != nullptr) { // hasn't been through checker + return HandleOpAssignment(ctx, checker, parser, checker->Allocator(), ast->AsAssignmentExpression()); + } } return ast; diff --git a/ets2panda/compiler/lowering/ets/unionLowering.cpp b/ets2panda/compiler/lowering/ets/unionLowering.cpp index ef64447b69..ecc6333715 100644 --- a/ets2panda/compiler/lowering/ets/unionLowering.cpp +++ b/ets2panda/compiler/lowering/ets/unionLowering.cpp @@ -167,7 +167,7 @@ ir::TSAsExpression *HandleUnionCastToPrimitive(checker::ETSChecker *checker, ir: ir::BinaryExpression *GenInstanceofExpr(checker::ETSChecker *checker, ir::Expression *unionNode, checker::Type *constituentType) { - auto *const lhsExpr = unionNode->Clone(checker->Allocator())->AsExpression(); + auto *const lhsExpr = unionNode->Clone(checker->Allocator(), nullptr)->AsExpression(); lhsExpr->Check(checker); lhsExpr->SetBoxingUnboxingFlags(unionNode->GetBoxingUnboxingFlags()); auto *rhsType = constituentType; diff --git a/ets2panda/ir/astNode.h b/ets2panda/ir/astNode.h index 4b20f93db3..3075935b3a 100644 --- a/ets2panda/ir/astNode.h +++ b/ets2panda/ir/astNode.h @@ -484,9 +484,8 @@ public: [[nodiscard]] ir::BlockStatement *GetTopStatement(); [[nodiscard]] const ir::BlockStatement *GetTopStatement() const; - // NOLINTNEXTLINE(google-default-arguments) [[nodiscard]] virtual AstNode *Clone([[maybe_unused]] ArenaAllocator *const allocator, - [[maybe_unused]] AstNode *const parent = nullptr) + [[maybe_unused]] AstNode *const parent) { UNREACHABLE(); } diff --git a/ets2panda/ir/base/classProperty.cpp b/ets2panda/ir/base/classProperty.cpp index 9d97cafada..6c70b74bef 100644 --- a/ets2panda/ir/base/classProperty.cpp +++ b/ets2panda/ir/base/classProperty.cpp @@ -136,11 +136,10 @@ checker::Type *ClassProperty::Check(checker::ETSChecker *checker) return checker->GetAnalyzer()->Check(this); } -// NOLINTNEXTLINE(google-default-arguments) ClassProperty *ClassProperty::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const key = key_->Clone(allocator)->AsExpression(); - auto *const value = value_->Clone(allocator)->AsExpression(); + auto *const key = key_->Clone(allocator, nullptr)->AsExpression(); + auto *const value = value_->Clone(allocator, nullptr)->AsExpression(); auto *const typeAnnotation = typeAnnotation_->Clone(allocator, this); if (auto *const clone = allocator->New(key, value, typeAnnotation, flags_, allocator, isComputed_); diff --git a/ets2panda/ir/base/classProperty.h b/ets2panda/ir/base/classProperty.h index 25ac075f90..0f2c7d5ba3 100644 --- a/ets2panda/ir/base/classProperty.h +++ b/ets2panda/ir/base/classProperty.h @@ -51,8 +51,7 @@ public: return isStatic ? PrivateFieldKind::STATIC_FIELD : PrivateFieldKind::FIELD; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] ClassProperty *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] ClassProperty *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/base/decorator.cpp b/ets2panda/ir/base/decorator.cpp index eed3b5f6db..4ae382fa25 100644 --- a/ets2panda/ir/base/decorator.cpp +++ b/ets2panda/ir/base/decorator.cpp @@ -65,10 +65,9 @@ checker::Type *Decorator::Check(checker::ETSChecker *checker) return checker->GetAnalyzer()->Check(this); } -// NOLINTNEXTLINE(google-default-arguments) Decorator *Decorator::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const expr = expr_ != nullptr ? expr_->Clone(allocator)->AsExpression() : nullptr; + auto *const expr = expr_ != nullptr ? expr_->Clone(allocator, nullptr)->AsExpression() : nullptr; if (auto *const clone = allocator->New(expr); clone != nullptr) { if (expr != nullptr) { diff --git a/ets2panda/ir/base/decorator.h b/ets2panda/ir/base/decorator.h index dfbcc9027c..779e08c90c 100644 --- a/ets2panda/ir/base/decorator.h +++ b/ets2panda/ir/base/decorator.h @@ -36,8 +36,7 @@ public: return expr_; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Decorator *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] Decorator *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/base/metaProperty.cpp b/ets2panda/ir/base/metaProperty.cpp index a5208db90f..bf4cb3a214 100644 --- a/ets2panda/ir/base/metaProperty.cpp +++ b/ets2panda/ir/base/metaProperty.cpp @@ -71,7 +71,6 @@ checker::Type *MetaProperty::Check(checker::ETSChecker *checker) return checker->GetAnalyzer()->Check(this); } -// NOLINTNEXTLINE(google-default-arguments) MetaProperty *MetaProperty::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(kind_); clone != nullptr) { diff --git a/ets2panda/ir/base/metaProperty.h b/ets2panda/ir/base/metaProperty.h index c5eb1bb844..369b6ba66b 100644 --- a/ets2panda/ir/base/metaProperty.h +++ b/ets2panda/ir/base/metaProperty.h @@ -43,8 +43,7 @@ public: void TransformChildren(const NodeTransformer &cb) override; - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] MetaProperty *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] MetaProperty *Clone(ArenaAllocator *allocator, AstNode *parent) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; diff --git a/ets2panda/ir/base/methodDefinition.cpp b/ets2panda/ir/base/methodDefinition.cpp index 9ab31f5844..c30e7536cf 100644 --- a/ets2panda/ir/base/methodDefinition.cpp +++ b/ets2panda/ir/base/methodDefinition.cpp @@ -192,11 +192,10 @@ checker::Type *MethodDefinition::Check(checker::ETSChecker *checker) return checker->GetAnalyzer()->Check(this); } -// NOLINTNEXTLINE(google-default-arguments) MethodDefinition *MethodDefinition::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const key = key_ != nullptr ? key_->Clone(allocator)->AsExpression() : nullptr; - auto *const value = value_ != nullptr ? value_->Clone(allocator)->AsExpression() : nullptr; + auto *const key = key_ != nullptr ? key_->Clone(allocator, nullptr)->AsExpression() : nullptr; + auto *const value = value_ != nullptr ? value_->Clone(allocator, nullptr)->AsExpression() : nullptr; if (auto *const clone = allocator->New(kind_, key, value, flags_, allocator, isComputed_); clone != nullptr) { diff --git a/ets2panda/ir/base/methodDefinition.h b/ets2panda/ir/base/methodDefinition.h index d3a314df0b..906301cac4 100644 --- a/ets2panda/ir/base/methodDefinition.h +++ b/ets2panda/ir/base/methodDefinition.h @@ -104,8 +104,7 @@ public: const ScriptFunction *Function() const; PrivateFieldKind ToPrivateFieldKind(bool isStatic) const override; - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] MethodDefinition *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] MethodDefinition *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/base/property.cpp b/ets2panda/ir/base/property.cpp index c6811cba02..d70ba1108c 100644 --- a/ets2panda/ir/base/property.cpp +++ b/ets2panda/ir/base/property.cpp @@ -31,11 +31,10 @@ Property::Property([[maybe_unused]] Tag const tag, Property const &other, Expres value_ = value; } -// NOLINTNEXTLINE(google-default-arguments) Property *Property::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const key = key_ != nullptr ? key_->Clone(allocator)->AsExpression() : nullptr; - auto *const value = value_ != nullptr ? value_->Clone(allocator)->AsExpression() : nullptr; + auto *const key = key_ != nullptr ? key_->Clone(allocator, nullptr)->AsExpression() : nullptr; + auto *const value = value_ != nullptr ? value_->Clone(allocator, nullptr)->AsExpression() : nullptr; if (auto *const clone = allocator->New(Tag {}, *this, key, value); clone != nullptr) { if (key != nullptr) { diff --git a/ets2panda/ir/base/property.h b/ets2panda/ir/base/property.h index d643644cfb..ccfdde132f 100644 --- a/ets2panda/ir/base/property.h +++ b/ets2panda/ir/base/property.h @@ -102,8 +102,7 @@ public: return kind == PropertyKind::GET || kind == PropertyKind::SET; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Property *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] Property *Clone(ArenaAllocator *allocator, AstNode *parent) override; bool ConvertibleToPatternProperty(); ValidationInfo ValidateExpression(); diff --git a/ets2panda/ir/base/spreadElement.cpp b/ets2panda/ir/base/spreadElement.cpp index f66d003679..c9d519118e 100644 --- a/ets2panda/ir/base/spreadElement.cpp +++ b/ets2panda/ir/base/spreadElement.cpp @@ -42,7 +42,6 @@ SpreadElement::SpreadElement([[maybe_unused]] Tag const tag, SpreadElement const } } -// NOLINTNEXTLINE(google-default-arguments) SpreadElement *SpreadElement::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(Tag {}, *this, allocator); clone != nullptr) { diff --git a/ets2panda/ir/base/spreadElement.h b/ets2panda/ir/base/spreadElement.h index 939f60c975..40c8b0dbe6 100644 --- a/ets2panda/ir/base/spreadElement.h +++ b/ets2panda/ir/base/spreadElement.h @@ -78,8 +78,7 @@ public: optional_ = optional; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] SpreadElement *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] SpreadElement *Clone(ArenaAllocator *allocator, AstNode *parent) override; ValidationInfo ValidateExpression(); [[nodiscard]] bool ConvertibleToRest(bool isDeclaration, bool allowPattern = true); diff --git a/ets2panda/ir/base/templateElement.cpp b/ets2panda/ir/base/templateElement.cpp index 8816ba413c..09a61236ab 100644 --- a/ets2panda/ir/base/templateElement.cpp +++ b/ets2panda/ir/base/templateElement.cpp @@ -58,7 +58,6 @@ checker::Type *TemplateElement::Check(checker::ETSChecker *checker) return checker->GetAnalyzer()->Check(this); } -// NOLINTNEXTLINE(google-default-arguments) TemplateElement *TemplateElement::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(raw_, cooked_); clone != nullptr) { diff --git a/ets2panda/ir/base/templateElement.h b/ets2panda/ir/base/templateElement.h index 85154cdd14..45f96e6202 100644 --- a/ets2panda/ir/base/templateElement.h +++ b/ets2panda/ir/base/templateElement.h @@ -44,8 +44,7 @@ public: return cooked_; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] TemplateElement *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] TemplateElement *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/base/tsIndexSignature.cpp b/ets2panda/ir/base/tsIndexSignature.cpp index c85adb93c7..a878eeb13a 100644 --- a/ets2panda/ir/base/tsIndexSignature.cpp +++ b/ets2panda/ir/base/tsIndexSignature.cpp @@ -72,11 +72,10 @@ checker::Type *TSIndexSignature::Check(checker::ETSChecker *checker) return checker->GetAnalyzer()->Check(this); } -// NOLINTNEXTLINE(google-default-arguments) TSIndexSignature *TSIndexSignature::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const param = param_ != nullptr ? param_->Clone(allocator)->AsExpression() : nullptr; - auto *const typeAnnotation = typeAnnotation_->Clone(allocator); + auto *const param = param_ != nullptr ? param_->Clone(allocator, nullptr)->AsExpression() : nullptr; + auto *const typeAnnotation = typeAnnotation_->Clone(allocator, nullptr); if (auto *const clone = allocator->New(param, typeAnnotation, readonly_); clone != nullptr) { if (parent != nullptr) { diff --git a/ets2panda/ir/base/tsIndexSignature.h b/ets2panda/ir/base/tsIndexSignature.h index cff8d5fd21..9b1b1c1d29 100644 --- a/ets2panda/ir/base/tsIndexSignature.h +++ b/ets2panda/ir/base/tsIndexSignature.h @@ -60,8 +60,7 @@ public: [[nodiscard]] TSIndexSignatureKind Kind() const noexcept; - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] TSIndexSignature *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] TSIndexSignature *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/base/tsPropertySignature.cpp b/ets2panda/ir/base/tsPropertySignature.cpp index 4dd052b5d6..49c0ac995c 100644 --- a/ets2panda/ir/base/tsPropertySignature.cpp +++ b/ets2panda/ir/base/tsPropertySignature.cpp @@ -74,11 +74,10 @@ checker::Type *TSPropertySignature::Check(checker::ETSChecker *checker) return checker->GetAnalyzer()->Check(this); } -// NOLINTNEXTLINE(google-default-arguments) TSPropertySignature *TSPropertySignature::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const key = key_ != nullptr ? key_->Clone(allocator)->AsExpression() : nullptr; - auto *const typeAnnotation = TypeAnnotation()->Clone(allocator); + auto *const key = key_ != nullptr ? key_->Clone(allocator, nullptr)->AsExpression() : nullptr; + auto *const typeAnnotation = TypeAnnotation()->Clone(allocator, nullptr); if (auto *const clone = allocator->New(key, typeAnnotation, computed_, optional_, readonly_); clone != nullptr) { diff --git a/ets2panda/ir/base/tsPropertySignature.h b/ets2panda/ir/base/tsPropertySignature.h index c3a0f73429..8171be38e4 100644 --- a/ets2panda/ir/base/tsPropertySignature.h +++ b/ets2panda/ir/base/tsPropertySignature.h @@ -63,8 +63,7 @@ public: return readonly_; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] TSPropertySignature *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] TSPropertySignature *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/ets/etsClassLiteral.cpp b/ets2panda/ir/ets/etsClassLiteral.cpp index ad0eabe305..787e96b377 100644 --- a/ets2panda/ir/ets/etsClassLiteral.cpp +++ b/ets2panda/ir/ets/etsClassLiteral.cpp @@ -62,10 +62,9 @@ checker::Type *ETSClassLiteral::Check(checker::ETSChecker *checker) return checker->GetAnalyzer()->Check(this); } -// NOLINTNEXTLINE(google-default-arguments) ETSClassLiteral *ETSClassLiteral::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const expr = expr_ != nullptr ? expr_->Clone(allocator) : nullptr; + auto *const expr = expr_ != nullptr ? expr_->Clone(allocator, nullptr) : nullptr; if (auto *const clone = allocator->New(expr); clone != nullptr) { if (expr != nullptr) { diff --git a/ets2panda/ir/ets/etsClassLiteral.h b/ets2panda/ir/ets/etsClassLiteral.h index 592f3536fd..d52bf955f6 100644 --- a/ets2panda/ir/ets/etsClassLiteral.h +++ b/ets2panda/ir/ets/etsClassLiteral.h @@ -38,8 +38,7 @@ public: explicit ETSClassLiteral(ir::TypeNode *const expr) : Expression(AstNodeType::ETS_CLASS_LITERAL), expr_(expr) {} - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] ETSClassLiteral *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] ETSClassLiteral *Clone(ArenaAllocator *allocator, AstNode *parent) override; // NOTE (csabahurton): these friend relationships can be removed once there are getters for private fields friend class checker::ETSAnalyzer; diff --git a/ets2panda/ir/ets/etsFunctionType.cpp b/ets2panda/ir/ets/etsFunctionType.cpp index 0eec9494ff..d2e0888bae 100644 --- a/ets2panda/ir/ets/etsFunctionType.cpp +++ b/ets2panda/ir/ets/etsFunctionType.cpp @@ -97,20 +97,20 @@ checker::Type *ETSFunctionType::GetType(checker::ETSChecker *checker) return Check(checker); } -// NOLINTNEXTLINE(google-default-arguments) ETSFunctionType *ETSFunctionType::Clone(ArenaAllocator *const allocator, AstNode *const parent) { ArenaVector paramsClone(allocator->Adapter()); for (auto *const param : signature_.Params()) { - paramsClone.emplace_back(param->Clone(allocator)->AsExpression()); + paramsClone.emplace_back(param->Clone(allocator, nullptr)->AsExpression()); } - auto *const typeParamsClone = signature_.TypeParams() != nullptr - ? signature_.TypeParams()->Clone(allocator)->AsTSTypeParameterDeclaration() - : nullptr; + auto *const typeParamsClone = + signature_.TypeParams() != nullptr + ? signature_.TypeParams()->Clone(allocator, nullptr)->AsTSTypeParameterDeclaration() + : nullptr; auto *const returnTypeClone = - signature_.ReturnType() != nullptr ? signature_.ReturnType()->Clone(allocator)->AsTypeNode() : nullptr; + signature_.ReturnType() != nullptr ? signature_.ReturnType()->Clone(allocator, nullptr)->AsTypeNode() : nullptr; if (auto *const clone = allocator->New( FunctionSignature(typeParamsClone, std::move(paramsClone), returnTypeClone), funcFlags_); diff --git a/ets2panda/ir/ets/etsFunctionType.h b/ets2panda/ir/ets/etsFunctionType.h index 42f7323db5..027a6941fc 100644 --- a/ets2panda/ir/ets/etsFunctionType.h +++ b/ets2panda/ir/ets/etsFunctionType.h @@ -109,8 +109,7 @@ public: v->Accept(this); } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] ETSFunctionType *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] ETSFunctionType *Clone(ArenaAllocator *allocator, AstNode *parent) override; private: varbinder::Scope *scope_ {}; diff --git a/ets2panda/ir/ets/etsLaunchExpression.cpp b/ets2panda/ir/ets/etsLaunchExpression.cpp index a492c7c3f2..3805370754 100644 --- a/ets2panda/ir/ets/etsLaunchExpression.cpp +++ b/ets2panda/ir/ets/etsLaunchExpression.cpp @@ -75,10 +75,9 @@ bool ETSLaunchExpression::IsStaticCall() const return expr_->Signature()->HasSignatureFlag(checker::SignatureFlags::STATIC); } -// NOLINTNEXTLINE(google-default-arguments) ETSLaunchExpression *ETSLaunchExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const expr = expr_ != nullptr ? expr_->Clone(allocator) : nullptr; + auto *const expr = expr_ != nullptr ? expr_->Clone(allocator, nullptr) : nullptr; if (auto *const clone = allocator->New(expr); clone != nullptr) { if (expr != nullptr) { diff --git a/ets2panda/ir/ets/etsLaunchExpression.h b/ets2panda/ir/ets/etsLaunchExpression.h index 5f41d342c8..eee51886e9 100644 --- a/ets2panda/ir/ets/etsLaunchExpression.h +++ b/ets2panda/ir/ets/etsLaunchExpression.h @@ -44,8 +44,7 @@ public: friend class checker::ETSAnalyzer; friend class compiler::ETSCompiler; - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] ETSLaunchExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] ETSLaunchExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/ets/etsNewArrayInstanceExpression.cpp b/ets2panda/ir/ets/etsNewArrayInstanceExpression.cpp index 71277d9384..b5f892f7e1 100644 --- a/ets2panda/ir/ets/etsNewArrayInstanceExpression.cpp +++ b/ets2panda/ir/ets/etsNewArrayInstanceExpression.cpp @@ -72,12 +72,11 @@ checker::Type *ETSNewArrayInstanceExpression::Check(checker::ETSChecker *checker return checker->GetAnalyzer()->Check(this); } -// NOLINTNEXTLINE(google-default-arguments) ETSNewArrayInstanceExpression *ETSNewArrayInstanceExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const typeRef = typeReference_ != nullptr ? typeReference_->Clone(allocator) : nullptr; - auto *const dimension = dimension_ != nullptr ? dimension_->Clone(allocator)->AsExpression() : nullptr; + auto *const typeRef = typeReference_ != nullptr ? typeReference_->Clone(allocator, nullptr) : nullptr; + auto *const dimension = dimension_ != nullptr ? dimension_->Clone(allocator, nullptr)->AsExpression() : nullptr; if (auto *const clone = allocator->New(allocator, typeRef, dimension); clone != nullptr) { diff --git a/ets2panda/ir/ets/etsNewArrayInstanceExpression.h b/ets2panda/ir/ets/etsNewArrayInstanceExpression.h index e1f121eaee..b44afebdd0 100644 --- a/ets2panda/ir/ets/etsNewArrayInstanceExpression.h +++ b/ets2panda/ir/ets/etsNewArrayInstanceExpression.h @@ -74,8 +74,7 @@ public: dimension_ = dimension; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] ETSNewArrayInstanceExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] ETSNewArrayInstanceExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/ets/etsNewClassInstanceExpression.cpp b/ets2panda/ir/ets/etsNewClassInstanceExpression.cpp index c85d7639ca..c0c75152a5 100644 --- a/ets2panda/ir/ets/etsNewClassInstanceExpression.cpp +++ b/ets2panda/ir/ets/etsNewClassInstanceExpression.cpp @@ -104,7 +104,6 @@ ETSNewClassInstanceExpression::ETSNewClassInstanceExpression(ETSNewClassInstance } } -// NOLINTNEXTLINE(google-default-arguments) ETSNewClassInstanceExpression *ETSNewClassInstanceExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { diff --git a/ets2panda/ir/ets/etsNewClassInstanceExpression.h b/ets2panda/ir/ets/etsNewClassInstanceExpression.h index 6cbef0d123..4df829352a 100644 --- a/ets2panda/ir/ets/etsNewClassInstanceExpression.h +++ b/ets2panda/ir/ets/etsNewClassInstanceExpression.h @@ -85,8 +85,7 @@ public: signature_ = signature; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] ETSNewClassInstanceExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] ETSNewClassInstanceExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/ets/etsNewMultiDimArrayInstanceExpression.cpp b/ets2panda/ir/ets/etsNewMultiDimArrayInstanceExpression.cpp index 4b2bc1500d..a4ab86f944 100644 --- a/ets2panda/ir/ets/etsNewMultiDimArrayInstanceExpression.cpp +++ b/ets2panda/ir/ets/etsNewMultiDimArrayInstanceExpression.cpp @@ -90,7 +90,6 @@ ETSNewMultiDimArrayInstanceExpression::ETSNewMultiDimArrayInstanceExpression( } } -// NOLINTNEXTLINE(google-default-arguments) ETSNewMultiDimArrayInstanceExpression *ETSNewMultiDimArrayInstanceExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { diff --git a/ets2panda/ir/ets/etsNewMultiDimArrayInstanceExpression.h b/ets2panda/ir/ets/etsNewMultiDimArrayInstanceExpression.h index 825aae727d..993a655807 100644 --- a/ets2panda/ir/ets/etsNewMultiDimArrayInstanceExpression.h +++ b/ets2panda/ir/ets/etsNewMultiDimArrayInstanceExpression.h @@ -81,9 +81,7 @@ public: return signature_; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] ETSNewMultiDimArrayInstanceExpression *Clone(ArenaAllocator *allocator, - AstNode *parent = nullptr) override; + [[nodiscard]] ETSNewMultiDimArrayInstanceExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/ets/etsPackageDeclaration.cpp b/ets2panda/ir/ets/etsPackageDeclaration.cpp index 27a44e419c..d321134e91 100644 --- a/ets2panda/ir/ets/etsPackageDeclaration.cpp +++ b/ets2panda/ir/ets/etsPackageDeclaration.cpp @@ -64,7 +64,6 @@ checker::Type *ETSPackageDeclaration::Check(checker::ETSChecker *checker) return checker->GetAnalyzer()->Check(this); } -// NOLINTNEXTLINE(google-default-arguments) ETSPackageDeclaration *ETSPackageDeclaration::Clone(ArenaAllocator *const allocator, AstNode *const parent) { auto const name = name_ != nullptr ? name_->Clone(allocator, this)->AsExpression() : nullptr; diff --git a/ets2panda/ir/ets/etsPackageDeclaration.h b/ets2panda/ir/ets/etsPackageDeclaration.h index 88d51f0c08..98463a9102 100644 --- a/ets2panda/ir/ets/etsPackageDeclaration.h +++ b/ets2panda/ir/ets/etsPackageDeclaration.h @@ -33,8 +33,7 @@ public: { } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] ETSPackageDeclaration *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] ETSPackageDeclaration *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/ets/etsParameterExpression.cpp b/ets2panda/ir/ets/etsParameterExpression.cpp index 7b808c79c3..7ffa81c823 100644 --- a/ets2panda/ir/ets/etsParameterExpression.cpp +++ b/ets2panda/ir/ets/etsParameterExpression.cpp @@ -187,12 +187,12 @@ checker::Type *ETSParameterExpression::Check(checker::ETSChecker *const checker) return checker->GetAnalyzer()->Check(this); } -// NOLINTNEXTLINE(google-default-arguments) ETSParameterExpression *ETSParameterExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const identOrSpread = spread_ != nullptr ? spread_->Clone(allocator)->AsAnnotatedExpression() - : ident_->Clone(allocator)->AsAnnotatedExpression(); - auto *const initializer = initializer_ != nullptr ? initializer_->Clone(allocator)->AsExpression() : nullptr; + auto *const identOrSpread = spread_ != nullptr ? spread_->Clone(allocator, nullptr)->AsAnnotatedExpression() + : ident_->Clone(allocator, nullptr)->AsAnnotatedExpression(); + auto *const initializer = + initializer_ != nullptr ? initializer_->Clone(allocator, nullptr)->AsExpression() : nullptr; if (auto *const clone = allocator->New(identOrSpread, initializer); clone != nullptr) { identOrSpread->SetParent(clone); diff --git a/ets2panda/ir/ets/etsParameterExpression.h b/ets2panda/ir/ets/etsParameterExpression.h index aedc3e7166..ec6fde41a5 100644 --- a/ets2panda/ir/ets/etsParameterExpression.h +++ b/ets2panda/ir/ets/etsParameterExpression.h @@ -78,8 +78,7 @@ public: extraValue_ = value; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] ETSParameterExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] ETSParameterExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; void Iterate(const NodeTraverser &cb) const override; void TransformChildren(const NodeTransformer &cb) override; diff --git a/ets2panda/ir/ets/etsPrimitiveType.cpp b/ets2panda/ir/ets/etsPrimitiveType.cpp index bfc3562cfa..c4d2449538 100644 --- a/ets2panda/ir/ets/etsPrimitiveType.cpp +++ b/ets2panda/ir/ets/etsPrimitiveType.cpp @@ -132,7 +132,6 @@ checker::Type *ETSPrimitiveType::GetType([[maybe_unused]] checker::ETSChecker *c } } -// NOLINTNEXTLINE(google-default-arguments) ETSPrimitiveType *ETSPrimitiveType::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(type_); clone != nullptr) { diff --git a/ets2panda/ir/ets/etsPrimitiveType.h b/ets2panda/ir/ets/etsPrimitiveType.h index b2ad1451df..2fb0d55172 100644 --- a/ets2panda/ir/ets/etsPrimitiveType.h +++ b/ets2panda/ir/ets/etsPrimitiveType.h @@ -46,8 +46,7 @@ public: v->Accept(this); } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] ETSPrimitiveType *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] ETSPrimitiveType *Clone(ArenaAllocator *allocator, AstNode *parent) override; private: PrimitiveType type_; diff --git a/ets2panda/ir/ets/etsStructDeclaration.cpp b/ets2panda/ir/ets/etsStructDeclaration.cpp index 37026f4a62..8e5038efe7 100644 --- a/ets2panda/ir/ets/etsStructDeclaration.cpp +++ b/ets2panda/ir/ets/etsStructDeclaration.cpp @@ -75,7 +75,6 @@ checker::Type *ETSStructDeclaration::Check(checker::ETSChecker *checker) return checker->GetAnalyzer()->Check(this); } -// NOLINTNEXTLINE(google-default-arguments) ETSStructDeclaration *ETSStructDeclaration::Clone(ArenaAllocator *const allocator, AstNode *const parent) { auto *const def = def_ != nullptr ? def_->Clone(allocator, this)->AsClassDefinition() : nullptr; diff --git a/ets2panda/ir/ets/etsStructDeclaration.h b/ets2panda/ir/ets/etsStructDeclaration.h index b7d6176e72..f16200a8dd 100644 --- a/ets2panda/ir/ets/etsStructDeclaration.h +++ b/ets2panda/ir/ets/etsStructDeclaration.h @@ -67,8 +67,7 @@ public: return true; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] ETSStructDeclaration *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] ETSStructDeclaration *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/ets/etsTypeReference.cpp b/ets2panda/ir/ets/etsTypeReference.cpp index b65b9a68d6..1f9adbd3c9 100644 --- a/ets2panda/ir/ets/etsTypeReference.cpp +++ b/ets2panda/ir/ets/etsTypeReference.cpp @@ -107,10 +107,9 @@ checker::Type *ETSTypeReference::GetType(checker::ETSChecker *checker) return type; } -// NOLINTNEXTLINE(google-default-arguments) ETSTypeReference *ETSTypeReference::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const partClone = part_ != nullptr ? part_->Clone(allocator)->AsETSTypeReferencePart() : nullptr; + auto *const partClone = part_ != nullptr ? part_->Clone(allocator, nullptr)->AsETSTypeReferencePart() : nullptr; if (auto *const clone = allocator->New(partClone); clone != nullptr) { if (partClone != nullptr) { diff --git a/ets2panda/ir/ets/etsTypeReference.h b/ets2panda/ir/ets/etsTypeReference.h index d67d7f49ac..dfcecf74bb 100644 --- a/ets2panda/ir/ets/etsTypeReference.h +++ b/ets2panda/ir/ets/etsTypeReference.h @@ -53,8 +53,7 @@ public: v->Accept(this); } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] ETSTypeReference *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] ETSTypeReference *Clone(ArenaAllocator *allocator, AstNode *parent) override; private: ir::ETSTypeReferencePart *part_; diff --git a/ets2panda/ir/ets/etsTypeReferencePart.cpp b/ets2panda/ir/ets/etsTypeReferencePart.cpp index 792e942e8c..d3efd9574b 100644 --- a/ets2panda/ir/ets/etsTypeReferencePart.cpp +++ b/ets2panda/ir/ets/etsTypeReferencePart.cpp @@ -110,13 +110,12 @@ checker::Type *ETSTypeReferencePart::GetType(checker::ETSChecker *checker) return checker->GetReferencedTypeFromBase(baseType, name_); } -// NOLINTNEXTLINE(google-default-arguments) ETSTypeReferencePart *ETSTypeReferencePart::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const nameClone = name_ != nullptr ? name_->Clone(allocator)->AsExpression() : nullptr; + auto *const nameClone = name_ != nullptr ? name_->Clone(allocator, nullptr)->AsExpression() : nullptr; auto *const typeParamsClone = - typeParams_ != nullptr ? typeParams_->Clone(allocator)->AsTSTypeParameterInstantiation() : nullptr; - auto *const prevClone = prev_ != nullptr ? prev_->Clone(allocator)->AsETSTypeReferencePart() : nullptr; + typeParams_ != nullptr ? typeParams_->Clone(allocator, nullptr)->AsTSTypeParameterInstantiation() : nullptr; + auto *const prevClone = prev_ != nullptr ? prev_->Clone(allocator, nullptr)->AsETSTypeReferencePart() : nullptr; if (auto *const clone = allocator->New(nameClone, typeParamsClone, prevClone); clone != nullptr) { if (nameClone != nullptr) { diff --git a/ets2panda/ir/ets/etsTypeReferencePart.h b/ets2panda/ir/ets/etsTypeReferencePart.h index ab785f6f9c..4493d56307 100644 --- a/ets2panda/ir/ets/etsTypeReferencePart.h +++ b/ets2panda/ir/ets/etsTypeReferencePart.h @@ -70,8 +70,7 @@ public: v->Accept(this); } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] ETSTypeReferencePart *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] ETSTypeReferencePart *Clone(ArenaAllocator *allocator, AstNode *parent) override; private: ir::Expression *name_; diff --git a/ets2panda/ir/expressions/arrayExpression.cpp b/ets2panda/ir/expressions/arrayExpression.cpp index 294f8f23ae..653b922f98 100644 --- a/ets2panda/ir/expressions/arrayExpression.cpp +++ b/ets2panda/ir/expressions/arrayExpression.cpp @@ -53,7 +53,6 @@ ArrayExpression::ArrayExpression([[maybe_unused]] Tag const tag, ArrayExpression } } -// NOLINTNEXTLINE(google-default-arguments) ArrayExpression *ArrayExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(Tag {}, *this, allocator); clone != nullptr) { diff --git a/ets2panda/ir/expressions/arrayExpression.h b/ets2panda/ir/expressions/arrayExpression.h index 34e834a776..90dfd3e7aa 100644 --- a/ets2panda/ir/expressions/arrayExpression.h +++ b/ets2panda/ir/expressions/arrayExpression.h @@ -119,8 +119,7 @@ public: return true; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] ArrayExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] ArrayExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; [[nodiscard]] bool ConvertibleToArrayPattern(); [[nodiscard]] ValidationInfo ValidateExpression(); diff --git a/ets2panda/ir/expressions/arrowFunctionExpression.cpp b/ets2panda/ir/expressions/arrowFunctionExpression.cpp index 3e4f53a46e..afb8ef46cf 100644 --- a/ets2panda/ir/expressions/arrowFunctionExpression.cpp +++ b/ets2panda/ir/expressions/arrowFunctionExpression.cpp @@ -86,7 +86,6 @@ ArrowFunctionExpression::ArrowFunctionExpression(ArrowFunctionExpression const & } } -// NOLINTNEXTLINE(google-default-arguments) ArrowFunctionExpression *ArrowFunctionExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(*this, allocator); clone != nullptr) { diff --git a/ets2panda/ir/expressions/arrowFunctionExpression.h b/ets2panda/ir/expressions/arrowFunctionExpression.h index c1358a1722..79bc5b379f 100644 --- a/ets2panda/ir/expressions/arrowFunctionExpression.h +++ b/ets2panda/ir/expressions/arrowFunctionExpression.h @@ -83,8 +83,7 @@ public: propagateThis_ = true; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] ArrowFunctionExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] ArrowFunctionExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/assignmentExpression.cpp b/ets2panda/ir/expressions/assignmentExpression.cpp index b4a288a823..ffe10cc0f0 100644 --- a/ets2panda/ir/expressions/assignmentExpression.cpp +++ b/ets2panda/ir/expressions/assignmentExpression.cpp @@ -174,11 +174,10 @@ AssignmentExpression::AssignmentExpression([[maybe_unused]] Tag const tag, Assig } } -// NOLINTNEXTLINE(google-default-arguments) AssignmentExpression *AssignmentExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const left = left_ != nullptr ? left_->Clone(allocator)->AsExpression() : nullptr; - auto *const right = right_ != nullptr ? right_->Clone(allocator)->AsExpression() : nullptr; + auto *const left = left_ != nullptr ? left_->Clone(allocator, nullptr)->AsExpression() : nullptr; + auto *const right = right_ != nullptr ? right_->Clone(allocator, nullptr)->AsExpression() : nullptr; if (auto *const clone = allocator->New(Tag {}, *this, left, right); clone != nullptr) { if (parent != nullptr) { diff --git a/ets2panda/ir/expressions/assignmentExpression.h b/ets2panda/ir/expressions/assignmentExpression.h index ae8eea3397..4077716d10 100644 --- a/ets2panda/ir/expressions/assignmentExpression.h +++ b/ets2panda/ir/expressions/assignmentExpression.h @@ -112,8 +112,7 @@ public: return target_; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] AssignmentExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] AssignmentExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; [[nodiscard]] bool ConvertibleToAssignmentPattern(bool mustBePattern = true); diff --git a/ets2panda/ir/expressions/awaitExpression.cpp b/ets2panda/ir/expressions/awaitExpression.cpp index 5048bd86c4..fa15d9662b 100644 --- a/ets2panda/ir/expressions/awaitExpression.cpp +++ b/ets2panda/ir/expressions/awaitExpression.cpp @@ -66,10 +66,9 @@ checker::Type *AwaitExpression::Check(checker::ETSChecker *checker) return checker->GetAnalyzer()->Check(this); } -// NOLINTNEXTLINE(google-default-arguments) AwaitExpression *AwaitExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const argument = argument_ != nullptr ? argument_->Clone(allocator)->AsExpression() : nullptr; + auto *const argument = argument_ != nullptr ? argument_->Clone(allocator, nullptr)->AsExpression() : nullptr; if (auto *const clone = allocator->New(argument); clone != nullptr) { if (argument != nullptr) { diff --git a/ets2panda/ir/expressions/awaitExpression.h b/ets2panda/ir/expressions/awaitExpression.h index ab1160ad37..5754b7b976 100644 --- a/ets2panda/ir/expressions/awaitExpression.h +++ b/ets2panda/ir/expressions/awaitExpression.h @@ -41,8 +41,7 @@ public: return argument_; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] AwaitExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] AwaitExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/binaryExpression.cpp b/ets2panda/ir/expressions/binaryExpression.cpp index 69de433333..27ba9aba9b 100644 --- a/ets2panda/ir/expressions/binaryExpression.cpp +++ b/ets2panda/ir/expressions/binaryExpression.cpp @@ -75,11 +75,10 @@ checker::Type *BinaryExpression::Check(checker::ETSChecker *checker) return checker->GetAnalyzer()->Check(this); } -// NOLINTNEXTLINE(google-default-arguments) BinaryExpression *BinaryExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const left = left_ != nullptr ? left_->Clone(allocator)->AsExpression() : nullptr; - auto *const right = right_ != nullptr ? right_->Clone(allocator)->AsExpression() : nullptr; + auto *const left = left_ != nullptr ? left_->Clone(allocator, nullptr)->AsExpression() : nullptr; + auto *const right = right_ != nullptr ? right_->Clone(allocator, nullptr)->AsExpression() : nullptr; if (auto *const clone = allocator->New(left, right, operator_); clone != nullptr) { if (operationType_ != nullptr) { diff --git a/ets2panda/ir/expressions/binaryExpression.h b/ets2panda/ir/expressions/binaryExpression.h index c4222f4db9..82b484185e 100644 --- a/ets2panda/ir/expressions/binaryExpression.h +++ b/ets2panda/ir/expressions/binaryExpression.h @@ -142,8 +142,7 @@ public: return operationType_; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] BinaryExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] BinaryExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/blockExpression.cpp b/ets2panda/ir/expressions/blockExpression.cpp index 63b795532e..eaf53644da 100644 --- a/ets2panda/ir/expressions/blockExpression.cpp +++ b/ets2panda/ir/expressions/blockExpression.cpp @@ -40,7 +40,6 @@ BlockExpression::BlockExpression([[maybe_unused]] Tag const tag, BlockExpression } } -// NOLINTNEXTLINE(google-default-arguments) BlockExpression *BlockExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(Tag {}, *this, allocator); clone != nullptr) { diff --git a/ets2panda/ir/expressions/blockExpression.h b/ets2panda/ir/expressions/blockExpression.h index 6c6329ccd2..0180304f97 100644 --- a/ets2panda/ir/expressions/blockExpression.h +++ b/ets2panda/ir/expressions/blockExpression.h @@ -41,8 +41,7 @@ public: return statements_; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] BlockExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] BlockExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/callExpression.cpp b/ets2panda/ir/expressions/callExpression.cpp index 577a4393b3..782f4c1911 100644 --- a/ets2panda/ir/expressions/callExpression.cpp +++ b/ets2panda/ir/expressions/callExpression.cpp @@ -119,7 +119,6 @@ CallExpression::CallExpression(CallExpression const &other, ArenaAllocator *cons } } -// NOLINTNEXTLINE(google-default-arguments) CallExpression *CallExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(*this, allocator); clone != nullptr) { diff --git a/ets2panda/ir/expressions/callExpression.h b/ets2panda/ir/expressions/callExpression.h index cd2e29cb97..5cda890237 100644 --- a/ets2panda/ir/expressions/callExpression.h +++ b/ets2panda/ir/expressions/callExpression.h @@ -151,8 +151,7 @@ public: return isTrailingBlockInNewLine_; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] CallExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] CallExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/chainExpression.cpp b/ets2panda/ir/expressions/chainExpression.cpp index 7513d034fe..83f5181212 100644 --- a/ets2panda/ir/expressions/chainExpression.cpp +++ b/ets2panda/ir/expressions/chainExpression.cpp @@ -76,10 +76,9 @@ checker::Type *ChainExpression::Check(checker::ETSChecker *checker) return checker->GetAnalyzer()->Check(this); } -// NOLINTNEXTLINE(google-default-arguments) ChainExpression *ChainExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const expression = expression_ != nullptr ? expression_->Clone(allocator)->AsExpression() : nullptr; + auto *const expression = expression_ != nullptr ? expression_->Clone(allocator, nullptr)->AsExpression() : nullptr; if (auto *const clone = allocator->New(expression); clone != nullptr) { if (expression != nullptr) { diff --git a/ets2panda/ir/expressions/chainExpression.h b/ets2panda/ir/expressions/chainExpression.h index 9c124c9c91..0ee4506fc9 100644 --- a/ets2panda/ir/expressions/chainExpression.h +++ b/ets2panda/ir/expressions/chainExpression.h @@ -45,8 +45,7 @@ public: return expression_; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] ChainExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] ChainExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/classExpression.cpp b/ets2panda/ir/expressions/classExpression.cpp index 6caf00999f..7d8e14ddff 100644 --- a/ets2panda/ir/expressions/classExpression.cpp +++ b/ets2panda/ir/expressions/classExpression.cpp @@ -62,10 +62,9 @@ checker::Type *ClassExpression::Check(checker::ETSChecker *checker) return checker->GetAnalyzer()->Check(this); } -// NOLINTNEXTLINE(google-default-arguments) ClassExpression *ClassExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const def = def_ != nullptr ? def_->Clone(allocator)->AsClassDefinition() : nullptr; + auto *const def = def_ != nullptr ? def_->Clone(allocator, nullptr)->AsClassDefinition() : nullptr; if (auto *const clone = allocator->New(def); clone != nullptr) { if (parent != nullptr) { diff --git a/ets2panda/ir/expressions/classExpression.h b/ets2panda/ir/expressions/classExpression.h index 3277ec23ae..2073d0690d 100644 --- a/ets2panda/ir/expressions/classExpression.h +++ b/ets2panda/ir/expressions/classExpression.h @@ -36,8 +36,7 @@ public: return def_; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] ClassExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] ClassExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/conditionalExpression.cpp b/ets2panda/ir/expressions/conditionalExpression.cpp index c75255d971..ed82594bee 100644 --- a/ets2panda/ir/expressions/conditionalExpression.cpp +++ b/ets2panda/ir/expressions/conditionalExpression.cpp @@ -82,12 +82,11 @@ checker::Type *ConditionalExpression::Check(checker::ETSChecker *checker) return checker->GetAnalyzer()->Check(this); } -// NOLINTNEXTLINE(google-default-arguments) ConditionalExpression *ConditionalExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const test = test_ != nullptr ? test_->Clone(allocator)->AsExpression() : nullptr; - auto *const consequent = consequent_ != nullptr ? consequent_->Clone(allocator)->AsExpression() : nullptr; - auto *const alternate = alternate_ != nullptr ? alternate_->Clone(allocator)->AsExpression() : nullptr; + auto *const test = test_ != nullptr ? test_->Clone(allocator, nullptr)->AsExpression() : nullptr; + auto *const consequent = consequent_ != nullptr ? consequent_->Clone(allocator, nullptr)->AsExpression() : nullptr; + auto *const alternate = alternate_ != nullptr ? alternate_->Clone(allocator, nullptr)->AsExpression() : nullptr; if (auto *const clone = allocator->New(test, consequent, alternate); clone != nullptr) { if (test != nullptr) { diff --git a/ets2panda/ir/expressions/conditionalExpression.h b/ets2panda/ir/expressions/conditionalExpression.h index f7e3bb822a..0095154c0e 100644 --- a/ets2panda/ir/expressions/conditionalExpression.h +++ b/ets2panda/ir/expressions/conditionalExpression.h @@ -66,8 +66,7 @@ public: test_ = test; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] ConditionalExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] ConditionalExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/functionExpression.cpp b/ets2panda/ir/expressions/functionExpression.cpp index 243a94df42..d677d21281 100644 --- a/ets2panda/ir/expressions/functionExpression.cpp +++ b/ets2panda/ir/expressions/functionExpression.cpp @@ -62,10 +62,9 @@ checker::Type *FunctionExpression::Check([[maybe_unused]] checker::ETSChecker *c return checker->GetAnalyzer()->Check(this); } -// NOLINTNEXTLINE(google-default-arguments) FunctionExpression *FunctionExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const func = func_->Clone(allocator)->AsScriptFunction(); + auto *const func = func_->Clone(allocator, nullptr)->AsScriptFunction(); if (auto *const clone = allocator->New(func); clone != nullptr) { func->SetParent(clone); diff --git a/ets2panda/ir/expressions/functionExpression.h b/ets2panda/ir/expressions/functionExpression.h index ae284499ce..ce81316c51 100644 --- a/ets2panda/ir/expressions/functionExpression.h +++ b/ets2panda/ir/expressions/functionExpression.h @@ -58,8 +58,7 @@ public: return exprName_; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] FunctionExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] FunctionExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/identifier.cpp b/ets2panda/ir/expressions/identifier.cpp index 03d77fb781..a81d265c81 100644 --- a/ets2panda/ir/expressions/identifier.cpp +++ b/ets2panda/ir/expressions/identifier.cpp @@ -36,7 +36,6 @@ Identifier::Identifier([[maybe_unused]] Tag const tag, Identifier const &other, } } -// NOLINTNEXTLINE(google-default-arguments) Identifier *Identifier::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(Tag {}, *this, allocator); clone != nullptr) { diff --git a/ets2panda/ir/expressions/identifier.h b/ets2panda/ir/expressions/identifier.h index b91b01311f..48196b964b 100644 --- a/ets2panda/ir/expressions/identifier.h +++ b/ets2panda/ir/expressions/identifier.h @@ -190,8 +190,7 @@ public: decorators_ = std::move(decorators); } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Identifier *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] Identifier *Clone(ArenaAllocator *allocator, AstNode *parent) override; bool CanHaveDecorator([[maybe_unused]] bool inTs) const override { diff --git a/ets2panda/ir/expressions/importExpression.cpp b/ets2panda/ir/expressions/importExpression.cpp index 21a048c903..37a2df2530 100644 --- a/ets2panda/ir/expressions/importExpression.cpp +++ b/ets2panda/ir/expressions/importExpression.cpp @@ -61,10 +61,9 @@ checker::Type *ImportExpression::Check(checker::ETSChecker *checker) return checker->GetAnalyzer()->Check(this); } -// NOLINTNEXTLINE(google-default-arguments) ImportExpression *ImportExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const source = source_ != nullptr ? source_->Clone(allocator)->AsExpression() : nullptr; + auto *const source = source_ != nullptr ? source_->Clone(allocator, nullptr)->AsExpression() : nullptr; if (auto *const clone = allocator->New(source); clone != nullptr) { if (source != nullptr) { diff --git a/ets2panda/ir/expressions/importExpression.h b/ets2panda/ir/expressions/importExpression.h index 4ac17ab188..bb3a5fab15 100644 --- a/ets2panda/ir/expressions/importExpression.h +++ b/ets2panda/ir/expressions/importExpression.h @@ -34,8 +34,7 @@ public: return source_; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] ImportExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] ImportExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/literals/bigIntLiteral.cpp b/ets2panda/ir/expressions/literals/bigIntLiteral.cpp index 9b72a6a358..ece9eecdfe 100644 --- a/ets2panda/ir/expressions/literals/bigIntLiteral.cpp +++ b/ets2panda/ir/expressions/literals/bigIntLiteral.cpp @@ -56,7 +56,6 @@ checker::Type *BigIntLiteral::Check([[maybe_unused]] checker::ETSChecker *checke return checker->GetAnalyzer()->Check(this); } -// NOLINTNEXTLINE(google-default-arguments) BigIntLiteral *BigIntLiteral::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(src_); clone != nullptr) { diff --git a/ets2panda/ir/expressions/literals/bigIntLiteral.h b/ets2panda/ir/expressions/literals/bigIntLiteral.h index 6ac3d77385..217e99057d 100644 --- a/ets2panda/ir/expressions/literals/bigIntLiteral.h +++ b/ets2panda/ir/expressions/literals/bigIntLiteral.h @@ -35,8 +35,7 @@ public: return src_; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] BigIntLiteral *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] BigIntLiteral *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/literals/booleanLiteral.cpp b/ets2panda/ir/expressions/literals/booleanLiteral.cpp index 40bfa7bc65..203fb259b5 100644 --- a/ets2panda/ir/expressions/literals/booleanLiteral.cpp +++ b/ets2panda/ir/expressions/literals/booleanLiteral.cpp @@ -56,7 +56,6 @@ checker::Type *BooleanLiteral::Check([[maybe_unused]] checker::ETSChecker *check return checker->GetAnalyzer()->Check(this); } -// NOLINTNEXTLINE(google-default-arguments) BooleanLiteral *BooleanLiteral::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(boolean_); clone != nullptr) { diff --git a/ets2panda/ir/expressions/literals/booleanLiteral.h b/ets2panda/ir/expressions/literals/booleanLiteral.h index 88f62c6bf7..f3ede215ba 100644 --- a/ets2panda/ir/expressions/literals/booleanLiteral.h +++ b/ets2panda/ir/expressions/literals/booleanLiteral.h @@ -34,8 +34,7 @@ public: return boolean_; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] BooleanLiteral *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] BooleanLiteral *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/literals/charLiteral.cpp b/ets2panda/ir/expressions/literals/charLiteral.cpp index ce4be05ffc..2bbed46adf 100644 --- a/ets2panda/ir/expressions/literals/charLiteral.cpp +++ b/ets2panda/ir/expressions/literals/charLiteral.cpp @@ -59,7 +59,6 @@ checker::Type *CharLiteral::Check([[maybe_unused]] checker::ETSChecker *checker) return checker->GetAnalyzer()->Check(this); } -// NOLINTNEXTLINE(google-default-arguments) CharLiteral *CharLiteral::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(char_); clone != nullptr) { diff --git a/ets2panda/ir/expressions/literals/charLiteral.h b/ets2panda/ir/expressions/literals/charLiteral.h index 629e1a0d03..003e922b4a 100644 --- a/ets2panda/ir/expressions/literals/charLiteral.h +++ b/ets2panda/ir/expressions/literals/charLiteral.h @@ -40,8 +40,7 @@ public: return char_ == other.char_; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] CharLiteral *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] CharLiteral *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/literals/nullLiteral.cpp b/ets2panda/ir/expressions/literals/nullLiteral.cpp index 74c0e57816..0d266b8335 100644 --- a/ets2panda/ir/expressions/literals/nullLiteral.cpp +++ b/ets2panda/ir/expressions/literals/nullLiteral.cpp @@ -55,7 +55,6 @@ checker::Type *NullLiteral::Check(checker::ETSChecker *checker) return checker->GetAnalyzer()->Check(this); } -// NOLINTNEXTLINE(google-default-arguments) NullLiteral *NullLiteral::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(); clone != nullptr) { diff --git a/ets2panda/ir/expressions/literals/nullLiteral.h b/ets2panda/ir/expressions/literals/nullLiteral.h index 4fb46bb414..40a5f7b299 100644 --- a/ets2panda/ir/expressions/literals/nullLiteral.h +++ b/ets2panda/ir/expressions/literals/nullLiteral.h @@ -28,8 +28,7 @@ public: explicit NullLiteral() : Literal(AstNodeType::NULL_LITERAL) {} - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] NullLiteral *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] NullLiteral *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/literals/numberLiteral.cpp b/ets2panda/ir/expressions/literals/numberLiteral.cpp index dc7e40501b..ca4bb4c4e0 100644 --- a/ets2panda/ir/expressions/literals/numberLiteral.cpp +++ b/ets2panda/ir/expressions/literals/numberLiteral.cpp @@ -74,7 +74,6 @@ checker::Type *NumberLiteral::Check(checker::ETSChecker *checker) return checker->GetAnalyzer()->Check(this); } -// NOLINTNEXTLINE(google-default-arguments) NumberLiteral *NumberLiteral::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(number_); clone != nullptr) { diff --git a/ets2panda/ir/expressions/literals/numberLiteral.h b/ets2panda/ir/expressions/literals/numberLiteral.h index 0abcbbce6d..7a4412d2f3 100644 --- a/ets2panda/ir/expressions/literals/numberLiteral.h +++ b/ets2panda/ir/expressions/literals/numberLiteral.h @@ -49,8 +49,7 @@ public: [[nodiscard]] bool HasFloatingPoint() const; - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] NumberLiteral *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] NumberLiteral *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/literals/regExpLiteral.cpp b/ets2panda/ir/expressions/literals/regExpLiteral.cpp index e14f0fad2d..400e4b5155 100644 --- a/ets2panda/ir/expressions/literals/regExpLiteral.cpp +++ b/ets2panda/ir/expressions/literals/regExpLiteral.cpp @@ -57,7 +57,6 @@ checker::Type *RegExpLiteral::Check(checker::ETSChecker *checker) return checker->GetAnalyzer()->Check(this); } -// NOLINTNEXTLINE(google-default-arguments) RegExpLiteral *RegExpLiteral::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(pattern_, flags_, flagsStr_); clone != nullptr) { diff --git a/ets2panda/ir/expressions/literals/regExpLiteral.h b/ets2panda/ir/expressions/literals/regExpLiteral.h index 9666670fe7..9e21afa71f 100644 --- a/ets2panda/ir/expressions/literals/regExpLiteral.h +++ b/ets2panda/ir/expressions/literals/regExpLiteral.h @@ -44,8 +44,7 @@ public: return flags_; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] RegExpLiteral *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] RegExpLiteral *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/literals/stringLiteral.cpp b/ets2panda/ir/expressions/literals/stringLiteral.cpp index 11bc091825..209a143480 100644 --- a/ets2panda/ir/expressions/literals/stringLiteral.cpp +++ b/ets2panda/ir/expressions/literals/stringLiteral.cpp @@ -87,7 +87,6 @@ checker::Type *StringLiteral::Check(checker::ETSChecker *checker) return checker->GetAnalyzer()->Check(this); } -// NOLINTNEXTLINE(google-default-arguments) StringLiteral *StringLiteral::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(str_); clone != nullptr) { diff --git a/ets2panda/ir/expressions/literals/stringLiteral.h b/ets2panda/ir/expressions/literals/stringLiteral.h index 081eed374f..3183fd6cd3 100644 --- a/ets2panda/ir/expressions/literals/stringLiteral.h +++ b/ets2panda/ir/expressions/literals/stringLiteral.h @@ -41,8 +41,7 @@ public: return str_ == other.str_; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] StringLiteral *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] StringLiteral *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/memberExpression.cpp b/ets2panda/ir/expressions/memberExpression.cpp index c705d084eb..ed040ff318 100644 --- a/ets2panda/ir/expressions/memberExpression.cpp +++ b/ets2panda/ir/expressions/memberExpression.cpp @@ -384,11 +384,10 @@ checker::Type *MemberExpression::Check(checker::ETSChecker *checker) return checker->GetAnalyzer()->Check(this); } -// NOLINTNEXTLINE(google-default-arguments) MemberExpression *MemberExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const object = object_ != nullptr ? object_->Clone(allocator)->AsExpression() : nullptr; - auto *const property = property_ != nullptr ? property_->Clone(allocator)->AsExpression() : nullptr; + auto *const object = object_ != nullptr ? object_->Clone(allocator, nullptr)->AsExpression() : nullptr; + auto *const property = property_ != nullptr ? property_->Clone(allocator, nullptr)->AsExpression() : nullptr; if (auto *const clone = allocator->New(object, property, kind_, computed_, MaybeOptionalExpression::IsOptional()); diff --git a/ets2panda/ir/expressions/memberExpression.h b/ets2panda/ir/expressions/memberExpression.h index b59a73b409..fd36624403 100644 --- a/ets2panda/ir/expressions/memberExpression.h +++ b/ets2panda/ir/expressions/memberExpression.h @@ -172,8 +172,7 @@ public: [[nodiscard]] bool IsPrivateReference() const noexcept; - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] MemberExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] MemberExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/newExpression.cpp b/ets2panda/ir/expressions/newExpression.cpp index f56cdeb805..8fb67ccc9f 100644 --- a/ets2panda/ir/expressions/newExpression.cpp +++ b/ets2panda/ir/expressions/newExpression.cpp @@ -36,7 +36,6 @@ NewExpression::NewExpression([[maybe_unused]] Tag const tag, NewExpression const } } -// NOLINTNEXTLINE(google-default-arguments) NewExpression *NewExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(Tag {}, *this, allocator); clone != nullptr) { diff --git a/ets2panda/ir/expressions/newExpression.h b/ets2panda/ir/expressions/newExpression.h index a1d974cd3f..883e310a29 100644 --- a/ets2panda/ir/expressions/newExpression.h +++ b/ets2panda/ir/expressions/newExpression.h @@ -53,8 +53,7 @@ public: return arguments_; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] NewExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] NewExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/objectExpression.cpp b/ets2panda/ir/expressions/objectExpression.cpp index 6ebf574910..4ba78c48b3 100644 --- a/ets2panda/ir/expressions/objectExpression.cpp +++ b/ets2panda/ir/expressions/objectExpression.cpp @@ -65,7 +65,6 @@ ObjectExpression::ObjectExpression([[maybe_unused]] Tag const tag, ObjectExpress } } -// NOLINTNEXTLINE(google-default-arguments) ObjectExpression *ObjectExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(Tag {}, *this, allocator); clone != nullptr) { diff --git a/ets2panda/ir/expressions/objectExpression.h b/ets2panda/ir/expressions/objectExpression.h index 0beef0b780..758a46c161 100644 --- a/ets2panda/ir/expressions/objectExpression.h +++ b/ets2panda/ir/expressions/objectExpression.h @@ -96,8 +96,7 @@ public: return true; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] ObjectExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] ObjectExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; [[nodiscard]] ValidationInfo ValidateExpression(); [[nodiscard]] bool ConvertibleToObjectPattern(); diff --git a/ets2panda/ir/expressions/omittedExpression.cpp b/ets2panda/ir/expressions/omittedExpression.cpp index 0ab3d1f332..abbfdd6774 100644 --- a/ets2panda/ir/expressions/omittedExpression.cpp +++ b/ets2panda/ir/expressions/omittedExpression.cpp @@ -55,7 +55,6 @@ checker::Type *OmittedExpression::Check(checker::ETSChecker *checker) return checker->GetAnalyzer()->Check(this); } -// NOLINTNEXTLINE(google-default-arguments) OmittedExpression *OmittedExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(); clone != nullptr) { diff --git a/ets2panda/ir/expressions/omittedExpression.h b/ets2panda/ir/expressions/omittedExpression.h index 4f1f340b78..b29553d7c4 100644 --- a/ets2panda/ir/expressions/omittedExpression.h +++ b/ets2panda/ir/expressions/omittedExpression.h @@ -30,8 +30,7 @@ public: void TransformChildren(const NodeTransformer &cb) override; - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] OmittedExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] OmittedExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; diff --git a/ets2panda/ir/expressions/sequenceExpression.cpp b/ets2panda/ir/expressions/sequenceExpression.cpp index 3830204255..d4f37ffaef 100644 --- a/ets2panda/ir/expressions/sequenceExpression.cpp +++ b/ets2panda/ir/expressions/sequenceExpression.cpp @@ -32,7 +32,6 @@ SequenceExpression::SequenceExpression([[maybe_unused]] Tag const tag, SequenceE } } -// NOLINTNEXTLINE(google-default-arguments) SequenceExpression *SequenceExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(Tag {}, *this, allocator); clone != nullptr) { diff --git a/ets2panda/ir/expressions/sequenceExpression.h b/ets2panda/ir/expressions/sequenceExpression.h index 98c53be093..4c46022aad 100644 --- a/ets2panda/ir/expressions/sequenceExpression.h +++ b/ets2panda/ir/expressions/sequenceExpression.h @@ -47,8 +47,7 @@ public: return sequence_; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] SequenceExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] SequenceExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/superExpression.cpp b/ets2panda/ir/expressions/superExpression.cpp index 02e8244316..8707b2b35e 100644 --- a/ets2panda/ir/expressions/superExpression.cpp +++ b/ets2panda/ir/expressions/superExpression.cpp @@ -57,7 +57,6 @@ checker::Type *SuperExpression::Check([[maybe_unused]] checker::ETSChecker *chec return checker->GetAnalyzer()->Check(this); } -// NOLINTNEXTLINE(google-default-arguments) SuperExpression *SuperExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(); clone != nullptr) { diff --git a/ets2panda/ir/expressions/superExpression.h b/ets2panda/ir/expressions/superExpression.h index 29d12a994d..a3d33a1f18 100644 --- a/ets2panda/ir/expressions/superExpression.h +++ b/ets2panda/ir/expressions/superExpression.h @@ -28,8 +28,7 @@ public: explicit SuperExpression() : Expression(AstNodeType::SUPER_EXPRESSION) {} - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] SuperExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] SuperExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/taggedTemplateExpression.cpp b/ets2panda/ir/expressions/taggedTemplateExpression.cpp index 238deecd37..bd0bce7063 100644 --- a/ets2panda/ir/expressions/taggedTemplateExpression.cpp +++ b/ets2panda/ir/expressions/taggedTemplateExpression.cpp @@ -81,12 +81,11 @@ checker::Type *TaggedTemplateExpression::Check([[maybe_unused]] checker::ETSChec return checker->GetAnalyzer()->Check(this); } -// NOLINTNEXTLINE(google-default-arguments) TaggedTemplateExpression *TaggedTemplateExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const tag = tag_ != nullptr ? tag_->Clone(allocator)->AsExpression() : nullptr; - auto *const quasi = quasi_ != nullptr ? quasi_->Clone(allocator) : nullptr; - auto *const typeParams = typeParams_ != nullptr ? typeParams_->Clone(allocator) : nullptr; + auto *const tag = tag_ != nullptr ? tag_->Clone(allocator, nullptr)->AsExpression() : nullptr; + auto *const quasi = quasi_ != nullptr ? quasi_->Clone(allocator, nullptr) : nullptr; + auto *const typeParams = typeParams_ != nullptr ? typeParams_->Clone(allocator, nullptr) : nullptr; if (auto *const clone = allocator->New(tag, quasi, typeParams); clone != nullptr) { if (tag != nullptr) { diff --git a/ets2panda/ir/expressions/taggedTemplateExpression.h b/ets2panda/ir/expressions/taggedTemplateExpression.h index d8853db8a9..2f70a9451a 100644 --- a/ets2panda/ir/expressions/taggedTemplateExpression.h +++ b/ets2panda/ir/expressions/taggedTemplateExpression.h @@ -50,8 +50,7 @@ public: return typeParams_; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] TaggedTemplateExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] TaggedTemplateExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/templateLiteral.cpp b/ets2panda/ir/expressions/templateLiteral.cpp index 732c96706b..30e37189f8 100644 --- a/ets2panda/ir/expressions/templateLiteral.cpp +++ b/ets2panda/ir/expressions/templateLiteral.cpp @@ -39,7 +39,6 @@ TemplateLiteral::TemplateLiteral([[maybe_unused]] Tag const tag, TemplateLiteral } } -// NOLINTNEXTLINE(google-default-arguments) TemplateLiteral *TemplateLiteral::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(Tag {}, *this, allocator); clone != nullptr) { diff --git a/ets2panda/ir/expressions/templateLiteral.h b/ets2panda/ir/expressions/templateLiteral.h index 046ea69c4f..0b7b587116 100644 --- a/ets2panda/ir/expressions/templateLiteral.h +++ b/ets2panda/ir/expressions/templateLiteral.h @@ -48,8 +48,7 @@ public: return expressions_; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] TemplateLiteral *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] TemplateLiteral *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/thisExpression.cpp b/ets2panda/ir/expressions/thisExpression.cpp index 9598cea01a..7ab66d905c 100644 --- a/ets2panda/ir/expressions/thisExpression.cpp +++ b/ets2panda/ir/expressions/thisExpression.cpp @@ -63,7 +63,6 @@ checker::Type *ThisExpression::Check(checker::ETSChecker *checker) return checker->GetAnalyzer()->Check(this); } -// NOLINTNEXTLINE(google-default-arguments) ThisExpression *ThisExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(); clone != nullptr) { diff --git a/ets2panda/ir/expressions/thisExpression.h b/ets2panda/ir/expressions/thisExpression.h index 51ab041129..c1db0af614 100644 --- a/ets2panda/ir/expressions/thisExpression.h +++ b/ets2panda/ir/expressions/thisExpression.h @@ -28,8 +28,7 @@ public: explicit ThisExpression() : Expression(AstNodeType::THIS_EXPRESSION) {} - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] ThisExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] ThisExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/unaryExpression.cpp b/ets2panda/ir/expressions/unaryExpression.cpp index 835456d9c4..c04d856395 100644 --- a/ets2panda/ir/expressions/unaryExpression.cpp +++ b/ets2panda/ir/expressions/unaryExpression.cpp @@ -71,10 +71,9 @@ checker::Type *UnaryExpression::Check(checker::ETSChecker *checker) return checker->GetAnalyzer()->Check(this); } -// NOLINTNEXTLINE(google-default-arguments) UnaryExpression *UnaryExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const argument = argument_ != nullptr ? argument_->Clone(allocator)->AsExpression() : nullptr; + auto *const argument = argument_ != nullptr ? argument_->Clone(allocator, nullptr)->AsExpression() : nullptr; if (auto *const clone = allocator->New(argument, operator_); clone != nullptr) { if (argument != nullptr) { diff --git a/ets2panda/ir/expressions/unaryExpression.h b/ets2panda/ir/expressions/unaryExpression.h index bbb261d3a0..af060bca82 100644 --- a/ets2panda/ir/expressions/unaryExpression.h +++ b/ets2panda/ir/expressions/unaryExpression.h @@ -58,8 +58,7 @@ public: return argument_; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] UnaryExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] UnaryExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/updateExpression.cpp b/ets2panda/ir/expressions/updateExpression.cpp index 5453e7543c..b3c39981e1 100644 --- a/ets2panda/ir/expressions/updateExpression.cpp +++ b/ets2panda/ir/expressions/updateExpression.cpp @@ -78,10 +78,9 @@ checker::Type *UpdateExpression::Check(checker::ETSChecker *checker) return checker->GetAnalyzer()->Check(this); } -// NOLINTNEXTLINE(google-default-arguments) UpdateExpression *UpdateExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const argument = argument_ != nullptr ? argument_->Clone(allocator)->AsExpression() : nullptr; + auto *const argument = argument_ != nullptr ? argument_->Clone(allocator, nullptr)->AsExpression() : nullptr; if (auto *const clone = allocator->New(argument, operator_, prefix_); clone != nullptr) { if (argument != nullptr) { diff --git a/ets2panda/ir/expressions/updateExpression.h b/ets2panda/ir/expressions/updateExpression.h index 312a73df33..51539cccf5 100644 --- a/ets2panda/ir/expressions/updateExpression.h +++ b/ets2panda/ir/expressions/updateExpression.h @@ -62,8 +62,7 @@ public: return prefix_; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] UpdateExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] UpdateExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/yieldExpression.cpp b/ets2panda/ir/expressions/yieldExpression.cpp index 36ce163da7..3c8400649d 100644 --- a/ets2panda/ir/expressions/yieldExpression.cpp +++ b/ets2panda/ir/expressions/yieldExpression.cpp @@ -67,10 +67,9 @@ checker::Type *YieldExpression::Check([[maybe_unused]] checker::ETSChecker *chec return checker->GetAnalyzer()->Check(this); } -// NOLINTNEXTLINE(google-default-arguments) YieldExpression *YieldExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const argument = argument_ != nullptr ? argument_->Clone(allocator)->AsExpression() : nullptr; + auto *const argument = argument_ != nullptr ? argument_->Clone(allocator, nullptr)->AsExpression() : nullptr; if (auto *const clone = allocator->New(argument, delegate_); clone != nullptr) { if (argument != nullptr) { diff --git a/ets2panda/ir/expressions/yieldExpression.h b/ets2panda/ir/expressions/yieldExpression.h index 793843063c..c7e2f278f9 100644 --- a/ets2panda/ir/expressions/yieldExpression.h +++ b/ets2panda/ir/expressions/yieldExpression.h @@ -46,8 +46,7 @@ public: return argument_; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] YieldExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] YieldExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/ts/tsArrayType.cpp b/ets2panda/ir/ts/tsArrayType.cpp index b4c9d27cae..328476307b 100644 --- a/ets2panda/ir/ts/tsArrayType.cpp +++ b/ets2panda/ir/ts/tsArrayType.cpp @@ -78,10 +78,9 @@ checker::Type *TSArrayType::GetType(checker::ETSChecker *checker) return checker->CreateETSArrayType(elementType); } -// NOLINTNEXTLINE(google-default-arguments) TSArrayType *TSArrayType::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const elementTypeClone = elementType_ != nullptr ? elementType_->Clone(allocator) : nullptr; + auto *const elementTypeClone = elementType_ != nullptr ? elementType_->Clone(allocator, nullptr) : nullptr; if (auto *const clone = allocator->New(elementTypeClone); clone != nullptr) { if (elementTypeClone != nullptr) { diff --git a/ets2panda/ir/ts/tsArrayType.h b/ets2panda/ir/ts/tsArrayType.h index 12752a3004..131d10a5d0 100644 --- a/ets2panda/ir/ts/tsArrayType.h +++ b/ets2panda/ir/ts/tsArrayType.h @@ -53,8 +53,7 @@ public: v->Accept(this); } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] TSArrayType *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] TSArrayType *Clone(ArenaAllocator *allocator, AstNode *parent) override; private: TypeNode *elementType_; diff --git a/ets2panda/ir/ts/tsTypeParameterInstantiation.cpp b/ets2panda/ir/ts/tsTypeParameterInstantiation.cpp index ef538c9bcf..84496dcd92 100644 --- a/ets2panda/ir/ts/tsTypeParameterInstantiation.cpp +++ b/ets2panda/ir/ts/tsTypeParameterInstantiation.cpp @@ -35,7 +35,6 @@ TSTypeParameterInstantiation::TSTypeParameterInstantiation([[maybe_unused]] Tag } } -// NOLINTNEXTLINE(google-default-arguments) TSTypeParameterInstantiation *TSTypeParameterInstantiation::Clone(ArenaAllocator *const allocator, AstNode *const parent) { diff --git a/ets2panda/ir/ts/tsTypeParameterInstantiation.h b/ets2panda/ir/ts/tsTypeParameterInstantiation.h index be57a1c502..e6c02c9e58 100644 --- a/ets2panda/ir/ts/tsTypeParameterInstantiation.h +++ b/ets2panda/ir/ts/tsTypeParameterInstantiation.h @@ -42,8 +42,7 @@ public: return params_; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] TSTypeParameterInstantiation *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] TSTypeParameterInstantiation *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/typeNode.cpp b/ets2panda/ir/typeNode.cpp index be22e10ee7..c90e0234ae 100644 --- a/ets2panda/ir/typeNode.cpp +++ b/ets2panda/ir/typeNode.cpp @@ -20,7 +20,6 @@ namespace panda::es2panda::ir { -// NOLINTNEXTLINE(google-default-arguments) TypeNode *TypeNode::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const type = TsType(); type != nullptr) { diff --git a/ets2panda/ir/typeNode.h b/ets2panda/ir/typeNode.h index 7933f9b5e4..72f4ceb540 100644 --- a/ets2panda/ir/typeNode.h +++ b/ets2panda/ir/typeNode.h @@ -47,8 +47,7 @@ public: return nullptr; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] TypeNode *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] TypeNode *Clone(ArenaAllocator *allocator, AstNode *parent) override; protected: explicit TypeNode(AstNodeType const type) : Expression(type) {} -- Gitee From 43f4e5576c3c52bab65db7a9ae677d5bb56ddc20 Mon Sep 17 00:00:00 2001 From: Vadim Lomovtsev Date: Wed, 10 Jan 2024 10:15:46 +0300 Subject: [PATCH 23/26] project-wide: rework proxy function to overload(s) In order to fix the default constructor invoking issue (see link below) the proxy-function based approach is reworked into overload-based one and moved to specific lowering (defaultParameterLowering). The former implementation with proxy-function is removed along with related code. Thus overal code complexity is reduced. Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/I8MXJY The new test, for tracking possible issue with calls to class members has been implemented. It has two following scenarios: - access to super class constructor with default parameter; - using private class member as default parameter initializer; Testing: Testing was done by invoking following test suites: - run ninja ets_tests; - run tests_full; default_parameter8.ets: add class constructor with default parameter test default_parameter9.ets: add test with generic function Signed-off-by: Vadim Lomovtsev --- ets2panda/BUILD.gn | 1 + ets2panda/CMakeLists.txt | 1 + ets2panda/checker/ETSAnalyzer.cpp | 2 - ets2panda/checker/ETSchecker.h | 19 +- ets2panda/checker/ets/function.cpp | 121 +- ets2panda/checker/ets/helpers.cpp | 32 - ets2panda/compiler/core/ASTVerifier.h | 1 + ets2panda/compiler/core/ETSGen.cpp | 2 + ets2panda/compiler/core/ETSGen.h | 7 +- .../lowering/ets/defaultParameterLowering.cpp | 374 ++ .../lowering/ets/defaultParameterLowering.h | 54 + ets2panda/compiler/lowering/phase.cpp | 24 +- .../lowering/scopesInit/scopesInitPhase.cpp | 8 +- ets2panda/ir/astNodeFlags.h | 7 +- ets2panda/ir/base/scriptFunction.h | 10 - .../ir/ets/etsNewClassInstanceExpression.cpp | 4 +- ets2panda/ir/ets/etsParameterExpression.h | 7 +- ets2panda/ir/expressions/callExpression.cpp | 4 +- ets2panda/parser/ETSparser.cpp | 117 +- ets2panda/parser/ETSparser.h | 5 - ets2panda/public/es2panda_lib.cpp | 6 - ets2panda/public/es2panda_lib.h | 7 +- .../ets/optionalLambdaParameter-expected.txt | 404 +-- ...ametersWithGenericReturnTypes-expected.txt | 852 +---- .../ets/default_parameter1-expected.txt | 382 +- .../ets/default_parameter2-expected.txt | 382 +- .../ets/default_parameter4-expected.txt | 1059 ++---- .../ets/default_parameter5-expected.txt | 546 +-- .../ets/default_parameter6-expected.txt | 1800 +++++---- .../ets/default_parameter7-expected.txt | 879 ++--- .../ets/default_parameter8-expected.txt | 3219 +++++++++++++++++ .../test/parser/ets/default_parameter8.ets | 47 + .../ets/default_parameter9-expected.txt | 984 +++++ .../test/parser/ets/default_parameter9.ets | 18 + ..._implicitly_typed_return_void-expected.txt | 810 ++--- .../ets/optional_union_paramter-expected.txt | 568 +-- .../test/parser/ets/override-expected.txt | 954 ++--- .../ets/proxyVoidGeneration-expected.txt | 796 +--- .../test/parser/ets/proxy_method-expected.txt | 446 +-- .../parser/ets/rest_parameter_02-expected.txt | 417 +-- 40 files changed, 7632 insertions(+), 7744 deletions(-) create mode 100644 ets2panda/compiler/lowering/ets/defaultParameterLowering.cpp create mode 100644 ets2panda/compiler/lowering/ets/defaultParameterLowering.h create mode 100644 ets2panda/test/parser/ets/default_parameter8-expected.txt create mode 100644 ets2panda/test/parser/ets/default_parameter8.ets create mode 100644 ets2panda/test/parser/ets/default_parameter9-expected.txt create mode 100644 ets2panda/test/parser/ets/default_parameter9.ets diff --git a/ets2panda/BUILD.gn b/ets2panda/BUILD.gn index ad1b41851c..184a1159a1 100644 --- a/ets2panda/BUILD.gn +++ b/ets2panda/BUILD.gn @@ -156,6 +156,7 @@ libes2panda_sources = [ "compiler/function/functionBuilder.cpp", "compiler/function/generatorFunctionBuilder.cpp", "compiler/lowering/checkerPhase.cpp", + "compiler/lowering/ets/defaultParameterLowering.cpp", "compiler/lowering/ets/expandBrackets.cpp", "compiler/lowering/ets/generateDeclarations.cpp", "compiler/lowering/ets/interfacePropertyDeclarations.cpp", diff --git a/ets2panda/CMakeLists.txt b/ets2panda/CMakeLists.txt index 6a662e36a5..dfd0e446c1 100644 --- a/ets2panda/CMakeLists.txt +++ b/ets2panda/CMakeLists.txt @@ -160,6 +160,7 @@ set(ES2PANDA_LIB_SRC compiler/lowering/ets/expandBrackets.cpp compiler/lowering/ets/promiseVoid.cpp compiler/lowering/ets/structLowering.cpp + compiler/lowering/ets/defaultParameterLowering.cpp ir/astDump.cpp ir/srcDump.cpp ir/astNode.cpp diff --git a/ets2panda/checker/ETSAnalyzer.cpp b/ets2panda/checker/ETSAnalyzer.cpp index 810934b8e5..73009f32b1 100644 --- a/ets2panda/checker/ETSAnalyzer.cpp +++ b/ets2panda/checker/ETSAnalyzer.cpp @@ -564,7 +564,6 @@ checker::Type *ETSAnalyzer::Check(ir::ETSNewClassInstanceExpression *expr) const auto *signature = checker->ResolveConstructExpression(calleeObj, expr->GetArguments(), expr->Start()); checker->CheckObjectLiteralArguments(signature, expr->GetArguments()); - checker->AddUndefinedParamsForDefaultParams(signature, expr->arguments_, checker); checker->ValidateSignatureAccessibility(calleeObj, nullptr, signature, expr->Start()); @@ -1087,7 +1086,6 @@ checker::Type *ETSAnalyzer::GetReturnType(ir::CallExpression *expr, checker::Typ ResolveSignature(checker, expr, calleeType, isFunctionalInterface, isUnionTypeWithFunctionalInterface); checker->CheckObjectLiteralArguments(signature, expr->Arguments()); - checker->AddUndefinedParamsForDefaultParams(signature, expr->Arguments(), checker); if (!isFunctionalInterface) { checker::ETSObjectType *calleeObj = ChooseCalleeObj(checker, expr, calleeType, isConstructorCall); diff --git a/ets2panda/checker/ETSchecker.h b/ets2panda/checker/ETSchecker.h index e909286f93..69f2c7306d 100644 --- a/ets2panda/checker/ETSchecker.h +++ b/ets2panda/checker/ETSchecker.h @@ -324,15 +324,9 @@ public: const ArenaVector &arguments, const lexer::SourcePosition &pos, std::string_view signatureKind, TypeRelationFlag resolveFlags = TypeRelationFlag::NONE); - bool ValidateProxySignature(Signature *signature, const ir::TSTypeParameterInstantiation *typeArguments, - const ArenaVector &arguments, - const std::vector &argTypeInferenceRequired); Signature *ChooseMostSpecificSignature(ArenaVector &signatures, const std::vector &argTypeInferenceRequired, const lexer::SourcePosition &pos, size_t argumentsSize = ULONG_MAX); - Signature *ChooseMostSpecificProxySignature(ArenaVector &signatures, - const std::vector &argTypeInferenceRequired, - const lexer::SourcePosition &pos, size_t argumentsSize); Signature *ResolveCallExpression(ArenaVector &signatures, const ir::TSTypeParameterInstantiation *typeArguments, const ArenaVector &arguments, const lexer::SourcePosition &pos); @@ -539,9 +533,6 @@ public: util::StringView GetHashFromSubstitution(const Substitution *substitution); ETSObjectType *GetOriginalBaseType(Type *object); Type *GetTypeFromTypeAnnotation(ir::TypeNode *typeAnnotation); - void AddUndefinedParamsForDefaultParams(const Signature *signature, - ArenaVector &arguments, - ETSChecker *checker); void SetArrayPreferredTypeForNestedMemberExpressions(ir::MemberExpression *expr, Type *annotationType); bool ExtensionETSFunctionType(checker::Type *type); void ValidateTupleMinElementSize(ir::ArrayExpression *arrayExpr, ETSTupleType *tuple); @@ -690,14 +681,14 @@ private: ETSObjectType *AsETSObjectType(Type *(GlobalTypesHolder::*typeFunctor)()) const; Signature *GetMostSpecificSignature(ArenaVector &compatibleSignatures, - ArenaVector &proxySignatures, const ArenaVector &arguments, std::vector &argTypeInferenceRequired, const lexer::SourcePosition &pos, TypeRelationFlag resolveFlags); - std::pair, ArenaVector> CollectSignatures( - ArenaVector &signatures, const ir::TSTypeParameterInstantiation *typeArguments, - const ArenaVector &arguments, std::vector &argTypeInferenceRequired, - const lexer::SourcePosition &pos, TypeRelationFlag resolveFlags); + ArenaVector CollectSignatures(ArenaVector &signatures, + const ir::TSTypeParameterInstantiation *typeArguments, + const ArenaVector &arguments, + std::vector &argTypeInferenceRequired, + const lexer::SourcePosition &pos, TypeRelationFlag resolveFlags); // Trailing lambda void MoveTrailingBlockToEnclosingBlockStatement(ir::CallExpression *callExpr); void TransformTraillingLambda(ir::CallExpression *callExpr); diff --git a/ets2panda/checker/ets/function.cpp b/ets2panda/checker/ets/function.cpp index e6476c47e5..0d1363bc56 100644 --- a/ets2panda/checker/ets/function.cpp +++ b/ets2panda/checker/ets/function.cpp @@ -292,10 +292,6 @@ Signature *ETSChecker::ValidateSignature(Signature *signature, const ir::TSTypeP const lexer::SourcePosition &pos, TypeRelationFlag flags, const std::vector &argTypeInferenceRequired) { - if (signature->Function()->IsDefaultParamProxy() && ((flags & TypeRelationFlag::CHECK_PROXY) == 0)) { - return nullptr; - } - Signature *substitutedSig = MaybeSubstituteTypeParameters(this, signature, typeArguments, arguments, pos, flags); if (substitutedSig == nullptr) { return nullptr; @@ -306,13 +302,11 @@ Signature *ETSChecker::ValidateSignature(Signature *signature, const ir::TSTypeP std::size_t const parameterCount = substitutedSig->MinArgCount(); auto const throwError = (flags & TypeRelationFlag::NO_THROW) == 0; - if (!signature->Function()->IsDefaultParamProxy()) { - if (argumentCount < parameterCount || (argumentCount > parameterCount && !hasRestParameter)) { - if (throwError) { - ThrowTypeError({"Expected ", parameterCount, " arguments, got ", argumentCount, "."}, pos); - } - return nullptr; + if (argumentCount < parameterCount || (argumentCount > parameterCount && !hasRestParameter)) { + if (throwError) { + ThrowTypeError({"Expected ", parameterCount, " arguments, got ", argumentCount, "."}, pos); } + return nullptr; } auto count = std::min(parameterCount, argumentCount); @@ -332,30 +326,6 @@ Signature *ETSChecker::ValidateSignature(Signature *signature, const ir::TSTypeP return substitutedSig; } -bool ETSChecker::ValidateProxySignature(Signature *const signature, - const ir::TSTypeParameterInstantiation *typeArguments, - const ArenaVector &arguments, - const std::vector &argTypeInferenceRequired) -{ - if (!signature->Function()->IsDefaultParamProxy()) { - return false; - } - - auto const *const proxyParam = signature->Function()->Params().back()->AsETSParameterExpression(); - if (!proxyParam->Ident()->Name().Is(ir::PROXY_PARAMETER_NAME)) { - return false; - } - - if (arguments.size() < proxyParam->GetRequiredParams()) { - return false; - } - - return ValidateSignature(signature, typeArguments, arguments, signature->Function()->Start(), - TypeRelationFlag::CHECK_PROXY | TypeRelationFlag::NO_THROW | - TypeRelationFlag::NO_UNBOXING | TypeRelationFlag::NO_BOXING, - argTypeInferenceRequired) != nullptr; -} - Signature *ETSChecker::CollectParameterlessConstructor(ArenaVector &signatures, const lexer::SourcePosition &pos, TypeRelationFlag resolveFlags) { @@ -387,26 +357,16 @@ Signature *ETSChecker::CollectParameterlessConstructor(ArenaVector return compatibleSignature; } -std::pair, ArenaVector> ETSChecker::CollectSignatures( - ArenaVector &signatures, const ir::TSTypeParameterInstantiation *typeArguments, - const ArenaVector &arguments, std::vector &argTypeInferenceRequired, - const lexer::SourcePosition &pos, TypeRelationFlag resolveFlags) +ArenaVector ETSChecker::CollectSignatures(ArenaVector &signatures, + const ir::TSTypeParameterInstantiation *typeArguments, + const ArenaVector &arguments, + std::vector &argTypeInferenceRequired, + const lexer::SourcePosition &pos, TypeRelationFlag resolveFlags) { ArenaVector compatibleSignatures(Allocator()->Adapter()); - ArenaVector proxySignatures(Allocator()->Adapter()); - - for (auto *sig : signatures) { - if (sig->Function()->IsDefaultParamProxy() && - ValidateProxySignature(sig, typeArguments, arguments, argTypeInferenceRequired)) { - proxySignatures.push_back(sig); - } - } auto collectSignatures = [&](TypeRelationFlag relationFlags) { for (auto *sig : signatures) { - if (sig->Function()->IsDefaultParamProxy()) { - continue; - } auto *concreteSig = ValidateSignature(sig, typeArguments, arguments, pos, relationFlags, argTypeInferenceRequired); if (concreteSig != nullptr) { @@ -435,11 +395,10 @@ std::pair, ArenaVector> ETSChecker::Collec } } } - return std::make_pair(compatibleSignatures, proxySignatures); + return compatibleSignatures; } Signature *ETSChecker::GetMostSpecificSignature(ArenaVector &compatibleSignatures, - ArenaVector &proxySignatures, const ArenaVector &arguments, std::vector &argTypeInferenceRequired, const lexer::SourcePosition &pos, TypeRelationFlag resolveFlags) @@ -454,26 +413,6 @@ Signature *ETSChecker::GetMostSpecificSignature(ArenaVector &compat return nullptr; } - // Just to avoid extra nesting level - auto const checkAmbiguous = [this, mostSpecificSignature, &pos](Signature const *const proxySignature) -> void { - auto const *const proxyParam = proxySignature->Function()->Params().back()->AsETSParameterExpression(); - if (!proxyParam->Ident()->Name().Is(ir::PROXY_PARAMETER_NAME)) { - ThrowTypeError({"Proxy parameter '", proxyParam->Ident()->Name(), "' has invalid name."}, pos); - } - - if (mostSpecificSignature->Params().size() == proxyParam->GetRequiredParams()) { - ThrowTypeError({"Reference to ", mostSpecificSignature->Function()->Id()->Name(), " is ambiguous"}, pos); - } - }; - - if (!proxySignatures.empty()) { - auto *const proxySignature = - ChooseMostSpecificProxySignature(proxySignatures, argTypeInferenceRequired, pos, arguments.size()); - if (proxySignature != nullptr) { - checkAmbiguous(proxySignature); - } - } - return mostSpecificSignature; } @@ -484,20 +423,10 @@ Signature *ETSChecker::ValidateSignatures(ArenaVector &signatures, TypeRelationFlag resolveFlags) { std::vector argTypeInferenceRequired = FindTypeInferenceArguments(arguments); - auto [compatibleSignatures, proxySignatures] = + auto compatibleSignatures = CollectSignatures(signatures, typeArguments, arguments, argTypeInferenceRequired, pos, resolveFlags); - if (!compatibleSignatures.empty()) { - return GetMostSpecificSignature(compatibleSignatures, proxySignatures, arguments, argTypeInferenceRequired, pos, - resolveFlags); - } - - if (!proxySignatures.empty()) { - auto *const proxySignature = - ChooseMostSpecificProxySignature(proxySignatures, argTypeInferenceRequired, pos, arguments.size()); - if (proxySignature != nullptr) { - return proxySignature; - } + return GetMostSpecificSignature(compatibleSignatures, arguments, argTypeInferenceRequired, pos, resolveFlags); } if ((resolveFlags & TypeRelationFlag::NO_THROW) == 0 && !arguments.empty() && !signatures.empty()) { @@ -665,26 +594,6 @@ Signature *ETSChecker::ChooseMostSpecificSignature(ArenaVector &sig return mostSpecificSignature; } -Signature *ETSChecker::ChooseMostSpecificProxySignature(ArenaVector &signatures, - const std::vector &argTypeInferenceRequired, - const lexer::SourcePosition &pos, size_t argumentsSize) -{ - if (pos.index == 0 && pos.line == 0) { - return nullptr; - } - - const auto mostSpecificSignature = - ChooseMostSpecificSignature(signatures, argTypeInferenceRequired, pos, argumentsSize); - - if (mostSpecificSignature == nullptr) { - const auto str = signatures.front()->Function()->Id()->Name().Mutf8().substr( - 0, signatures.front()->Function()->Id()->Name().Length() - 6); - ThrowTypeError("Reference to " + str + " is ambiguous", pos); - } - - return mostSpecificSignature; -} - Signature *ETSChecker::ResolveCallExpression(ArenaVector &signatures, const ir::TSTypeParameterInstantiation *typeArguments, const ArenaVector &arguments, @@ -790,10 +699,6 @@ void ETSChecker::CheckIdenticalOverloads(ETSFunctionType *func, ETSFunctionType { SavedTypeRelationFlagsContext savedFlagsCtx(Relation(), TypeRelationFlag::NO_RETURN_TYPE_CHECK); - if (currentFunc->Function()->IsDefaultParamProxy()) { - return; - } - Relation()->IsIdenticalTo(func, overload); if (Relation()->IsTrue()) { ThrowTypeError("Function already declared.", currentFunc->Start()); @@ -1287,7 +1192,7 @@ void ETSChecker::CheckOverride(Signature *signature) iter = iter->SuperType(); } - if (!isOverriding && signature->Function()->IsOverride() && !(signature->Function()->IsDefaultParamProxy())) { + if (!isOverriding && signature->Function()->IsOverride()) { ThrowTypeError({"Method ", signature->Function()->Id()->Name(), signature, " in ", signature->Owner(), " not overriding any method"}, signature->Function()->Start()); diff --git a/ets2panda/checker/ets/helpers.cpp b/ets2panda/checker/ets/helpers.cpp index 0f1e672c72..b129ec3eca 100644 --- a/ets2panda/checker/ets/helpers.cpp +++ b/ets2panda/checker/ets/helpers.cpp @@ -2556,38 +2556,6 @@ bool ETSChecker::TypeInference(Signature *signature, const ArenaVector &arguments, - ETSChecker *checker) -{ - if (!signature->Function()->IsDefaultParamProxy() || signature->Function()->Params().size() <= arguments.size()) { - return; - } - - uint32_t num = 0; - for (size_t i = arguments.size(); i != signature->Function()->Params().size() - 1; i++) { - if (auto const *const param = signature->Function()->Params()[i]->AsETSParameterExpression(); - !param->IsRestParameter()) { - auto const *const typeAnn = param->Ident()->TypeAnnotation(); - if (typeAnn->IsETSPrimitiveType()) { - if (typeAnn->AsETSPrimitiveType()->GetPrimitiveType() == ir::PrimitiveType::BOOLEAN) { - arguments.push_back(checker->Allocator()->New(false)); - } else { - arguments.push_back(checker->Allocator()->New(lexer::Number(0))); - } - } else { - // A proxy-function is called, so default reference parameters - // are initialized with null instead of undefined - auto *const nullLiteral = checker->Allocator()->New(); - nullLiteral->SetTsType(checker->GlobalETSNullType()); - arguments.push_back(nullLiteral); - } - num |= (1U << (arguments.size() - 1)); - } - } - arguments.push_back(checker->Allocator()->New(lexer::Number(num))); -} - bool ETSChecker::ExtensionETSFunctionType(checker::Type *type) { if (!type->IsETSFunctionType()) { diff --git a/ets2panda/compiler/core/ASTVerifier.h b/ets2panda/compiler/core/ASTVerifier.h index 6602c533f9..87b9b91dc3 100644 --- a/ets2panda/compiler/core/ASTVerifier.h +++ b/ets2panda/compiler/core/ASTVerifier.h @@ -184,6 +184,7 @@ public: } const std::set withoutAdditionalChecks = {"PromiseVoidInferencePhase", "StructLowering", + "DefaultParameterLowering", "GenerateTsDeclarationsPhase", "InterfacePropertyDeclarationsPhase", "LambdaConstructionPhase", diff --git a/ets2panda/compiler/core/ETSGen.cpp b/ets2panda/compiler/core/ETSGen.cpp index 3b1b3792a2..b65e0c1ba9 100644 --- a/ets2panda/compiler/core/ETSGen.cpp +++ b/ets2panda/compiler/core/ETSGen.cpp @@ -144,6 +144,7 @@ void ETSGen::StoreAccumulator(const ir::AstNode *const node, const VReg vreg) { const auto *const accType = GetAccumulatorType(); + ASSERT(accType != nullptr); if (accType->HasTypeFlag(TYPE_FLAG_BYTECODE_REF)) { Ra().Emit(node, vreg); } else if (accType->HasTypeFlag(checker::TypeFlag::ETS_WIDE_NUMERIC)) { @@ -159,6 +160,7 @@ void ETSGen::LoadAccumulator(const ir::AstNode *node, VReg vreg) { const auto *const vregType = GetVRegType(vreg); + ASSERT(vregType != nullptr); if (vregType->HasTypeFlag(TYPE_FLAG_BYTECODE_REF)) { Ra().Emit(node, vreg); } else if (vregType->HasTypeFlag(checker::TypeFlag::ETS_WIDE_NUMERIC)) { diff --git a/ets2panda/compiler/core/ETSGen.h b/ets2panda/compiler/core/ETSGen.h index b1c5907351..0555fd0c60 100644 --- a/ets2panda/compiler/core/ETSGen.h +++ b/ets2panda/compiler/core/ETSGen.h @@ -974,7 +974,8 @@ private: auto ttctx = TargetTypeContext(this, arg->TsType()); VReg argReg = AllocReg(); arg->Compile(this); - StoreAccumulator(node, argReg); + ApplyConversion(arg, nullptr); + ApplyConversionAndStoreAccumulator(arg, argReg, arg->TsType()); } Rra().Emit(node, ctor, arguments.size() + 1, name, ctor); @@ -1082,7 +1083,8 @@ private: auto ttctx = TargetTypeContext(this, arg->TsType()); VReg argReg = AllocReg(); arg->Compile(this); - StoreAccumulator(node, argReg); + ApplyConversion(arg, nullptr); + ApplyConversionAndStoreAccumulator(node, argReg, arg->TsType()); } Rra().Emit(node, argStart, arguments.size(), name, argStart); @@ -1134,6 +1136,7 @@ private: // + 2U since we need to skip first 2 args in signature; first args is obj, // second arg is param2 auto *argType = signature->Params()[index + 2U]->TsType(); + ApplyConversion(arg, nullptr); ApplyConversionAndStoreAccumulator(node, argReg, argType); index++; } diff --git a/ets2panda/compiler/lowering/ets/defaultParameterLowering.cpp b/ets2panda/compiler/lowering/ets/defaultParameterLowering.cpp new file mode 100644 index 0000000000..ba4e2892b2 --- /dev/null +++ b/ets2panda/compiler/lowering/ets/defaultParameterLowering.cpp @@ -0,0 +1,374 @@ +/** + * Copyright (c) 2023 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. + */ + +#include "defaultParameterLowering.h" +#include +#include "checker/ETSchecker.h" +#include "parser/ETSparser.h" +#include "parser/parserImpl.h" +#include "lexer.h" +#include "utils/arena_containers.h" +#include "ir/statement.h" +#include "varbinder/ETSBinder.h" + +namespace panda::es2panda::compiler { + +std::string_view DefaultParameterLowering::Name() +{ + static std::string_view name = "DefaultParameterLowering"; + return name; +} + +std::pair DefaultParameterLowering::HasDefaultParam(const ir::ScriptFunction *function, + parser::Program *program) +{ + bool hasDefaultParameter = false; + bool hasRestParameter = false; + std::size_t requiredParametersNumber = 0U; + + for (auto *const it : function->Params()) { + auto const *const param = it->AsETSParameterExpression(); + + if (param->IsRestParameter()) { + hasRestParameter = true; + continue; + } + + if (hasRestParameter) { + ThrowSyntaxError("Rest parameter should be the last one.", param->Start(), program); + } + + if (param->IsDefault()) { + hasDefaultParameter = true; + continue; + } + + if (hasDefaultParameter) { + ThrowSyntaxError("Required parameter follows default parameter(s).", param->Start(), program); + } + + ++requiredParametersNumber; + } + + if (hasDefaultParameter && hasRestParameter) { + ThrowSyntaxError("Both optional and rest parameters are not allowed in function's parameter list.", + function->Start(), program); + } + + return std::make_pair(hasDefaultParameter, requiredParametersNumber); +} + +ir::TSTypeParameterDeclaration *DefaultParameterLowering::CreateParameterDeclaraion(ir::MethodDefinition *method, + CompilerContext *ctx) +{ + auto *checker = ctx->Checker()->AsETSChecker(); + if (method->Function()->TypeParams() == nullptr || method->Function()->TypeParams()->Params().empty()) { + return nullptr; + } + + ArenaVector typeParams(checker->Allocator()->Adapter()); + + auto parentParams = method->Function()->TypeParams()->Params(); + std::for_each(parentParams.begin(), parentParams.end(), [&typeParams, checker](ir::TSTypeParameter *par) { + ir::Identifier *ident = par->Name()->Clone(checker->Allocator(), nullptr)->AsIdentifier(); + auto *constraint = par->Constraint() != nullptr + ? par->Constraint()->Clone(checker->Allocator(), nullptr)->AsTypeNode() + : nullptr; + auto *defaultType = par->DefaultType() != nullptr + ? par->DefaultType()->Clone(checker->Allocator(), nullptr)->AsTypeNode() + : nullptr; + typeParams.push_back(checker->AllocNode(ident, constraint, defaultType)); + }); + return checker->AllocNode(std::move(typeParams), typeParams.size()); +} + +ir::FunctionSignature DefaultParameterLowering::CreateFunctionSignature(ir::MethodDefinition *method, + ArenaVector funcParam, + CompilerContext *ctx) +{ + auto *checker = ctx->Checker()->AsETSChecker(); + + ir::TSTypeParameterDeclaration *typeParamDecl = CreateParameterDeclaraion(method, ctx); + std::for_each(funcParam.begin(), funcParam.end(), [checker](ir::Expression *expr) { + if (expr->IsETSParameterExpression()) { + auto *typeAnnot = expr->AsETSParameterExpression()->TypeAnnotation()->Clone(checker->Allocator(), nullptr); + typeAnnot->SetParent(expr); + auto *parIdent = expr->AsETSParameterExpression()->Ident(); + parIdent->SetTsTypeAnnotation(typeAnnot); + } + }); + + auto *returnTypeAnnotation = + method->Function()->ReturnTypeAnnotation() != nullptr + ? method->Function()->ReturnTypeAnnotation()->Clone(checker->Allocator(), nullptr)->AsTypeNode() + : nullptr; + + return ir::FunctionSignature(typeParamDecl, std::move(funcParam), returnTypeAnnotation); +} + +ir::TSTypeParameterInstantiation *DefaultParameterLowering::CreateTypeParameterInstantiation( + ir::MethodDefinition *method, CompilerContext *ctx) +{ + auto *checker = ctx->Checker()->AsETSChecker(); + ArenaVector params(checker->Allocator()->Adapter()); + + if (method->Function()->TypeParams() == nullptr || method->Function()->TypeParams()->Params().empty()) { + return nullptr; + } + ArenaVector selfParams(checker->Allocator()->Adapter()); + ir::ETSTypeReferencePart *referencePart = nullptr; + + for (const auto ¶m : method->Function()->TypeParams()->Params()) { + auto *identRef = + checker->AllocNode(param->AsTSTypeParameter()->Name()->Name(), checker->Allocator()); + identRef->AsIdentifier()->SetReference(); + + referencePart = checker->AllocNode(identRef, nullptr, nullptr); + + auto *typeReference = checker->AllocNode(referencePart); + + selfParams.push_back(typeReference); + } + + return checker->AllocNode(std::move(selfParams)); +} + +ir::AstNode *DefaultParameterLowering::CreateFunctionBody(ir::MethodDefinition *method, CompilerContext *ctx, + ArenaVector funcCallArgs) +{ + auto *checker = ctx->Checker()->AsETSChecker(); + ArenaVector funcStatements(checker->Allocator()->Adapter()); + + ir::CallExpression *callExpression = nullptr; + ir::Expression *id = nullptr; + ir::Expression *accessor = nullptr; + auto *const callee = checker->AllocNode(method->Id()->Name(), checker->Allocator()); + callee->SetReference(); + + if (method->IsConstructor()) { + accessor = checker->AllocNode(); + } else { + if (method->Parent()->IsClassDefinition() && (!method->Parent()->AsClassDefinition()->IsGlobal())) { + if (method->IsStatic()) { + id = checker->AllocNode(method->Parent()->AsClassDefinition()->Ident()->Name(), + checker->Allocator()); + } else { + id = checker->AllocNode(); + } + accessor = checker->AllocNode(id, callee, ir::MemberExpressionKind::PROPERTY_ACCESS, + false, false); + } + } + auto *paramInst = CreateTypeParameterInstantiation(method, ctx); + callExpression = checker->AllocNode(accessor != nullptr ? accessor : callee, + std::move(funcCallArgs), paramInst, false, false); + + ir::Statement *stmt = nullptr; + if ((method->Function()->ReturnTypeAnnotation() != nullptr) || + ((method->Function()->AsScriptFunction()->Flags() & ir::ScriptFunctionFlags::HAS_RETURN) != 0)) { + stmt = checker->AllocNode(callExpression); + } else { + stmt = checker->AllocNode(callExpression); + } + funcStatements.push_back(stmt); + callExpression->SetParent(stmt); + + return checker->AllocNode(checker->Allocator(), std::move(funcStatements)); +} + +ir::FunctionExpression *DefaultParameterLowering::CreateFunctionExpression( + ir::MethodDefinition *method, CompilerContext *ctx, ArenaVector funcDefinitionArgs, + ArenaVector funcCallArgs) +{ + lexer::SourcePosition startLoc(method->Start().line, method->Start().index); + lexer::SourcePosition endLoc = startLoc; + ir::FunctionSignature signature = CreateFunctionSignature(method, std::move(funcDefinitionArgs), ctx); + + auto *checker = ctx->Checker()->AsETSChecker(); + ir::Identifier *id = nullptr; + + ir::AstNode *body = CreateFunctionBody(method, ctx, std::move(funcCallArgs)); + + ir::ScriptFunction *funcNode = nullptr; + id = method->Id()->Clone(checker->Allocator(), nullptr)->AsIdentifier(); + funcNode = checker->AllocNode(std::move(signature), body, method->Function()->Flags(), false, + method->Function()->Language()); + body->SetParent(funcNode); + funcNode->AddModifier(method->Function()->Modifiers()); + funcNode->SetRange({startLoc, endLoc}); + funcNode->SetIdent(id); + + auto *func = checker->AllocNode(funcNode); + id->SetParent(func); + funcNode->SetParent(func); + + return func; +} + +void DefaultParameterLowering::CreateOverloadFunction(ir::AstNode *ast, ArenaVector funcCallArgs, + ArenaVector funcDefinitionArgs, + CompilerContext *ctx) +{ + auto *checker = ctx->Checker()->AsETSChecker(); + auto *method = ast->AsMethodDefinition(); + auto *funcExpression = CreateFunctionExpression(ast->AsMethodDefinition(), ctx, std::move(funcDefinitionArgs), + std::move(funcCallArgs)); + auto *const overloadMethod = + checker->AllocNode(ast->AsMethodDefinition()->Kind(), funcExpression->Function()->Id(), + funcExpression, method->Modifiers(), checker->Allocator(), false); + funcExpression->SetParent(overloadMethod); + + overloadMethod->Function()->AddFlag(ir::ScriptFunctionFlags::OVERLOAD); + overloadMethod->SetRange(funcExpression->Range()); + method->AddOverload(overloadMethod); +} + +void DefaultParameterLowering::ProcessGlobalFunctionDefinition(ir::AstNode *ast, CompilerContext *ctx) +{ + auto *checker = ctx->Checker()->AsETSChecker(); + auto params = ast->AsMethodDefinition()->Function()->Params(); + + // go through default parameters list and create overloading for each combination of them + // i.e. each new overload method has less actual paramaters than previous one and more + // default parameters values used to call original method. + + // NOTE: args counter (i), intentionally starts with 1 as we would need to process at least 1 argument with + // initializer. + for (auto [it, i] = std::tuple {params.rbegin(), 1}; it != params.rend(); ++it, i++) { + if (!((*it)->AsETSParameterExpression()->IsDefault())) { + // do not process regular arguments; + break; + } + + ArenaVector defaultArgs(checker->Allocator()->Adapter()); // will have Initializers + ArenaVector funcDefinitionArgs( + checker->Allocator()->Adapter()); // will have ETSParameterExpression + ArenaVector funcCallArgs(checker->Allocator()->Adapter()); // will have ir::Identifier + + // crate funciton/method definition with less mandatory args than overloaded one + // 1. create copy of found function arguemnts + // 2. move out of them optional ones (one by one),and each time the one + // optional is moved out we need to create new overload method with the rest of + // arguments (as new method args) and move the optional one(s) to the explicit + // call to the original method + // + // foo(x : int = 0, y : int = 1, z : int = 2) + // + // 1. loop step 1 + // foo (x : int, y : int) + // calls foo(x, y, 2) + // 2. loop step 2 + // foo (x :int) + // calls foo(x, 1, 2) + // 3. loop step 3 + // foo () + // calls foo(0, 1, 2) + auto pt = it; + do { + // extract default value from pt and make the function call argument out of it + // for now simple put whole parameter node to vector + ir::Expression *clone = nullptr; + auto *par = (*pt)->AsETSParameterExpression(); + if (par->Initializer()->IsArrowFunctionExpression()) { + clone = par->Initializer(); + } else { + clone = par->Initializer()->Clone(checker->Allocator(), nullptr)->AsExpression(); + } + if (clone != nullptr) { + defaultArgs.push_back(clone); + } + } while (params.rbegin() != pt--); + + // ok, now we need to copy the 'valid' (for now) arguments from original function + // and make the arguments for current overload out of them. + + funcCallArgs.reserve(params.size()); + funcDefinitionArgs.reserve(params.size() - i); + std::for_each( + params.begin(), params.end() - i, [&funcCallArgs, &funcDefinitionArgs, checker](ir::Expression *expr) { + // NOTE: we don't need Initializer here, as overload-method will have strict list of parameters + // will reset all of them once parsing loop completes + auto *funcArg = + expr->AsETSParameterExpression()->Ident()->Clone(checker->Allocator(), nullptr)->AsIdentifier(); + + // update list of functional call arguments + funcCallArgs.push_back(funcArg); + + auto *ident = + expr->AsETSParameterExpression()->Ident()->Clone(checker->Allocator(), nullptr)->AsIdentifier(); + auto *funcParam = checker->Allocator()->New(ident->AsIdentifier(), nullptr); + + // it seems that Clone() didn't copy TypeAnnotaion section .. + // and this causes a problem later on the chcker phase, so set it explicitly + funcParam->AsETSParameterExpression()->Ident()->SetTsTypeAnnotation( + expr->AsETSParameterExpression() + ->TypeAnnotation() + ->Clone(checker->Allocator(), nullptr) + ->AsTypeNode()); + + // prepare args list for overloade method definition + funcDefinitionArgs.push_back(funcParam); + }); + + // finally append arguemnts list with hard-coded literals, + // so eventually we have list of call expression arguments + funcCallArgs.insert(funcCallArgs.end(), defaultArgs.begin(), defaultArgs.end()); + CreateOverloadFunction(ast, std::move(funcCallArgs), std::move(funcDefinitionArgs), ctx); + } + + // done with overloads, now need to cleanup all initializers, + // to make parent function signature strict + std::for_each(params.begin(), params.end(), [](ir::Expression *expr) { + if (expr->AsETSParameterExpression()->IsDefault()) { + expr->AsETSParameterExpression()->SetInitializer(); + } + }); +} + +bool DefaultParameterLowering::Perform(public_lib::Context *ctx, parser::Program *program) +{ + for (auto &[_, extPrograms] : program->ExternalSources()) { + (void)_; + for (auto *extProg : extPrograms) { + Perform(ctx, extProg); + } + } + + checker::ETSChecker *checker = ctx->checker->AsETSChecker(); + ArenaVector foundNodes(checker->Allocator()->Adapter()); + program->Ast()->TransformChildrenRecursively([&foundNodes, this, program](ir::AstNode *ast) -> ir::AstNode * { + if (ast->IsMethodDefinition()) { + auto [hasDefaultParam, requiredParamsCount] = + HasDefaultParam(ast->AsMethodDefinition()->Function(), program); + if (hasDefaultParam) { + // store all nodes (which is function definition with default/optional parameters) + // to specific list, to process them later, as for now we can't modify AST in the + // middle of walking through it + foundNodes.push_back(ast); + } + } + return ast; + }); + + if (!foundNodes.empty()) { + for (auto &it : foundNodes) { + ProcessGlobalFunctionDefinition(it, ctx->compilerContext); + } + } + + return true; +} + +} // namespace panda::es2panda::compiler diff --git a/ets2panda/compiler/lowering/ets/defaultParameterLowering.h b/ets2panda/compiler/lowering/ets/defaultParameterLowering.h new file mode 100644 index 0000000000..49f66ec04a --- /dev/null +++ b/ets2panda/compiler/lowering/ets/defaultParameterLowering.h @@ -0,0 +1,54 @@ +/** + * Copyright (c) 2023 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. + */ + +#ifndef ES2PANDA_COMPILER_LOWERING_DEFAULT_PARAM_LOWERING_H +#define ES2PANDA_COMPILER_LOWERING_DEFAULT_PARAM_LOWERING_H + +#include "compiler/lowering/phase.h" + +namespace panda::es2panda::compiler { + +class DefaultParameterLowering : public Phase { + std::pair HasDefaultParam(const ir::ScriptFunction *function, parser::Program *program); + void ThrowSyntaxError(std::string_view errorMessage, const lexer::SourcePosition &pos, + parser::Program *program) const + { + lexer::LineIndex index(program->SourceCode()); + lexer::SourceLocation loc = index.GetLocation(pos); + + throw Error {ErrorType::SYNTAX, program->SourceFilePath().Utf8(), errorMessage, loc.line, loc.col}; + } + ir::TSTypeParameterDeclaration *CreateParameterDeclaraion(ir::MethodDefinition *method, CompilerContext *ctx); + ir::FunctionSignature CreateFunctionSignature(ir::MethodDefinition *method, ArenaVector funcParam, + CompilerContext *ctx); + ir::TSTypeParameterInstantiation *CreateTypeParameterInstantiation(ir::MethodDefinition *method, + CompilerContext *ctx); + ir::AstNode *CreateFunctionBody(ir::MethodDefinition *method, CompilerContext *ctx, + ArenaVector funcCallArgs); + ir::FunctionExpression *CreateFunctionExpression(ir::MethodDefinition *method, CompilerContext *ctx, + ArenaVector funcDefinitionArgs, + ArenaVector funcCallArgs); + void CreateOverloadFunction(ir::AstNode *ast, ArenaVector funcCallArgs, + ArenaVector funcDefinitionArgs, CompilerContext *ctx); + void ProcessGlobalFunctionDefinition(ir::AstNode *ast, CompilerContext *ctx); + +public: + std::string_view Name() override; + bool Perform(public_lib::Context *ctx, parser::Program *program) override; +}; + +} // namespace panda::es2panda::compiler + +#endif // ES2PANDA_COMPILER_LOWERING_DEFAULT_PARAM_LOWERING_H diff --git a/ets2panda/compiler/lowering/phase.cpp b/ets2panda/compiler/lowering/phase.cpp index ad5e543ef4..a247eb1ac4 100644 --- a/ets2panda/compiler/lowering/phase.cpp +++ b/ets2panda/compiler/lowering/phase.cpp @@ -18,6 +18,7 @@ #include "compiler/core/ASTVerifier.h" #include "compiler/core/compilerContext.h" #include "compiler/lowering/ets/objectIndexAccess.h" +#include "ets/defaultParameterLowering.h" #include "lexer/token/sourceLocation.h" #include "compiler/lowering/checkerPhase.h" #include "compiler/lowering/plugin_phase.h" @@ -33,6 +34,7 @@ #include "public/es2panda_lib.h" #include "compiler/lowering/ets/promiseVoid.h" #include "utils/json_builder.h" +#include "compiler/lowering/ets/defaultParameterLowering.h" namespace panda::es2panda::compiler { @@ -55,6 +57,7 @@ static UnionLowering g_unionLowering; static ExpandBracketsPhase g_expandBracketsPhase; static PromiseVoidInferencePhase g_promiseVoidInferencePhase; static StructLowering g_structLowering; +static DefaultParameterLowering g_defaultParameterLowering; static PluginPhase g_pluginsAfterParse {"plugins-after-parse", ES2PANDA_STATE_PARSED, &util::Plugin::AfterParse}; static PluginPhase g_pluginsAfterCheck {"plugins-after-check", ES2PANDA_STATE_CHECKED, &util::Plugin::AfterCheck}; static PluginPhase g_pluginsAfterLowerings {"plugins-after-lowering", ES2PANDA_STATE_LOWERED, @@ -69,11 +72,22 @@ static InitScopesPhaseJs g_initScopesPhaseJs; std::vector GetETSPhaseList() { return { - &g_pluginsAfterParse, &g_initScopesPhaseEts, &g_promiseVoidInferencePhase, - &g_structLowering, &g_lambdaConstructionPhase, &g_interfacePropDeclPhase, - &g_checkerPhase, &g_pluginsAfterCheck, &g_generateTsDeclarationsPhase, - &g_opAssignmentLowering, &g_objectIndexLowering, &g_tupleLowering, - &g_unionLowering, &g_expandBracketsPhase, &g_pluginsAfterLowerings, + &g_defaultParameterLowering, + &g_pluginsAfterParse, + &g_initScopesPhaseEts, + &g_promiseVoidInferencePhase, + &g_structLowering, + &g_lambdaConstructionPhase, + &g_interfacePropDeclPhase, + &g_checkerPhase, + &g_pluginsAfterCheck, + &g_generateTsDeclarationsPhase, + &g_opAssignmentLowering, + &g_objectIndexLowering, + &g_tupleLowering, + &g_unionLowering, + &g_expandBracketsPhase, + &g_pluginsAfterLowerings, }; } diff --git a/ets2panda/compiler/lowering/scopesInit/scopesInitPhase.cpp b/ets2panda/compiler/lowering/scopesInit/scopesInitPhase.cpp index 736ba8c6cd..8fc6292ab4 100644 --- a/ets2panda/compiler/lowering/scopesInit/scopesInitPhase.cpp +++ b/ets2panda/compiler/lowering/scopesInit/scopesInitPhase.cpp @@ -740,7 +740,7 @@ void InitScopesPhaseETS::DeclareClassMethod(ir::MethodDefinition *method) ASSERT(VarBinder()->GetScope()->IsClassScope()); - if (method->AsMethodDefinition()->Function()->IsDefaultParamProxy()) { + if ((method->AsMethodDefinition()->Function()->Flags() & ir::ScriptFunctionFlags::OVERLOAD) != 0) { return; } @@ -774,7 +774,7 @@ void InitScopesPhaseETS::DeclareClassMethod(ir::MethodDefinition *method) var->AddFlag(varbinder::VariableFlags::METHOD); methodName->SetVariable(var); for (auto *overload : method->Overloads()) { - ASSERT(overload->Function()->IsDefaultParamProxy()); + ASSERT((overload->Function()->Flags() & ir::ScriptFunctionFlags::OVERLOAD)); overload->Id()->SetVariable(var); overload->SetParent(var->Declaration()->Node()); } @@ -785,9 +785,9 @@ void InitScopesPhaseETS::DeclareClassMethod(ir::MethodDefinition *method) addOverload(method, found); method->Function()->AddFlag(ir::ScriptFunctionFlags::OVERLOAD); - // default params proxy + // default params overloads for (auto *overload : method->Overloads()) { - ASSERT(overload->Function()->IsDefaultParamProxy()); + ASSERT((overload->Function()->Flags() & ir::ScriptFunctionFlags::OVERLOAD)); addOverload(overload, found); } method->ClearOverloads(); diff --git a/ets2panda/ir/astNodeFlags.h b/ets2panda/ir/astNodeFlags.h index fb74be021b..ab3b2b157f 100644 --- a/ets2panda/ir/astNodeFlags.h +++ b/ets2panda/ir/astNodeFlags.h @@ -80,10 +80,9 @@ enum class ScriptFunctionFlags : uint32_t { RETHROWS = 1U << 14U, GETTER = 1U << 15U, SETTER = 1U << 16U, - DEFAULT_PARAM_PROXY = 1U << 17U, - ENTRY_POINT = 1U << 18U, - INSTANCE_EXTENSION_METHOD = 1U << 19U, - HAS_RETURN = 1U << 20U + ENTRY_POINT = 1U << 17U, + INSTANCE_EXTENSION_METHOD = 1U << 18U, + HAS_RETURN = 1U << 19U }; enum class TSOperatorType { READONLY, KEYOF, UNIQUE }; diff --git a/ets2panda/ir/base/scriptFunction.h b/ets2panda/ir/base/scriptFunction.h index 36e35e5461..afbc8ebbd8 100644 --- a/ets2panda/ir/base/scriptFunction.h +++ b/ets2panda/ir/base/scriptFunction.h @@ -224,16 +224,6 @@ public: return (funcFlags_ & ir::ScriptFunctionFlags::RETHROWS) != 0; } - [[nodiscard]] bool IsDefaultParamProxy() const noexcept - { - return (funcFlags_ & ir::ScriptFunctionFlags::DEFAULT_PARAM_PROXY) != 0; - } - - void SetDefaultParamProxy() noexcept - { - AddFlag(ir::ScriptFunctionFlags::DEFAULT_PARAM_PROXY); - } - [[nodiscard]] bool IsDynamic() const noexcept { return lang_.IsDynamic(); diff --git a/ets2panda/ir/ets/etsNewClassInstanceExpression.cpp b/ets2panda/ir/ets/etsNewClassInstanceExpression.cpp index c0c75152a5..f8e3233845 100644 --- a/ets2panda/ir/ets/etsNewClassInstanceExpression.cpp +++ b/ets2panda/ir/ets/etsNewClassInstanceExpression.cpp @@ -97,7 +97,9 @@ ETSNewClassInstanceExpression::ETSNewClassInstanceExpression(ETSNewClassInstance : Expression(static_cast(other)), arguments_(allocator->Adapter()), signature_(other.signature_) { typeReference_ = other.typeReference_->Clone(allocator, this)->AsExpression(); - classDef_ = other.classDef_->Clone(allocator, this)->AsClassDefinition(); + if (other.classDef_ != nullptr) { + classDef_ = other.classDef_->Clone(allocator, this)->AsClassDefinition(); + } for (auto *const argument : other.arguments_) { arguments_.emplace_back(argument->Clone(allocator, this)->AsExpression()); diff --git a/ets2panda/ir/ets/etsParameterExpression.h b/ets2panda/ir/ets/etsParameterExpression.h index ec6fde41a5..0cc2ba1701 100644 --- a/ets2panda/ir/ets/etsParameterExpression.h +++ b/ets2panda/ir/ets/etsParameterExpression.h @@ -23,9 +23,6 @@ class ETSAnalyzer; } // namespace panda::es2panda::checker namespace panda::es2panda::ir { -// NOLINTBEGIN(modernize-avoid-c-arrays) -inline constexpr char const PROXY_PARAMETER_NAME[] = "$proxy_mask$"; -// NOLINTEND(modernize-avoid-c-arrays) class ETSParameterExpression final : public Expression { public: @@ -88,6 +85,10 @@ public: void Compile(compiler::ETSGen *etsg) const override; checker::Type *Check(checker::TSChecker *checker) override; checker::Type *Check(checker::ETSChecker *checker) override; + void SetInitializer(Expression *initExpr = nullptr) + { + initializer_ = initExpr; + }; void Accept(ASTVisitorT *v) override { diff --git a/ets2panda/ir/expressions/callExpression.cpp b/ets2panda/ir/expressions/callExpression.cpp index 782f4c1911..e15dcb94a4 100644 --- a/ets2panda/ir/expressions/callExpression.cpp +++ b/ets2panda/ir/expressions/callExpression.cpp @@ -108,7 +108,9 @@ CallExpression::CallExpression(CallExpression const &other, ArenaAllocator *cons isTrailingBlockInNewLine_(other.isTrailingBlockInNewLine_) { callee_ = other.callee_->Clone(allocator, this)->AsExpression(); - typeParams_ = other.typeParams_->Clone(allocator, this); + if (other.typeParams_ != nullptr) { + typeParams_ = other.typeParams_->Clone(allocator, this); + } for (auto *const argument : other.arguments_) { arguments_.emplace_back(argument->Clone(allocator, this)->AsExpression()); diff --git a/ets2panda/parser/ETSparser.cpp b/ets2panda/parser/ETSparser.cpp index b91b25f816..b53a0b37bd 100644 --- a/ets2panda/parser/ETSparser.cpp +++ b/ets2panda/parser/ETSparser.cpp @@ -1408,7 +1408,8 @@ lexer::SourcePosition ETSParser::InitializeGlobalVariable(ir::Identifier *fieldN } ir::MethodDefinition *ETSParser::ParseClassMethodDefinition(ir::Identifier *methodName, ir::ModifierFlags modifiers, - ir::Identifier *className, ir::Identifier *identNode) + ir::Identifier *className, + [[maybe_unused]] ir::Identifier *identNode) { auto newStatus = ParserStatus::NEED_RETURN_TYPE | ParserStatus::ALLOW_SUPER; auto methodKind = ir::MethodDefinitionKind::METHOD; @@ -1444,7 +1445,6 @@ ir::MethodDefinition *ETSParser::ParseClassMethodDefinition(ir::Identifier *meth method->SetRange(funcExpr->Range()); fieldMap_.insert({methodName->Name(), method}); - AddProxyOverloadToMethodWithDefaultParams(method, identNode); return method; } @@ -2243,119 +2243,6 @@ std::pair ETSParser::CheckDefaultParameters(const ir::ScriptF return std::make_pair(hasDefaultParameter, requiredParametersNumber); } -ir::MethodDefinition *ETSParser::CreateProxyConstructorDefinition(ir::MethodDefinition const *const method) -{ - ASSERT(method->IsConstructor()); - - const auto *const function = method->Function(); - std::string proxyMethod = function->Id()->Name().Mutf8() + '('; - - for (const auto *const it : function->Params()) { - auto const *const param = it->AsETSParameterExpression(); - proxyMethod += param->Ident()->Name().Mutf8() + ": " + GetNameForTypeNode(param->TypeAnnotation()) + ", "; - } - - proxyMethod += ir::PROXY_PARAMETER_NAME; - proxyMethod += ": int) { this("; - - auto const parametersNumber = function->Params().size(); - for (size_t i = 0U; i < parametersNumber; ++i) { - if (auto const *const param = function->Params()[i]->AsETSParameterExpression(); param->IsDefault()) { - std::string proxyIf = "(((" + std::string {ir::PROXY_PARAMETER_NAME} + " >> " + std::to_string(i) + - ") & 0x1) == 0) ? " + param->Ident()->Name().Mutf8() + " : (" + - param->LexerSaved().Mutf8() + "), "; - proxyMethod += proxyIf; - } else { - proxyMethod += function->Params()[i]->AsETSParameterExpression()->Ident()->Name().Mutf8() + ", "; - } - } - - proxyMethod.pop_back(); // Note: at least one parameter always should present! - proxyMethod.pop_back(); - proxyMethod += ") }"; - - return CreateConstructorDefinition(method->Modifiers(), proxyMethod, DEFAULT_PROXY_FILE); -} - -ir::MethodDefinition *ETSParser::CreateProxyMethodDefinition(ir::MethodDefinition const *const method, - ir::Identifier const *const identNode) -{ - ASSERT(!method->IsConstructor()); - - const auto *const function = method->Function(); - std::string proxyMethod = function->Id()->Name().Mutf8() + "_proxy("; - - for (const auto *const it : function->Params()) { - auto const *const param = it->AsETSParameterExpression(); - proxyMethod += param->Ident()->Name().Mutf8() + ": " + GetNameForTypeNode(param->TypeAnnotation()) + ", "; - } - - const bool hasFunctionReturnType = function->ReturnTypeAnnotation() != nullptr; - const std::string returnType = hasFunctionReturnType ? GetNameForTypeNode(function->ReturnTypeAnnotation()) : ""; - - proxyMethod += ir::PROXY_PARAMETER_NAME; - proxyMethod += ": int)"; - if (hasFunctionReturnType) { - proxyMethod += ": " + returnType; - } - proxyMethod += " { "; - - auto const parametersNumber = function->Params().size(); - for (size_t i = 0U; i < parametersNumber; ++i) { - if (auto const *const param = function->Params()[i]->AsETSParameterExpression(); param->IsDefault()) { - std::string proxyIf = "if (((" + std::string {ir::PROXY_PARAMETER_NAME} + " >> " + std::to_string(i) + - ") & 0x1) == 1) { " + param->Ident()->Name().Mutf8() + " = " + - param->LexerSaved().Mutf8() + " } "; - proxyMethod += proxyIf; - } - } - - proxyMethod += ' '; - if ((function->AsScriptFunction()->Flags() & ir::ScriptFunctionFlags::HAS_RETURN) != 0) { - proxyMethod += "return "; - } - - if (identNode != nullptr) { - if (method->IsStatic()) { - ASSERT(identNode != nullptr); - proxyMethod += identNode->Name().Mutf8() + "."; - } else { - proxyMethod += "this."; - } - } - - proxyMethod += function->Id()->Name().Mutf8(); - proxyMethod += '('; - - for (const auto *const it : function->Params()) { - proxyMethod += it->AsETSParameterExpression()->Ident()->Name().Mutf8() + ", "; - } - proxyMethod.pop_back(); - proxyMethod.pop_back(); - proxyMethod += ") }"; - - return CreateMethodDefinition(method->Modifiers(), proxyMethod, DEFAULT_PROXY_FILE); -} - -void ETSParser::AddProxyOverloadToMethodWithDefaultParams(ir::MethodDefinition *method, ir::Identifier *identNode) -{ - if (auto const [has_default_parameters, required_parameters] = CheckDefaultParameters(method->Function()); - has_default_parameters) { - if (ir::MethodDefinition *proxyMethodDef = !method->IsConstructor() - ? CreateProxyMethodDefinition(method, identNode) - : CreateProxyConstructorDefinition(method); - proxyMethodDef != nullptr) { - auto *const proxyParam = proxyMethodDef->Function()->Params().back()->AsETSParameterExpression(); - proxyParam->SetRequiredParams(required_parameters); - - proxyMethodDef->Function()->SetDefaultParamProxy(); - proxyMethodDef->Function()->AddFlag(ir::ScriptFunctionFlags::OVERLOAD); - method->AddOverload(proxyMethodDef); - proxyMethodDef->SetParent(method); - } - } -} - std::string ETSParser::PrimitiveTypeToName(ir::PrimitiveType type) { switch (type) { diff --git a/ets2panda/parser/ETSparser.h b/ets2panda/parser/ETSparser.h index 4b4afef511..a7de8a807f 100644 --- a/ets2panda/parser/ETSparser.h +++ b/ets2panda/parser/ETSparser.h @@ -194,10 +194,6 @@ private: ir::TypeNode *ParseFunctionType(); ir::TypeNode *ParseETSTupleType(TypeAnnotationParsingOptions *options); std::pair CheckDefaultParameters(const ir::ScriptFunction *function) const; - ir::MethodDefinition *CreateProxyMethodDefinition(ir::MethodDefinition const *const method, - ir::Identifier const *const identNode); - ir::MethodDefinition *CreateProxyConstructorDefinition(ir::MethodDefinition const *const method); - void AddProxyOverloadToMethodWithDefaultParams(ir::MethodDefinition *method, ir::Identifier *identNode = nullptr); static std::string PrimitiveTypeToName(ir::PrimitiveType type); std::string GetNameForTypeNode(const ir::TypeNode *typeAnnotation, bool adjust = true) const; std::string GetNameForETSUnionType(const ir::TypeNode *typeAnnotation) const; @@ -346,7 +342,6 @@ private: // and correct parent and, probably, variable set to the node(s) after obtaining // NOLINTBEGIN(modernize-avoid-c-arrays) inline static constexpr char const DEFAULT_SOURCE_FILE[] = ".ets"; - inline static constexpr char const DEFAULT_PROXY_FILE[] = ".ets"; // NOLINTEND(modernize-avoid-c-arrays) // NOLINTBEGIN(google-default-arguments) diff --git a/ets2panda/public/es2panda_lib.cpp b/ets2panda/public/es2panda_lib.cpp index 4386ff754f..0d36487ec9 100644 --- a/ets2panda/public/es2panda_lib.cpp +++ b/ets2panda/public/es2panda_lib.cpp @@ -303,9 +303,6 @@ static ir::ScriptFunctionFlags E2pToIrScriptFunctionFlags(es2panda_ScriptFunctio : ir::ScriptFunctionFlags::NONE; irFlags |= (e2pFlags & ES2PANDA_SCRIPT_FUNCTION_RETHROWS) != 0 ? ir::ScriptFunctionFlags::RETHROWS : ir::ScriptFunctionFlags::NONE; - irFlags |= (e2pFlags & ES2PANDA_SCRIPT_FUNCTION_DEFAULT_PARAM_PROXY) != 0 - ? ir::ScriptFunctionFlags::DEFAULT_PARAM_PROXY - : ir::ScriptFunctionFlags::NONE; irFlags |= (e2pFlags & ES2PANDA_SCRIPT_FUNCTION_ENTRY_POINT) != 0 ? ir::ScriptFunctionFlags::ENTRY_POINT : ir::ScriptFunctionFlags::NONE; irFlags |= (e2pFlags & ES2PANDA_SCRIPT_FUNCTION_HAS_RETURN) != 0 ? ir::ScriptFunctionFlags::HAS_RETURN @@ -368,9 +365,6 @@ static es2panda_ScriptFunctionFlags IrToE2pScriptFunctionFlags(ir::ScriptFunctio (irFlags & ir::ScriptFunctionFlags::THROWS) != 0 ? e2pFlags | ES2PANDA_SCRIPT_FUNCTION_THROWS : e2pFlags); e2pFlags = static_cast( (irFlags & ir::ScriptFunctionFlags::RETHROWS) != 0 ? e2pFlags | ES2PANDA_SCRIPT_FUNCTION_RETHROWS : e2pFlags); - e2pFlags = static_cast((irFlags & ir::ScriptFunctionFlags::DEFAULT_PARAM_PROXY) != 0 - ? e2pFlags | ES2PANDA_SCRIPT_FUNCTION_DEFAULT_PARAM_PROXY - : e2pFlags); e2pFlags = static_cast((irFlags & ir::ScriptFunctionFlags::ENTRY_POINT) != 0 ? e2pFlags | ES2PANDA_SCRIPT_FUNCTION_ENTRY_POINT : e2pFlags); diff --git a/ets2panda/public/es2panda_lib.h b/ets2panda/public/es2panda_lib.h index c28f1e708b..29870ed03f 100644 --- a/ets2panda/public/es2panda_lib.h +++ b/ets2panda/public/es2panda_lib.h @@ -102,10 +102,9 @@ enum es2panda_ScriptFunctionFlags { ES2PANDA_SCRIPT_FUNCTION_RETHROWS = 1U << 14U, ES2PANDA_SCRIPT_FUNCTION_GETTER = 1U << 15U, ES2PANDA_SCRIPT_FUNCTION_SETTER = 1U << 16U, - ES2PANDA_SCRIPT_FUNCTION_DEFAULT_PARAM_PROXY = 1U << 17U, - ES2PANDA_SCRIPT_FUNCTION_ENTRY_POINT = 1U << 18U, - ES2PANDA_SCRIPT_FUNCTION_INSTANCE_EXTENSION_METHOD = 1U << 19U, - ES2PANDA_SCRIPT_FUNCTION_HAS_RETURN = 1U << 20U + ES2PANDA_SCRIPT_FUNCTION_ENTRY_POINT = 1U << 17U, + ES2PANDA_SCRIPT_FUNCTION_INSTANCE_EXTENSION_METHOD = 1U << 18U, + ES2PANDA_SCRIPT_FUNCTION_HAS_RETURN = 1U << 19U }; typedef enum es2panda_ScriptFunctionFlags es2panda_ScriptFunctionFlags; diff --git a/ets2panda/test/compiler/ets/optionalLambdaParameter-expected.txt b/ets2panda/test/compiler/ets/optionalLambdaParameter-expected.txt index 9924e957d6..24be78cae4 100644 --- a/ets2panda/test/compiler/ets/optionalLambdaParameter-expected.txt +++ b/ets2panda/test/compiler/ets/optionalLambdaParameter-expected.txt @@ -233,20 +233,6 @@ } } }, - "initializer": { - "type": "UndefinedLiteral", - "value": undefined, - "loc": { - "start": { - "line": 1, - "column": 1 - }, - "end": { - "line": 1, - "column": 1 - } - } - }, "loc": { "start": { "line": 16, @@ -385,16 +371,16 @@ "type": "MethodDefinition", "key": { "type": "Identifier", - "name": "foo_proxy", + "name": "foo", "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 10 }, "end": { - "line": 1, - "column": 3 + "line": 16, + "column": 13 } } }, @@ -409,148 +395,23 @@ "type": "ScriptFunction", "id": { "type": "Identifier", - "name": "foo_proxy", + "name": "foo", "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 10 }, "end": { - "line": 1, - "column": 3 + "line": 16, + "column": 13 } } }, "generator": false, "async": false, "expression": false, - "params": [ - { - "type": "ETSParameterExpression", - "name": { - "type": "Identifier", - "name": "exec", - "typeAnnotation": { - "type": "ETSFunctionType", - "params": [], - "returnType": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "void", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - { - "type": "ETSParameterExpression", - "name": { - "type": "Identifier", - "name": "$proxy_mask$", - "typeAnnotation": { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - } - ], + "params": [], "returnType": { "type": "ETSTypeReference", "part": { @@ -561,34 +422,34 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 16, + "column": 34 }, "end": { - "line": 1, - "column": 3 + "line": 16, + "column": 38 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -596,192 +457,8 @@ "type": "BlockStatement", "statements": [ { - "type": "IfStatement", - "test": { - "type": "BinaryExpression", - "operator": "==", - "left": { - "type": "BinaryExpression", - "operator": "&", - "left": { - "type": "BinaryExpression", - "operator": ">>", - "left": { - "type": "Identifier", - "name": "$proxy_mask$", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 0, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 1, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 1, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "consequent": { - "type": "BlockStatement", - "statements": [ - { - "type": "ExpressionStatement", - "expression": { - "type": "AssignmentExpression", - "operator": "=", - "left": { - "type": "Identifier", - "name": "exec", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "UndefinedLiteral", - "value": undefined, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - } - ], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "alternate": null, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - { - "type": "ExpressionStatement", - "expression": { + "type": "ReturnStatement", + "argument": { "type": "CallExpression", "callee": { "type": "Identifier", @@ -790,27 +467,26 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "arguments": [ { - "type": "Identifier", - "name": "exec", - "decorators": [], + "type": "UndefinedLiteral", + "value": undefined, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } } @@ -819,22 +495,22 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } } @@ -842,33 +518,33 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { - "line": 1, - "column": 3 + "line": 606, + "column": 1 }, "end": { - "line": 1, - "column": 3 + "line": 606, + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -881,7 +557,7 @@ }, "end": { "line": 1, - "column": 3 + "column": 1 } } } diff --git a/ets2panda/test/parser/ets/OptionalParametersWithGenericReturnTypes-expected.txt b/ets2panda/test/parser/ets/OptionalParametersWithGenericReturnTypes-expected.txt index e93759c224..729267764b 100644 --- a/ets2panda/test/parser/ets/OptionalParametersWithGenericReturnTypes-expected.txt +++ b/ets2panda/test/parser/ets/OptionalParametersWithGenericReturnTypes-expected.txt @@ -168,20 +168,6 @@ } } }, - "initializer": { - "type": "UndefinedLiteral", - "value": undefined, - "loc": { - "start": { - "line": 1, - "column": 1 - }, - "end": { - "line": 1, - "column": 1 - } - } - }, "loc": { "start": { "line": 17, @@ -359,16 +345,16 @@ "type": "MethodDefinition", "key": { "type": "Identifier", - "name": "foo_proxy", + "name": "foo", "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 3 + "line": 17, + "column": 8 } } }, @@ -383,134 +369,23 @@ "type": "ScriptFunction", "id": { "type": "Identifier", - "name": "foo_proxy", + "name": "foo", "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 3 + "line": 17, + "column": 8 } } }, "generator": false, "async": false, "expression": false, - "params": [ - { - "type": "ETSParameterExpression", - "name": { - "type": "Identifier", - "name": "param", - "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Number", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - { - "type": "ETSParameterExpression", - "name": { - "type": "Identifier", - "name": "$proxy_mask$", - "typeAnnotation": { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - } - ], + "params": [], "returnType": { "type": "ETSTypeReference", "part": { @@ -521,12 +396,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 17, + "column": 26 }, "end": { - "line": 1, - "column": 3 + "line": 17, + "column": 27 } } }, @@ -543,258 +418,74 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 17, + "column": 28 }, "end": { - "line": 1, - "column": 3 + "line": 17, + "column": 29 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } } ], "loc": { "start": { - "line": 1, - "column": 3 + "line": 17, + "column": 27 }, "end": { - "line": 1, - "column": 3 + "line": 17, + "column": 30 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "body": { "type": "BlockStatement", "statements": [ - { - "type": "IfStatement", - "test": { - "type": "BinaryExpression", - "operator": "==", - "left": { - "type": "BinaryExpression", - "operator": "&", - "left": { - "type": "BinaryExpression", - "operator": ">>", - "left": { - "type": "Identifier", - "name": "$proxy_mask$", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 0, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 1, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 1, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "consequent": { - "type": "BlockStatement", - "statements": [ - { - "type": "ExpressionStatement", - "expression": { - "type": "AssignmentExpression", - "operator": "=", - "left": { - "type": "Identifier", - "name": "param", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "UndefinedLiteral", - "value": undefined, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - } - ], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "alternate": null, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, { "type": "ReturnStatement", "argument": { @@ -806,11 +497,11 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -821,11 +512,11 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -834,27 +525,26 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "arguments": [ { - "type": "Identifier", - "name": "param", - "decorators": [], + "type": "UndefinedLiteral", + "value": undefined, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } } @@ -863,22 +553,22 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } } @@ -886,33 +576,33 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { - "line": 1, - "column": 3 + "line": 628, + "column": 1 }, "end": { - "line": 1, - "column": 3 + "line": 628, + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -925,7 +615,7 @@ }, "end": { "line": 1, - "column": 3 + "column": 1 } } } @@ -1253,20 +943,6 @@ } } }, - "initializer": { - "type": "UndefinedLiteral", - "value": undefined, - "loc": { - "start": { - "line": 1, - "column": 1 - }, - "end": { - "line": 1, - "column": 1 - } - } - }, "loc": { "start": { "line": 23, @@ -1485,16 +1161,16 @@ "type": "MethodDefinition", "key": { "type": "Identifier", - "name": "foo_proxy", + "name": "foo", "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 23, + "column": 5 }, "end": { - "line": 1, - "column": 3 + "line": 23, + "column": 8 } } }, @@ -1509,134 +1185,23 @@ "type": "ScriptFunction", "id": { "type": "Identifier", - "name": "foo_proxy", + "name": "foo", "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 23, + "column": 5 }, "end": { - "line": 1, - "column": 3 + "line": 23, + "column": 8 } } }, "generator": false, "async": false, "expression": false, - "params": [ - { - "type": "ETSParameterExpression", - "name": { - "type": "Identifier", - "name": "param", - "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Number", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - { - "type": "ETSParameterExpression", - "name": { - "type": "Identifier", - "name": "$proxy_mask$", - "typeAnnotation": { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - } - ], + "params": [], "returnType": { "type": "ETSTypeReference", "part": { @@ -1647,12 +1212,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 23, + "column": 26 }, "end": { - "line": 1, - "column": 3 + "line": 23, + "column": 27 } } }, @@ -1669,34 +1234,34 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 23, + "column": 28 }, "end": { - "line": 1, - "column": 3 + "line": 23, + "column": 29 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -1710,258 +1275,74 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 23, + "column": 30 }, "end": { - "line": 1, - "column": 3 + "line": 23, + "column": 31 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } } ], "loc": { "start": { - "line": 1, - "column": 3 + "line": 23, + "column": 27 }, "end": { - "line": 1, - "column": 3 + "line": 23, + "column": 32 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "body": { "type": "BlockStatement", "statements": [ - { - "type": "IfStatement", - "test": { - "type": "BinaryExpression", - "operator": "==", - "left": { - "type": "BinaryExpression", - "operator": "&", - "left": { - "type": "BinaryExpression", - "operator": ">>", - "left": { - "type": "Identifier", - "name": "$proxy_mask$", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 0, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 1, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 1, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "consequent": { - "type": "BlockStatement", - "statements": [ - { - "type": "ExpressionStatement", - "expression": { - "type": "AssignmentExpression", - "operator": "=", - "left": { - "type": "Identifier", - "name": "param", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "UndefinedLiteral", - "value": undefined, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - } - ], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "alternate": null, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, { "type": "ReturnStatement", "argument": { @@ -1973,11 +1354,11 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -1988,11 +1369,11 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -2001,27 +1382,26 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "arguments": [ { - "type": "Identifier", - "name": "param", - "decorators": [], + "type": "UndefinedLiteral", + "value": undefined, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } } @@ -2030,22 +1410,22 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } } @@ -2053,33 +1433,33 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { - "line": 1, - "column": 3 + "line": 704, + "column": 1 }, "end": { - "line": 1, - "column": 3 + "line": 704, + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -2092,7 +1472,7 @@ }, "end": { "line": 1, - "column": 3 + "column": 1 } } } diff --git a/ets2panda/test/parser/ets/default_parameter1-expected.txt b/ets2panda/test/parser/ets/default_parameter1-expected.txt index 41c4146c87..2c507550eb 100644 --- a/ets2panda/test/parser/ets/default_parameter1-expected.txt +++ b/ets2panda/test/parser/ets/default_parameter1-expected.txt @@ -426,20 +426,6 @@ } } }, - "initializer": { - "type": "NumberLiteral", - "value": 10, - "loc": { - "start": { - "line": 21, - "column": 33 - }, - "end": { - "line": 21, - "column": 35 - } - } - }, "loc": { "start": { "line": 21, @@ -564,16 +550,16 @@ "type": "MethodDefinition", "key": { "type": "Identifier", - "name": "foo_proxy", + "name": "foo", "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 10 }, "end": { - "line": 1, - "column": 3 + "line": 21, + "column": 13 } } }, @@ -588,16 +574,16 @@ "type": "ScriptFunction", "id": { "type": "Identifier", - "name": "foo_proxy", + "name": "foo", "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 10 }, "end": { - "line": 1, - "column": 3 + "line": 21, + "column": 13 } } }, @@ -615,116 +601,34 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - { - "type": "ETSParameterExpression", - "name": { - "type": "Identifier", - "name": "b", - "typeAnnotation": { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - { - "type": "ETSParameterExpression", - "name": { - "type": "Identifier", - "name": "$proxy_mask$", - "typeAnnotation": { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 + "line": 21, + "column": 14 }, "end": { - "line": 1, - "column": 3 + "line": 21, + "column": 21 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } } @@ -734,201 +638,17 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "body": { "type": "BlockStatement", "statements": [ - { - "type": "IfStatement", - "test": { - "type": "BinaryExpression", - "operator": "==", - "left": { - "type": "BinaryExpression", - "operator": "&", - "left": { - "type": "BinaryExpression", - "operator": ">>", - "left": { - "type": "Identifier", - "name": "$proxy_mask$", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 1, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 1, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 1, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "consequent": { - "type": "BlockStatement", - "statements": [ - { - "type": "ExpressionStatement", - "expression": { - "type": "AssignmentExpression", - "operator": "=", - "left": { - "type": "Identifier", - "name": "b", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 10, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - } - ], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "alternate": null, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, { "type": "ReturnStatement", "argument": { @@ -940,11 +660,11 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -952,30 +672,42 @@ { "type": "Identifier", "name": "a", + "typeAnnotation": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 21, + "column": 14 }, "end": { - "line": 1, - "column": 3 + "line": 21, + "column": 21 } } }, { - "type": "Identifier", - "name": "b", - "decorators": [], + "type": "NumberLiteral", + "value": 10, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } } @@ -984,22 +716,22 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } } @@ -1007,33 +739,33 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { - "line": 1, - "column": 3 + "line": 646, + "column": 1 }, "end": { - "line": 1, - "column": 3 + "line": 646, + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -1046,7 +778,7 @@ }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -1276,4 +1008,4 @@ } } } -TypeError: Function already declared. [default_parameter1.ets:26:1] +TypeError: Function with this assembly signature already declared. [default_parameter1.ets:26:1] diff --git a/ets2panda/test/parser/ets/default_parameter2-expected.txt b/ets2panda/test/parser/ets/default_parameter2-expected.txt index 1bc729dc18..4983c78f49 100644 --- a/ets2panda/test/parser/ets/default_parameter2-expected.txt +++ b/ets2panda/test/parser/ets/default_parameter2-expected.txt @@ -411,20 +411,6 @@ } } }, - "initializer": { - "type": "NumberLiteral", - "value": 10, - "loc": { - "start": { - "line": 21, - "column": 33 - }, - "end": { - "line": 21, - "column": 35 - } - } - }, "loc": { "start": { "line": 21, @@ -549,16 +535,16 @@ "type": "MethodDefinition", "key": { "type": "Identifier", - "name": "foo_proxy", + "name": "foo", "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 10 }, "end": { - "line": 1, - "column": 3 + "line": 21, + "column": 13 } } }, @@ -573,16 +559,16 @@ "type": "ScriptFunction", "id": { "type": "Identifier", - "name": "foo_proxy", + "name": "foo", "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 10 }, "end": { - "line": 1, - "column": 3 + "line": 21, + "column": 13 } } }, @@ -600,116 +586,34 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - { - "type": "ETSParameterExpression", - "name": { - "type": "Identifier", - "name": "b", - "typeAnnotation": { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - { - "type": "ETSParameterExpression", - "name": { - "type": "Identifier", - "name": "$proxy_mask$", - "typeAnnotation": { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 + "line": 21, + "column": 14 }, "end": { - "line": 1, - "column": 3 + "line": 21, + "column": 21 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } } @@ -719,201 +623,17 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "body": { "type": "BlockStatement", "statements": [ - { - "type": "IfStatement", - "test": { - "type": "BinaryExpression", - "operator": "==", - "left": { - "type": "BinaryExpression", - "operator": "&", - "left": { - "type": "BinaryExpression", - "operator": ">>", - "left": { - "type": "Identifier", - "name": "$proxy_mask$", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 1, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 1, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 1, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "consequent": { - "type": "BlockStatement", - "statements": [ - { - "type": "ExpressionStatement", - "expression": { - "type": "AssignmentExpression", - "operator": "=", - "left": { - "type": "Identifier", - "name": "b", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 10, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - } - ], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "alternate": null, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, { "type": "ReturnStatement", "argument": { @@ -925,11 +645,11 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -937,30 +657,42 @@ { "type": "Identifier", "name": "a", + "typeAnnotation": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 21, + "column": 14 }, "end": { - "line": 1, - "column": 3 + "line": 21, + "column": 21 } } }, { - "type": "Identifier", - "name": "b", - "decorators": [], + "type": "NumberLiteral", + "value": 10, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } } @@ -969,22 +701,22 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } } @@ -992,33 +724,33 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { - "line": 1, - "column": 3 + "line": 645, + "column": 1 }, "end": { - "line": 1, - "column": 3 + "line": 645, + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -1031,7 +763,7 @@ }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -1261,4 +993,4 @@ } } } -TypeError: Function already declared. [default_parameter2.ets:26:1] +TypeError: Function with this assembly signature already declared. [default_parameter2.ets:26:1] diff --git a/ets2panda/test/parser/ets/default_parameter4-expected.txt b/ets2panda/test/parser/ets/default_parameter4-expected.txt index 9ddd359583..cdb523e6a2 100644 --- a/ets2panda/test/parser/ets/default_parameter4-expected.txt +++ b/ets2panda/test/parser/ets/default_parameter4-expected.txt @@ -426,20 +426,6 @@ } } }, - "initializer": { - "type": "NumberLiteral", - "value": 10, - "loc": { - "start": { - "line": 21, - "column": 33 - }, - "end": { - "line": 21, - "column": 35 - } - } - }, "loc": { "start": { "line": 21, @@ -481,20 +467,6 @@ } } }, - "initializer": { - "type": "NumberLiteral", - "value": 15, - "loc": { - "start": { - "line": 21, - "column": 47 - }, - "end": { - "line": 21, - "column": 49 - } - } - }, "loc": { "start": { "line": 21, @@ -648,16 +620,16 @@ "type": "MethodDefinition", "key": { "type": "Identifier", - "name": "foo_proxy", + "name": "foo", "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 10 }, "end": { - "line": 1, - "column": 3 + "line": 21, + "column": 13 } } }, @@ -672,16 +644,16 @@ "type": "ScriptFunction", "id": { "type": "Identifier", - "name": "foo_proxy", + "name": "foo", "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 10 }, "end": { - "line": 1, - "column": 3 + "line": 21, + "column": 13 } } }, @@ -699,34 +671,34 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 21, + "column": 14 }, "end": { - "line": 1, - "column": 3 + "line": 21, + "column": 21 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -740,116 +712,34 @@ "loc": { "start": { "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - { - "type": "ETSParameterExpression", - "name": { - "type": "Identifier", - "name": "c", - "typeAnnotation": { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - { - "type": "ETSParameterExpression", - "name": { - "type": "Identifier", - "name": "$proxy_mask$", - "typeAnnotation": { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 21, + "column": 23 }, "end": { - "line": 1, - "column": 3 + "line": 21, + "column": 30 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } } @@ -859,11 +749,11 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -871,373 +761,269 @@ "type": "BlockStatement", "statements": [ { - "type": "IfStatement", - "test": { - "type": "BinaryExpression", - "operator": "==", - "left": { - "type": "BinaryExpression", - "operator": "&", - "left": { - "type": "BinaryExpression", - "operator": ">>", - "left": { - "type": "Identifier", - "name": "$proxy_mask$", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 1, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 1, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 1, + "type": "ReturnStatement", + "argument": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "foo", + "decorators": [], "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "consequent": { - "type": "BlockStatement", - "statements": [ + "arguments": [ { - "type": "ExpressionStatement", - "expression": { - "type": "AssignmentExpression", - "operator": "=", - "left": { - "type": "Identifier", - "name": "b", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 10, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, + "type": "Identifier", + "name": "a", + "typeAnnotation": { + "type": "ETSPrimitiveType", "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, + "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 21, + "column": 14 }, "end": { - "line": 1, - "column": 3 + "line": 21, + "column": 21 } } - } - ], - "loc": { - "start": { - "line": 1, - "column": 3 }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "alternate": null, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - { - "type": "IfStatement", - "test": { - "type": "BinaryExpression", - "operator": "==", - "left": { - "type": "BinaryExpression", - "operator": "&", - "left": { - "type": "BinaryExpression", - "operator": ">>", - "left": { - "type": "Identifier", - "name": "$proxy_mask$", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 2, + { + "type": "Identifier", + "name": "b", + "typeAnnotation": { + "type": "ETSPrimitiveType", "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, + "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 21, + "column": 23 }, "end": { - "line": 1, - "column": 3 + "line": 21, + "column": 30 } } }, - "right": { + { "type": "NumberLiteral", - "value": 1, + "value": 15, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 1, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } } - }, + ], + "optional": false, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, - "consequent": { - "type": "BlockStatement", - "statements": [ - { - "type": "ExpressionStatement", - "expression": { - "type": "AssignmentExpression", - "operator": "=", - "left": { - "type": "Identifier", - "name": "c", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 15, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - } - ], + "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": 646, + "column": 1 + }, + "end": { + "line": 646, + "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": "foo", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 10 + }, + "end": { + "line": 21, + "column": 13 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 10 + }, + "end": { + "line": 21, + "column": 13 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "a", + "typeAnnotation": { + "type": "ETSPrimitiveType", "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, - "alternate": null, + "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 21, + "column": 14 }, "end": { - "line": 1, - "column": 3 + "line": 21, + "column": 21 } } }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "returnType": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ { "type": "ReturnStatement", "argument": { @@ -1249,11 +1035,11 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -1261,45 +1047,56 @@ { "type": "Identifier", "name": "a", + "typeAnnotation": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 21, + "column": 14 }, "end": { - "line": 1, - "column": 3 + "line": 21, + "column": 21 } } }, { - "type": "Identifier", - "name": "b", - "decorators": [], + "type": "NumberLiteral", + "value": 10, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, { - "type": "Identifier", - "name": "c", - "decorators": [], + "type": "NumberLiteral", + "value": 15, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } } @@ -1308,22 +1105,22 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } } @@ -1331,33 +1128,33 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { - "line": 1, - "column": 3 + "line": 646, + "column": 1 }, "end": { - "line": 1, - "column": 3 + "line": 646, + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -1370,7 +1167,7 @@ }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -1449,20 +1246,6 @@ } } }, - "initializer": { - "type": "NumberLiteral", - "value": 5, - "loc": { - "start": { - "line": 26, - "column": 24 - }, - "end": { - "line": 26, - "column": 25 - } - } - }, "loc": { "start": { "line": 26, @@ -1570,16 +1353,16 @@ "type": "MethodDefinition", "key": { "type": "Identifier", - "name": "foo_proxy", + "name": "foo", "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 26, + "column": 10 }, "end": { - "line": 1, - "column": 3 + "line": 26, + "column": 13 } } }, @@ -1594,306 +1377,39 @@ "type": "ScriptFunction", "id": { "type": "Identifier", - "name": "foo_proxy", + "name": "foo", "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 26, + "column": 10 }, "end": { - "line": 1, - "column": 3 + "line": 26, + "column": 13 } } }, "generator": false, "async": false, "expression": false, - "params": [ - { - "type": "ETSParameterExpression", - "name": { - "type": "Identifier", - "name": "a", - "typeAnnotation": { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - { - "type": "ETSParameterExpression", - "name": { - "type": "Identifier", - "name": "$proxy_mask$", - "typeAnnotation": { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - } - ], + "params": [], "returnType": { "type": "ETSPrimitiveType", "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "body": { "type": "BlockStatement", "statements": [ - { - "type": "IfStatement", - "test": { - "type": "BinaryExpression", - "operator": "==", - "left": { - "type": "BinaryExpression", - "operator": "&", - "left": { - "type": "BinaryExpression", - "operator": ">>", - "left": { - "type": "Identifier", - "name": "$proxy_mask$", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 0, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 1, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 1, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "consequent": { - "type": "BlockStatement", - "statements": [ - { - "type": "ExpressionStatement", - "expression": { - "type": "AssignmentExpression", - "operator": "=", - "left": { - "type": "Identifier", - "name": "a", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 5, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - } - ], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "alternate": null, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, { "type": "ReturnStatement", "argument": { @@ -1905,27 +1421,26 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "arguments": [ { - "type": "Identifier", - "name": "a", - "decorators": [], + "type": "NumberLiteral", + "value": 5, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } } @@ -1934,22 +1449,22 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } } @@ -1957,33 +1472,33 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { - "line": 1, - "column": 3 + "line": 729, + "column": 1 }, "end": { - "line": 1, - "column": 3 + "line": 729, + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -1996,7 +1511,7 @@ }, "end": { "line": 1, - "column": 3 + "column": 1 } } } @@ -2048,4 +1563,4 @@ } } } -TypeError: Function already declared. [default_parameter4.ets:26:1] +TypeError: Function with this assembly signature already declared. [default_parameter4.ets:26:1] diff --git a/ets2panda/test/parser/ets/default_parameter5-expected.txt b/ets2panda/test/parser/ets/default_parameter5-expected.txt index ab0a5a6760..8fac2d5966 100644 --- a/ets2panda/test/parser/ets/default_parameter5-expected.txt +++ b/ets2panda/test/parser/ets/default_parameter5-expected.txt @@ -481,65 +481,6 @@ } } }, - "initializer": { - "type": "CallExpression", - "callee": { - "type": "Identifier", - "name": "boo2", - "decorators": [], - "loc": { - "start": { - "line": 21, - "column": 46 - }, - "end": { - "line": 21, - "column": 50 - } - } - }, - "arguments": [ - { - "type": "NumberLiteral", - "value": 1, - "loc": { - "start": { - "line": 21, - "column": 51 - }, - "end": { - "line": 21, - "column": 52 - } - } - }, - { - "type": "NumberLiteral", - "value": 2, - "loc": { - "start": { - "line": 21, - "column": 53 - }, - "end": { - "line": 21, - "column": 54 - } - } - } - ], - "optional": false, - "loc": { - "start": { - "line": 21, - "column": 46 - }, - "end": { - "line": 21, - "column": 55 - } - } - }, "loc": { "start": { "line": 21, @@ -693,16 +634,16 @@ "type": "MethodDefinition", "key": { "type": "Identifier", - "name": "boo2_proxy", + "name": "boo2", "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 10 }, "end": { - "line": 1, - "column": 3 + "line": 21, + "column": 14 } } }, @@ -717,16 +658,16 @@ "type": "ScriptFunction", "id": { "type": "Identifier", - "name": "boo2_proxy", + "name": "boo2", "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 10 }, "end": { - "line": 1, - "column": 3 + "line": 21, + "column": 14 } } }, @@ -744,34 +685,34 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 21, + "column": 15 }, "end": { - "line": 1, - "column": 3 + "line": 21, + "column": 23 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -785,116 +726,34 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - { - "type": "ETSParameterExpression", - "name": { - "type": "Identifier", - "name": "a2", - "typeAnnotation": { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - { - "type": "ETSParameterExpression", - "name": { - "type": "Identifier", - "name": "$proxy_mask$", - "typeAnnotation": { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 + "line": 21, + "column": 25 }, "end": { - "line": 1, - "column": 3 + "line": 21, + "column": 33 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } } @@ -904,11 +763,11 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -916,296 +775,137 @@ "type": "BlockStatement", "statements": [ { - "type": "IfStatement", - "test": { - "type": "BinaryExpression", - "operator": "==", - "left": { - "type": "BinaryExpression", - "operator": "&", - "left": { - "type": "BinaryExpression", - "operator": ">>", - "left": { - "type": "Identifier", - "name": "$proxy_mask$", - "decorators": [], + "type": "ReturnStatement", + "argument": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "boo2", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "arguments": [ + { + "type": "Identifier", + "name": "a0", + "typeAnnotation": { + "type": "ETSPrimitiveType", "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, - "right": { - "type": "NumberLiteral", - "value": 2, + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 15 + }, + "end": { + "line": 21, + "column": 23 + } + } + }, + { + "type": "Identifier", + "name": "a1", + "typeAnnotation": { + "type": "ETSPrimitiveType", "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, + "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 21, + "column": 25 }, "end": { - "line": 1, - "column": 3 + "line": 21, + "column": 33 } } }, - "right": { - "type": "NumberLiteral", - "value": 1, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 + { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "boo2", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 46 + }, + "end": { + "line": 21, + "column": 50 + } } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 1, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "consequent": { - "type": "BlockStatement", - "statements": [ - { - "type": "ExpressionStatement", - "expression": { - "type": "AssignmentExpression", - "operator": "=", - "left": { - "type": "Identifier", - "name": "a2", - "decorators": [], + "arguments": [ + { + "type": "NumberLiteral", + "value": 1, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, - "right": { - "type": "CallExpression", - "callee": { - "type": "Identifier", - "name": "boo2", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "arguments": [ - { - "type": "NumberLiteral", - "value": 1, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - { - "type": "NumberLiteral", - "value": 2, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - } - ], - "optional": false, + { + "type": "NumberLiteral", + "value": 2, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 } - } - } - ], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "alternate": null, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - { - "type": "ReturnStatement", - "argument": { - "type": "CallExpression", - "callee": { - "type": "Identifier", - "name": "boo2", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "arguments": [ - { - "type": "Identifier", - "name": "a0", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - { - "type": "Identifier", - "name": "a1", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - { - "type": "Identifier", - "name": "a2", - "decorators": [], + ], + "optional": false, "loc": { "start": { - "line": 1, - "column": 3 + "line": 21, + "column": 46 }, "end": { - "line": 1, - "column": 3 + "line": 21, + "column": 55 } } } @@ -1214,22 +914,22 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } } @@ -1237,33 +937,33 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { - "line": 1, - "column": 3 + "line": 667, + "column": 1 }, "end": { - "line": 1, - "column": 3 + "line": 667, + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -1276,7 +976,7 @@ }, "end": { "line": 1, - "column": 3 + "column": 1 } } } diff --git a/ets2panda/test/parser/ets/default_parameter6-expected.txt b/ets2panda/test/parser/ets/default_parameter6-expected.txt index ad8c1be4b1..465604404e 100644 --- a/ets2panda/test/parser/ets/default_parameter6-expected.txt +++ b/ets2panda/test/parser/ets/default_parameter6-expected.txt @@ -288,20 +288,6 @@ } } }, - "initializer": { - "type": "NumberLiteral", - "value": 20, - "loc": { - "start": { - "line": 16, - "column": 33 - }, - "end": { - "line": 16, - "column": 35 - } - } - }, "loc": { "start": { "line": 16, @@ -371,20 +357,6 @@ } } }, - "initializer": { - "type": "NumberLiteral", - "value": 30, - "loc": { - "start": { - "line": 16, - "column": 47 - }, - "end": { - "line": 16, - "column": 49 - } - } - }, "loc": { "start": { "line": 16, @@ -507,16 +479,16 @@ "type": "MethodDefinition", "key": { "type": "Identifier", - "name": "foo_proxy", + "name": "foo", "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 10 }, "end": { - "line": 1, - "column": 3 + "line": 16, + "column": 13 } } }, @@ -531,16 +503,16 @@ "type": "ScriptFunction", "id": { "type": "Identifier", - "name": "foo_proxy", + "name": "foo", "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 10 }, "end": { - "line": 1, - "column": 3 + "line": 16, + "column": 13 } } }, @@ -563,57 +535,57 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 16, + "column": 18 }, "end": { - "line": 1, - "column": 3 + "line": 16, + "column": 21 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 16, + "column": 14 }, "end": { - "line": 1, - "column": 3 + "line": 16, + "column": 22 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -632,167 +604,57 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - { - "type": "ETSParameterExpression", - "name": { - "type": "Identifier", - "name": "c", - "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Int", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 + "line": 16, + "column": 27 }, "end": { - "line": 1, - "column": 3 + "line": 16, + "column": 30 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - { - "type": "ETSParameterExpression", - "name": { - "type": "Identifier", - "name": "$proxy_mask$", - "typeAnnotation": { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 16, + "column": 23 }, "end": { - "line": 1, - "column": 3 + "line": 16, + "column": 32 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } } @@ -807,34 +669,34 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 16, + "column": 53 }, "end": { - "line": 1, - "column": 3 + "line": 16, + "column": 56 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -842,373 +704,381 @@ "type": "BlockStatement", "statements": [ { - "type": "IfStatement", - "test": { - "type": "BinaryExpression", - "operator": "==", - "left": { - "type": "BinaryExpression", - "operator": "&", - "left": { - "type": "BinaryExpression", - "operator": ">>", - "left": { - "type": "Identifier", - "name": "$proxy_mask$", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 + "type": "ReturnStatement", + "argument": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "arguments": [ + { + "type": "Identifier", + "name": "a", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 18 + }, + "end": { + "line": 16, + "column": 21 + } + } }, - "end": { - "line": 1, - "column": 3 + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } } - } - }, - "right": { - "type": "NumberLiteral", - "value": 1, + }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, + "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 1, - "loc": { - "start": { - "line": 1, - "column": 3 + "line": 16, + "column": 14 }, "end": { - "line": 1, - "column": 3 + "line": 16, + "column": 22 } } }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 1, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "consequent": { - "type": "BlockStatement", - "statements": [ { - "type": "ExpressionStatement", - "expression": { - "type": "AssignmentExpression", - "operator": "=", - "left": { - "type": "Identifier", - "name": "b", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 + "type": "Identifier", + "name": "b", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 27 + }, + "end": { + "line": 16, + "column": 30 + } } - } - }, - "right": { - "type": "NumberLiteral", - "value": 20, + }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 23 + }, + "end": { + "line": 16, + "column": 32 + } + } + }, + { + "type": "NumberLiteral", + "value": 30, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } } ], + "optional": false, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, - "alternate": null, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 }, - { - "type": "IfStatement", - "test": { - "type": "BinaryExpression", - "operator": "==", - "left": { - "type": "BinaryExpression", - "operator": "&", - "left": { - "type": "BinaryExpression", - "operator": ">>", - "left": { - "type": "Identifier", - "name": "$proxy_mask$", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 2, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 1, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 606, + "column": 1 + }, + "end": { + "line": 606, + "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": "foo", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 10 + }, + "end": { + "line": 16, + "column": 13 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 10 + }, + "end": { + "line": 16, + "column": 13 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "a", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 16, + "column": 18 }, "end": { - "line": 1, - "column": 3 + "line": 16, + "column": 21 } } }, "loc": { "start": { "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 1, - "loc": { - "start": { - "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, - "consequent": { - "type": "BlockStatement", - "statements": [ - { - "type": "ExpressionStatement", - "expression": { - "type": "AssignmentExpression", - "operator": "=", - "left": { - "type": "Identifier", - "name": "c", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 30, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - } - ], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 14 + }, + "end": { + "line": 16, + "column": 22 } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 }, - "alternate": null, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 16, + "column": 53 }, "end": { - "line": 1, - "column": 3 + "line": 16, + "column": 56 } } }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ { "type": "ReturnStatement", "argument": { @@ -1220,11 +1090,11 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -1232,45 +1102,84 @@ { "type": "Identifier", "name": "a", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 18 + }, + "end": { + "line": 16, + "column": 21 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 16, + "column": 14 }, "end": { - "line": 1, - "column": 3 + "line": 16, + "column": 22 } } }, { - "type": "Identifier", - "name": "b", - "decorators": [], + "type": "NumberLiteral", + "value": 20, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, { - "type": "Identifier", - "name": "c", - "decorators": [], + "type": "NumberLiteral", + "value": 30, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } } @@ -1279,22 +1188,22 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } } @@ -1302,33 +1211,33 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { - "line": 1, - "column": 3 + "line": 606, + "column": 1 }, "end": { - "line": 1, - "column": 3 + "line": 606, + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -1341,7 +1250,7 @@ }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -1517,20 +1426,6 @@ } } }, - "initializer": { - "type": "StringLiteral", - "value": "a", - "loc": { - "start": { - "line": 21, - "column": 36 - }, - "end": { - "line": 21, - "column": 39 - } - } - }, "loc": { "start": { "line": 21, @@ -1600,20 +1495,6 @@ } } }, - "initializer": { - "type": "NumberLiteral", - "value": 30, - "loc": { - "start": { - "line": 21, - "column": 51 - }, - "end": { - "line": 21, - "column": 53 - } - } - }, "loc": { "start": { "line": 21, @@ -1748,16 +1629,16 @@ "type": "MethodDefinition", "key": { "type": "Identifier", - "name": "foo_proxy", + "name": "foo", "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 10 }, "end": { - "line": 1, - "column": 3 + "line": 21, + "column": 13 } } }, @@ -1772,158 +1653,89 @@ "type": "ScriptFunction", "id": { "type": "Identifier", - "name": "foo_proxy", + "name": "foo", "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "generator": false, - "async": false, - "expression": false, - "params": [ - { - "type": "ETSParameterExpression", - "name": { - "type": "Identifier", - "name": "a", - "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Int", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } + "line": 21, + "column": 10 }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } + "end": { + "line": 21, + "column": 13 } - }, + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ { "type": "ETSParameterExpression", "name": { "type": "Identifier", - "name": "b", + "name": "a", "typeAnnotation": { "type": "ETSTypeReference", "part": { "type": "ETSTypeReferencePart", "name": { "type": "Identifier", - "name": "string", + "name": "Int", "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 21, + "column": 18 }, "end": { - "line": 1, - "column": 3 + "line": 21, + "column": 21 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 21, + "column": 14 }, "end": { - "line": 1, - "column": 3 + "line": 21, + "column": 22 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -1931,109 +1743,68 @@ "type": "ETSParameterExpression", "name": { "type": "Identifier", - "name": "c", + "name": "b", "typeAnnotation": { "type": "ETSTypeReference", "part": { "type": "ETSTypeReferencePart", "name": { "type": "Identifier", - "name": "Int", + "name": "string", "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 21, + "column": 27 }, "end": { - "line": 1, - "column": 3 + "line": 21, + "column": 33 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - { - "type": "ETSParameterExpression", - "name": { - "type": "Identifier", - "name": "$proxy_mask$", - "typeAnnotation": { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 21, + "column": 23 }, "end": { - "line": 1, - "column": 3 + "line": 21, + "column": 35 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } } @@ -2048,34 +1819,34 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 21, + "column": 57 }, "end": { - "line": 1, - "column": 3 + "line": 21, + "column": 60 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -2083,373 +1854,381 @@ "type": "BlockStatement", "statements": [ { - "type": "IfStatement", - "test": { - "type": "BinaryExpression", - "operator": "==", - "left": { - "type": "BinaryExpression", - "operator": "&", - "left": { - "type": "BinaryExpression", - "operator": ">>", - "left": { - "type": "Identifier", - "name": "$proxy_mask$", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 1, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 1, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 1, + "type": "ReturnStatement", + "argument": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "foo", + "decorators": [], "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "consequent": { - "type": "BlockStatement", - "statements": [ + "arguments": [ { - "type": "ExpressionStatement", - "expression": { - "type": "AssignmentExpression", - "operator": "=", - "left": { - "type": "Identifier", - "name": "b", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 + "type": "Identifier", + "name": "a", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 18 + }, + "end": { + "line": 21, + "column": 21 + } } - } - }, - "right": { - "type": "StringLiteral", - "value": "a", + }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - } - ], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "alternate": null, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - { - "type": "IfStatement", - "test": { - "type": "BinaryExpression", - "operator": "==", - "left": { - "type": "BinaryExpression", - "operator": "&", - "left": { - "type": "BinaryExpression", - "operator": ">>", - "left": { - "type": "Identifier", - "name": "$proxy_mask$", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 2, - "loc": { - "start": { - "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, + "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 1, - "loc": { - "start": { - "line": 1, - "column": 3 + "line": 21, + "column": 14 }, "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 1, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "consequent": { - "type": "BlockStatement", - "statements": [ + "line": 21, + "column": 22 + } + } + }, { - "type": "ExpressionStatement", - "expression": { - "type": "AssignmentExpression", - "operator": "=", - "left": { - "type": "Identifier", - "name": "c", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 + "type": "Identifier", + "name": "b", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 27 + }, + "end": { + "line": 21, + "column": 33 + } } - } - }, - "right": { - "type": "NumberLiteral", - "value": 30, + }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 23 + }, + "end": { + "line": 21, + "column": 35 + } + } + }, + { + "type": "NumberLiteral", + "value": 30, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } } ], + "optional": false, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, - "alternate": null, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 681, + "column": 1 + }, + "end": { + "line": 681, + "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": "foo", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 10 + }, + "end": { + "line": 21, + "column": 13 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 10 + }, + "end": { + "line": 21, + "column": 13 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "a", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 18 + }, + "end": { + "line": 21, + "column": 21 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 14 + }, + "end": { + "line": 21, + "column": 22 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 57 + }, + "end": { + "line": 21, + "column": 60 } } }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ { "type": "ReturnStatement", "argument": { @@ -2461,11 +2240,11 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -2473,45 +2252,84 @@ { "type": "Identifier", "name": "a", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 18 + }, + "end": { + "line": 21, + "column": 21 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 21, + "column": 14 }, "end": { - "line": 1, - "column": 3 + "line": 21, + "column": 22 } } }, { - "type": "Identifier", - "name": "b", - "decorators": [], + "type": "StringLiteral", + "value": "a", "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, { - "type": "Identifier", - "name": "c", - "decorators": [], + "type": "NumberLiteral", + "value": 30, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } } @@ -2520,22 +2338,22 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } } @@ -2543,33 +2361,33 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { - "line": 1, - "column": 3 + "line": 681, + "column": 1 }, "end": { - "line": 1, - "column": 3 + "line": 681, + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -2582,7 +2400,7 @@ }, "end": { "line": 1, - "column": 3 + "column": 1 } } } @@ -2634,4 +2452,4 @@ } } } -TypeError: Function already declared. [default_parameter6.ets:21:1] +TypeError: Function with this assembly signature already declared. [default_parameter6.ets:1:1] diff --git a/ets2panda/test/parser/ets/default_parameter7-expected.txt b/ets2panda/test/parser/ets/default_parameter7-expected.txt index c6d4b58f37..def50f4bb4 100644 --- a/ets2panda/test/parser/ets/default_parameter7-expected.txt +++ b/ets2panda/test/parser/ets/default_parameter7-expected.txt @@ -535,20 +535,6 @@ } } }, - "initializer": { - "type": "UndefinedLiteral", - "value": undefined, - "loc": { - "start": { - "line": 1, - "column": 1 - }, - "end": { - "line": 1, - "column": 1 - } - } - }, "loc": { "start": { "line": 21, @@ -618,20 +604,6 @@ } } }, - "initializer": { - "type": "NumberLiteral", - "value": 30, - "loc": { - "start": { - "line": 21, - "column": 46 - }, - "end": { - "line": 21, - "column": 48 - } - } - }, "loc": { "start": { "line": 21, @@ -766,16 +738,16 @@ "type": "MethodDefinition", "key": { "type": "Identifier", - "name": "foo_proxy", + "name": "foo", "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 10 }, "end": { - "line": 1, - "column": 3 + "line": 21, + "column": 13 } } }, @@ -790,16 +762,16 @@ "type": "ScriptFunction", "id": { "type": "Identifier", - "name": "foo_proxy", + "name": "foo", "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 10 }, "end": { - "line": 1, - "column": 3 + "line": 21, + "column": 13 } } }, @@ -822,57 +794,57 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 21, + "column": 18 }, "end": { - "line": 1, - "column": 3 + "line": 21, + "column": 21 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 21, + "column": 14 }, "end": { - "line": 1, - "column": 3 + "line": 21, + "column": 22 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -891,167 +863,57 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - { - "type": "ETSParameterExpression", - "name": { - "type": "Identifier", - "name": "c", - "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Int", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 + "line": 21, + "column": 28 }, "end": { - "line": 1, - "column": 3 + "line": 21, + "column": 34 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - { - "type": "ETSParameterExpression", - "name": { - "type": "Identifier", - "name": "$proxy_mask$", - "typeAnnotation": { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 21, + "column": 23 }, "end": { - "line": 1, - "column": 3 + "line": 21, + "column": 35 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } } @@ -1066,34 +928,34 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 21, + "column": 52 }, "end": { - "line": 1, - "column": 3 + "line": 21, + "column": 55 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -1101,373 +963,381 @@ "type": "BlockStatement", "statements": [ { - "type": "IfStatement", - "test": { - "type": "BinaryExpression", - "operator": "==", - "left": { - "type": "BinaryExpression", - "operator": "&", - "left": { - "type": "BinaryExpression", - "operator": ">>", - "left": { - "type": "Identifier", - "name": "$proxy_mask$", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 + "type": "ReturnStatement", + "argument": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "arguments": [ + { + "type": "Identifier", + "name": "a", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 18 + }, + "end": { + "line": 21, + "column": 21 + } + } }, - "end": { - "line": 1, - "column": 3 + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } } - } - }, - "right": { - "type": "NumberLiteral", - "value": 1, + }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, + "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 1, - "loc": { - "start": { - "line": 1, - "column": 3 + "line": 21, + "column": 14 }, "end": { - "line": 1, - "column": 3 + "line": 21, + "column": 22 } } }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 1, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "consequent": { - "type": "BlockStatement", - "statements": [ { - "type": "ExpressionStatement", - "expression": { - "type": "AssignmentExpression", - "operator": "=", - "left": { - "type": "Identifier", - "name": "b", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 + "type": "Identifier", + "name": "b", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "String", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 28 + }, + "end": { + "line": 21, + "column": 34 + } } - } - }, - "right": { - "type": "UndefinedLiteral", - "value": undefined, + }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, + "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 21, + "column": 23 }, "end": { - "line": 1, - "column": 3 + "line": 21, + "column": 35 } } - } - ], + }, + { + "type": "NumberLiteral", + "value": 30, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, - "alternate": null, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 }, - { - "type": "IfStatement", - "test": { - "type": "BinaryExpression", - "operator": "==", - "left": { - "type": "BinaryExpression", - "operator": "&", - "left": { - "type": "BinaryExpression", - "operator": ">>", - "left": { - "type": "Identifier", - "name": "$proxy_mask$", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 2, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 1, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 658, + "column": 1 + }, + "end": { + "line": 658, + "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": "foo", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 10 + }, + "end": { + "line": 21, + "column": 13 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 10 + }, + "end": { + "line": 21, + "column": 13 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "a", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 21, + "column": 18 }, "end": { - "line": 1, - "column": 3 + "line": 21, + "column": 21 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 1, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, - "consequent": { - "type": "BlockStatement", - "statements": [ - { - "type": "ExpressionStatement", - "expression": { - "type": "AssignmentExpression", - "operator": "=", - "left": { - "type": "Identifier", - "name": "c", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 30, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - } - ], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 14 + }, + "end": { + "line": 21, + "column": 22 } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 }, - "alternate": null, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 21, + "column": 52 }, "end": { - "line": 1, - "column": 3 + "line": 21, + "column": 55 } } }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ { "type": "ReturnStatement", "argument": { @@ -1479,11 +1349,11 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -1491,45 +1361,84 @@ { "type": "Identifier", "name": "a", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 18 + }, + "end": { + "line": 21, + "column": 21 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 21, + "column": 14 }, "end": { - "line": 1, - "column": 3 + "line": 21, + "column": 22 } } }, { - "type": "Identifier", - "name": "b", - "decorators": [], + "type": "UndefinedLiteral", + "value": undefined, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, { - "type": "Identifier", - "name": "c", - "decorators": [], + "type": "NumberLiteral", + "value": 30, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } } @@ -1538,22 +1447,22 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } } @@ -1561,33 +1470,33 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { - "line": 1, - "column": 3 + "line": 658, + "column": 1 }, "end": { - "line": 1, - "column": 3 + "line": 658, + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -1600,7 +1509,7 @@ }, "end": { "line": 1, - "column": 3 + "column": 1 } } } @@ -1652,4 +1561,4 @@ } } } -TypeError: Function already declared. [default_parameter7.ets:21:1] +TypeError: Function already declared. [default_parameter7.ets:1:1] diff --git a/ets2panda/test/parser/ets/default_parameter8-expected.txt b/ets2panda/test/parser/ets/default_parameter8-expected.txt new file mode 100644 index 0000000000..1c10f4020e --- /dev/null +++ b/ets2panda/test/parser/ets/default_parameter8-expected.txt @@ -0,0 +1,3219 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 7 + }, + "end": { + "line": 16, + "column": 8 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "a", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 12 + }, + "end": { + "line": 17, + "column": 13 + } + } + }, + "accessibility": "public", + "static": false, + "readonly": false, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 17, + "column": 14 + }, + "end": { + "line": 17, + "column": 17 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 12 + }, + "end": { + "line": 17, + "column": 17 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "accessibility": "public", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "param", + "typeAnnotation": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 18, + "column": 24 + }, + "end": { + "line": 18, + "column": 27 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 17 + }, + "end": { + "line": 18, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 17 + }, + "end": { + "line": 18, + "column": 31 + } + } + } + ], + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "MemberExpression", + "object": { + "type": "ThisExpression", + "loc": { + "start": { + "line": 19, + "column": 7 + }, + "end": { + "line": 19, + "column": 11 + } + } + }, + "property": { + "type": "Identifier", + "name": "a", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 12 + }, + "end": { + "line": 19, + "column": 13 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 19, + "column": 7 + }, + "end": { + "line": 19, + "column": 13 + } + } + }, + "right": { + "type": "Identifier", + "name": "param", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 16 + }, + "end": { + "line": 19, + "column": 21 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 7 + }, + "end": { + "line": 19, + "column": 21 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 7 + }, + "end": { + "line": 19, + "column": 22 + } + } + } + ], + "loc": { + "start": { + "line": 18, + "column": 33 + }, + "end": { + "line": 20, + "column": 6 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 16 + }, + "end": { + "line": 20, + "column": 6 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 16 + }, + "end": { + "line": 20, + "column": 6 + } + } + }, + "overloads": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "accessibility": "public", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "CallExpression", + "callee": { + "type": "ThisExpression", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "arguments": [ + { + "type": "NumberLiteral", + "value": 101, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "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 + } + } + }, + "loc": { + "start": { + "line": 638, + "column": 1 + }, + "end": { + "line": 638, + "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 + } + } + } + ], + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 20, + "column": 6 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "SetA", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 12 + }, + "end": { + "line": 21, + "column": 16 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "SetA", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 12 + }, + "end": { + "line": 21, + "column": 16 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "param", + "typeAnnotation": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 21, + "column": 24 + }, + "end": { + "line": 21, + "column": 27 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 17 + }, + "end": { + "line": 21, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 17 + }, + "end": { + "line": 21, + "column": 32 + } + } + } + ], + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "MemberExpression", + "object": { + "type": "ThisExpression", + "loc": { + "start": { + "line": 22, + "column": 9 + }, + "end": { + "line": 22, + "column": 13 + } + } + }, + "property": { + "type": "Identifier", + "name": "a", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 14 + }, + "end": { + "line": 22, + "column": 15 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 22, + "column": 9 + }, + "end": { + "line": 22, + "column": 15 + } + } + }, + "right": { + "type": "Identifier", + "name": "param", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 18 + }, + "end": { + "line": 22, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 9 + }, + "end": { + "line": 22, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 9 + }, + "end": { + "line": 22, + "column": 24 + } + } + } + ], + "loc": { + "start": { + "line": 21, + "column": 34 + }, + "end": { + "line": 23, + "column": 6 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 16 + }, + "end": { + "line": 23, + "column": 6 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 16 + }, + "end": { + "line": 23, + "column": 6 + } + } + }, + "overloads": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "SetA", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 12 + }, + "end": { + "line": 21, + "column": 16 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "SetA", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 12 + }, + "end": { + "line": 21, + "column": 16 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "ThisExpression", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "SetA", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "arguments": [ + { + "type": "NumberLiteral", + "value": 99, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "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 + } + } + }, + "loc": { + "start": { + "line": 700, + "column": 1 + }, + "end": { + "line": 700, + "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 + } + } + } + ], + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 5 + }, + "end": { + "line": 23, + "column": 6 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 24, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 24, + "column": 2 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "C", + "decorators": [], + "loc": { + "start": { + "line": 26, + "column": 7 + }, + "end": { + "line": 26, + "column": 8 + } + } + }, + "superClass": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 26, + "column": 17 + }, + "end": { + "line": 26, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 26, + "column": 17 + }, + "end": { + "line": 26, + "column": 20 + } + } + }, + "loc": { + "start": { + "line": 26, + "column": 17 + }, + "end": { + "line": 26, + "column": 20 + } + } + }, + "implements": [], + "body": [ + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "fs", + "decorators": [], + "loc": { + "start": { + "line": 27, + "column": 12 + }, + "end": { + "line": 27, + "column": 14 + } + } + }, + "value": { + "type": "NumberLiteral", + "value": 102, + "loc": { + "start": { + "line": 27, + "column": 19 + }, + "end": { + "line": 27, + "column": 22 + } + } + }, + "accessibility": "public", + "static": true, + "readonly": false, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 27, + "column": 15 + }, + "end": { + "line": 27, + "column": 18 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 27, + "column": 12 + }, + "end": { + "line": 27, + "column": 22 + } + } + }, + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "fc", + "decorators": [], + "loc": { + "start": { + "line": 28, + "column": 5 + }, + "end": { + "line": 28, + "column": 7 + } + } + }, + "value": { + "type": "NumberLiteral", + "value": 10001, + "loc": { + "start": { + "line": 28, + "column": 12 + }, + "end": { + "line": 28, + "column": 17 + } + } + }, + "accessibility": "public", + "static": false, + "readonly": false, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 28, + "column": 8 + }, + "end": { + "line": 28, + "column": 11 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 28, + "column": 5 + }, + "end": { + "line": 28, + "column": 17 + } + } + }, + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "c", + "decorators": [], + "loc": { + "start": { + "line": 29, + "column": 5 + }, + "end": { + "line": 29, + "column": 6 + } + } + }, + "accessibility": "public", + "static": false, + "readonly": false, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 29, + "column": 7 + }, + "end": { + "line": 29, + "column": 10 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 29, + "column": 5 + }, + "end": { + "line": 29, + "column": 10 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "setC", + "decorators": [], + "loc": { + "start": { + "line": 30, + "column": 12 + }, + "end": { + "line": 30, + "column": 16 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "setC", + "decorators": [], + "loc": { + "start": { + "line": 30, + "column": 12 + }, + "end": { + "line": 30, + "column": 16 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "param", + "typeAnnotation": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 30, + "column": 24 + }, + "end": { + "line": 30, + "column": 27 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 30, + "column": 18 + }, + "end": { + "line": 30, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 30, + "column": 18 + }, + "end": { + "line": 30, + "column": 35 + } + } + } + ], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "void", + "decorators": [], + "loc": { + "start": { + "line": 30, + "column": 39 + }, + "end": { + "line": 30, + "column": 43 + } + } + }, + "loc": { + "start": { + "line": 30, + "column": 39 + }, + "end": { + "line": 30, + "column": 45 + } + } + }, + "loc": { + "start": { + "line": 30, + "column": 39 + }, + "end": { + "line": 30, + "column": 45 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "MemberExpression", + "object": { + "type": "ThisExpression", + "loc": { + "start": { + "line": 31, + "column": 9 + }, + "end": { + "line": 31, + "column": 13 + } + } + }, + "property": { + "type": "Identifier", + "name": "c", + "decorators": [], + "loc": { + "start": { + "line": 31, + "column": 14 + }, + "end": { + "line": 31, + "column": 15 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 31, + "column": 9 + }, + "end": { + "line": 31, + "column": 15 + } + } + }, + "right": { + "type": "Identifier", + "name": "param", + "decorators": [], + "loc": { + "start": { + "line": 31, + "column": 18 + }, + "end": { + "line": 31, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 31, + "column": 9 + }, + "end": { + "line": 31, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 31, + "column": 9 + }, + "end": { + "line": 31, + "column": 24 + } + } + } + ], + "loc": { + "start": { + "line": 30, + "column": 44 + }, + "end": { + "line": 32, + "column": 6 + } + } + }, + "loc": { + "start": { + "line": 30, + "column": 17 + }, + "end": { + "line": 32, + "column": 6 + } + } + }, + "loc": { + "start": { + "line": 30, + "column": 17 + }, + "end": { + "line": 32, + "column": 6 + } + } + }, + "overloads": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "setC", + "decorators": [], + "loc": { + "start": { + "line": 30, + "column": 12 + }, + "end": { + "line": 30, + "column": 16 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "setC", + "decorators": [], + "loc": { + "start": { + "line": 30, + "column": 12 + }, + "end": { + "line": 30, + "column": 16 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "void", + "decorators": [], + "loc": { + "start": { + "line": 30, + "column": 39 + }, + "end": { + "line": 30, + "column": 43 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "ThisExpression", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "setC", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "arguments": [ + { + "type": "MemberExpression", + "object": { + "type": "ThisExpression", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "fc", + "decorators": [], + "loc": { + "start": { + "line": 30, + "column": 33 + }, + "end": { + "line": 30, + "column": 35 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "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 + } + } + }, + "loc": { + "start": { + "line": 839, + "column": 1 + }, + "end": { + "line": 839, + "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 + } + } + } + ], + "decorators": [], + "loc": { + "start": { + "line": 30, + "column": 5 + }, + "end": { + "line": 32, + "column": 6 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "getC", + "decorators": [], + "loc": { + "start": { + "line": 33, + "column": 12 + }, + "end": { + "line": 33, + "column": 16 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "getC", + "decorators": [], + "loc": { + "start": { + "line": 33, + "column": 12 + }, + "end": { + "line": 33, + "column": 16 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "returnType": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 33, + "column": 21 + }, + "end": { + "line": 33, + "column": 24 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "MemberExpression", + "object": { + "type": "ThisExpression", + "loc": { + "start": { + "line": 34, + "column": 16 + }, + "end": { + "line": 34, + "column": 20 + } + } + }, + "property": { + "type": "Identifier", + "name": "c", + "decorators": [], + "loc": { + "start": { + "line": 34, + "column": 21 + }, + "end": { + "line": 34, + "column": 22 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 34, + "column": 16 + }, + "end": { + "line": 34, + "column": 22 + } + } + }, + "loc": { + "start": { + "line": 34, + "column": 9 + }, + "end": { + "line": 34, + "column": 23 + } + } + } + ], + "loc": { + "start": { + "line": 33, + "column": 25 + }, + "end": { + "line": 35, + "column": 6 + } + } + }, + "loc": { + "start": { + "line": 33, + "column": 16 + }, + "end": { + "line": 35, + "column": 6 + } + } + }, + "loc": { + "start": { + "line": 33, + "column": 16 + }, + "end": { + "line": 35, + "column": 6 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 33, + "column": 5 + }, + "end": { + "line": 35, + "column": 6 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 36, + "column": 12 + }, + "end": { + "line": 36, + "column": 15 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 36, + "column": 12 + }, + "end": { + "line": 36, + "column": 15 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "param", + "typeAnnotation": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 36, + "column": 23 + }, + "end": { + "line": 36, + "column": 26 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 36, + "column": 16 + }, + "end": { + "line": 36, + "column": 26 + } + } + }, + "loc": { + "start": { + "line": 36, + "column": 16 + }, + "end": { + "line": 36, + "column": 31 + } + } + } + ], + "returnType": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 36, + "column": 35 + }, + "end": { + "line": 36, + "column": 38 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "BinaryExpression", + "operator": "+", + "left": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "C", + "decorators": [], + "loc": { + "start": { + "line": 37, + "column": 14 + }, + "end": { + "line": 37, + "column": 15 + } + } + }, + "property": { + "type": "Identifier", + "name": "fs", + "decorators": [], + "loc": { + "start": { + "line": 37, + "column": 16 + }, + "end": { + "line": 37, + "column": 18 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 37, + "column": 14 + }, + "end": { + "line": 37, + "column": 18 + } + } + }, + "right": { + "type": "Identifier", + "name": "param", + "decorators": [], + "loc": { + "start": { + "line": 37, + "column": 19 + }, + "end": { + "line": 37, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 37, + "column": 14 + }, + "end": { + "line": 37, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 37, + "column": 7 + }, + "end": { + "line": 37, + "column": 25 + } + } + } + ], + "loc": { + "start": { + "line": 36, + "column": 39 + }, + "end": { + "line": 38, + "column": 6 + } + } + }, + "loc": { + "start": { + "line": 36, + "column": 15 + }, + "end": { + "line": 38, + "column": 6 + } + } + }, + "loc": { + "start": { + "line": 36, + "column": 15 + }, + "end": { + "line": 38, + "column": 6 + } + } + }, + "overloads": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 36, + "column": 12 + }, + "end": { + "line": 36, + "column": 15 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 36, + "column": 12 + }, + "end": { + "line": 36, + "column": 15 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "returnType": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "C", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "arguments": [ + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "C", + "decorators": [], + "loc": { + "start": { + "line": 36, + "column": 27 + }, + "end": { + "line": 36, + "column": 28 + } + } + }, + "property": { + "type": "Identifier", + "name": "fs", + "decorators": [], + "loc": { + "start": { + "line": 36, + "column": 29 + }, + "end": { + "line": 36, + "column": 31 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "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 + } + } + }, + "loc": { + "start": { + "line": 969, + "column": 1 + }, + "end": { + "line": 969, + "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 + } + } + } + ], + "decorators": [], + "loc": { + "start": { + "line": 36, + "column": 5 + }, + "end": { + "line": 38, + "column": 6 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "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": 39, + "column": 2 + }, + "end": { + "line": 39, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 26, + "column": 19 + }, + "end": { + "line": 39, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 26, + "column": 1 + }, + "end": { + "line": 39, + "column": 2 + } + } + }, + { + "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": "main", + "decorators": [], + "loc": { + "start": { + "line": 41, + "column": 10 + }, + "end": { + "line": 41, + "column": 14 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 41, + "column": 10 + }, + "end": { + "line": 41, + "column": 14 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "void", + "decorators": [], + "loc": { + "start": { + "line": 41, + "column": 18 + }, + "end": { + "line": 41, + "column": 22 + } + } + }, + "loc": { + "start": { + "line": 41, + "column": 18 + }, + "end": { + "line": 41, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 41, + "column": 18 + }, + "end": { + "line": 41, + "column": 24 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "b", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "C", + "decorators": [], + "loc": { + "start": { + "line": 42, + "column": 12 + }, + "end": { + "line": 42, + "column": 13 + } + } + }, + "loc": { + "start": { + "line": 42, + "column": 12 + }, + "end": { + "line": 42, + "column": 15 + } + } + }, + "loc": { + "start": { + "line": 42, + "column": 12 + }, + "end": { + "line": 42, + "column": 15 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 42, + "column": 9 + }, + "end": { + "line": 42, + "column": 10 + } + } + }, + "init": { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "C", + "decorators": [], + "loc": { + "start": { + "line": 42, + "column": 20 + }, + "end": { + "line": 42, + "column": 21 + } + } + }, + "loc": { + "start": { + "line": 42, + "column": 20 + }, + "end": { + "line": 42, + "column": 22 + } + } + }, + "loc": { + "start": { + "line": 42, + "column": 20 + }, + "end": { + "line": 42, + "column": 22 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 42, + "column": 16 + }, + "end": { + "line": 42, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 42, + "column": 9 + }, + "end": { + "line": 42, + "column": 24 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 42, + "column": 5 + }, + "end": { + "line": 42, + "column": 24 + } + } + }, + { + "type": "AssertStatement", + "test": { + "type": "BinaryExpression", + "operator": "==", + "left": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "b", + "decorators": [], + "loc": { + "start": { + "line": 43, + "column": 13 + }, + "end": { + "line": 43, + "column": 14 + } + } + }, + "property": { + "type": "Identifier", + "name": "a", + "decorators": [], + "loc": { + "start": { + "line": 43, + "column": 15 + }, + "end": { + "line": 43, + "column": 16 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 43, + "column": 13 + }, + "end": { + "line": 43, + "column": 16 + } + } + }, + "right": { + "type": "NumberLiteral", + "value": 101, + "loc": { + "start": { + "line": 43, + "column": 20 + }, + "end": { + "line": 43, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 43, + "column": 12 + }, + "end": { + "line": 43, + "column": 24 + } + } + }, + "second": null, + "loc": { + "start": { + "line": 43, + "column": 5 + }, + "end": { + "line": 43, + "column": 24 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "b", + "decorators": [], + "loc": { + "start": { + "line": 44, + "column": 5 + }, + "end": { + "line": 44, + "column": 6 + } + } + }, + "property": { + "type": "Identifier", + "name": "setC", + "decorators": [], + "loc": { + "start": { + "line": 44, + "column": 7 + }, + "end": { + "line": 44, + "column": 11 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 44, + "column": 5 + }, + "end": { + "line": 44, + "column": 11 + } + } + }, + "arguments": [], + "optional": false, + "loc": { + "start": { + "line": 44, + "column": 5 + }, + "end": { + "line": 44, + "column": 13 + } + } + }, + "loc": { + "start": { + "line": 44, + "column": 5 + }, + "end": { + "line": 44, + "column": 14 + } + } + }, + { + "type": "AssertStatement", + "test": { + "type": "BinaryExpression", + "operator": "==", + "left": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "b", + "decorators": [], + "loc": { + "start": { + "line": 45, + "column": 12 + }, + "end": { + "line": 45, + "column": 13 + } + } + }, + "property": { + "type": "Identifier", + "name": "getC", + "decorators": [], + "loc": { + "start": { + "line": 45, + "column": 14 + }, + "end": { + "line": 45, + "column": 18 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 45, + "column": 12 + }, + "end": { + "line": 45, + "column": 18 + } + } + }, + "arguments": [], + "optional": false, + "loc": { + "start": { + "line": 45, + "column": 12 + }, + "end": { + "line": 45, + "column": 20 + } + } + }, + "right": { + "type": "NumberLiteral", + "value": 10001, + "loc": { + "start": { + "line": 45, + "column": 24 + }, + "end": { + "line": 45, + "column": 29 + } + } + }, + "loc": { + "start": { + "line": 45, + "column": 11 + }, + "end": { + "line": 45, + "column": 30 + } + } + }, + "second": null, + "loc": { + "start": { + "line": 45, + "column": 5 + }, + "end": { + "line": 45, + "column": 30 + } + } + }, + { + "type": "AssertStatement", + "test": { + "type": "BinaryExpression", + "operator": "==", + "left": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "C", + "decorators": [], + "loc": { + "start": { + "line": 46, + "column": 12 + }, + "end": { + "line": 46, + "column": 13 + } + } + }, + "property": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 46, + "column": 14 + }, + "end": { + "line": 46, + "column": 17 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 46, + "column": 12 + }, + "end": { + "line": 46, + "column": 17 + } + } + }, + "arguments": [], + "optional": false, + "loc": { + "start": { + "line": 46, + "column": 12 + }, + "end": { + "line": 46, + "column": 19 + } + } + }, + "right": { + "type": "BinaryExpression", + "operator": "*", + "left": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "C", + "decorators": [], + "loc": { + "start": { + "line": 46, + "column": 24 + }, + "end": { + "line": 46, + "column": 25 + } + } + }, + "property": { + "type": "Identifier", + "name": "fs", + "decorators": [], + "loc": { + "start": { + "line": 46, + "column": 26 + }, + "end": { + "line": 46, + "column": 28 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 46, + "column": 24 + }, + "end": { + "line": 46, + "column": 28 + } + } + }, + "right": { + "type": "NumberLiteral", + "value": 2, + "loc": { + "start": { + "line": 46, + "column": 29 + }, + "end": { + "line": 46, + "column": 30 + } + } + }, + "loc": { + "start": { + "line": 46, + "column": 23 + }, + "end": { + "line": 46, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 46, + "column": 11 + }, + "end": { + "line": 46, + "column": 32 + } + } + }, + "second": null, + "loc": { + "start": { + "line": 46, + "column": 5 + }, + "end": { + "line": 46, + "column": 32 + } + } + } + ], + "loc": { + "start": { + "line": 41, + "column": 23 + }, + "end": { + "line": 47, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 41, + "column": 14 + }, + "end": { + "line": 47, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 41, + "column": 14 + }, + "end": { + "line": 47, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 41, + "column": 1 + }, + "end": { + "line": 47, + "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": 48, + "column": 1 + } + } +} diff --git a/ets2panda/test/parser/ets/default_parameter8.ets b/ets2panda/test/parser/ets/default_parameter8.ets new file mode 100644 index 0000000000..4dec3e6715 --- /dev/null +++ b/ets2panda/test/parser/ets/default_parameter8.ets @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2024 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. + */ + +class A { + public a:int; + constructor(param: int=101) { + this.a = param; + } + public SetA(param: int = 99) { + this.a = param; + } +} + +class C extends A { + static fs:int=102 + fc:int=10001; + c:int; + public setC (param:int=this.fc) : void { + this.c = param; + } + public getC() : int { + return this.c; + } + static foo(param: int=C.fs) : int { + return C.fs+param; + } +} + +function main(): void { + let b: C = new C(); + assert (b.a == 101) + b.setC(); + assert(b.getC() == 10001) + assert(C.foo() == (C.fs*2)) +} diff --git a/ets2panda/test/parser/ets/default_parameter9-expected.txt b/ets2panda/test/parser/ets/default_parameter9-expected.txt new file mode 100644 index 0000000000..e13401507a --- /dev/null +++ b/ets2panda/test/parser/ets/default_parameter9-expected.txt @@ -0,0 +1,984 @@ +{ + "type": "Program", + "statements": [ + { + "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": "copyWithin", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 17 + }, + "end": { + "line": 16, + "column": 27 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "copyWithin", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 17 + }, + "end": { + "line": 16, + "column": 27 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "self", + "typeAnnotation": { + "type": "TSArrayType", + "elementType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 37 + }, + "end": { + "line": 16, + "column": 38 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 37 + }, + "end": { + "line": 16, + "column": 39 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 37 + }, + "end": { + "line": 16, + "column": 39 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 40 + }, + "end": { + "line": 16, + "column": 41 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 31 + }, + "end": { + "line": 16, + "column": 41 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 31 + }, + "end": { + "line": 16, + "column": 41 + } + } + }, + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "end", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Number", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 48 + }, + "end": { + "line": 16, + "column": 54 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 48 + }, + "end": { + "line": 16, + "column": 55 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 48 + }, + "end": { + "line": 16, + "column": 55 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 42 + }, + "end": { + "line": 16, + "column": 55 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 42 + }, + "end": { + "line": 16, + "column": 55 + } + } + } + ], + "returnType": { + "type": "TSArrayType", + "elementType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 57 + }, + "end": { + "line": 16, + "column": 58 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 57 + }, + "end": { + "line": 16, + "column": 59 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 57 + }, + "end": { + "line": 16, + "column": 59 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 61 + }, + "end": { + "line": 16, + "column": 62 + } + } + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "params": [ + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 28 + }, + "end": { + "line": 16, + "column": 29 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 28 + }, + "end": { + "line": 16, + "column": 30 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 27 + }, + "end": { + "line": 16, + "column": 30 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "Identifier", + "name": "self", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 12 + }, + "end": { + "line": 17, + "column": 16 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 5 + }, + "end": { + "line": 17, + "column": 17 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 61 + }, + "end": { + "line": 18, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 27 + }, + "end": { + "line": 18, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 27 + }, + "end": { + "line": 18, + "column": 2 + } + } + }, + "overloads": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "copyWithin", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 17 + }, + "end": { + "line": 16, + "column": 27 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "copyWithin", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 17 + }, + "end": { + "line": 16, + "column": 27 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "self", + "typeAnnotation": { + "type": "TSArrayType", + "elementType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 37 + }, + "end": { + "line": 16, + "column": 38 + } + } + }, + "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 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 31 + }, + "end": { + "line": 16, + "column": 41 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "returnType": { + "type": "TSArrayType", + "elementType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 57 + }, + "end": { + "line": 16, + "column": 58 + } + } + }, + "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 + } + } + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "params": [ + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 28 + }, + "end": { + "line": 16, + "column": 29 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "copyWithin", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "arguments": [ + { + "type": "Identifier", + "name": "self", + "typeAnnotation": { + "type": "TSArrayType", + "elementType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 37 + }, + "end": { + "line": 16, + "column": 38 + } + } + }, + "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 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 31 + }, + "end": { + "line": 16, + "column": 41 + } + } + }, + { + "type": "UndefinedLiteral", + "value": undefined, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "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 + } + } + } + ], + "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 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 613, + "column": 1 + }, + "end": { + "line": 613, + "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 + } + } + } + ], + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 8 + }, + "end": { + "line": 18, + "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": 19, + "column": 1 + } + } +} diff --git a/ets2panda/test/parser/ets/default_parameter9.ets b/ets2panda/test/parser/ets/default_parameter9.ets new file mode 100644 index 0000000000..851d4cc1ba --- /dev/null +++ b/ets2panda/test/parser/ets/default_parameter9.ets @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2024 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. + */ + +export function copyWithin(self: T[], end?: Number): T[] { + return self; +} diff --git a/ets2panda/test/parser/ets/default_parameter_implicitly_typed_return_void-expected.txt b/ets2panda/test/parser/ets/default_parameter_implicitly_typed_return_void-expected.txt index bb716f90ae..9f64e604a9 100644 --- a/ets2panda/test/parser/ets/default_parameter_implicitly_typed_return_void-expected.txt +++ b/ets2panda/test/parser/ets/default_parameter_implicitly_typed_return_void-expected.txt @@ -288,20 +288,6 @@ } } }, - "initializer": { - "type": "StringLiteral", - "value": "default", - "loc": { - "start": { - "line": 16, - "column": 38 - }, - "end": { - "line": 16, - "column": 47 - } - } - }, "loc": { "start": { "line": 16, @@ -371,20 +357,6 @@ } } }, - "initializer": { - "type": "StringLiteral", - "value": "another", - "loc": { - "start": { - "line": 16, - "column": 61 - }, - "end": { - "line": 16, - "column": 70 - } - } - }, "loc": { "start": { "line": 16, @@ -438,16 +410,16 @@ "type": "MethodDefinition", "key": { "type": "Identifier", - "name": "foo_proxy", + "name": "foo", "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 10 }, "end": { - "line": 1, - "column": 3 + "line": 16, + "column": 13 } } }, @@ -462,16 +434,16 @@ "type": "ScriptFunction", "id": { "type": "Identifier", - "name": "foo_proxy", + "name": "foo", "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 10 }, "end": { - "line": 1, - "column": 3 + "line": 16, + "column": 13 } } }, @@ -494,57 +466,57 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 16, + "column": 17 }, "end": { - "line": 1, - "column": 3 + "line": 16, + "column": 23 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 16, + "column": 14 }, "end": { - "line": 1, - "column": 3 + "line": 16, + "column": 24 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -563,542 +535,399 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 16, + "column": 29 }, "end": { - "line": 1, - "column": 3 + "line": 16, + "column": 35 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 16, + "column": 25 }, "end": { - "line": 1, - "column": 3 + "line": 16, + "column": 37 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } - }, - { - "type": "ETSParameterExpression", - "name": { - "type": "Identifier", - "name": "y", - "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "string", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, + } + ], + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "foo", + "decorators": [], "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - { - "type": "ETSParameterExpression", - "name": { - "type": "Identifier", - "name": "$proxy_mask$", - "typeAnnotation": { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - } - ], - "body": { - "type": "BlockStatement", - "statements": [ - { - "type": "IfStatement", - "test": { - "type": "BinaryExpression", - "operator": "==", - "left": { - "type": "BinaryExpression", - "operator": "&", - "left": { - "type": "BinaryExpression", - "operator": ">>", - "left": { - "type": "Identifier", - "name": "$proxy_mask$", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 + "arguments": [ + { + "type": "Identifier", + "name": "t", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 17 + }, + "end": { + "line": 16, + "column": 23 + } + } }, - "end": { - "line": 1, - "column": 3 + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } } - } - }, - "right": { - "type": "NumberLiteral", - "value": 1, + }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, + "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 1, - "loc": { - "start": { - "line": 1, - "column": 3 + "line": 16, + "column": 14 }, "end": { - "line": 1, - "column": 3 + "line": 16, + "column": 24 } } }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 1, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "consequent": { - "type": "BlockStatement", - "statements": [ { - "type": "ExpressionStatement", - "expression": { - "type": "AssignmentExpression", - "operator": "=", - "left": { - "type": "Identifier", - "name": "x", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 + "type": "Identifier", + "name": "x", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 29 + }, + "end": { + "line": 16, + "column": 35 + } } - } - }, - "right": { - "type": "StringLiteral", - "value": "default", + }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 25 + }, + "end": { + "line": 16, + "column": 37 + } + } + }, + { + "type": "StringLiteral", + "value": "another", "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } } ], + "optional": false, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, - "alternate": null, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 }, - { - "type": "IfStatement", - "test": { - "type": "BinaryExpression", - "operator": "==", - "left": { - "type": "BinaryExpression", - "operator": "&", - "left": { - "type": "BinaryExpression", - "operator": ">>", - "left": { - "type": "Identifier", - "name": "$proxy_mask$", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 2, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 1, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 576, + "column": 1 + }, + "end": { + "line": 576, + "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": "foo", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 10 + }, + "end": { + "line": 16, + "column": 13 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 10 + }, + "end": { + "line": 16, + "column": 13 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "t", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 16, + "column": 17 }, "end": { - "line": 1, - "column": 3 + "line": 16, + "column": 23 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 1, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, - "consequent": { - "type": "BlockStatement", - "statements": [ - { - "type": "ExpressionStatement", - "expression": { - "type": "AssignmentExpression", - "operator": "=", - "left": { - "type": "Identifier", - "name": "y", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "StringLiteral", - "value": "another", - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - } - ], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "alternate": null, + "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 16, + "column": 14 }, "end": { - "line": 1, - "column": 3 + "line": 16, + "column": 24 } } }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "body": { + "type": "BlockStatement", + "statements": [ { "type": "ExpressionStatement", "expression": { @@ -1110,11 +939,11 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -1122,45 +951,84 @@ { "type": "Identifier", "name": "t", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 17 + }, + "end": { + "line": 16, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 16, + "column": 14 }, "end": { - "line": 1, - "column": 3 + "line": 16, + "column": 24 } } }, { - "type": "Identifier", - "name": "x", - "decorators": [], + "type": "StringLiteral", + "value": "default", "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, { - "type": "Identifier", - "name": "y", - "decorators": [], + "type": "StringLiteral", + "value": "another", "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } } @@ -1169,22 +1037,22 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } } @@ -1192,33 +1060,33 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { - "line": 1, - "column": 3 + "line": 576, + "column": 1 }, "end": { - "line": 1, - "column": 3 + "line": 576, + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -1231,7 +1099,7 @@ }, "end": { "line": 1, - "column": 3 + "column": 1 } } } diff --git a/ets2panda/test/parser/ets/optional_union_paramter-expected.txt b/ets2panda/test/parser/ets/optional_union_paramter-expected.txt index a48d7291b6..3a880a2d53 100644 --- a/ets2panda/test/parser/ets/optional_union_paramter-expected.txt +++ b/ets2panda/test/parser/ets/optional_union_paramter-expected.txt @@ -250,20 +250,6 @@ } } }, - "initializer": { - "type": "UndefinedLiteral", - "value": undefined, - "loc": { - "start": { - "line": 1, - "column": 1 - }, - "end": { - "line": 1, - "column": 1 - } - } - }, "loc": { "start": { "line": 17, @@ -414,16 +400,16 @@ "type": "MethodDefinition", "key": { "type": "Identifier", - "name": "split_proxy", + "name": "split", "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 12 }, "end": { - "line": 1, - "column": 3 + "line": 17, + "column": 17 } } }, @@ -438,16 +424,16 @@ "type": "ScriptFunction", "id": { "type": "Identifier", - "name": "split_proxy", + "name": "split", "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 12 }, "end": { - "line": 1, - "column": 3 + "line": 17, + "column": 17 } } }, @@ -473,34 +459,34 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 17, + "column": 30 }, "end": { - "line": 1, - "column": 3 + "line": 17, + "column": 36 } } }, "loc": { "start": { - "line": 1, - "column": 3 + "line": 17, + "column": 30 }, "end": { - "line": 1, - "column": 3 + "line": 17, + "column": 38 } } }, "loc": { "start": { - "line": 1, - "column": 3 + "line": 17, + "column": 30 }, "end": { - "line": 1, - "column": 3 + "line": 17, + "column": 38 } } }, @@ -514,179 +500,69 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 17, + "column": 39 }, "end": { - "line": 1, - "column": 3 + "line": 17, + "column": 42 } } }, "loc": { "start": { - "line": 1, - "column": 3 + "line": 17, + "column": 39 }, "end": { - "line": 1, - "column": 3 + "line": 17, + "column": 43 } } }, "loc": { "start": { - "line": 1, - "column": 3 + "line": 17, + "column": 39 }, "end": { - "line": 1, - "column": 3 + "line": 17, + "column": 43 } } } ], "loc": { "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - { - "type": "ETSParameterExpression", - "name": { - "type": "Identifier", - "name": "limit", - "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Number", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - { - "type": "ETSParameterExpression", - "name": { - "type": "Identifier", - "name": "$proxy_mask$", - "typeAnnotation": { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 1, - "column": 3 + "line": 17, + "column": 30 }, "end": { - "line": 1, - "column": 3 + "line": 17, + "column": 43 } } }, "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 17, + "column": 19 }, "end": { - "line": 1, - "column": 3 + "line": 17, + "column": 43 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } } @@ -703,235 +579,51 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 17, + "column": 61 }, "end": { - "line": 1, - "column": 3 + "line": 17, + "column": 67 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "body": { "type": "BlockStatement", "statements": [ - { - "type": "IfStatement", - "test": { - "type": "BinaryExpression", - "operator": "==", - "left": { - "type": "BinaryExpression", - "operator": "&", - "left": { - "type": "BinaryExpression", - "operator": ">>", - "left": { - "type": "Identifier", - "name": "$proxy_mask$", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 1, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 1, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 1, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "consequent": { - "type": "BlockStatement", - "statements": [ - { - "type": "ExpressionStatement", - "expression": { - "type": "AssignmentExpression", - "operator": "=", - "left": { - "type": "Identifier", - "name": "limit", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "UndefinedLiteral", - "value": undefined, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - } - ], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "alternate": null, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, { "type": "ReturnStatement", "argument": { @@ -943,11 +635,11 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -958,11 +650,11 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -971,11 +663,11 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -983,30 +675,126 @@ { "type": "Identifier", "name": "separator", + "typeAnnotation": { + "type": "ETSUnionType", + "types": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "String", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 30 + }, + "end": { + "line": 17, + "column": 36 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 30 + }, + "end": { + "line": 17, + "column": 38 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 30 + }, + "end": { + "line": 17, + "column": 38 + } + } + }, + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 39 + }, + "end": { + "line": 17, + "column": 42 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 39 + }, + "end": { + "line": 17, + "column": 43 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 39 + }, + "end": { + "line": 17, + "column": 43 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 30 + }, + "end": { + "line": 17, + "column": 43 + } + } + }, "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 17, + "column": 19 }, "end": { - "line": 1, - "column": 3 + "line": 17, + "column": 43 } } }, { - "type": "Identifier", - "name": "limit", - "decorators": [], + "type": "UndefinedLiteral", + "value": undefined, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } } @@ -1015,22 +803,22 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } } @@ -1038,33 +826,33 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { - "line": 1, - "column": 3 + "line": 620, + "column": 1 }, "end": { - "line": 1, - "column": 3 + "line": 620, + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -1077,7 +865,7 @@ }, "end": { "line": 1, - "column": 3 + "column": 1 } } } diff --git a/ets2panda/test/parser/ets/override-expected.txt b/ets2panda/test/parser/ets/override-expected.txt index 6fb7ad9495..1d3766e42e 100644 --- a/ets2panda/test/parser/ets/override-expected.txt +++ b/ets2panda/test/parser/ets/override-expected.txt @@ -237,20 +237,6 @@ } } }, - "initializer": { - "type": "UndefinedLiteral", - "value": undefined, - "loc": { - "start": { - "line": 1, - "column": 1 - }, - "end": { - "line": 1, - "column": 1 - } - } - }, "loc": { "start": { "line": 17, @@ -374,16 +360,16 @@ "type": "MethodDefinition", "key": { "type": "Identifier", - "name": "foo_proxy", + "name": "foo", "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 3 }, "end": { - "line": 1, - "column": 3 + "line": 17, + "column": 6 } } }, @@ -398,16 +384,16 @@ "type": "ScriptFunction", "id": { "type": "Identifier", - "name": "foo_proxy", + "name": "foo", "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 3 }, "end": { - "line": 1, - "column": 3 + "line": 17, + "column": 6 } } }, @@ -430,167 +416,57 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - { - "type": "ETSParameterExpression", - "name": { - "type": "Identifier", - "name": "op", - "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "T", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 + "line": 17, + "column": 10 }, "end": { - "line": 1, - "column": 3 + "line": 17, + "column": 11 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - { - "type": "ETSParameterExpression", - "name": { - "type": "Identifier", - "name": "$proxy_mask$", - "typeAnnotation": { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 17, + "column": 7 }, "end": { - "line": 1, - "column": 3 + "line": 17, + "column": 12 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } } @@ -605,34 +481,34 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 17, + "column": 22 }, "end": { - "line": 1, - "column": 3 + "line": 17, + "column": 23 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -640,322 +516,178 @@ "type": "BlockStatement", "statements": [ { - "type": "IfStatement", - "test": { - "type": "BinaryExpression", - "operator": "==", - "left": { - "type": "BinaryExpression", - "operator": "&", - "left": { - "type": "BinaryExpression", - "operator": ">>", - "left": { - "type": "Identifier", - "name": "$proxy_mask$", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 1, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, + "type": "ReturnStatement", + "argument": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "ThisExpression", "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, - "right": { - "type": "NumberLiteral", - "value": 1, + "property": { + "type": "Identifier", + "name": "foo", + "decorators": [], "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, + "computed": false, + "optional": false, "loc": { "start": { "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 1, - "loc": { - "start": { - "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "consequent": { - "type": "BlockStatement", - "statements": [ + "arguments": [ { - "type": "ExpressionStatement", - "expression": { - "type": "AssignmentExpression", - "operator": "=", - "left": { - "type": "Identifier", - "name": "op", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 + "type": "Identifier", + "name": "a", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 10 + }, + "end": { + "line": 17, + "column": 11 + } } - } - }, - "right": { - "type": "UndefinedLiteral", - "value": undefined, + }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 7 + }, + "end": { + "line": 17, + "column": 12 + } + } + }, + { + "type": "UndefinedLiteral", + "value": undefined, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } } ], + "optional": false, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, - "alternate": null, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } - }, - { - "type": "ReturnStatement", - "argument": { - "type": "CallExpression", - "callee": { - "type": "MemberExpression", - "object": { - "type": "ThisExpression", - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "property": { - "type": "Identifier", - "name": "foo", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "computed": false, - "optional": false, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "arguments": [ - { - "type": "Identifier", - "name": "a", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - { - "type": "Identifier", - "name": "op", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - } - ], - "optional": false, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - } - ], - "loc": { - "start": { - "line": 1, - "column": 3 + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { - "line": 1, - "column": 3 + "line": 621, + "column": 1 }, "end": { - "line": 1, - "column": 3 + "line": 621, + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -968,7 +700,7 @@ }, "end": { "line": 1, - "column": 3 + "column": 1 } } } @@ -1433,20 +1165,6 @@ } } }, - "initializer": { - "type": "UndefinedLiteral", - "value": undefined, - "loc": { - "start": { - "line": 1, - "column": 1 - }, - "end": { - "line": 1, - "column": 1 - } - } - }, "loc": { "start": { "line": 20, @@ -1570,16 +1288,16 @@ "type": "MethodDefinition", "key": { "type": "Identifier", - "name": "foo_proxy", + "name": "foo", "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 12 }, "end": { - "line": 1, - "column": 3 + "line": 20, + "column": 15 } } }, @@ -1594,16 +1312,16 @@ "type": "ScriptFunction", "id": { "type": "Identifier", - "name": "foo_proxy", + "name": "foo", "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 12 }, "end": { - "line": 1, - "column": 3 + "line": 20, + "column": 15 } } }, @@ -1626,167 +1344,57 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 20, + "column": 19 }, "end": { - "line": 1, - "column": 3 + "line": 20, + "column": 20 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - { - "type": "ETSParameterExpression", - "name": { - "type": "Identifier", - "name": "op", - "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "T", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - { - "type": "ETSParameterExpression", - "name": { - "type": "Identifier", - "name": "$proxy_mask$", - "typeAnnotation": { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 20, + "column": 16 }, "end": { - "line": 1, - "column": 3 + "line": 20, + "column": 21 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } } @@ -1801,34 +1409,34 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 20, + "column": 31 }, "end": { - "line": 1, - "column": 3 + "line": 20, + "column": 32 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -1836,264 +1444,120 @@ "type": "BlockStatement", "statements": [ { - "type": "IfStatement", - "test": { - "type": "BinaryExpression", - "operator": "==", - "left": { - "type": "BinaryExpression", - "operator": "&", - "left": { - "type": "BinaryExpression", - "operator": ">>", - "left": { - "type": "Identifier", - "name": "$proxy_mask$", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 1, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, + "type": "ReturnStatement", + "argument": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "ThisExpression", "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, - "right": { - "type": "NumberLiteral", - "value": 1, + "property": { + "type": "Identifier", + "name": "foo", + "decorators": [], "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, + "computed": false, + "optional": false, "loc": { "start": { "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 1, - "loc": { - "start": { - "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "consequent": { - "type": "BlockStatement", - "statements": [ + "arguments": [ { - "type": "ExpressionStatement", - "expression": { - "type": "AssignmentExpression", - "operator": "=", - "left": { - "type": "Identifier", - "name": "op", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 + "type": "Identifier", + "name": "a", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 19 + }, + "end": { + "line": 20, + "column": 20 + } } - } - }, - "right": { - "type": "UndefinedLiteral", - "value": undefined, + }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - } - ], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "alternate": null, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - { - "type": "ReturnStatement", - "argument": { - "type": "CallExpression", - "callee": { - "type": "MemberExpression", - "object": { - "type": "ThisExpression", - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "property": { - "type": "Identifier", - "name": "foo", "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 20, + "column": 16 }, "end": { - "line": 1, - "column": 3 + "line": 20, + "column": 21 } } }, - "computed": false, - "optional": false, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "arguments": [ { - "type": "Identifier", - "name": "a", - "decorators": [], + "type": "UndefinedLiteral", + "value": undefined, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 - } - } - }, - { - "type": "Identifier", - "name": "op", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 + "column": 1 } } } @@ -2102,22 +1566,22 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } } @@ -2125,33 +1589,33 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { - "line": 1, - "column": 3 + "line": 685, + "column": 1 }, "end": { - "line": 1, - "column": 3 + "line": 685, + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -2164,7 +1628,7 @@ }, "end": { "line": 1, - "column": 3 + "column": 1 } } } diff --git a/ets2panda/test/parser/ets/proxyVoidGeneration-expected.txt b/ets2panda/test/parser/ets/proxyVoidGeneration-expected.txt index 20b3942afa..226e6d78ad 100644 --- a/ets2panda/test/parser/ets/proxyVoidGeneration-expected.txt +++ b/ets2panda/test/parser/ets/proxyVoidGeneration-expected.txt @@ -125,20 +125,6 @@ } } }, - "initializer": { - "type": "NullLiteral", - "value": null, - "loc": { - "start": { - "line": 17, - "column": 31 - }, - "end": { - "line": 17, - "column": 35 - } - } - }, "loc": { "start": { "line": 17, @@ -233,16 +219,16 @@ "type": "MethodDefinition", "key": { "type": "Identifier", - "name": "exit_proxy", + "name": "exit", "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 3 + "line": 17, + "column": 9 } } }, @@ -257,134 +243,23 @@ "type": "ScriptFunction", "id": { "type": "Identifier", - "name": "exit_proxy", + "name": "exit", "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 3 + "line": 17, + "column": 9 } } }, "generator": false, "async": false, "expression": false, - "params": [ - { - "type": "ETSParameterExpression", - "name": { - "type": "Identifier", - "name": "log_", - "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Boolean", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - { - "type": "ETSParameterExpression", - "name": { - "type": "Identifier", - "name": "$proxy_mask$", - "typeAnnotation": { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - } - ], + "params": [], "returnType": { "type": "ETSTypeReference", "part": { @@ -395,34 +270,34 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 17, + "column": 38 }, "end": { - "line": 1, - "column": 3 + "line": 17, + "column": 42 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -430,192 +305,8 @@ "type": "BlockStatement", "statements": [ { - "type": "IfStatement", - "test": { - "type": "BinaryExpression", - "operator": "==", - "left": { - "type": "BinaryExpression", - "operator": "&", - "left": { - "type": "BinaryExpression", - "operator": ">>", - "left": { - "type": "Identifier", - "name": "$proxy_mask$", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 0, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 1, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 1, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "consequent": { - "type": "BlockStatement", - "statements": [ - { - "type": "ExpressionStatement", - "expression": { - "type": "AssignmentExpression", - "operator": "=", - "left": { - "type": "Identifier", - "name": "log_", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NullLiteral", - "value": null, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - } - ], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "alternate": null, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - { - "type": "ExpressionStatement", - "expression": { + "type": "ReturnStatement", + "argument": { "type": "CallExpression", "callee": { "type": "MemberExpression", @@ -624,11 +315,11 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -639,11 +330,11 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -652,27 +343,26 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "arguments": [ { - "type": "Identifier", - "name": "log_", - "decorators": [], + "type": "NullLiteral", + "value": null, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } } @@ -681,22 +371,22 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } } @@ -704,33 +394,33 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { - "line": 1, - "column": 3 + "line": 620, + "column": 1 }, "end": { - "line": 1, - "column": 3 + "line": 620, + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -743,7 +433,7 @@ }, "end": { "line": 1, - "column": 3 + "column": 1 } } } @@ -863,20 +553,6 @@ } } }, - "initializer": { - "type": "UndefinedLiteral", - "value": undefined, - "loc": { - "start": { - "line": 1, - "column": 1 - }, - "end": { - "line": 1, - "column": 1 - } - } - }, "loc": { "start": { "line": 18, @@ -971,16 +647,16 @@ "type": "MethodDefinition", "key": { "type": "Identifier", - "name": "exthat_proxy", + "name": "exthat", "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 5 }, "end": { - "line": 1, - "column": 3 + "line": 18, + "column": 11 } } }, @@ -995,134 +671,23 @@ "type": "ScriptFunction", "id": { "type": "Identifier", - "name": "exthat_proxy", + "name": "exthat", "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 5 }, "end": { - "line": 1, - "column": 3 + "line": 18, + "column": 11 } } }, "generator": false, "async": false, "expression": false, - "params": [ - { - "type": "ETSParameterExpression", - "name": { - "type": "Identifier", - "name": "log_", - "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Boolean", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - { - "type": "ETSParameterExpression", - "name": { - "type": "Identifier", - "name": "$proxy_mask$", - "typeAnnotation": { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - } - ], + "params": [], "returnType": { "type": "ETSTypeReference", "part": { @@ -1133,34 +698,34 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 18, + "column": 29 }, "end": { - "line": 1, - "column": 3 + "line": 18, + "column": 33 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -1168,192 +733,8 @@ "type": "BlockStatement", "statements": [ { - "type": "IfStatement", - "test": { - "type": "BinaryExpression", - "operator": "==", - "left": { - "type": "BinaryExpression", - "operator": "&", - "left": { - "type": "BinaryExpression", - "operator": ">>", - "left": { - "type": "Identifier", - "name": "$proxy_mask$", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 0, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 1, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 1, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "consequent": { - "type": "BlockStatement", - "statements": [ - { - "type": "ExpressionStatement", - "expression": { - "type": "AssignmentExpression", - "operator": "=", - "left": { - "type": "Identifier", - "name": "log_", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "UndefinedLiteral", - "value": undefined, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - } - ], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "alternate": null, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - { - "type": "ExpressionStatement", - "expression": { + "type": "ReturnStatement", + "argument": { "type": "CallExpression", "callee": { "type": "MemberExpression", @@ -1362,11 +743,11 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -1377,11 +758,11 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -1390,27 +771,26 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "arguments": [ { - "type": "Identifier", - "name": "log_", - "decorators": [], + "type": "UndefinedLiteral", + "value": undefined, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } } @@ -1419,22 +799,22 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } } @@ -1442,33 +822,33 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { - "line": 1, - "column": 3 + "line": 665, + "column": 1 }, "end": { - "line": 1, - "column": 3 + "line": 665, + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -1481,7 +861,7 @@ }, "end": { "line": 1, - "column": 3 + "column": 1 } } } diff --git a/ets2panda/test/parser/ets/proxy_method-expected.txt b/ets2panda/test/parser/ets/proxy_method-expected.txt index fa34056abf..50bf23a4d5 100644 --- a/ets2panda/test/parser/ets/proxy_method-expected.txt +++ b/ets2panda/test/parser/ets/proxy_method-expected.txt @@ -194,20 +194,6 @@ } } }, - "initializer": { - "type": "UndefinedLiteral", - "value": undefined, - "loc": { - "start": { - "line": 1, - "column": 1 - }, - "end": { - "line": 1, - "column": 1 - } - } - }, "loc": { "start": { "line": 17, @@ -379,16 +365,16 @@ "type": "MethodDefinition", "key": { "type": "Identifier", - "name": "met_proxy", + "name": "met", "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 3 + "line": 17, + "column": 8 } } }, @@ -403,16 +389,16 @@ "type": "ScriptFunction", "id": { "type": "Identifier", - "name": "met_proxy", + "name": "met", "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 3 + "line": 17, + "column": 8 } } }, @@ -435,167 +421,57 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 17, + "column": 12 }, "end": { - "line": 1, - "column": 3 + "line": 17, + "column": 18 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - { - "type": "ETSParameterExpression", - "name": { - "type": "Identifier", - "name": "q", - "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "string", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - { - "type": "ETSParameterExpression", - "name": { - "type": "Identifier", - "name": "$proxy_mask$", - "typeAnnotation": { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 + "line": 17, + "column": 9 }, "end": { - "line": 1, - "column": 3 + "line": 17, + "column": 19 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } } @@ -604,264 +480,120 @@ "type": "BlockStatement", "statements": [ { - "type": "IfStatement", - "test": { - "type": "BinaryExpression", - "operator": "==", - "left": { - "type": "BinaryExpression", - "operator": "&", - "left": { - "type": "BinaryExpression", - "operator": ">>", - "left": { - "type": "Identifier", - "name": "$proxy_mask$", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 1, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, + "type": "ExpressionStatement", + "expression": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "ThisExpression", "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, - "right": { - "type": "NumberLiteral", - "value": 1, + "property": { + "type": "Identifier", + "name": "met", + "decorators": [], "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, + "computed": false, + "optional": false, "loc": { "start": { "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 1, - "loc": { - "start": { - "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "consequent": { - "type": "BlockStatement", - "statements": [ + "arguments": [ { - "type": "ExpressionStatement", - "expression": { - "type": "AssignmentExpression", - "operator": "=", - "left": { - "type": "Identifier", - "name": "q", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 + "type": "Identifier", + "name": "s", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 12 + }, + "end": { + "line": 17, + "column": 18 + } } - } - }, - "right": { - "type": "UndefinedLiteral", - "value": undefined, + }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - } - ], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "alternate": null, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - { - "type": "ExpressionStatement", - "expression": { - "type": "CallExpression", - "callee": { - "type": "MemberExpression", - "object": { - "type": "ThisExpression", - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "property": { - "type": "Identifier", - "name": "met", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "computed": false, - "optional": false, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "arguments": [ - { - "type": "Identifier", - "name": "s", "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 17, + "column": 9 }, "end": { - "line": 1, - "column": 3 + "line": 17, + "column": 19 } } }, { - "type": "Identifier", - "name": "q", - "decorators": [], + "type": "UndefinedLiteral", + "value": undefined, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } } @@ -870,22 +602,22 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } } @@ -893,33 +625,33 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { - "line": 1, - "column": 3 + "line": 620, + "column": 1 }, "end": { - "line": 1, - "column": 3 + "line": 620, + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -932,7 +664,7 @@ }, "end": { "line": 1, - "column": 3 + "column": 1 } } } diff --git a/ets2panda/test/parser/ets/rest_parameter_02-expected.txt b/ets2panda/test/parser/ets/rest_parameter_02-expected.txt index 87a53b8d5a..5cb49ef973 100644 --- a/ets2panda/test/parser/ets/rest_parameter_02-expected.txt +++ b/ets2panda/test/parser/ets/rest_parameter_02-expected.txt @@ -505,20 +505,6 @@ } } }, - "initializer": { - "type": "NumberLiteral", - "value": 0, - "loc": { - "start": { - "line": 20, - "column": 40 - }, - "end": { - "line": 20, - "column": 41 - } - } - }, "loc": { "start": { "line": 20, @@ -625,16 +611,16 @@ "type": "MethodDefinition", "key": { "type": "Identifier", - "name": "foo_proxy", + "name": "foo", "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 10 }, "end": { - "line": 1, - "column": 3 + "line": 20, + "column": 13 } } }, @@ -649,16 +635,16 @@ "type": "ScriptFunction", "id": { "type": "Identifier", - "name": "foo_proxy", + "name": "foo", "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 10 }, "end": { - "line": 1, - "column": 3 + "line": 20, + "column": 13 } } }, @@ -676,34 +662,34 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 20, + "column": 15 }, "end": { - "line": 1, - "column": 3 + "line": 20, + "column": 21 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -717,116 +703,34 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - { - "type": "ETSParameterExpression", - "name": { - "type": "Identifier", - "name": "z", - "typeAnnotation": { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - { - "type": "ETSParameterExpression", - "name": { - "type": "Identifier", - "name": "$proxy_mask$", - "typeAnnotation": { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 + "line": 20, + "column": 23 }, "end": { - "line": 1, - "column": 3 + "line": 20, + "column": 29 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } } @@ -836,201 +740,17 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "body": { "type": "BlockStatement", "statements": [ - { - "type": "IfStatement", - "test": { - "type": "BinaryExpression", - "operator": "==", - "left": { - "type": "BinaryExpression", - "operator": "&", - "left": { - "type": "BinaryExpression", - "operator": ">>", - "left": { - "type": "Identifier", - "name": "$proxy_mask$", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 2, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 1, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 1, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "consequent": { - "type": "BlockStatement", - "statements": [ - { - "type": "ExpressionStatement", - "expression": { - "type": "AssignmentExpression", - "operator": "=", - "left": { - "type": "Identifier", - "name": "z", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 0, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - } - ], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "alternate": null, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, { "type": "ReturnStatement", "argument": { @@ -1042,11 +762,11 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -1054,45 +774,70 @@ { "type": "Identifier", "name": "x", + "typeAnnotation": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 20, + "column": 15 }, "end": { - "line": 1, - "column": 3 + "line": 20, + "column": 21 } } }, { "type": "Identifier", "name": "y", + "typeAnnotation": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 20, + "column": 23 }, "end": { - "line": 1, - "column": 3 + "line": 20, + "column": 29 } } }, { - "type": "Identifier", - "name": "z", - "decorators": [], + "type": "NumberLiteral", + "value": 0, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } } @@ -1101,22 +846,22 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } } @@ -1124,33 +869,33 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { - "line": 1, - "column": 3 + "line": 658, + "column": 1 }, "end": { - "line": 1, - "column": 3 + "line": 658, + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -1163,7 +908,7 @@ }, "end": { "line": 1, - "column": 3 + "column": 1 } } } -- Gitee From cc75a24354f2dcb335156e22524ec6b80b51c861 Mon Sep 17 00:00:00 2001 From: Martin Sajti Date: Fri, 19 Jan 2024 16:18:50 +0100 Subject: [PATCH 24/26] Fix null coalescing operator fails with type parameter Refactor flag cleaning in ETSObjectType Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/I8YNOC Internal issue: #15170 Test: build, new checker tests Signed-off-by: Martin Sajti --- ets2panda/checker/ets/arithmetic.cpp | 26 +- ets2panda/checker/types/ets/etsObjectType.cpp | 20 +- .../null_coalescing_generic_1-expected.txt | 1853 +++++++++++++++++ .../ets/null_coalescing_generic_1.ets | 32 + ...null_coalescing_generic_1_neg-expected.txt | 600 ++++++ .../ets/null_coalescing_generic_1_neg.ets | 19 + 6 files changed, 2537 insertions(+), 13 deletions(-) create mode 100644 ets2panda/test/compiler/ets/null_coalescing_generic_1-expected.txt create mode 100644 ets2panda/test/compiler/ets/null_coalescing_generic_1.ets create mode 100644 ets2panda/test/compiler/ets/null_coalescing_generic_1_neg-expected.txt create mode 100644 ets2panda/test/compiler/ets/null_coalescing_generic_1_neg.ets diff --git a/ets2panda/checker/ets/arithmetic.cpp b/ets2panda/checker/ets/arithmetic.cpp index 46b8207153..b3df0dc49d 100644 --- a/ets2panda/checker/ets/arithmetic.cpp +++ b/ets2panda/checker/ets/arithmetic.cpp @@ -516,9 +516,9 @@ std::tuple ETSChecker::CheckBinaryOperatorInstanceOf(lexer::Sour } Type *ETSChecker::CheckBinaryOperatorNullishCoalescing(ir::Expression *right, lexer::SourcePosition pos, - checker::Type *const leftType, checker::Type *const rightType) + checker::Type *leftType, checker::Type *rightType) { - if (!leftType->HasTypeFlag(checker::TypeFlag::ETS_ARRAY_OR_OBJECT)) { + if (!leftType->HasTypeFlag(checker::TypeFlag::ETS_ARRAY_OR_OBJECT) && !leftType->IsETSTypeParameter()) { ThrowTypeError("Left-hand side expression must be a reference type.", pos); } @@ -532,12 +532,30 @@ Type *ETSChecker::CheckBinaryOperatorNullishCoalescing(ir::Expression *right, le if (rightType->HasTypeFlag(checker::TypeFlag::ETS_PRIMITIVE)) { Relation()->SetNode(right); - auto boxedRightType = PrimitiveTypeAsETSBuiltinType(rightType); + auto *const boxedRightType = PrimitiveTypeAsETSBuiltinType(rightType); if (boxedRightType == nullptr) { ThrowTypeError("Invalid right-hand side expression", pos); } right->AddBoxingUnboxingFlags(GetBoxingFlag(boxedRightType)); - return FindLeastUpperBound(nonNullishLeftType, boxedRightType); + rightType = boxedRightType; + } + + if (rightType->IsETSNullType()) { + return CreateNullishType(nonNullishLeftType, TypeFlag::NULL_TYPE, Allocator(), Relation(), + GetGlobalTypesHolder()); + } + + if (rightType->IsETSUndefinedType()) { + return CreateNullishType(nonNullishLeftType, TypeFlag::UNDEFINED, Allocator(), Relation(), + GetGlobalTypesHolder()); + } + + if (nonNullishLeftType->IsETSTypeParameter()) { + nonNullishLeftType = nonNullishLeftType->AsETSTypeParameter()->GetConstraintType(); + } + + if (rightType->IsETSTypeParameter()) { + rightType = rightType->AsETSTypeParameter()->GetConstraintType(); } return FindLeastUpperBound(nonNullishLeftType, rightType); diff --git a/ets2panda/checker/types/ets/etsObjectType.cpp b/ets2panda/checker/types/ets/etsObjectType.cpp index 9e82f59c79..5891c50641 100644 --- a/ets2panda/checker/types/ets/etsObjectType.cpp +++ b/ets2panda/checker/types/ets/etsObjectType.cpp @@ -405,16 +405,18 @@ void ETSObjectType::Identical(TypeRelation *relation, Type *other) IdenticalUptoNullability(relation, other); } -bool ETSObjectType::CheckIdenticalFlags(ETSObjectFlags target) const +bool ETSObjectType::CheckIdenticalFlags(const ETSObjectFlags target) const { - auto cleanedTargetFlags = static_cast(target & (~ETSObjectFlags::COMPLETELY_RESOLVED)); - cleanedTargetFlags &= ~ETSObjectFlags::INCOMPLETE_INSTANTIATION; - cleanedTargetFlags &= ~ETSObjectFlags::CHECKED_COMPATIBLE_ABSTRACTS; - cleanedTargetFlags &= ~ETSObjectFlags::CHECKED_INVOKE_LEGITIMACY; - auto cleanedSelfFlags = static_cast(ObjectFlags() & (~ETSObjectFlags::COMPLETELY_RESOLVED)); - cleanedSelfFlags &= ~ETSObjectFlags::INCOMPLETE_INSTANTIATION; - cleanedSelfFlags &= ~ETSObjectFlags::CHECKED_COMPATIBLE_ABSTRACTS; - cleanedSelfFlags &= ~ETSObjectFlags::CHECKED_INVOKE_LEGITIMACY; + constexpr auto FLAGS_TO_REMOVE = ETSObjectFlags::COMPLETELY_RESOLVED | ETSObjectFlags::INCOMPLETE_INSTANTIATION | + ETSObjectFlags::CHECKED_COMPATIBLE_ABSTRACTS | + ETSObjectFlags::CHECKED_INVOKE_LEGITIMACY; + + auto cleanedTargetFlags = target; + cleanedTargetFlags &= ~FLAGS_TO_REMOVE; + + auto cleanedSelfFlags = ObjectFlags(); + cleanedSelfFlags &= ~FLAGS_TO_REMOVE; + return cleanedSelfFlags == cleanedTargetFlags; } diff --git a/ets2panda/test/compiler/ets/null_coalescing_generic_1-expected.txt b/ets2panda/test/compiler/ets/null_coalescing_generic_1-expected.txt new file mode 100644 index 0000000000..f309c04503 --- /dev/null +++ b/ets2panda/test/compiler/ets/null_coalescing_generic_1-expected.txt @@ -0,0 +1,1853 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "C", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 7 + }, + "end": { + "line": 23, + "column": 8 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "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": 23, + "column": 11 + }, + "end": { + "line": 23, + "column": 11 + } + } + } + ], + "loc": { + "start": { + "line": 23, + "column": 9 + }, + "end": { + "line": 23, + "column": 11 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 1 + }, + "end": { + "line": 23, + "column": 11 + } + } + }, + { + "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": "foo", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 10 + }, + "end": { + "line": 16, + "column": 13 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 10 + }, + "end": { + "line": 16, + "column": 13 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "data", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "C", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 11 + }, + "end": { + "line": 17, + "column": 12 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 11 + }, + "end": { + "line": 17, + "column": 14 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 11 + }, + "end": { + "line": 17, + "column": 14 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 5 + }, + "end": { + "line": 17, + "column": 14 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 5 + }, + "end": { + "line": 17, + "column": 14 + } + } + }, + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "exec", + "typeAnnotation": { + "type": "ETSFunctionType", + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "pointer", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "C", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 21 + }, + "end": { + "line": 18, + "column": 22 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 21 + }, + "end": { + "line": 18, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 21 + }, + "end": { + "line": 18, + "column": 24 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 12 + }, + "end": { + "line": 18, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 12 + }, + "end": { + "line": 18, + "column": 24 + } + } + } + ], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "R", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 39 + }, + "end": { + "line": 18, + "column": 40 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 39 + }, + "end": { + "line": 19, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 39 + }, + "end": { + "line": 19, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 11 + }, + "end": { + "line": 19, + "column": 2 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 19, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 19, + "column": 2 + } + } + } + ], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "R", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 4 + }, + "end": { + "line": 19, + "column": 5 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 4 + }, + "end": { + "line": 19, + "column": 7 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 4 + }, + "end": { + "line": 19, + "column": 7 + } + } + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "params": [ + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "C", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 14 + }, + "end": { + "line": 16, + "column": 15 + } + } + }, + "constraint": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Uint8Array", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 24 + }, + "end": { + "line": 16, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 24 + }, + "end": { + "line": 16, + "column": 35 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 24 + }, + "end": { + "line": 16, + "column": 35 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 14 + }, + "end": { + "line": 16, + "column": 35 + } + } + }, + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "R", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 36 + }, + "end": { + "line": 16, + "column": 37 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 36 + }, + "end": { + "line": 16, + "column": 38 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 13 + }, + "end": { + "line": 16, + "column": 38 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "exec", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 12 + }, + "end": { + "line": 20, + "column": 16 + } + } + }, + "arguments": [ + { + "type": "LogicalExpression", + "operator": "??", + "left": { + "type": "Identifier", + "name": "data", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 17 + }, + "end": { + "line": 20, + "column": 21 + } + } + }, + "right": { + "type": "UndefinedLiteral", + "value": undefined, + "loc": { + "start": { + "line": 20, + "column": 25 + }, + "end": { + "line": 20, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 17 + }, + "end": { + "line": 20, + "column": 34 + } + } + } + ], + "optional": false, + "loc": { + "start": { + "line": 20, + "column": 12 + }, + "end": { + "line": 20, + "column": 35 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 5 + }, + "end": { + "line": 20, + "column": 36 + } + } + } + ], + "loc": { + "start": { + "line": 19, + "column": 6 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 13 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 13 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "bar", + "decorators": [], + "loc": { + "start": { + "line": 24, + "column": 10 + }, + "end": { + "line": 24, + "column": 13 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "bar", + "decorators": [], + "loc": { + "start": { + "line": 24, + "column": 10 + }, + "end": { + "line": 24, + "column": 13 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "data", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 24, + "column": 35 + }, + "end": { + "line": 24, + "column": 36 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 35 + }, + "end": { + "line": 24, + "column": 37 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 35 + }, + "end": { + "line": 24, + "column": 37 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 24, + "column": 29 + }, + "end": { + "line": 24, + "column": 37 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 29 + }, + "end": { + "line": 24, + "column": 37 + } + } + } + ], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "void", + "decorators": [], + "loc": { + "start": { + "line": 24, + "column": 39 + }, + "end": { + "line": 24, + "column": 43 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 39 + }, + "end": { + "line": 24, + "column": 45 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 39 + }, + "end": { + "line": 24, + "column": 45 + } + } + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "params": [ + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 24, + "column": 14 + }, + "end": { + "line": 24, + "column": 15 + } + } + }, + "constraint": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], + "loc": { + "start": { + "line": 24, + "column": 24 + }, + "end": { + "line": 24, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 24 + }, + "end": { + "line": 24, + "column": 28 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 24 + }, + "end": { + "line": 24, + "column": 28 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 14 + }, + "end": { + "line": 24, + "column": 28 + } + } + } + ], + "loc": { + "start": { + "line": 24, + "column": 13 + }, + "end": { + "line": 24, + "column": 28 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "c_class", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "C", + "decorators": [], + "loc": { + "start": { + "line": 25, + "column": 18 + }, + "end": { + "line": 25, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 25, + "column": 18 + }, + "end": { + "line": 25, + "column": 21 + } + } + }, + "loc": { + "start": { + "line": 25, + "column": 18 + }, + "end": { + "line": 25, + "column": 21 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 25, + "column": 9 + }, + "end": { + "line": 25, + "column": 16 + } + } + }, + "init": { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "C", + "decorators": [], + "loc": { + "start": { + "line": 25, + "column": 26 + }, + "end": { + "line": 25, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 25, + "column": 26 + }, + "end": { + "line": 25, + "column": 28 + } + } + }, + "loc": { + "start": { + "line": 25, + "column": 26 + }, + "end": { + "line": 25, + "column": 28 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 25, + "column": 22 + }, + "end": { + "line": 25, + "column": 30 + } + } + }, + "loc": { + "start": { + "line": 25, + "column": 9 + }, + "end": { + "line": 25, + "column": 30 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 25, + "column": 5 + }, + "end": { + "line": 25, + "column": 30 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "myvar", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Object", + "decorators": [], + "loc": { + "start": { + "line": 26, + "column": 16 + }, + "end": { + "line": 26, + "column": 22 + } + } + }, + "loc": { + "start": { + "line": 26, + "column": 16 + }, + "end": { + "line": 26, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 26, + "column": 16 + }, + "end": { + "line": 26, + "column": 24 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 26, + "column": 9 + }, + "end": { + "line": 26, + "column": 14 + } + } + }, + "init": { + "type": "LogicalExpression", + "operator": "??", + "left": { + "type": "Identifier", + "name": "data", + "decorators": [], + "loc": { + "start": { + "line": 26, + "column": 25 + }, + "end": { + "line": 26, + "column": 29 + } + } + }, + "right": { + "type": "Identifier", + "name": "c_class", + "decorators": [], + "loc": { + "start": { + "line": 26, + "column": 33 + }, + "end": { + "line": 26, + "column": 40 + } + } + }, + "loc": { + "start": { + "line": 26, + "column": 25 + }, + "end": { + "line": 26, + "column": 40 + } + } + }, + "loc": { + "start": { + "line": 26, + "column": 9 + }, + "end": { + "line": 26, + "column": 40 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 26, + "column": 5 + }, + "end": { + "line": 26, + "column": 41 + } + } + } + ], + "loc": { + "start": { + "line": 24, + "column": 44 + }, + "end": { + "line": 27, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 13 + }, + "end": { + "line": 27, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 13 + }, + "end": { + "line": 27, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 24, + "column": 1 + }, + "end": { + "line": 27, + "column": 2 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "baz", + "decorators": [], + "loc": { + "start": { + "line": 29, + "column": 10 + }, + "end": { + "line": 29, + "column": 13 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "baz", + "decorators": [], + "loc": { + "start": { + "line": 29, + "column": 10 + }, + "end": { + "line": 29, + "column": 13 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "a0", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 29, + "column": 33 + }, + "end": { + "line": 29, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 29, + "column": 33 + }, + "end": { + "line": 29, + "column": 35 + } + } + }, + "loc": { + "start": { + "line": 29, + "column": 33 + }, + "end": { + "line": 29, + "column": 35 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 29, + "column": 29 + }, + "end": { + "line": 29, + "column": 35 + } + } + }, + "loc": { + "start": { + "line": 29, + "column": 29 + }, + "end": { + "line": 29, + "column": 35 + } + } + } + ], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Integral", + "decorators": [], + "loc": { + "start": { + "line": 29, + "column": 37 + }, + "end": { + "line": 29, + "column": 45 + } + } + }, + "loc": { + "start": { + "line": 29, + "column": 37 + }, + "end": { + "line": 29, + "column": 47 + } + } + }, + "loc": { + "start": { + "line": 29, + "column": 37 + }, + "end": { + "line": 29, + "column": 47 + } + } + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "params": [ + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 29, + "column": 14 + }, + "end": { + "line": 29, + "column": 15 + } + } + }, + "constraint": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], + "loc": { + "start": { + "line": 29, + "column": 24 + }, + "end": { + "line": 29, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 29, + "column": 24 + }, + "end": { + "line": 29, + "column": 28 + } + } + }, + "loc": { + "start": { + "line": 29, + "column": 24 + }, + "end": { + "line": 29, + "column": 28 + } + } + }, + "loc": { + "start": { + "line": 29, + "column": 14 + }, + "end": { + "line": 29, + "column": 28 + } + } + } + ], + "loc": { + "start": { + "line": 29, + "column": 13 + }, + "end": { + "line": 29, + "column": 28 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "myval", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Short", + "decorators": [], + "loc": { + "start": { + "line": 30, + "column": 16 + }, + "end": { + "line": 30, + "column": 21 + } + } + }, + "loc": { + "start": { + "line": 30, + "column": 16 + }, + "end": { + "line": 30, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 30, + "column": 16 + }, + "end": { + "line": 30, + "column": 23 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 30, + "column": 9 + }, + "end": { + "line": 30, + "column": 14 + } + } + }, + "init": { + "type": "NumberLiteral", + "value": 2, + "loc": { + "start": { + "line": 30, + "column": 24 + }, + "end": { + "line": 30, + "column": 25 + } + } + }, + "loc": { + "start": { + "line": 30, + "column": 9 + }, + "end": { + "line": 30, + "column": 25 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 30, + "column": 5 + }, + "end": { + "line": 30, + "column": 26 + } + } + }, + { + "type": "ReturnStatement", + "argument": { + "type": "LogicalExpression", + "operator": "??", + "left": { + "type": "Identifier", + "name": "a0", + "decorators": [], + "loc": { + "start": { + "line": 31, + "column": 12 + }, + "end": { + "line": 31, + "column": 14 + } + } + }, + "right": { + "type": "Identifier", + "name": "myval", + "decorators": [], + "loc": { + "start": { + "line": 31, + "column": 18 + }, + "end": { + "line": 31, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 31, + "column": 12 + }, + "end": { + "line": 31, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 31, + "column": 5 + }, + "end": { + "line": 31, + "column": 24 + } + } + } + ], + "loc": { + "start": { + "line": 29, + "column": 46 + }, + "end": { + "line": 32, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 29, + "column": 13 + }, + "end": { + "line": 32, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 29, + "column": 13 + }, + "end": { + "line": 32, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 29, + "column": 1 + }, + "end": { + "line": 32, + "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": 33, + "column": 1 + } + } +} diff --git a/ets2panda/test/compiler/ets/null_coalescing_generic_1.ets b/ets2panda/test/compiler/ets/null_coalescing_generic_1.ets new file mode 100644 index 0000000000..c9eced6616 --- /dev/null +++ b/ets2panda/test/compiler/ets/null_coalescing_generic_1.ets @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2023 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 foo( + data: C | undefined, + exec: (pointer: C | undefined) => R +): R { + return exec(data ?? undefined); +} + +class C {} +function bar(data: T): void { + let c_class: C = new C(); + let myvar: Object = data ?? c_class; +} + +function baz(a0: T): Integral { + let myval: Short = 2; + return a0 ?? myval; +} diff --git a/ets2panda/test/compiler/ets/null_coalescing_generic_1_neg-expected.txt b/ets2panda/test/compiler/ets/null_coalescing_generic_1_neg-expected.txt new file mode 100644 index 0000000000..ffbe88bb73 --- /dev/null +++ b/ets2panda/test/compiler/ets/null_coalescing_generic_1_neg-expected.txt @@ -0,0 +1,600 @@ +{ + "type": "Program", + "statements": [ + { + "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": "fos", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 10 + }, + "end": { + "line": 16, + "column": 13 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "fos", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 10 + }, + "end": { + "line": 16, + "column": 13 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "a0", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 38 + }, + "end": { + "line": 16, + "column": 39 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 38 + }, + "end": { + "line": 16, + "column": 40 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 38 + }, + "end": { + "line": 16, + "column": 40 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 34 + }, + "end": { + "line": 16, + "column": 40 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 34 + }, + "end": { + "line": 16, + "column": 40 + } + } + } + ], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 42 + }, + "end": { + "line": 16, + "column": 43 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 42 + }, + "end": { + "line": 16, + "column": 45 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 42 + }, + "end": { + "line": 16, + "column": 45 + } + } + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "params": [ + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 14 + }, + "end": { + "line": 16, + "column": 15 + } + } + }, + "constraint": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Integral", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 24 + }, + "end": { + "line": 16, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 24 + }, + "end": { + "line": 16, + "column": 33 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 24 + }, + "end": { + "line": 16, + "column": 33 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 14 + }, + "end": { + "line": 16, + "column": 33 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 13 + }, + "end": { + "line": 16, + "column": 33 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "myval", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Short", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 16 + }, + "end": { + "line": 17, + "column": 21 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 16 + }, + "end": { + "line": 17, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 16 + }, + "end": { + "line": 17, + "column": 23 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 9 + }, + "end": { + "line": 17, + "column": 14 + } + } + }, + "init": { + "type": "NumberLiteral", + "value": 2, + "loc": { + "start": { + "line": 17, + "column": 24 + }, + "end": { + "line": 17, + "column": 25 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 9 + }, + "end": { + "line": 17, + "column": 25 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 17, + "column": 5 + }, + "end": { + "line": 17, + "column": 26 + } + } + }, + { + "type": "ReturnStatement", + "argument": { + "type": "LogicalExpression", + "operator": "??", + "left": { + "type": "Identifier", + "name": "a0", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 12 + }, + "end": { + "line": 18, + "column": 14 + } + } + }, + "right": { + "type": "Identifier", + "name": "myval", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 18 + }, + "end": { + "line": 18, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 12 + }, + "end": { + "line": 18, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 24 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 44 + }, + "end": { + "line": 19, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 13 + }, + "end": { + "line": 19, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 13 + }, + "end": { + "line": 19, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 19, + "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": 20, + "column": 1 + } + } +} +TypeError: Type 'Integral' is not compatible with the enclosing method's return type 'T' [null_coalescing_generic_1_neg.ets:18:12] diff --git a/ets2panda/test/compiler/ets/null_coalescing_generic_1_neg.ets b/ets2panda/test/compiler/ets/null_coalescing_generic_1_neg.ets new file mode 100644 index 0000000000..557016f5f1 --- /dev/null +++ b/ets2panda/test/compiler/ets/null_coalescing_generic_1_neg.ets @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2023 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 fos(a0: T): T { + let myval: Short = 2; + return a0 ?? myval; +} -- Gitee From 032cb27933c6ab33866f9c07d9498326a3ca70a5 Mon Sep 17 00:00:00 2001 From: Vivien Voros Date: Fri, 19 Jan 2024 15:37:59 +0100 Subject: [PATCH 25/26] [ArkTS verifier] Verifier fails on string concatenation with undefined Contcatenation some string with 'undefined' as value. Fixes internal issue #14767 Change-Id: I976f8d1ef66c949afd50233c86df5d3bb621e950 Signed-off-by: Vivien Voros --- ets2panda/compiler/core/ETSGen.cpp | 9 ++-- .../test/runtime/ets/stringConcatenation.ets | 44 +++++++++++++++++++ 2 files changed, 50 insertions(+), 3 deletions(-) create mode 100644 ets2panda/test/runtime/ets/stringConcatenation.ets diff --git a/ets2panda/compiler/core/ETSGen.cpp b/ets2panda/compiler/core/ETSGen.cpp index b65e0c1ba9..9e444048a5 100644 --- a/ets2panda/compiler/core/ETSGen.cpp +++ b/ets2panda/compiler/core/ETSGen.cpp @@ -2389,9 +2389,12 @@ void ETSGen::StringBuilderAppend(const ir::AstNode *node, VReg builder) signature = Signatures::BUILTIN_STRING_BUILDER_APPEND_BUILTIN_STRING; } - if ((GetAccumulatorType()->IsETSObjectType() || GetAccumulatorType()->IsETSTypeParameter() || - GetAccumulatorType()->IsETSArrayType()) && - !GetAccumulatorType()->IsETSStringType()) { + const checker::Type *accumulatorType = GetAccumulatorType(); + bool isNullOrUndefined = accumulatorType->ContainsNull() || accumulatorType->ContainsUndefined(); + bool isETSRefType = accumulatorType->IsETSObjectType() || accumulatorType->IsETSTypeParameter() || + accumulatorType->IsETSArrayType(); + bool isStringType = accumulatorType->IsETSStringType(); + if (isETSRefType && (!isStringType || isNullOrUndefined)) { if (Checker()->MayHaveNullValue(GetAccumulatorType())) { Label *ifnull = AllocLabel(); Label *end = AllocLabel(); diff --git a/ets2panda/test/runtime/ets/stringConcatenation.ets b/ets2panda/test/runtime/ets/stringConcatenation.ets new file mode 100644 index 0000000000..ff66d04edc --- /dev/null +++ b/ets2panda/test/runtime/ets/stringConcatenation.ets @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2024 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 main() { + let src: string | undefined = undefined; + let s = "_str_"; + let udef = undefined; + let a :string = "A_"; + let n : string | undefined | null = null; + + let dst: string = "" + src; + let dst_s : string = src + ""; + let a_dst :string = a + dst; + let n_dst : string = n + a_dst; + let dst_a : string = dst + a; + + + + assert dst == "undefined"; + assert dst_s == "undefined"; + assert a_dst == "A_undefined"; + assert dst_a == "undefinedA_"; + assert n_dst == "nullA_undefined"; + assert udef + s == "undefined_str_"; + assert s + udef == "_str_undefined"; + assert a + n == "A_null"; + assert a + s == "A__str_"; + assert a + s + udef == "A__str_undefined"; + assert a + udef + a == "A_undefinedA_"; + assert udef + s + n == "undefined_str_null"; + +} -- Gitee From b2a553f14ef295f3a7cf2101accc2118a1991afb Mon Sep 17 00:00:00 2001 From: aleksisch Date: Wed, 20 Dec 2023 17:40:31 +0300 Subject: [PATCH 26/26] extract top level statements from parser Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/I8V5Z5 Description: Top level statements handling should be done outside of the parser. Also import path-s related code should be extracted from the parser Signed-off-by: aleksisch --- ets2panda/BUILD.gn | 7 + ets2panda/CMakeLists.txt | 7 + ets2panda/checker/ETSAnalyzer.cpp | 13 +- ets2panda/checker/ETSchecker.h | 4 +- ets2panda/checker/TSAnalyzer.cpp | 5 + ets2panda/compiler/core/ASTVerifier.h | 1 + ets2panda/compiler/core/ETSCompiler.cpp | 5 + ets2panda/compiler/core/JSCompiler.cpp | 5 + ets2panda/compiler/core/compilerImpl.cpp | 4 - ets2panda/compiler/lowering/checkerPhase.cpp | 6 + .../ets/topLevelStmts/globalClassHandler.cpp | 228 +++ .../ets/topLevelStmts/globalClassHandler.h | 77 + .../topLevelStmts/globalDeclTransformer.cpp | 123 ++ .../ets/topLevelStmts/globalDeclTransformer.h | 81 + .../ets/topLevelStmts/importExportDecls.cpp | 92 ++ .../ets/topLevelStmts/importExportDecls.h | 75 + .../ets/topLevelStmts/topLevelStmts.cpp | 40 + .../ets/topLevelStmts/topLevelStmts.h | 49 + ets2panda/compiler/lowering/phase.cpp | 5 +- .../lowering/scopesInit/scopesInitPhase.cpp | 15 +- .../lowering/scopesInit/scopesInitPhase.h | 6 + ets2panda/ir/astNodeMapping.h | 1 + ets2panda/ir/base/classElement.cpp | 8 + ets2panda/ir/base/classElement.h | 2 + ets2panda/ir/ets/etsReExportDeclaration.cpp | 51 + ets2panda/ir/ets/etsReExportDeclaration.h | 40 +- ets2panda/ir/visitor/IterateAstVisitor.h | 75 +- ets2panda/lexer/lexer.h | 20 + ets2panda/parser/ETSparser.cpp | 1390 +++++------------ ets2panda/parser/ETSparser.h | 118 +- ets2panda/parser/TypedParser.cpp | 2 +- ets2panda/parser/TypedParser.h | 7 - ets2panda/parser/context/parserContext.h | 2 - ets2panda/parser/expressionParser.cpp | 1 + ets2panda/parser/parserImpl.cpp | 7 +- ets2panda/parser/parserImpl.h | 32 +- ets2panda/parser/program/program.h | 5 + ets2panda/parser/statementParser.cpp | 4 +- .../compiler/ets/FunctionType1-expected.txt | 2 +- .../compiler/ets/FunctionType2-expected.txt | 2 +- .../compiler/ets/FunctionType3-expected.txt | 2 +- .../compiler/ets/FunctionType4-expected.txt | 8 +- .../compiler/ets/FunctionType5-expected.txt | 4 +- ...ing_with_chaining_non_nullish-expected.txt | 12 +- ...ndexing_with_chaining_nullish-expected.txt | 12 +- ..._without_chaining_non_nullish-expected.txt | 12 +- ...xing_without_chaining_nullish-expected.txt | 12 +- .../ets/etsObjectToString4-expected.txt | 4 +- .../ets/identifierReference2-expected.txt | 4 +- .../ets/identifierReference3-expected.txt | 6 +- .../ets/identifierReference4-expected.txt | 6 +- .../ets/inferTypeOfArray-expected.txt | 14 +- .../inferTypeOfArrayNegative1-expected.txt | 2 +- .../inferTypeOfArrayNegative2-expected.txt | 4 +- .../inferTypeOfArrayNegative3-expected.txt | 2 +- .../compiler/ets/lambdaFunction1-expected.txt | 6 +- .../lambda_cast_infer_type_void-expected.txt | 4 +- .../lambda_cast_type_has_pramas-expected.txt | 4 +- ...lambda_infer_type_retrun_enum-expected.txt | 4 +- ...ambda_infer_type_return_array-expected.txt | 4 +- ...type_return_lambda_expression-expected.txt | 6 +- ...bda_infer_type_return_literal-expected.txt | 4 +- ...ambda_infer_type_return_union-expected.txt | 4 +- .../lambda_infer_type_scope-expected.txt | 8 +- .../ets/launch_expression-expected.txt | 16 +- .../ets/objectLiteralAbstract-expected.txt | 6 +- .../ets/objectLiteralBadKey-expected.txt | 8 +- .../objectLiteralInaccessibleKey-expected.txt | 8 +- .../ets/objectLiteralInterface-expected.txt | 6 +- .../objectLiteralNoContextType-expected.txt | 4 +- ...ralNoParameterlessConstructor-expected.txt | 6 +- .../ets/objectLiteralNoSuchKey-expected.txt | 8 +- ...ctLiteralPrimitiveContextType-expected.txt | 6 +- ...jectLiteralPrivateConstructor-expected.txt | 6 +- .../ets/objectLiteralReadonlyKey-expected.txt | 8 +- .../objectLiteralWrongValueType-expected.txt | 8 +- .../ets/throwingFunctionCheck1-expected.txt | 4 +- .../test/compiler/ets/typeAlias-expected.txt | 4 +- .../parser/ets/Dollar_dollar_1-expected.txt | 2 +- .../parser/ets/Dollar_dollar_3-expected.txt | 4 +- .../parser/ets/Dollar_dollar_4-expected.txt | 2 +- .../test/parser/ets/FunctionType-expected.txt | 4 +- .../parser/ets/ambiguous_call_1-expected.txt | 12 +- .../parser/ets/ambiguous_call_2-expected.txt | 16 +- .../parser/ets/ambiguous_call_3-expected.txt | 12 +- ets2panda/test/parser/ets/array-expected.txt | 12 +- .../ets/arrayHoldingNullValue-expected.txt | 18 +- ets2panda/test/parser/ets/assign-expected.txt | 4 +- .../ets/async_function_bad-expected.txt | 2 +- .../parser/ets/async_with_lambda-expected.txt | 2 +- .../parser/ets/await_keyword-expected.txt | 10 +- .../test/parser/ets/binary_op-expected.txt | 172 +- .../test/parser/ets/boolean-expected.txt | 6 +- ets2panda/test/parser/ets/break-expected.txt | 6 +- .../parser/ets/cast_expressions5-expected.txt | 6 +- .../parser/ets/class_instance-expected.txt | 20 +- .../test/parser/ets/const_enum-expected.txt | 2 +- .../test/parser/ets/continue-expected.txt | 6 +- .../test/parser/ets/decl_infer-expected.txt | 20 +- .../test/parser/ets/exports-expected.txt | 4 +- ets2panda/test/parser/ets/for_of-expected.txt | 6 +- .../test/parser/ets/for_of_02-expected.txt | 6 +- .../ets/functionTypeThrows-expected.txt | 2 +- ...unction_implicit_return_type3-expected.txt | 4 +- .../ets/genericDefaultParam_1-expected.txt | 6 +- ...erics_type_param_constraint_3-expected.txt | 4 +- .../test/parser/ets/identifier-expected.txt | 18 +- .../import_tests/diamond/test2-expected.txt | 4 +- .../import_tests/diamond/test3-expected.txt | 4 +- .../import_tests/diamond/test4-expected.txt | 4 +- .../import_alias/export-expected.txt | 8 +- .../ets/import_tests/import_all-expected.txt | 12 +- .../import_all_alias_1-expected.txt | 8 +- .../import_all_alias_2-expected.txt | 4 +- .../import_all_type_alias-expected.txt | 2 +- .../import_tests/import_name_1-expected.txt | 6 +- .../import_tests/import_name_2-expected.txt | 4 +- .../import_name_alias_1-expected.txt | 8 +- .../import_name_alias_2-expected.txt | 4 +- .../import_relative_path-expected.txt | 8 +- .../import_several_1-expected.txt | 8 +- .../import_several_2-expected.txt | 4 +- .../import_several_3-expected.txt | 8 +- .../import_several_4-expected.txt | 8 +- .../import_several_5-expected.txt | 8 +- .../import_several_6-expected.txt | 8 +- .../import_several_7-expected.txt | 8 +- .../too_many_default_exports_2-expected.txt | 2 +- .../relative_import/alias2-expected.txt | 4 +- .../parser/ets/index_expressions-expected.txt | 16 +- .../ets/lambda_import_alias_1-2-expected.txt | 2 +- .../launch_with_call_expression-expected.txt | 2 +- ets2panda/test/parser/ets/null-expected.txt | 10 +- .../test/parser/ets/null_invalid-expected.txt | 6 +- .../test/parser/ets/null_valid-expected.txt | 6 +- ets2panda/test/parser/ets/object-expected.txt | 2 +- .../ets/optional-chaining-array-expected.txt | 16 +- ...nal_chaining_invalid_property-expected.txt | 10 +- ...onal_chaining_nested_property-expected.txt | 10 +- ...onal_chaining_object_property-expected.txt | 16 +- .../ets/optional_union_paramter-expected.txt | 4 +- .../parentheses_expression_value-expected.txt | 16 +- .../parser/ets/predefined_types-expected.txt | 14 +- .../re_export/folder/re_export_6-expected.txt | 70 + .../re_export/folder/re_export_7-expected.txt | 70 + .../re_export/folderIndex/index-expected.txt | 85 + .../ets/re_export/re_export-expected.txt | 70 + .../ets/re_export/re_export_2-expected.txt | 85 + .../ets/re_export/re_export_3-expected.txt | 85 + .../ets/re_export/re_export_4-expected.txt | 170 ++ .../ets/re_export/re_export_5-expected.txt | 140 ++ .../parser/ets/rest_parameter_01-expected.txt | 8 +- .../parser/ets/rest_parameter_02-expected.txt | 8 +- .../parser/ets/rest_parameter_03-expected.txt | 2 +- ets2panda/test/parser/ets/return-expected.txt | 6 +- .../selective_export_bad-expected.txt | 2 +- .../test/parser/ets/simple_types-expected.txt | 56 +- ets2panda/test/parser/ets/string-expected.txt | 12 +- .../test/parser/ets/ternary-expected.txt | 12 +- .../test/parser/ets/test_jsvalue-expected.txt | 2 +- .../ets/test_jsvalue_get_double-expected.txt | 8 +- .../test_jsvalue_get_property_1-expected.txt | 8 +- .../test_jsvalue_get_property_2-expected.txt | 8 +- .../parser/ets/test_type_alias9-expected.txt | 12 +- .../throwsRethrowsAsVariables-expected.txt | 8 +- ...bda_mismatch_lambda_signature-expected.txt | 2 +- .../test/parser/ets/tuple_type_1-expected.txt | 36 +- .../test/parser/ets/unary_op-expected.txt | 36 +- .../parser/ets/user_defined_22-expected.txt | 6 +- .../parser/ets/user_defined_3-expected.txt | 16 +- .../test/unit/public/es2panda_public_test.cpp | 5 +- .../test/unit/public/plugin_test.expected.txt | 5 - .../test/unit/union_normalization_test.cpp | 4 - ets2panda/util/arktsconfig.cpp | 4 +- ets2panda/util/arktsconfig.h | 2 +- ets2panda/util/error_handler.cpp | 34 + ets2panda/util/error_handler.h | 39 + ets2panda/util/helpers.cpp | 14 +- ets2panda/util/helpers.h | 45 +- ets2panda/util/importPathResolver.cpp | 354 +++++ ets2panda/util/importPathResolver.h | 154 ++ ets2panda/util/result.h | 149 ++ ets2panda/varbinder/ETSBinder.cpp | 2 +- ets2panda/varbinder/ETSBinder.h | 29 +- ets2panda/varbinder/varbinder.h | 5 + 185 files changed, 3614 insertions(+), 1769 deletions(-) create mode 100644 ets2panda/compiler/lowering/ets/topLevelStmts/globalClassHandler.cpp create mode 100644 ets2panda/compiler/lowering/ets/topLevelStmts/globalClassHandler.h create mode 100644 ets2panda/compiler/lowering/ets/topLevelStmts/globalDeclTransformer.cpp create mode 100644 ets2panda/compiler/lowering/ets/topLevelStmts/globalDeclTransformer.h create mode 100644 ets2panda/compiler/lowering/ets/topLevelStmts/importExportDecls.cpp create mode 100644 ets2panda/compiler/lowering/ets/topLevelStmts/importExportDecls.h create mode 100644 ets2panda/compiler/lowering/ets/topLevelStmts/topLevelStmts.cpp create mode 100644 ets2panda/compiler/lowering/ets/topLevelStmts/topLevelStmts.h create mode 100644 ets2panda/ir/ets/etsReExportDeclaration.cpp create mode 100644 ets2panda/util/error_handler.cpp create mode 100644 ets2panda/util/error_handler.h create mode 100644 ets2panda/util/importPathResolver.cpp create mode 100644 ets2panda/util/importPathResolver.h create mode 100644 ets2panda/util/result.h diff --git a/ets2panda/BUILD.gn b/ets2panda/BUILD.gn index 184a1159a1..e61bda868e 100644 --- a/ets2panda/BUILD.gn +++ b/ets2panda/BUILD.gn @@ -165,6 +165,10 @@ libes2panda_sources = [ "compiler/lowering/ets/opAssignment.cpp", "compiler/lowering/ets/promiseVoid.cpp", "compiler/lowering/ets/structLowering.cpp", + "compiler/lowering/ets/topLevelStmts/globalClassHandler.cpp", + "compiler/lowering/ets/topLevelStmts/globalDeclTransformer.cpp", + "compiler/lowering/ets/topLevelStmts/importExportDecls.cpp", + "compiler/lowering/ets/topLevelStmts/topLevelStmts.cpp", "compiler/lowering/ets/tupleLowering.cpp", "compiler/lowering/ets/unionLowering.cpp", "compiler/lowering/phase.cpp", @@ -204,6 +208,7 @@ libes2panda_sources = [ "ir/ets/etsPackageDeclaration.cpp", "ir/ets/etsParameterExpression.cpp", "ir/ets/etsPrimitiveType.cpp", + "ir/ets/etsReExportDeclaration.cpp", "ir/ets/etsScript.cpp", "ir/ets/etsStructDeclaration.cpp", "ir/ets/etsTuple.cpp", @@ -358,7 +363,9 @@ libes2panda_sources = [ "util/arktsconfig.cpp", "util/bitset.cpp", "util/declgenEts2Ts.cpp", + "util/error_handler.cpp", "util/helpers.cpp", + "util/importPathResolver.cpp", "util/path.cpp", "util/plugin.cpp", "util/ustring.cpp", diff --git a/ets2panda/CMakeLists.txt b/ets2panda/CMakeLists.txt index dfd0e446c1..54293f61a8 100644 --- a/ets2panda/CMakeLists.txt +++ b/ets2panda/CMakeLists.txt @@ -150,6 +150,10 @@ set(ES2PANDA_LIB_SRC compiler/lowering/phase.cpp compiler/lowering/plugin_phase.cpp compiler/lowering/util.cpp + compiler/lowering/ets/topLevelStmts/importExportDecls.cpp + compiler/lowering/ets/topLevelStmts/globalClassHandler.cpp + compiler/lowering/ets/topLevelStmts/globalDeclTransformer.cpp + compiler/lowering/ets/topLevelStmts/topLevelStmts.cpp compiler/lowering/ets/lambdaLowering.cpp compiler/lowering/ets/generateDeclarations.cpp compiler/lowering/ets/objectIndexAccess.cpp @@ -234,6 +238,7 @@ set(ES2PANDA_LIB_SRC ir/statements/breakStatement.cpp ir/statements/classDeclaration.cpp ir/ets/etsStructDeclaration.cpp + ir/ets/etsReExportDeclaration.cpp ir/statements/continueStatement.cpp ir/statements/debuggerStatement.cpp ir/statements/doWhileStatement.cpp @@ -436,7 +441,9 @@ set(ES2PANDA_LIB_SRC util/arktsconfig.cpp util/bitset.cpp util/declgenEts2Ts.cpp + util/error_handler.cpp util/helpers.cpp + util/importPathResolver.cpp util/path.cpp util/ustring.cpp ) diff --git a/ets2panda/checker/ETSAnalyzer.cpp b/ets2panda/checker/ETSAnalyzer.cpp index 73009f32b1..2219e368b0 100644 --- a/ets2panda/checker/ETSAnalyzer.cpp +++ b/ets2panda/checker/ETSAnalyzer.cpp @@ -1175,6 +1175,11 @@ checker::Type *ETSAnalyzer::Check([[maybe_unused]] ir::ClassExpression *expr) co UNREACHABLE(); } +checker::Type *ETSAnalyzer::Check([[maybe_unused]] ir::ETSReExportDeclaration *expr) const +{ + UNREACHABLE(); +} + checker::Type *ETSAnalyzer::Check(ir::ConditionalExpression *expr) const { ETSChecker *checker = GetETSChecker(); @@ -2237,13 +2242,7 @@ void ProcessReturnStatements(ETSChecker *checker, ir::ScriptFunction *containing } const auto name = containingFunc->Scope()->InternalName().Mutf8(); - if (name.find(compiler::Signatures::ETS_MAIN_WITH_MANGLE_BEGIN) != std::string::npos) { - if (funcReturnType == checker->GlobalBuiltinVoidType()) { - funcReturnType = checker->GlobalVoidType(); - } else if (!funcReturnType->IsETSVoidType() && !funcReturnType->IsIntType()) { - checker->ThrowTypeError("Bad return type, main enable only void or int type.", st->Start()); - } - } + CheckArgumentVoidType(funcReturnType, checker, name, st); if (stArgument->IsObjectExpression()) { stArgument->AsObjectExpression()->SetPreferredType(funcReturnType); diff --git a/ets2panda/checker/ETSchecker.h b/ets2panda/checker/ETSchecker.h index 69f2c7306d..ebedcb3f47 100644 --- a/ets2panda/checker/ETSchecker.h +++ b/ets2panda/checker/ETSchecker.h @@ -596,9 +596,7 @@ public: template T *AllocNode(Args &&...args) { - auto *ret = Allocator()->New(std::forward(args)...); - ret->Iterate([ret](auto *child) { child->SetParent(ret); }); - return ret; + return util::NodeAllocator::ForceSetParent(Allocator(), std::forward(args)...); } private: diff --git a/ets2panda/checker/TSAnalyzer.cpp b/ets2panda/checker/TSAnalyzer.cpp index 81909d5f75..9de796eb32 100644 --- a/ets2panda/checker/TSAnalyzer.cpp +++ b/ets2panda/checker/TSAnalyzer.cpp @@ -1708,6 +1708,11 @@ checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::TSConditionalType *node) c UNREACHABLE(); } +checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::ETSReExportDeclaration *node) const +{ + UNREACHABLE(); +} + checker::Type *TSAnalyzer::Check(ir::TSConstructorType *node) const { TSChecker *checker = GetTSChecker(); diff --git a/ets2panda/compiler/core/ASTVerifier.h b/ets2panda/compiler/core/ASTVerifier.h index 87b9b91dc3..f6f3d5a83b 100644 --- a/ets2panda/compiler/core/ASTVerifier.h +++ b/ets2panda/compiler/core/ASTVerifier.h @@ -183,6 +183,7 @@ public: }}; } const std::set withoutAdditionalChecks = {"PromiseVoidInferencePhase", + "TopLevelStatements", "StructLowering", "DefaultParameterLowering", "GenerateTsDeclarationsPhase", diff --git a/ets2panda/compiler/core/ETSCompiler.cpp b/ets2panda/compiler/core/ETSCompiler.cpp index fd2476ce94..6a2a1a6c14 100644 --- a/ets2panda/compiler/core/ETSCompiler.cpp +++ b/ets2panda/compiler/core/ETSCompiler.cpp @@ -870,6 +870,11 @@ void ETSCompiler::Compile([[maybe_unused]] const ir::ClassExpression *expr) cons UNREACHABLE(); } +void ETSCompiler::Compile([[maybe_unused]] const ir::ETSReExportDeclaration *stmt) const +{ + UNREACHABLE(); +} + void ETSCompiler::Compile(const ir::ConditionalExpression *expr) const { ETSGen *etsg = GetETSGen(); diff --git a/ets2panda/compiler/core/JSCompiler.cpp b/ets2panda/compiler/core/JSCompiler.cpp index e7099b97f7..603e69fe1a 100644 --- a/ets2panda/compiler/core/JSCompiler.cpp +++ b/ets2panda/compiler/core/JSCompiler.cpp @@ -495,6 +495,11 @@ void JSCompiler::Compile([[maybe_unused]] const ir::ETSImportDeclaration *node) UNREACHABLE(); } +void JSCompiler::Compile([[maybe_unused]] const ir::ETSReExportDeclaration *node) const +{ + UNREACHABLE(); +} + void JSCompiler::Compile([[maybe_unused]] const ir::ETSLaunchExpression *expr) const { UNREACHABLE(); diff --git a/ets2panda/compiler/core/compilerImpl.cpp b/ets2panda/compiler/core/compilerImpl.cpp index a5bc7da17f..c9c54ce778 100644 --- a/ets2panda/compiler/core/compilerImpl.cpp +++ b/ets2panda/compiler/core/compilerImpl.cpp @@ -160,10 +160,6 @@ static pandasm::Program *CreateCompiler(const CompilationUnit &unit, const Phase &parser, &context); parser.ParseScript(unit.input, unit.options.compilationMode == CompilationMode::GEN_STD_LIB); - if constexpr (std::is_same_v && std::is_same_v) { - reinterpret_cast(varbinder)->FillResolvedImportPathes(parser.ResolvedParsedSourcesMap(), - &allocator); - } for (auto *phase : getPhases(unit.ext)) { if (!phase->Apply(&publicContext, &program)) { return nullptr; diff --git a/ets2panda/compiler/lowering/checkerPhase.cpp b/ets2panda/compiler/lowering/checkerPhase.cpp index c787655b87..df020fe882 100644 --- a/ets2panda/compiler/lowering/checkerPhase.cpp +++ b/ets2panda/compiler/lowering/checkerPhase.cpp @@ -16,11 +16,17 @@ #include "checkerPhase.h" #include "checker/checker.h" #include "compiler/core/ASTVerifier.h" +#include "varbinder/ETSBinder.h" #include "compiler/core/compilerContext.h" namespace panda::es2panda::compiler { bool CheckerPhase::Perform(public_lib::Context *ctx, [[maybe_unused]] parser::Program *program) { + auto varbinder = ctx->compilerContext->VarBinder(); + if (ctx->parser->IsETSParser() && varbinder->IsETSBinder()) { + varbinder->AsETSBinder()->FillResolvedImportPaths(ctx->parser->AsETSParser()->ResolvedParsedSourcesMap(), + ctx->allocator); + } return ctx->checker->StartChecker(ctx->compilerContext->VarBinder(), *ctx->compilerContext->Options()); } diff --git a/ets2panda/compiler/lowering/ets/topLevelStmts/globalClassHandler.cpp b/ets2panda/compiler/lowering/ets/topLevelStmts/globalClassHandler.cpp new file mode 100644 index 0000000000..167913fa43 --- /dev/null +++ b/ets2panda/compiler/lowering/ets/topLevelStmts/globalClassHandler.cpp @@ -0,0 +1,228 @@ +/* + * Copyright (c) 2021 - 2023 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. + */ + +#include "compiler/lowering/ets/topLevelStmts/globalClassHandler.h" + +#include "ir/statements/classDeclaration.h" +#include "ir/base/classDefinition.h" +#include "ir/base/classProperty.h" +#include "ir/base/classStaticBlock.h" +#include "ir/base/scriptFunction.h" +#include "ir/base/methodDefinition.h" +#include "ir/expressions/identifier.h" +#include "ir/expressions/classExpression.h" +#include "ir/expressions/functionExpression.h" +#include "ir/expressions/callExpression.h" +#include "ir/statements/expressionStatement.h" +#include "ir/statements/blockStatement.h" +#include "compiler/lowering/ets/topLevelStmts/globalDeclTransformer.h" +#include "util/helpers.h" + +namespace panda::es2panda::compiler { + +using util::NodeAllocator; + +void GlobalClassHandler::InitGlobalClass(const ArenaVector &programs) +{ + if (programs.empty()) { + return; + } + auto globalDecl = CreateGlobalClass(); + auto globalClass = globalDecl->Definition(); + + auto addCCtor = [this](ir::AstNode *node) { + if (node->IsClassDefinition()) { + auto classDef = node->AsClassDefinition(); + bool allowEmpty = false; + auto staticBlock = CreateCCtor(classDef->Body(), classDef->Start(), allowEmpty); + if (staticBlock != nullptr) { + classDef->Body().emplace_back(staticBlock); + staticBlock->SetParent(classDef); + } + } + }; + + ArenaVector statements(allocator_->Adapter()); + for (auto program : programs) { + program->Ast()->IterateRecursively(addCCtor); + auto stmts = MakeGlobalStatements(program->Ast(), globalClass, !program->GetPackageName().Empty()); + statements.emplace_back(GlobalStmts {program, std::move(stmts)}); + program->SetGlobalClass(globalClass); + } + InitCallToCCTOR(programs.front(), statements); +} + +ir::MethodDefinition *GlobalClassHandler::CreateAndFillInitMethod(const ArenaVector &initStatements) +{ + auto initMethod = CreateInitMethod(); + + for (const auto &stmts : initStatements) { + for (auto stmt : stmts.statements) { + initMethod->Function()->Body()->AsBlockStatement()->Statements().emplace_back(stmt); + stmt->SetParent(initMethod->Function()->Body()); + } + } + return initMethod; +} + +ir::MethodDefinition *GlobalClassHandler::CreateInitMethod() +{ + const auto functionFlags = ir::ScriptFunctionFlags::NONE; + const auto functionModifiers = ir::ModifierFlags::STATIC | ir::ModifierFlags::PUBLIC; + auto *initIdent = NodeAllocator::Alloc(allocator_, INIT_NAME, allocator_); + + ArenaVector params(allocator_->Adapter()); + + ArenaVector statements(allocator_->Adapter()); + auto *initBody = NodeAllocator::Alloc(allocator_, allocator_, std::move(statements)); + + auto *initFunc = + NodeAllocator::Alloc(allocator_, ir::FunctionSignature(nullptr, std::move(params), nullptr), + initBody, functionFlags, false, Language(Language::Id::ETS)); + + initFunc->SetIdent(initIdent); + initFunc->AddModifier(functionModifiers); + + auto *funcExpr = NodeAllocator::Alloc(allocator_, initFunc); + auto methodDef = NodeAllocator::Alloc(allocator_, ir::MethodDefinitionKind::METHOD, initIdent, + funcExpr, functionModifiers, allocator_, false); + return methodDef; +} + +void GlobalClassHandler::AddInitCall(ir::ClassDefinition *globalClass, ir::MethodDefinition *initMethod) +{ + ASSERT(initMethod != nullptr); + + auto &globalBody = globalClass->Body(); + auto maybeStaticBlock = std::find_if(globalBody.begin(), globalBody.end(), + [](ir::AstNode *cctor) { return cctor->IsClassStaticBlock(); }); + ASSERT(maybeStaticBlock != globalBody.end()); + + auto *staticBlock = (*maybeStaticBlock)->AsClassStaticBlock(); + auto *callee = RefIdent(initMethod->Id()->Name()); + + auto *const callExpr = NodeAllocator::Alloc( + allocator_, callee, ArenaVector(allocator_->Adapter()), nullptr, false, false); + + auto *blockBody = staticBlock->Function()->Body()->AsBlockStatement(); + auto exprStmt = NodeAllocator::Alloc(allocator_, callExpr); + exprStmt->SetParent(blockBody); + blockBody->Statements().emplace_back(exprStmt); +} + +ir::Identifier *GlobalClassHandler::RefIdent(const util::StringView &name) +{ + auto *const callee = NodeAllocator::Alloc(allocator_, name, allocator_); + callee->SetReference(); + return callee; +} + +ir::ClassStaticBlock *GlobalClassHandler::CreateCCtor(const ArenaVector &properties, + const lexer::SourcePosition &loc, bool allowEmptyCctor) +{ + bool hasStaticField = false; + for (const auto *prop : properties) { + if (prop->IsClassStaticBlock()) { + return nullptr; + } + + if (!prop->IsClassProperty()) { + continue; + } + + const auto *field = prop->AsClassProperty(); + + if (field->IsStatic()) { + hasStaticField = true; + } + } + + if (!hasStaticField && !allowEmptyCctor) { + return nullptr; + } + + ArenaVector params(allocator_->Adapter()); + + auto *id = NodeAllocator::Alloc(allocator_, compiler::Signatures::CCTOR, allocator_); + + ArenaVector statements(allocator_->Adapter()); + + auto *body = NodeAllocator::Alloc(allocator_, allocator_, std::move(statements)); + auto *func = NodeAllocator::Alloc( + allocator_, ir::FunctionSignature(nullptr, std::move(params), nullptr), body, + ir::ScriptFunctionFlags::STATIC_BLOCK | ir::ScriptFunctionFlags::HIDDEN, ir::ModifierFlags::STATIC, false, + Language(Language::Id::ETS)); + func->SetIdent(id); + + auto *funcExpr = NodeAllocator::Alloc(allocator_, func); + auto *staticBlock = NodeAllocator::Alloc(allocator_, funcExpr, allocator_); + staticBlock->AddModifier(ir::ModifierFlags::STATIC); + staticBlock->SetRange({loc, loc}); + return staticBlock; +} + +ArenaVector GlobalClassHandler::MakeGlobalStatements(ir::BlockStatement *globalStmts, + ir::ClassDefinition *classDef, bool isPackage) +{ + auto globalDecl = GlobalDeclTransformer(allocator_); + auto statements = globalDecl.TransformStatements(globalStmts->Statements(), isPackage); + classDef->AddProperties(util::Helpers::ConvertVector(statements.classProperties)); + globalDecl.FilterDeclarations(globalStmts->Statements()); + return std::move(statements.initStatements); +} + +void GlobalClassHandler::InitGlobalClass(ir::ClassDefinition *classDef, parser::ScriptKind scriptKind) +{ + auto &globalProperties = classDef->Body(); + auto staticBlock = CreateCCtor(globalProperties, classDef->Start(), scriptKind != parser::ScriptKind::STDLIB); + if (staticBlock != nullptr) { + staticBlock->SetParent(classDef); + globalProperties.emplace_back(staticBlock); + } + classDef->SetGlobalInitialized(); +} + +ir::ClassDeclaration *GlobalClassHandler::CreateGlobalClass() +{ + auto *ident = NodeAllocator::Alloc(allocator_, compiler::Signatures::ETS_GLOBAL, allocator_); + + auto *classDef = + NodeAllocator::Alloc(allocator_, allocator_, ident, ir::ClassDefinitionModifiers::GLOBAL, + ir::ModifierFlags::ABSTRACT, Language(Language::Id::ETS)); + auto *classDecl = NodeAllocator::Alloc(allocator_, classDef, allocator_); + return classDecl; +} + +void GlobalClassHandler::InitCallToCCTOR(parser::Program *program, const ArenaVector &initStatements) +{ + auto globalClass = program->GlobalClass(); + auto globalDecl = globalClass->Parent()->AsClassDeclaration(); + program->Ast()->Statements().emplace_back(globalDecl); + globalDecl->SetParent(program->Ast()); + InitGlobalClass(globalClass, program->Kind()); + auto &globalBody = globalClass->Body(); + if (program->GetPackageName().Empty() && program->Kind() != parser::ScriptKind::STDLIB) { + ir::MethodDefinition *initMethod = CreateAndFillInitMethod(initStatements); + if (initMethod != nullptr) { + initMethod->SetParent(program->GlobalClass()); + globalBody.insert(globalBody.begin(), initMethod); + if (!initMethod->Function()->Body()->AsBlockStatement()->Statements().empty()) { + AddInitCall(program->GlobalClass(), initMethod); + } + } + } +} + +} // namespace panda::es2panda::compiler \ No newline at end of file diff --git a/ets2panda/compiler/lowering/ets/topLevelStmts/globalClassHandler.h b/ets2panda/compiler/lowering/ets/topLevelStmts/globalClassHandler.h new file mode 100644 index 0000000000..4f9f0f0c0f --- /dev/null +++ b/ets2panda/compiler/lowering/ets/topLevelStmts/globalClassHandler.h @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2021 - 2023 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. + */ + +#ifndef PANDA_GLOBALCLASSHANDLER_H +#define PANDA_GLOBALCLASSHANDLER_H + +#include "parser/program/program.h" +#include "public/public.h" +#include "ir/astNode.h" + +namespace panda::es2panda::compiler { + +class GlobalClassHandler { + struct GlobalStmts { + parser::Program *program; + ArenaVector statements; + }; + +public: + GlobalClassHandler(ArenaAllocator *allocator) : allocator_(allocator) {}; + + /** + * Each "Module" has it's own global class, which contains all top level statements across "module" + * Result - creation of global class and _$init$_ method + * @param programs - vector of files in module + */ + void InitGlobalClass(const ArenaVector &programs); + +private: + /** + * Move top level statements to _$init$_ and + * @param program program of module + * @param init_statements statements which should be executed + */ + void InitCallToCCTOR(parser::Program *program, const ArenaVector &initStatements); + +private: + void InitGlobalClass(ir::ClassDefinition *classDef, parser::ScriptKind scriptKind); + ir::ClassDeclaration *CreateGlobalClass(); + ir::ClassStaticBlock *CreateCCtor(const ArenaVector &properties, const lexer::SourcePosition &loc, + bool allowEmptyCctor); + + /** + * + * @param global_stmts leave only declarations here + * @param class_def add new properties such as methods and fields + * @param is_package + * @return Statements, which should be executed before the start + */ + ArenaVector MakeGlobalStatements(ir::BlockStatement *globalStmts, ir::ClassDefinition *classDef, + bool isPackage); + + ir::MethodDefinition *CreateAndFillInitMethod(const ArenaVector &initStatements); + ir::MethodDefinition *CreateInitMethod(); + void AddInitCall(ir::ClassDefinition *globalClass, ir::MethodDefinition *initMethod); + + ir::Identifier *RefIdent(const util::StringView &name); + +private: + constexpr static std::string_view INIT_NAME = compiler::Signatures::INIT_METHOD; + ArenaAllocator *const allocator_; +}; +} // namespace panda::es2panda::compiler + +#endif // PANDA_GLOBALCLASSHANDLER_H diff --git a/ets2panda/compiler/lowering/ets/topLevelStmts/globalDeclTransformer.cpp b/ets2panda/compiler/lowering/ets/topLevelStmts/globalDeclTransformer.cpp new file mode 100644 index 0000000000..0ff4a8e88f --- /dev/null +++ b/ets2panda/compiler/lowering/ets/topLevelStmts/globalDeclTransformer.cpp @@ -0,0 +1,123 @@ +/* + * Copyright (c) 2021 - 2023 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. + */ + +#include "compiler/lowering/ets/topLevelStmts/globalDeclTransformer.h" + +namespace panda::es2panda::compiler { + +void GlobalDeclTransformer::FilterDeclarations(ArenaVector &stmts) +{ + const auto isDeclCb = [&types = typeDecl_](const ir::AstNode *node) { + return types.count(node->Type()) == 0U || + (node->IsExportNamedDeclaration() && !node->AsExportNamedDeclaration()->Specifiers().empty()); + }; + stmts.erase(std::remove_if(stmts.begin(), stmts.end(), isDeclCb), stmts.end()); +} + +GlobalDeclTransformer::ResultT GlobalDeclTransformer::TransformStatements(const ArenaVector &stmts, + bool isPackage) +{ + isPackage_ = isPackage; + result_.classProperties.clear(); + result_.initStatements.clear(); + for (auto stmt : stmts) { + stmt->Accept(this); + } + return std::move(result_); +} + +void GlobalDeclTransformer::VisitFunctionDeclaration(ir::FunctionDeclaration *funcDecl) +{ + auto *funcExpr = util::NodeAllocator::ForceSetParent(allocator_, funcDecl->Function()); + funcDecl->Function()->SetStart(funcDecl->Function()->Id()->End()); + funcExpr->SetRange(funcDecl->Function()->Range()); + ir::MethodDefinitionKind methodKind; + if (funcDecl->Function()->IsExtensionMethod()) { + methodKind = ir::MethodDefinitionKind::EXTENSION_METHOD; + } else { + methodKind = ir::MethodDefinitionKind::METHOD; + } + auto *method = util::NodeAllocator::ForceSetParent( + allocator_, methodKind, funcDecl->Function()->Id(), funcExpr, funcDecl->Function()->Modifiers(), allocator_, + false); + method->SetRange(funcDecl->Range()); + result_.classProperties.emplace_back(method); +} + +void GlobalDeclTransformer::VisitVariableDeclaration(ir::VariableDeclaration *varDecl) +{ + for (auto declarator : varDecl->Declarators()) { + auto id = declarator->Id()->AsIdentifier(); + auto typeAnn = id->TypeAnnotation(); + id->SetTsTypeAnnotation(nullptr); + auto *field = util::NodeAllocator::ForceSetParent( + allocator_, id, declarator->Init(), typeAnn, varDecl->Modifiers(), allocator_, false); + field->SetRange(declarator->Range()); + result_.classProperties.emplace_back(field); + if (auto stmt = InitTopLevelProperty(field); stmt != nullptr) { + result_.initStatements.emplace_back(stmt); + } + } +} + +ir::Identifier *GlobalDeclTransformer::RefIdent(const util::StringView &name) +{ + auto *const callee = util::NodeAllocator::Alloc(allocator_, name, allocator_); + callee->SetReference(); + return callee; +} + +ir::ExpressionStatement *GlobalDeclTransformer::InitTopLevelProperty(ir::ClassProperty *classProperty) +{ + ir::ExpressionStatement *initStmt = nullptr; + const auto initializer = classProperty->Value(); + if (!isPackage_ && !classProperty->IsConst() && initializer != nullptr && + !initializer->IsArrowFunctionExpression()) { + auto *ident = RefIdent(classProperty->Id()->Name()); + ident->SetRange(classProperty->Id()->Range()); + + initializer->SetParent(nullptr); + auto *assignmentExpression = util::NodeAllocator::Alloc( + allocator_, ident, initializer, lexer::TokenType::PUNCTUATOR_SUBSTITUTION); + assignmentExpression->SetRange({ident->Start(), initializer->End()}); + + auto expressionStatement = + util::NodeAllocator::Alloc(allocator_, assignmentExpression); + expressionStatement->SetRange(classProperty->Range()); + + classProperty->SetRange({ident->Start(), initializer->End()}); + + if (classProperty->TypeAnnotation() != nullptr && !classProperty->TypeAnnotation()->IsETSFunctionType()) { + classProperty->SetValue(nullptr); + } else { + initializer->SetParent(classProperty); + } + initStmt = expressionStatement; + } else { + classProperty->SetStart(classProperty->Id()->Start()); + } + return initStmt; +} + +void GlobalDeclTransformer::HandleNode(ir::AstNode *node) +{ + ASSERT(node->IsStatement()); + if (typeDecl_.count(node->Type()) == 0U) { + ASSERT(!propertiesDecl_.count(node->Type())); + result_.initStatements.emplace_back(node->AsStatement()); + } +} + +} // namespace panda::es2panda::compiler \ No newline at end of file diff --git a/ets2panda/compiler/lowering/ets/topLevelStmts/globalDeclTransformer.h b/ets2panda/compiler/lowering/ets/topLevelStmts/globalDeclTransformer.h new file mode 100644 index 0000000000..58d61110ef --- /dev/null +++ b/ets2panda/compiler/lowering/ets/topLevelStmts/globalDeclTransformer.h @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2021 - 2023 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. + */ + +#ifndef PANDA_GLOBALDECLTRANSFORMER_H +#define PANDA_GLOBALDECLTRANSFORMER_H + +#include "util/helpers.h" +#include "compiler/lowering/phase.h" +#include "ir/visitor/IterateAstVisitor.h" + +namespace panda::es2panda::compiler { + +class GlobalDeclTransformer : public ir::visitor::CustomAstVisitor { + const std::unordered_set typeDecl_ = { + ir::AstNodeType::CLASS_DECLARATION, ir::AstNodeType::STRUCT_DECLARATION, + ir::AstNodeType::TS_ENUM_DECLARATION, ir::AstNodeType::TS_INTERFACE_DECLARATION, + ir::AstNodeType::ETS_PACKAGE_DECLARATION, ir::AstNodeType::ETS_IMPORT_DECLARATION, + ir::AstNodeType::TS_TYPE_ALIAS_DECLARATION, ir::AstNodeType::EXPORT_ALL_DECLARATION, + ir::AstNodeType::EXPORT_NAMED_DECLARATION, ir::AstNodeType::REEXPORT_STATEMENT, + }; + + const std::unordered_set propertiesDecl_ = { + ir::AstNodeType::FUNCTION_DECLARATION, + ir::AstNodeType::VARIABLE_DECLARATION, + }; + +public: + struct ResultT { + explicit ResultT(ArenaAllocator *alloc) : classProperties(alloc->Adapter()), initStatements(alloc->Adapter()) {} + + // NOLINTNEXTLINE(misc-non-private-member-variables-in-classes) + ArenaVector classProperties; + // NOLINTNEXTLINE(misc-non-private-member-variables-in-classes) + ArenaVector initStatements; + }; + + explicit GlobalDeclTransformer(ArenaAllocator *allocator) : allocator_(allocator), result_(allocator) {} + + /** + * Removes top level statements, global variable declarations, global function declarations + * @param stmts + */ + void FilterDeclarations(ArenaVector &stmts); + + /** + * Creates ClassProperty for global variables and MethodFunction for global functions. + * Copy top level statements to vector. + * @param stmts top level statements + * @param is_package if current file is package. In package $init$ doesn't contain global variable initializers + * @return pair (class properties, init statements) + */ + ResultT TransformStatements(const ArenaVector &stmts, bool isPackage); + + void VisitFunctionDeclaration(ir::FunctionDeclaration *funcDecl) override; + void VisitVariableDeclaration(ir::VariableDeclaration *varDecl) override; + void HandleNode(ir::AstNode *node) override; + + ir::Identifier *RefIdent(const util::StringView &name); + + ir::ExpressionStatement *InitTopLevelProperty(ir::ClassProperty *classProperty); + +private: + ArenaAllocator *allocator_; + ResultT result_; + bool isPackage_ = false; +}; + +} // namespace panda::es2panda::compiler +#endif // PANDA_GLOBALDECLTRANSFORMER_H diff --git a/ets2panda/compiler/lowering/ets/topLevelStmts/importExportDecls.cpp b/ets2panda/compiler/lowering/ets/topLevelStmts/importExportDecls.cpp new file mode 100644 index 0000000000..073a956387 --- /dev/null +++ b/ets2panda/compiler/lowering/ets/topLevelStmts/importExportDecls.cpp @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2021 - 2023 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. + */ + +#include "compiler/lowering/ets/topLevelStmts/importExportDecls.h" +#include "ir/ets/etsReExportDeclaration.h" + +namespace panda::es2panda::compiler { + +void ImportExportDecls::ParseDefaultSources() +{ + auto imports = parser_->ParseDefaultSources(DEFAULT_IMPORT_SOURCE_FILE, defaultImportSource_, + util::ImportPathResolver::StdLib()); + varbinder_->SetDefaultImports(std::move(imports)); +} + +void ImportExportDecls::HandleGlobalStmts(const ArenaVector &programs) +{ + VerifySingleExportDefault(programs); + for (const auto &program : programs) { + auto errorHandler = util::ErrorHandler(program); + fieldMap_.clear(); + exportNameMap_.clear(); + for (auto stmt : program->Ast()->Statements()) { + stmt->Accept(this); + } + for (auto &[exportName, startLoc] : exportNameMap_) { + if (fieldMap_.count(exportName) == 0) { + auto errorStr = "Cannot find name '" + std::string(exportName.Utf8()) + "' to export."; + errorHandler.ThrowSyntaxError(errorStr, startLoc); + } + auto field = fieldMap_[exportName]; + field->AddModifier(ir::ModifierFlags::EXPORT); + } + } +} + +void ImportExportDecls::VisitFunctionDeclaration(ir::FunctionDeclaration *funcDecl) +{ + auto id = funcDecl->Function()->Id(); + fieldMap_.emplace(id->Name(), funcDecl->Function()); +} + +void ImportExportDecls::VisitVariableDeclaration(ir::VariableDeclaration *varDecl) +{ + for (const auto &decl : varDecl->Declarators()) { + auto id = decl->Id()->AsIdentifier(); + fieldMap_.emplace(id->Name(), varDecl); + } +} + +void ImportExportDecls::VisitExportNamedDeclaration(ir::ExportNamedDeclaration *exportDecl) +{ + for (auto spec : exportDecl->Specifiers()) { + auto local = spec->Local(); + exportNameMap_.emplace(local->Name(), local->Start()); + } +} + +void ImportExportDecls::VerifySingleExportDefault(const ArenaVector &programs) +{ + bool metDefaultExport = false; + auto verifyDefault = [&metDefaultExport](ir::Statement *stmt, parser::Program *program) { + if ((stmt->Modifiers() & ir::ModifierFlags::DEFAULT_EXPORT) == 0) { + return; + } + if (metDefaultExport) { + util::ErrorHandler::ThrowSyntaxError(program, "Only one default export is allowed in a module", + stmt->Start()); + } + metDefaultExport = true; + }; + for (const auto &program : programs) { + for (auto stmt : program->Ast()->Statements()) { + verifyDefault(stmt, program); + } + metDefaultExport = false; + } +} + +} // namespace panda::es2panda::compiler diff --git a/ets2panda/compiler/lowering/ets/topLevelStmts/importExportDecls.h b/ets2panda/compiler/lowering/ets/topLevelStmts/importExportDecls.h new file mode 100644 index 0000000000..80f8a83d53 --- /dev/null +++ b/ets2panda/compiler/lowering/ets/topLevelStmts/importExportDecls.h @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2021 - 2023 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. + */ + +#ifndef PANDA_IMPORTEXPORTDECLS_H +#define PANDA_IMPORTEXPORTDECLS_H + +#include "util/error_handler.h" +#include +#include "varbinder/ETSBinder.h" +#include "compiler/lowering/phase.h" +#include "ir/visitor/IterateAstVisitor.h" +#include "globalClassHandler.h" + +namespace panda::es2panda::compiler { + +class ImportExportDecls : ir::visitor::EmptyAstVisitor { + static constexpr std::string_view DEFAULT_IMPORT_SOURCE_FILE = ".ets"; + + static std::string CreateDefaultImportSource(const std::vector &paths) + { + std::string importStdlibFile; + for (const auto &path : paths) { + importStdlibFile += "import * from \"" + path + "\";"; + } + return importStdlibFile; + } + + const std::string defaultImportSource_ = CreateDefaultImportSource(util::ImportPathResolver::StdLib()); + +public: + ImportExportDecls() = default; + ImportExportDecls(varbinder::ETSBinder *varbinder, parser::ETSParser *parser) + : varbinder_(varbinder), parser_(parser) + { + } + + /** + * Add stdlib names to default imports + */ + void ParseDefaultSources(); + + /** + * Verifies import errors, and add Exported flag to top level variables and methods + * @param global_stmts program global statements + */ + void HandleGlobalStmts(const ArenaVector &programs); + + void VerifySingleExportDefault(const ArenaVector &programs); + +private: + void VisitFunctionDeclaration(ir::FunctionDeclaration *funcDecl) override; + void VisitVariableDeclaration(ir::VariableDeclaration *varDecl) override; + void VisitExportNamedDeclaration(ir::ExportNamedDeclaration *exportDecl) override; + +private: + varbinder::ETSBinder *varbinder_ {nullptr}; + std::map fieldMap_; + std::map exportNameMap_; + parser::ETSParser *parser_ {nullptr}; +}; +} // namespace panda::es2panda::compiler + +#endif // PANDA_IMPORTEXPORTDECLS_H diff --git a/ets2panda/compiler/lowering/ets/topLevelStmts/topLevelStmts.cpp b/ets2panda/compiler/lowering/ets/topLevelStmts/topLevelStmts.cpp new file mode 100644 index 0000000000..c654952b56 --- /dev/null +++ b/ets2panda/compiler/lowering/ets/topLevelStmts/topLevelStmts.cpp @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2021 - 2023 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. + */ + +#include "compiler/lowering/ets/topLevelStmts/topLevelStmts.h" + +#include "compiler/lowering/ets/topLevelStmts/globalClassHandler.h" + +namespace panda::es2panda::compiler { + +bool TopLevelStatements::Perform(public_lib::Context *ctx, parser::Program *program) +{ + GlobalClassHandler globalClass(program->Allocator()); + auto imports = ImportExportDecls(program->VarBinder()->AsETSBinder(), ctx->parser->AsETSParser()); + imports.ParseDefaultSources(); + auto extSrcs = program->ExternalSources(); + for (auto &[_, ext_programs] : extSrcs) { + (void)_; + imports.HandleGlobalStmts(ext_programs); + globalClass.InitGlobalClass(ext_programs); + } + ArenaVector mainModule(program->Allocator()->Adapter()); + mainModule.emplace_back(program); + imports.HandleGlobalStmts(mainModule); + globalClass.InitGlobalClass(mainModule); + return true; +} + +} // namespace panda::es2panda::compiler \ No newline at end of file diff --git a/ets2panda/compiler/lowering/ets/topLevelStmts/topLevelStmts.h b/ets2panda/compiler/lowering/ets/topLevelStmts/topLevelStmts.h new file mode 100644 index 0000000000..6a21e9ab87 --- /dev/null +++ b/ets2panda/compiler/lowering/ets/topLevelStmts/topLevelStmts.h @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2021 - 2023 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. + */ + +#ifndef ES2PANDA_COMPILER_LOWERING_INITMETHOD_H +#define ES2PANDA_COMPILER_LOWERING_INITMETHOD_H + +#include "compiler/lowering/phase.h" +#include "util/helpers.h" +#include "parser/program/program.h" +#include "compiler/lowering/ets/topLevelStmts/globalDeclTransformer.h" +#include "compiler/lowering/ets/topLevelStmts/importExportDecls.h" + +namespace panda::es2panda::compiler { + +/** + * Purpose of this lowering to: + * Create _$init$_ method + * Add all top level statements to _$init$_ + * Add call of _$init$_ to ETSGLOBAL CCTOR + * Handle imports/exports (re_exports, add stdlib, check existance of named exports) + * + * Expected to be called before ScopesInitPhase + */ +class TopLevelStatements : public Phase { +public: + std::string_view Name() override + { + return "TopLevelStatements"; + } + + bool Perform(public_lib::Context *ctx, parser::Program *program) override; + +private: +}; + +} // namespace panda::es2panda::compiler +#endif \ No newline at end of file diff --git a/ets2panda/compiler/lowering/phase.cpp b/ets2panda/compiler/lowering/phase.cpp index a247eb1ac4..c1e8c5306e 100644 --- a/ets2panda/compiler/lowering/phase.cpp +++ b/ets2panda/compiler/lowering/phase.cpp @@ -24,6 +24,7 @@ #include "compiler/lowering/plugin_phase.h" #include "compiler/lowering/scopesInit/scopesInitPhase.h" #include "compiler/lowering/ets/expandBrackets.h" +#include "compiler/lowering/ets/topLevelStmts/topLevelStmts.h" #include "compiler/lowering/ets/generateDeclarations.h" #include "compiler/lowering/ets/lambdaLowering.h" #include "compiler/lowering/ets/interfacePropertyDeclarations.h" @@ -58,6 +59,7 @@ static ExpandBracketsPhase g_expandBracketsPhase; static PromiseVoidInferencePhase g_promiseVoidInferencePhase; static StructLowering g_structLowering; static DefaultParameterLowering g_defaultParameterLowering; +static TopLevelStatements g_topLevelStatements; static PluginPhase g_pluginsAfterParse {"plugins-after-parse", ES2PANDA_STATE_PARSED, &util::Plugin::AfterParse}; static PluginPhase g_pluginsAfterCheck {"plugins-after-check", ES2PANDA_STATE_CHECKED, &util::Plugin::AfterCheck}; static PluginPhase g_pluginsAfterLowerings {"plugins-after-lowering", ES2PANDA_STATE_LOWERED, @@ -72,8 +74,9 @@ static InitScopesPhaseJs g_initScopesPhaseJs; std::vector GetETSPhaseList() { return { - &g_defaultParameterLowering, &g_pluginsAfterParse, + &g_topLevelStatements, + &g_defaultParameterLowering, &g_initScopesPhaseEts, &g_promiseVoidInferencePhase, &g_structLowering, diff --git a/ets2panda/compiler/lowering/scopesInit/scopesInitPhase.cpp b/ets2panda/compiler/lowering/scopesInit/scopesInitPhase.cpp index 8fc6292ab4..56eb2868ab 100644 --- a/ets2panda/compiler/lowering/scopesInit/scopesInitPhase.cpp +++ b/ets2panda/compiler/lowering/scopesInit/scopesInitPhase.cpp @@ -13,12 +13,14 @@ * limitations under the License. */ +#include "util/error_handler.h" #include "scopesInitPhase.h" namespace panda::es2panda::compiler { bool ScopesInitPhase::Perform(PhaseContext *ctx, parser::Program *program) { Prepare(ctx, program); + program->VarBinder()->InitTopScope(); HandleBlockStmt(program->Ast(), GetScope()); Finalize(); return true; @@ -320,10 +322,7 @@ void ScopesInitPhase::IterateNoTParams(ir::ClassDefinition *classDef) void ScopesInitPhase::ThrowSyntaxError(std::string_view errorMessage, const lexer::SourcePosition &pos) const { - lexer::LineIndex index(program_->SourceCode()); - lexer::SourceLocation loc = index.GetLocation(pos); - - throw Error {ErrorType::SYNTAX, program_->SourceFilePath().Utf8(), errorMessage, loc.line, loc.col}; + util::ErrorHandler::ThrowSyntaxError(Program(), errorMessage, pos); } void ScopesInitPhase::CreateFuncDecl(ir::ScriptFunction *func) @@ -794,6 +793,14 @@ void InitScopesPhaseETS::DeclareClassMethod(ir::MethodDefinition *method) } } +void InitScopesPhaseETS::VisitETSReExportDeclaration(ir::ETSReExportDeclaration *reExport) +{ + if (reExport->GetETSImportDeclarations()->Language().IsDynamic()) { + VarBinder()->AsETSBinder()->AddDynamicImport(reExport->GetETSImportDeclarations()); + } + VarBinder()->AsETSBinder()->AddReExportImport(reExport); +} + void InitScopesPhaseETS::VisitETSParameterExpression(ir::ETSParameterExpression *paramExpr) { auto *const var = std::get<1>(VarBinder()->AddParamDecl(paramExpr)); diff --git a/ets2panda/compiler/lowering/scopesInit/scopesInitPhase.h b/ets2panda/compiler/lowering/scopesInit/scopesInitPhase.h index cd0f14acd3..a0c467546b 100644 --- a/ets2panda/compiler/lowering/scopesInit/scopesInitPhase.h +++ b/ets2panda/compiler/lowering/scopesInit/scopesInitPhase.h @@ -131,6 +131,11 @@ protected: return program_; } + const parser::Program *Program() const + { + return program_; + } + PhaseContext *Context() { return ctx_; @@ -331,6 +336,7 @@ private: void VisitImportNamespaceSpecifier(ir::ImportNamespaceSpecifier *importSpec) override; void VisitImportSpecifier([[maybe_unused]] ir::ImportSpecifier *importSpec) override {}; void VisitImportDefaultSpecifier([[maybe_unused]] ir::ImportDefaultSpecifier *importSpec) override {}; + void VisitETSReExportDeclaration(ir::ETSReExportDeclaration *reExport) override; void VisitETSParameterExpression(ir::ETSParameterExpression *paramExpr) override; void VisitETSImportDeclaration(ir::ETSImportDeclaration *importDecl) override; void VisitTSEnumMember(ir::TSEnumMember *enumMember) override; diff --git a/ets2panda/ir/astNodeMapping.h b/ets2panda/ir/astNodeMapping.h index 94ad053988..652e7fed7a 100644 --- a/ets2panda/ir/astNodeMapping.h +++ b/ets2panda/ir/astNodeMapping.h @@ -72,6 +72,7 @@ _(PREFIX_ASSERTION_EXPRESSION, PrefixAssertionExpression) \ _(PROPERTY, Property) \ _(REGEXP_LITERAL, RegExpLiteral) \ + _(REEXPORT_STATEMENT, ETSReExportDeclaration) \ _(RETURN_STATEMENT, ReturnStatement) \ _(SCRIPT_FUNCTION, ScriptFunction) \ _(SEQUENCE_EXPRESSION, SequenceExpression) \ diff --git a/ets2panda/ir/base/classElement.cpp b/ets2panda/ir/base/classElement.cpp index 62b0ebb100..bcf983816e 100644 --- a/ets2panda/ir/base/classElement.cpp +++ b/ets2panda/ir/base/classElement.cpp @@ -20,6 +20,14 @@ namespace panda::es2panda::ir { +void ClassElement::SetValue(Expression *value) noexcept +{ + if (value != nullptr) { + value->SetParent(this); + } + value_ = value; +} + Identifier *ClassElement::Id() noexcept { return key_->IsIdentifier() ? key_->AsIdentifier() : nullptr; diff --git a/ets2panda/ir/base/classElement.h b/ets2panda/ir/base/classElement.h index b937cbf84e..ab2771fcf4 100644 --- a/ets2panda/ir/base/classElement.h +++ b/ets2panda/ir/base/classElement.h @@ -58,6 +58,8 @@ public: return value_; } + void SetValue(Expression *value) noexcept; + [[nodiscard]] const Expression *Value() const noexcept { return value_; diff --git a/ets2panda/ir/ets/etsReExportDeclaration.cpp b/ets2panda/ir/ets/etsReExportDeclaration.cpp new file mode 100644 index 0000000000..a085ad9827 --- /dev/null +++ b/ets2panda/ir/ets/etsReExportDeclaration.cpp @@ -0,0 +1,51 @@ +/** + * Copyright (c) 2023 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. + */ + +#include "ir/ets/etsReExportDeclaration.h" +#include "ir/astDump.h" + +namespace panda::es2panda::ir { + +ETSReExportDeclaration::ETSReExportDeclaration(ETSImportDeclaration *etsImportDeclarations, + const std::vector &userPaths, util::StringView programPath, + ArenaAllocator *allocator) + : Statement(AstNodeType::REEXPORT_STATEMENT), + etsImportDeclarations_(etsImportDeclarations), + userPaths_(allocator->Adapter()), + programPath_(programPath) +{ + for (const auto &path : userPaths) { + userPaths_.emplace_back(util::UString(path, allocator).View()); + } +} + +void ETSReExportDeclaration::TransformChildren(const NodeTransformer &cb) +{ + if (etsImportDeclarations_ != nullptr) { + etsImportDeclarations_ = cb(etsImportDeclarations_)->AsETSImportDeclaration(); + } +} + +void ETSReExportDeclaration::Iterate(const NodeTraverser &cb) const +{ + etsImportDeclarations_->Iterate(cb); +} + +void ETSReExportDeclaration::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "ETSReExportDeclaration"}, {"ets_import_declarations", etsImportDeclarations_}}); +} + +} // namespace panda::es2panda::ir diff --git a/ets2panda/ir/ets/etsReExportDeclaration.h b/ets2panda/ir/ets/etsReExportDeclaration.h index cc56e21a8d..e12e244ee4 100644 --- a/ets2panda/ir/ets/etsReExportDeclaration.h +++ b/ets2panda/ir/ets/etsReExportDeclaration.h @@ -23,17 +23,11 @@ namespace panda::es2panda::ir { -class ETSReExportDeclaration { +class ETSReExportDeclaration : public Statement { public: - explicit ETSReExportDeclaration(ETSImportDeclaration *const etsImportDeclarations, - std::vector const &userPaths, util::StringView programPath, - ArenaAllocator *allocator) - : etsImportDeclarations_(etsImportDeclarations), userPaths_(allocator->Adapter()), programPath_(programPath) - { - for (const auto &path : userPaths) { - userPaths_.emplace_back(util::UString(path, allocator).View()); - } - } + explicit ETSReExportDeclaration(ETSImportDeclaration *etsImportDeclarations, + const std::vector &userPaths, util::StringView programPath, + ArenaAllocator *allocator); ETSImportDeclaration *GetETSImportDeclarations() const { @@ -55,6 +49,32 @@ public: return programPath_; } + void TransformChildren(const NodeTransformer &cb) override; + + void Iterate(const NodeTraverser &cb) const override; + + void Dump(ir::AstDumper *dumper) const override; + void Dump([[maybe_unused]] ir::SrcDumper *dumper) const override {}; + + void Compile(compiler::PandaGen * /*pg*/) const override {} + + void Compile(compiler::ETSGen * /*gen*/) const override {} + + checker::Type *Check(checker::TSChecker * /*checker*/) override + { + return nullptr; + } + + checker::Type *Check(checker::ETSChecker * /*checker*/) override + { + return nullptr; + } + + void Accept(ASTVisitorT *v) override + { + v->Accept(this); + } + private: ETSImportDeclaration *etsImportDeclarations_; ArenaVector userPaths_; diff --git a/ets2panda/ir/visitor/IterateAstVisitor.h b/ets2panda/ir/visitor/IterateAstVisitor.h index a6aad93b01..d259b3d168 100644 --- a/ets2panda/ir/visitor/IterateAstVisitor.h +++ b/ets2panda/ir/visitor/IterateAstVisitor.h @@ -21,20 +21,56 @@ #include "ir/expressions/blockExpression.h" #include "ir/ets/etsUnionType.h" #include "ir/ets/etsTuple.h" +#include "ir/statements/functionDeclaration.h" +#include "ir/expressions/functionExpression.h" +#include "ir/base/scriptFunction.h" +#include "ir/base/methodDefinition.h" +#include "ir/base/classProperty.h" +#include "ir/expressions/identifier.h" +#include "ir/statements/variableDeclaration.h" +#include "ir/statements/variableDeclarator.h" namespace panda::es2panda::ir::visitor { +namespace detail { +class DefaultBehaviourAstVisitor : public ASTAbstractVisitor { +public: + DefaultBehaviourAstVisitor() = default; + virtual ~DefaultBehaviourAstVisitor() = 0; + NO_COPY_SEMANTIC(DefaultBehaviourAstVisitor); + NO_MOVE_SEMANTIC(DefaultBehaviourAstVisitor); + + virtual void HandleNode(ir::AstNode *node) = 0; + +// NOLINTNEXTLINE(cppcoreguidelines-macro-usage) +#define DECLARE_CLASSES(nodeType, className) \ + void Visit##className(className *node) override \ + { \ + HandleNode(static_cast(node)); \ + } + + AST_NODE_MAPPING(DECLARE_CLASSES) + +// NOLINTNEXTLINE(cppcoreguidelines-macro-usage) +#define DECLARE_AST_NODE_CHECK_METHOD(nodeType1, nodeType2, baseClass, reinterpretClass) \ + DECLARE_CLASSES(nodeType1, baseClass); + + AST_NODE_REINTERPRET_MAPPING(DECLARE_AST_NODE_CHECK_METHOD) +#undef DECLARE_AST_NODE_CHECK_METHOD + +#undef DECLARE_CLASSES +}; +inline DefaultBehaviourAstVisitor::~DefaultBehaviourAstVisitor() = default; +} // namespace detail + /** * Children should declare VisitNode methods (might be virtual might be not) * for all classes or provide default behaviour using * template VisitNode(T *t) {} */ -class IterateAstVisitor : public ASTAbstractVisitor { +class IterateAstVisitor : public detail::DefaultBehaviourAstVisitor { public: IterateAstVisitor() = default; - virtual ~IterateAstVisitor() = 0; - NO_COPY_SEMANTIC(IterateAstVisitor); - NO_MOVE_SEMANTIC(IterateAstVisitor); void Iterate(ir::AstNode *node) { @@ -43,25 +79,30 @@ public: } } -// NOLINTNEXTLINE(cppcoreguidelines-macro-usage) -#define DECLARE_CLASSES(nodeType, className) \ - void Visit##className(className *node) override \ - { \ - Iterate(static_cast(node)); \ + void HandleNode(ir::AstNode *node) final + { + Iterate(node); } +}; - AST_NODE_MAPPING(DECLARE_CLASSES) +class EmptyAstVisitor : public detail::DefaultBehaviourAstVisitor { +public: + EmptyAstVisitor() = default; -// NOLINTNEXTLINE(cppcoreguidelines-macro-usage) -#define DECLARE_AST_NODE_CHECK_METHOD(nodeType1, nodeType2, baseClass, reinterpretClass) \ - DECLARE_CLASSES(nodeType1, baseClass); + void HandleNode(ir::AstNode * /*node*/) final {} +}; - AST_NODE_REINTERPRET_MAPPING(DECLARE_AST_NODE_CHECK_METHOD) -#undef DECLARE_AST_NODE_CHECK_METHOD +class AbortAstVisitor : public detail::DefaultBehaviourAstVisitor { +public: + AbortAstVisitor() = default; -#undef DECLARE_CLASSES + void HandleNode(ir::AstNode * /*node*/) final + { + UNREACHABLE(); + } }; -inline IterateAstVisitor::~IterateAstVisitor() = default; + +using CustomAstVisitor = detail::DefaultBehaviourAstVisitor; } // namespace panda::es2panda::ir::visitor diff --git a/ets2panda/lexer/lexer.h b/ets2panda/lexer/lexer.h index 77e28f6b10..9824cbb151 100644 --- a/ets2panda/lexer/lexer.h +++ b/ets2panda/lexer/lexer.h @@ -114,6 +114,26 @@ public: const Token &GetToken() const; size_t Line() const; + bool TryEatTokenType(lexer::TokenType type) + { + auto token = GetToken(); + if (token.Type() == type) { + NextToken(); + return true; + } + return false; + } + + std::optional TryEatTokenKeyword(lexer::TokenType type) + { + auto token = GetToken(); + if (token.KeywordType() == type) { + NextToken(); + return token; + } + return std::nullopt; + } + LexerPosition Save() const; void Rewind(const LexerPosition &pos); void BackwardToken(TokenType type, size_t offset); diff --git a/ets2panda/parser/ETSparser.cpp b/ets2panda/parser/ETSparser.cpp index b53a0b37bd..fb20adabb9 100644 --- a/ets2panda/parser/ETSparser.cpp +++ b/ets2panda/parser/ETSparser.cpp @@ -67,6 +67,8 @@ #include "ir/module/importDeclaration.h" #include "ir/module/importDefaultSpecifier.h" #include "ir/module/importSpecifier.h" +#include "ir/module/exportSpecifier.h" +#include "ir/module/exportNamedDeclaration.h" #include "ir/statements/assertStatement.h" #include "ir/statements/blockStatement.h" #include "ir/statements/emptyStatement.h" @@ -122,24 +124,6 @@ #include "libpandabase/os/file.h" #include "generated/signatures.h" -#if defined PANDA_TARGET_MOBILE -#define USE_UNIX_SYSCALL -#endif - -#ifdef USE_UNIX_SYSCALL -#include -#include -#include -#else -#if __has_include() -#include -namespace fs = std::filesystem; -#elif __has_include() -#include -namespace fs = std::experimental::filesystem; -#endif -#endif - namespace panda::es2panda::parser { using namespace std::literals::string_literals; @@ -161,900 +145,233 @@ void ETSParser::ParseProgram(ScriptKind kind) // NOTE(user): handle multiple sourceFiles } - auto statements = PrepareGlobalClass(); - ParseDefaultSources(); - - ParseETSGlobalScript(startLoc, statements); -} - -void ETSParser::ParseETSGlobalScript(lexer::SourcePosition startLoc, ArenaVector &statements) -{ - auto paths = ParseImportDeclarations(statements); - - // clang-format off - auto removeParsedSources = [this](std::vector &items) { - items.erase(remove_if(begin(items), end(items), - [this](auto x) { - auto resolved = ResolveImportPath(x); - auto pathIter = - std::find_if(resolvedParsedSources_.begin(), resolvedParsedSources_.end(), - [resolved](const auto &p) { return p.second == resolved; }); - auto found = pathIter != resolvedParsedSources_.end(); - if (found) { - resolvedParsedSources_.emplace(x, resolved); - } - return found; - }), - end(items)); - - for (const auto &item : items) { - auto resolved = ResolveImportPath(item); - resolvedParsedSources_.emplace(item, resolved); - } - }; - // clang-format on - - removeParsedSources(paths); - - ParseSources(paths, false); - - if (!GetProgram()->VarBinder()->AsETSBinder()->ReExportImports().empty()) { - std::vector reExportPaths; - - for (auto reExport : GetProgram()->VarBinder()->AsETSBinder()->ReExportImports()) { - if (std::find(paths.begin(), paths.end(), reExport->GetProgramPath().Mutf8()) != paths.end()) { - auto path = - reExport->GetProgramPath().Mutf8().substr(0, reExport->GetProgramPath().Mutf8().find_last_of('/')); - for (auto item : reExport->GetUserPaths()) { - reExportPaths.push_back( - path + "/" + item.Mutf8().substr(item.Mutf8().find_first_of('/') + 1, item.Mutf8().length())); - } - } - } - - removeParsedSources(reExportPaths); - - ParseSources(reExportPaths, false); - } - - ParseTopLevelDeclaration(statements); - - auto *etsScript = AllocNode(Allocator(), std::move(statements), GetProgram()); - etsScript->SetRange({startLoc, Lexer()->GetToken().End()}); - GetProgram()->SetAst(etsScript); -} - -void ETSParser::CreateGlobalClass() -{ - auto *ident = AllocNode(compiler::Signatures::ETS_GLOBAL, Allocator()); - - auto *classDef = AllocNode(Allocator(), ident, ir::ClassDefinitionModifiers::GLOBAL, - ir::ModifierFlags::ABSTRACT, Language(Language::Id::ETS)); - GetProgram()->SetGlobalClass(classDef); - - [[maybe_unused]] auto *classDecl = AllocNode(classDef, Allocator()); -} - -ArenaVector ETSParser::PrepareGlobalClass() -{ ArenaVector statements(Allocator()->Adapter()); - ParsePackageDeclaration(statements); - CreateGlobalClass(); - - return statements; -} - -ArenaVector ETSParser::PrepareExternalGlobalClass([[maybe_unused]] const SourceFile &sourceFile) -{ - ArenaVector statements(Allocator()->Adapter()); - ParsePackageDeclaration(statements); - - if (statements.empty()) { - GetProgram()->SetGlobalClass(globalProgram_->GlobalClass()); - } - - auto &extSources = globalProgram_->ExternalSources(); - const util::StringView name = GetProgram()->SourceFileFolder(); - - auto res = extSources.end(); - if (!statements.empty()) { - res = extSources.find(name); - } else { - auto path = GetProgram()->SourceFileFolder().Mutf8() + panda::os::file::File::GetPathDelim().at(0) + - GetProgram()->GetPackageName().Mutf8(); - auto resolved = ResolveImportPath(path); - resolvedParsedSources_.emplace(path, resolved); - GetProgram()->SetSource(GetProgram()->SourceCode(), GetProgram()->SourceFilePath(), - util::UString(resolved, Allocator()).View()); - } - - if (res == extSources.end()) { - CreateGlobalClass(); - auto insRes = extSources.emplace(GetProgram()->SourceFileFolder(), Allocator()->Adapter()); - insRes.first->second.push_back(GetProgram()); - } else { - res->second.push_back(GetProgram()); - auto *extProg = res->second.front(); - GetProgram()->SetGlobalClass(extProg->GlobalClass()); - // NOTE(user): check nullptr cases and handle recursive imports - } - - return statements; -} - -static bool IsCompitableExtension(const std::string &extension) -{ - return extension == ".ets" || extension == ".ts"; -} - -std::vector ETSParser::UnixApiDefaultSources([[maybe_unused]] const std::vector &stdlib) -{ - std::vector paths; -#ifdef USE_UNIX_SYSCALL - for (auto const &path : stdlib) { - auto resolvedPath = ResolveImportPath(path); - DIR *dir = opendir(resolvedPath.c_str()); - - if (dir == nullptr) { - ThrowSyntaxError({"Cannot open folder: ", resolvedPath}); - } - - struct dirent *entry; - std::set orderedFiles; - while ((entry = readdir(dir)) != nullptr) { - if (entry->d_type != DT_REG) { - continue; - } - - std::string fileName = entry->d_name; - std::string::size_type pos = fileName.find_last_of('.'); - if (pos == std::string::npos || !IsCompitableExtension(fileName.substr(pos))) { - continue; - } - - std::string filePath = path + "/" + entry->d_name; - - if (fileName == "Object.ets") { - paths.emplace(paths.begin(), filePath); - } else { - orderedFiles.emplace(filePath); - } - } - paths.insert(paths.end(), orderedFiles.begin(), orderedFiles.end()); - closedir(dir); - } -#endif - return paths; -} - -std::vector ETSParser::CollectDefaultSources() -{ - std::vector stdlib = {"std/core", "std/math", "std/containers", - "std/time", "std/interop/js", "escompat"}; - -#ifdef USE_UNIX_SYSCALL - return UnixApiDefaultSources(stdlib); -#else - std::vector paths; - for (auto const &path : stdlib) { - std::set orderedFiles; - for (auto const &entry : fs::directory_iterator(ResolveImportPath(path))) { - if (!fs::is_regular_file(entry) || !IsCompitableExtension(entry.path().extension().string())) { - continue; - } - - std::string baseName = path; - std::size_t pos = entry.path().string().find_last_of(panda::os::file::File::GetPathDelim()); - - baseName.append(entry.path().string().substr(pos, entry.path().string().size())); - - if (entry.path().filename().string() == "Object.ets") { - paths.emplace(paths.begin(), baseName); - } else { - orderedFiles.emplace(baseName); - } - } - paths.insert(paths.end(), orderedFiles.begin(), orderedFiles.end()); - } - return paths; -#endif -} - -ETSParser::ImportData ETSParser::GetImportData(const std::string &path) -{ - auto &dynamicPaths = ArkTSConfig()->DynamicPaths(); - auto key = panda::os::NormalizePath(path); - - auto it = dynamicPaths.find(key); - if (it == dynamicPaths.cend()) { - key = panda::os::RemoveExtension(key); - } - - while (it == dynamicPaths.cend() && !key.empty()) { - it = dynamicPaths.find(key); - if (it != dynamicPaths.cend()) { - break; - } - key = panda::os::GetParentDir(key); - } - - if (it != dynamicPaths.cend()) { - return {it->second.GetLanguage(), key, it->second.HasDecl()}; + auto decl = ParsePackageDeclaration(); + if (decl != nullptr) { + statements.emplace_back(decl); } - return {ToLanguage(Extension()), path, true}; + auto script = ParseETSGlobalScript(startLoc, statements); + GetProgram()->SetAst(script); } -std::string ETSParser::ResolveFullPathFromRelative(const std::string &path) +ir::ETSScript *ETSParser::ParseETSGlobalScript(lexer::SourcePosition startLoc, ArenaVector &statements) { - char pathDelimiter = panda::os::file::File::GetPathDelim().at(0); - auto resolvedFp = GetProgram()->ResolvedFilePath().Mutf8(); - auto sourceFp = GetProgram()->SourceFileFolder().Mutf8(); - if (resolvedFp.empty()) { - auto fp = sourceFp + pathDelimiter + path; - return util::Helpers::IsRealPath(fp) ? fp : path; - } - auto fp = resolvedFp + pathDelimiter + path; - if (util::Helpers::IsRealPath(fp)) { - return fp; - } - if (path.find(sourceFp) == 0) { - return resolvedFp + pathDelimiter + path.substr(sourceFp.size()); - } - return path; -} - -std::string ETSParser::ResolveImportPath(const std::string &path) -{ - char pathDelimiter = panda::os::file::File::GetPathDelim().at(0); - if (util::Helpers::IsRelativePath(path)) { - return util::Helpers::GetAbsPath(ResolveFullPathFromRelative(path)); - } - - std::string baseUrl; - // Resolve delimeter character to basePath. - if (path.find('/') == 0) { - baseUrl = ArkTSConfig()->BaseUrl(); + auto [imports, paths] = ParseImportDeclarations(); + pathResolver_.FilterParsedSources(paths, GetProgram()); + statements.insert(statements.end(), imports.begin(), imports.end()); - baseUrl.append(path, 0, path.length()); - return baseUrl; - } + AddExternalSource(ParseSources(paths)); - auto &dynamicPaths = ArkTSConfig()->DynamicPaths(); - auto it = dynamicPaths.find(path); - if (it != dynamicPaths.cend() && !it->second.HasDecl()) { - return path; + if (!reExports_.empty()) { + auto reExportPaths = pathResolver_.ReExportPaths(reExports_, paths); + pathResolver_.FilterParsedSources(reExportPaths, GetProgram()); + AddExternalSource(ParseSources(reExportPaths)); } - // Resolve the root part of the path. - // E.g. root part of std/math is std. - std::string::size_type pos = path.find('/'); - bool containsDelim = (pos != std::string::npos); - std::string rootPart = containsDelim ? path.substr(0, pos) : path; - - if (rootPart == "std" && !GetOptions().stdLib.empty()) { // Get std path from CLI if provided - baseUrl = GetOptions().stdLib + "/std"; - } else if (rootPart == "escompat" && !GetOptions().stdLib.empty()) { // Get escompat path from CLI if provided - baseUrl = GetOptions().stdLib + "/escompat"; - } else { - auto resolvedPath = ArkTSConfig()->ResolvePath(path); - if (resolvedPath.empty()) { - ThrowSyntaxError({"Can't find prefix for '", path, "' in ", ArkTSConfig()->ConfigPath()}); - } - return resolvedPath; - } + auto topLevelStatements = ParseTopLevelDeclaration(); - if (containsDelim) { - baseUrl.append(1, pathDelimiter); - baseUrl.append(path, rootPart.length() + 1, path.length()); - } - - return baseUrl; + statements.insert(statements.end(), topLevelStatements.begin(), topLevelStatements.end()); + auto *etsScript = AllocNode(Allocator(), std::move(statements), GetProgram()); + etsScript->SetRange({startLoc, Lexer()->GetToken().End()}); + return etsScript; } -std::tuple ETSParser::GetSourceRegularPath(const std::string &path, const std::string &resolvedPath) +void ETSParser::AddExternalSource(const std::vector &programs) { - if (!panda::os::file::File::IsRegularFile(resolvedPath)) { - std::string importExtension = ".ets"; + for (auto *newProg : programs) { + auto &extSources = globalProgram_->ExternalSources(); - if (!panda::os::file::File::IsRegularFile(resolvedPath + importExtension)) { - importExtension = ".ts"; - - if (!panda::os::file::File::IsRegularFile(resolvedPath + importExtension)) { - ThrowSyntaxError("Incorrect path: " + resolvedPath); + if (extSources.count(newProg->SourceFileFolder()) == 0) { + auto isDeclPackage = newProg->Ast()->Statements().front()->IsETSPackageDeclaration(); + if (!isDeclPackage) { + auto path = newProg->PackagePath(); + auto resolved = ValidatePathResolver(pathResolver_.ResolveImportPath(path, GetProgram())); + newProg->SetSource(newProg->SourceCode(), newProg->SourceFilePath(), + util::UString(resolved, Allocator()).View()); } + extSources.emplace(newProg->SourceFileFolder(), Allocator()->Adapter()); } - return {path + importExtension, true}; + extSources.at(newProg->SourceFileFolder()).emplace_back(newProg); } - return {path, false}; -} - -void ETSParser::CollectUserSourcesFromIndex([[maybe_unused]] const std::string &path, - [[maybe_unused]] const std::string &resolvedPath, - [[maybe_unused]] std::vector &userPaths) -{ -#ifdef USE_UNIX_SYSCALL - DIR *dir = opendir(resolvedPath.c_str()); - bool isIndex = false; - std::set tmpPaths; - - if (dir == nullptr) { - ThrowSyntaxError({"Cannot open folder: ", resolvedPath}); - } - - struct dirent *entry; - while ((entry = readdir(dir)) != nullptr) { - if (entry->d_type != DT_REG) { - continue; - } - - std::string fileName = entry->d_name; - std::string::size_type pos = fileName.find_last_of('.'); - if (pos == std::string::npos || !IsCompitableExtension(fileName.substr(pos))) { - continue; - } - - std::string filePath = path + "/" + entry->d_name; - - if (fileName == "index.ets" || fileName == "index.ts") { - userPaths.emplace_back(filePath); - isIndex = true; - break; - } else if (fileName == "Object.ets") { - userPaths.emplace(userPaths.begin(), filePath); - } else { - tmpPaths.insert(filePath); - } - } - - closedir(dir); - - if (!isIndex) { - userPaths.insert(userPaths.end(), tmpPaths.begin(), tmpPaths.end()); - } -#endif } std::tuple, bool> ETSParser::CollectUserSources(const std::string &path) { - std::vector userPaths; - - const std::string resolvedPath = ResolveImportPath(path); - resolvedParsedSources_.emplace(path, resolvedPath); - const auto data = GetImportData(resolvedPath); - - if (!data.hasDecl) { - return {userPaths, false}; - } - - if (!panda::os::file::File::IsDirectory(resolvedPath)) { - std::string regularPath; - bool isModule = false; - std::tie(regularPath, isModule) = GetSourceRegularPath(path, resolvedPath); - userPaths.emplace_back(regularPath); - return {userPaths, isModule}; - } - -#ifdef USE_UNIX_SYSCALL - CollectUserSourcesFromIndex(path, resolvedPath, userPaths); -#else - if (fs::exists(resolvedPath + "/index.ets")) { - userPaths.emplace_back(path + "/index.ets"); - } else if (fs::exists(resolvedPath + "/index.ts")) { - userPaths.emplace_back(path + "/index.ts"); - } else { - std::set orderedFiles; - for (auto const &entry : fs::directory_iterator(resolvedPath)) { - if (!fs::is_regular_file(entry) || !IsCompitableExtension(entry.path().extension().string())) { - continue; - } - - std::string baseName = path; - std::size_t pos = entry.path().string().find_last_of(panda::os::file::File::GetPathDelim()); - - baseName.append(entry.path().string().substr(pos, entry.path().string().size())); - orderedFiles.emplace(baseName); - } - userPaths.insert(userPaths.begin(), orderedFiles.begin(), orderedFiles.end()); - } -#endif - return {userPaths, false}; -} - -void ETSParser::ParseSources(const std::vector &paths, bool isExternal) -{ - GetContext().Status() |= isExternal ? ParserStatus::IN_EXTERNAL : ParserStatus::IN_IMPORT; - - const std::size_t pathCount = paths.size(); - for (std::size_t idx = 0; idx < pathCount; idx++) { - std::string resolvedPath = ResolveImportPath(paths[idx]); - resolvedParsedSources_.emplace(paths[idx], resolvedPath); - - const auto data = GetImportData(resolvedPath); - - if (!data.hasDecl) { - continue; - } - - std::ifstream inputStream(resolvedPath.c_str()); - - if (GetProgram()->SourceFilePath().Is(resolvedPath)) { - break; - } - - if (inputStream.fail()) { - ThrowSyntaxError({"Failed to open file: ", resolvedPath.c_str()}); - } - - std::stringstream ss; - ss << inputStream.rdbuf(); - auto externalSource = ss.str(); - - auto currentLang = GetContext().SetLanguage(data.lang); - ParseSource({paths[idx].c_str(), externalSource.c_str(), resolvedPath.c_str(), false}); - GetContext().SetLanguage(currentLang); - } - - GetContext().Status() &= isExternal ? ~ParserStatus::IN_EXTERNAL : ~ParserStatus::IN_IMPORT; + const std::string resolvedPath = ValidatePathResolver(pathResolver_.ResolveImportPath(path, GetProgram())); + auto resolved = ValidatePathResolver(pathResolver_.CollectUserSources(path, GetProgram())); + return {std::move(resolved.sources), resolved.isModule}; } -void ETSParser::ParseDefaultSources() +ArenaVector ETSParser::ParseDefaultSources(std::string_view srcFile, + std::string_view importSrc, + const std::vector &paths) { auto isp = InnerSourceParser(this); - SourceFile source(varbinder::ETSBinder::DEFAULT_IMPORT_SOURCE_FILE, varbinder::ETSBinder::DEFAULT_IMPORT_SOURCE); + SourceFile source(srcFile, importSrc); auto lexer = InitLexer(source); - ArenaVector statements(Allocator()->Adapter()); Lexer()->NextToken(); GetContext().Status() |= ParserStatus::IN_DEFAULT_IMPORTS; - - ParseImportDeclarations(statements); + auto [statements, real_paths] = ParseImportDeclarations(); GetContext().Status() &= ~ParserStatus::IN_DEFAULT_IMPORTS; - - ParseSources(CollectDefaultSources(), true); -} - -void ETSParser::ParseSource(const SourceFile &sourceFile) -{ - auto *program = Allocator()->New(Allocator(), GetProgram()->VarBinder()); - auto esp = ExternalSourceParser(this, program); - auto lexer = InitLexer(sourceFile); - - lexer::SourcePosition startLoc = Lexer()->GetToken().Start(); - Lexer()->NextToken(); - - auto statements = PrepareExternalGlobalClass(sourceFile); - ParseETSGlobalScript(startLoc, statements); -} - -ir::ScriptFunction *ETSParser::AddInitMethod(ArenaVector &globalProperties) -{ - if (GetProgram()->Kind() == ScriptKind::STDLIB) { - return nullptr; - } - - // Lambda to create empty function node with signature: func(): void - // NOTE: replace with normal createFunction call - auto const createFunction = - [this](std::string_view const functionName, ir::ScriptFunctionFlags functionFlags, - ir::ModifierFlags const functionModifiers) -> std::pair { - auto *initIdent = AllocNode(functionName, Allocator()); - ir::ScriptFunction *initFunc; - - { - ArenaVector params(Allocator()->Adapter()); - - ArenaVector statements(Allocator()->Adapter()); - auto *initBody = AllocNode(Allocator(), std::move(statements)); - - initFunc = AllocNode(ir::FunctionSignature(nullptr, std::move(params), nullptr), - initBody, functionFlags, false, GetContext().GetLanguge()); - } - - initFunc->SetIdent(initIdent); - initFunc->AddModifier(functionModifiers); - - auto *funcExpr = AllocNode(initFunc); - - auto *initMethod = AllocNode(ir::MethodDefinitionKind::METHOD, initIdent, funcExpr, - functionModifiers, Allocator(), false); - - return std::make_pair(initFunc, initMethod); - }; - - // Create public method for module re-initialization. The assignments and statements are sequentially called inside. - auto [init_func, init_method] = createFunction(compiler::Signatures::INIT_METHOD, ir::ScriptFunctionFlags::NONE, - ir::ModifierFlags::STATIC | ir::ModifierFlags::PUBLIC); - globalProperties.emplace_back(init_method); - - return init_func; -} - -void ETSParser::MarkNodeAsExported(ir::AstNode *node, lexer::SourcePosition startPos, bool defaultExport, - std::size_t numOfElements) -{ - ir::ModifierFlags flag = defaultExport ? ir::ModifierFlags::DEFAULT_EXPORT : ir::ModifierFlags::EXPORT; - - if (UNLIKELY(flag == ir::ModifierFlags::DEFAULT_EXPORT)) { - if (numOfElements > 1) { - ThrowSyntaxError("Only one default export is allowed in a module", startPos); - } - } - - node->AddModifier(flag); -} - -ArenaVector ETSParser::ParseTopLevelStatements(ArenaVector &statements) -{ - ArenaVector globalProperties(Allocator()->Adapter()); - fieldMap_.clear(); - exportNameMap_.clear(); - - // Add special '_$init$_' method that will hold all the top-level variable initializations (as assignments) and - // statements. By default it will be called in the global class static constructor but also it can be called - // directly from outside using public '_$init$_' method call in global scope. - // NOTE: now only a single-file modules are supported. Such a technique can be implemented in packages directly. - ir::ScriptFunction *initFunction = nullptr; - if (GetProgram()->GetPackageName().Empty()) { - initFunction = AddInitMethod(globalProperties); - } - - ParseTopLevelNextToken(statements, globalProperties, initFunction); - - // Add export modifier flag to nodes exported in previous statements. - for (auto &iter : exportNameMap_) { - util::StringView exportName = iter.first; - lexer::SourcePosition startLoc = exportNameMap_[exportName]; - if (fieldMap_.count(exportName) == 0) { - ThrowSyntaxError("Cannot find name '" + std::string {exportName.Utf8()} + "' to export.", startLoc); - } - auto field = fieldMap_[exportName]; - // selective export does not support default - MarkNodeAsExported(field, startLoc, false); - } - return globalProperties; -} - -void ETSParser::ParseTopLevelType(ArenaVector &statements, bool &defaultExport, - std::size_t const currentPos, - std::function const &parserFunction) -{ - ir::Statement *node = nullptr; - - node = parserFunction(this); - if (node != nullptr) { - if (currentPos != std::numeric_limits::max()) { - MarkNodeAsExported(node, node->Start(), defaultExport); - defaultExport = false; - } - statements.push_back(node); - } -} - -void ETSParser::ParseTopLevelNextTokenDefault(ArenaVector &statements, - ir::ScriptFunction *initFunction, size_t currentPos, - lexer::TokenType tokenType, bool defaultExport) -{ - if (IsStructKeyword()) { - ParseTopLevelType(statements, defaultExport, currentPos, - [](ETSParser *obj) { return obj->ParseTypeDeclaration(false); }); - return; - } - - if (IsTypeKeyword()) { - ParseTopLevelType(statements, defaultExport, currentPos, &ETSParser::ParseTypeAliasDeclaration); - return; - } - - if (initFunction != nullptr) { - if (auto *const statement = ParseTopLevelStatement(); statement != nullptr) { - statement->SetParent(initFunction->Body()); - initFunction->Body()->AsBlockStatement()->Statements().emplace_back(statement); - } - return; - } - - ThrowUnexpectedToken(tokenType); -} - -ir::ModifierFlags ETSParser::ResolveMemberModifiers() -{ - auto memberModifiers = ir::ModifierFlags::STATIC | ir::ModifierFlags::PUBLIC; - - if (Lexer()->GetToken().KeywordType() == lexer::TokenType::KEYW_DECLARE) { - CheckDeclare(); - memberModifiers |= ir::ModifierFlags::DECLARE; - } - return memberModifiers; -} - -lexer::SourcePosition ETSParser::ParseTopLevelNextTokenResolution(ArenaVector &statements, - ArenaVector &globalProperties, - ir::ScriptFunction *initFunction, size_t currentPos, - bool defaultExport) -{ - lexer::SourcePosition startLoc = Lexer()->GetToken().Start(); - auto memberModifiers = ResolveMemberModifiers(); - - switch (auto const tokenType = Lexer()->GetToken().Type(); tokenType) { - case lexer::TokenType::KEYW_CONST: { - memberModifiers |= ir::ModifierFlags::CONST; - [[fallthrough]]; - } - case lexer::TokenType::KEYW_LET: { - Lexer()->NextToken(); - ParseClassFieldDefinition(ExpectIdentifier(), memberModifiers, &globalProperties, initFunction, &startLoc); - break; - } - case lexer::TokenType::KEYW_ASYNC: - case lexer::TokenType::KEYW_NATIVE: { - ParseTokenOfNative(tokenType, memberModifiers); - [[fallthrough]]; - } - case lexer::TokenType::KEYW_FUNCTION: { - ParseTokenOfFunction(memberModifiers, startLoc, globalProperties); - break; - } - case lexer::TokenType::KEYW_NAMESPACE: - [[fallthrough]]; - case lexer::TokenType::KEYW_STATIC: - [[fallthrough]]; - case lexer::TokenType::KEYW_ABSTRACT: - [[fallthrough]]; - case lexer::TokenType::KEYW_FINAL: - [[fallthrough]]; - case lexer::TokenType::KEYW_ENUM: - [[fallthrough]]; - case lexer::TokenType::KEYW_INTERFACE: - [[fallthrough]]; - case lexer::TokenType::KEYW_CLASS: { - // NOLINTBEGIN(modernize-avoid-bind) - ParseTopLevelType(statements, defaultExport, currentPos, - std::bind(&ETSParser::ParseTypeDeclaration, std::placeholders::_1, false)); - // NOLINTEND(modernize-avoid-bind) - break; - } - default: { - // If struct is a soft keyword, handle it here, otherwise it's an identifier. - ParseTopLevelNextTokenDefault(statements, initFunction, currentPos, tokenType, defaultExport); - } - } - return startLoc; -} - -void ETSParser::ParseTopLevelNextToken(ArenaVector &statements, - ArenaVector &globalProperties, ir::ScriptFunction *initFunction) -{ - bool defaultExport = false; - - while (Lexer()->GetToken().Type() != lexer::TokenType::EOS) { - if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_SEMI_COLON) { - Lexer()->NextToken(); - continue; - } - - auto currentPos = std::numeric_limits::max(); - if (Lexer()->GetToken().Type() == lexer::TokenType::KEYW_EXPORT) { - Lexer()->NextToken(); - currentPos = globalProperties.size(); - - if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_MULTIPLY || - Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_LEFT_BRACE) { - ParseExport(Lexer()->GetToken().Start()); - continue; - } - - if (Lexer()->GetToken().KeywordType() == lexer::TokenType::KEYW_DEFAULT) { - defaultExport = true; - Lexer()->NextToken(); - } - } - - lexer::SourcePosition startLoc = - ParseTopLevelNextTokenResolution(statements, globalProperties, initFunction, currentPos, defaultExport); - - GetContext().Status() &= ~ParserStatus::IN_AMBIENT_CONTEXT; - - while (currentPos < globalProperties.size()) { - MarkNodeAsExported(globalProperties[currentPos], startLoc, defaultExport, - globalProperties.size() - currentPos); - defaultExport = false; - currentPos++; - } - } -} - -void ETSParser::ParseTokenOfNative(panda::es2panda::lexer::TokenType tokenType, ir::ModifierFlags &memberModifiers) -{ - bool isAsync = tokenType == lexer::TokenType::KEYW_ASYNC; - - if (isAsync) { - memberModifiers |= ir::ModifierFlags::ASYNC; - } else { - memberModifiers |= ir::ModifierFlags::NATIVE; - } - - Lexer()->NextToken(); - - if (Lexer()->GetToken().Type() != lexer::TokenType::KEYW_FUNCTION) { - ThrowSyntaxError({isAsync ? "'async'" : "'native'", " flags must be used for functions at top-level."}); - } -} - -void ETSParser::ParseTokenOfFunction(ir::ModifierFlags memberModifiers, lexer::SourcePosition startLoc, - ArenaVector &globalProperties) -{ - Lexer()->NextToken(); - // check whether it is an extension function - ir::Identifier *className = nullptr; - if (Lexer()->Lookahead() == lexer::LEX_CHAR_DOT) { - className = ExpectIdentifier(); - Lexer()->NextToken(); - } - - auto *memberName = ExpectIdentifier(); - auto *classMethod = ParseClassMethodDefinition(memberName, memberModifiers, className); - classMethod->SetStart(startLoc); - if (!classMethod->Function()->IsOverload()) { - globalProperties.push_back(classMethod); - } + (void)real_paths; + auto defaultSources = ValidatePathResolver(pathResolver_.CollectDefaultSources(paths, GetProgram())); + AddExternalSource(ParseSources(defaultSources)); + return statements; } -// NOLINTNEXTLINE(google-default-arguments) -ir::Statement *ETSParser::ParseTopLevelStatement(StatementParsingFlags flags) -{ - switch (auto const tokenType = Lexer()->GetToken().Type(); tokenType) { - case lexer::TokenType::PUNCTUATOR_LEFT_BRACE: { - return ParseBlockStatement(); - } - case lexer::TokenType::PUNCTUATOR_SEMI_COLON: { - return ParseEmptyStatement(); - } - case lexer::TokenType::KEYW_ASSERT: { - return ParseAssertStatement(); - } - case lexer::TokenType::KEYW_IF: { - return ParseIfStatement(); - } - case lexer::TokenType::KEYW_DO: { - return ParseDoWhileStatement(); - } - case lexer::TokenType::KEYW_FOR: { - return ParseForStatement(); - } - case lexer::TokenType::KEYW_TRY: { - return ParseTryStatement(); - } - case lexer::TokenType::KEYW_WHILE: { - return ParseWhileStatement(); - } - case lexer::TokenType::KEYW_BREAK: { - return ParseBreakStatement(); - } - case lexer::TokenType::KEYW_CONTINUE: { - return ParseContinueStatement(); - } - case lexer::TokenType::KEYW_THROW: { - return ParseThrowStatement(); - } - case lexer::TokenType::KEYW_SWITCH: { - return ParseSwitchStatement(); - } - case lexer::TokenType::KEYW_DEBUGGER: { - return ParseDebuggerStatement(); - } - case lexer::TokenType::LITERAL_IDENT: { - if (Lexer()->Lookahead() == lexer::LEX_CHAR_COLON) { - const auto pos = Lexer()->Save(); - Lexer()->NextToken(); - return ParseLabelledStatement(pos); - } +std::vector ETSParser::ParseSources(std::vector paths) +{ + pathResolver_.FilterParsedSources(paths, GetProgram()); + std::vector programs; - return ParseExpressionStatement(flags); - } - // These cases never can occur here! - case lexer::TokenType::KEYW_EXPORT: - [[fallthrough]]; - case lexer::TokenType::KEYW_IMPORT: - [[fallthrough]]; - case lexer::TokenType::KEYW_RETURN: { - ThrowUnexpectedToken(tokenType); + auto sources = ValidatePathResolver(pathResolver_.ParseSources(paths, GetProgram())); + for (const auto &source : sources) { + std::ifstream inputStream(source.resolvedPath.c_str()); + + if (GetProgram()->SourceFilePath().Is(source.resolvedPath)) { + break; } - // Note: let's leave the default processing case separately, because it can be changed in the future. - default: { - ThrowUnexpectedToken(tokenType); - // return ParseExpressionStatement(flags); + + if (inputStream.fail()) { + ThrowSyntaxError({"Failed to open file: ", source.resolvedPath}); } + + std::stringstream ss; + ss << inputStream.rdbuf(); + auto externalSource = ss.str(); + + auto currentLang = GetContext().SetLanguage(source.lang); + auto newProg = ParseSource({source.filePath, externalSource, source.resolvedPath, false}); + programs.emplace_back(newProg); + GetContext().SetLanguage(currentLang); } + return programs; } -void ETSParser::ParseTopLevelDeclaration(ArenaVector &statements) +parser::Program *ETSParser::ParseSource(const SourceFile &sourceFile) { - lexer::SourcePosition classBodyStartLoc = Lexer()->GetToken().Start(); - auto globalProperties = ParseTopLevelStatements(statements); + auto *program = Allocator()->New(Allocator(), GetProgram()->VarBinder()); + auto esp = ExternalSourceParser(this, program); + auto lexer = InitLexer(sourceFile); - auto *classDef = GetProgram()->GlobalClass(); + lexer::SourcePosition startLoc = Lexer()->GetToken().Start(); + Lexer()->NextToken(); - if (classDef->IsGlobalInitialized()) { - classDef->AddProperties(std::move(globalProperties)); - Lexer()->NextToken(); - return; + ArenaVector statements(Allocator()->Adapter()); + auto decl = ParsePackageDeclaration(); + if (decl != nullptr) { + statements.emplace_back(decl); } - - CreateCCtor(globalProperties, classBodyStartLoc, GetProgram()->Kind() != ScriptKind::STDLIB); - classDef->AddProperties(std::move(globalProperties)); - auto *classDecl = classDef->Parent()->AsClassDeclaration(); - classDef->SetGlobalInitialized(); - classDef->SetRange(classDef->Range()); - - statements.push_back(classDecl); - Lexer()->NextToken(); + auto script = ParseETSGlobalScript(startLoc, statements); + program->SetAst(script); + return program; } -// NOLINTNEXTLINE(google-default-arguments) -void ETSParser::CreateCCtor(ArenaVector &properties, const lexer::SourcePosition &loc, - const bool inGlobalClass) +ArenaVector ETSParser::ParseTopLevelStatements() { - bool hasStaticField = false; - for (const auto *prop : properties) { - if (prop->IsClassStaticBlock()) { - return; - } - - if (!prop->IsClassProperty()) { + ArenaVector statements(Allocator()->Adapter()); + while (Lexer()->GetToken().Type() != lexer::TokenType::EOS) { + if (Lexer()->TryEatTokenType(lexer::TokenType::PUNCTUATOR_SEMI_COLON)) { continue; } - - const auto *field = prop->AsClassProperty(); - - if (field->IsStatic()) { - hasStaticField = true; + auto stmt = ParseTopLevelStatement(); + GetContext().Status() &= ~ParserStatus::IN_AMBIENT_CONTEXT; + if (stmt != nullptr) { + statements.emplace_back(stmt); } } - if (!hasStaticField && !inGlobalClass) { - return; - } + return statements; +} - ArenaVector params(Allocator()->Adapter()); +ir::Statement *ETSParser::ParseTopLevelDeclStatement(StatementParsingFlags flags) +{ + auto [memberModifiers, startLoc] = ParseMemberModifiers(); + if ((memberModifiers & ir::ModifierFlags::EXPORT) != 0U && + (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_MULTIPLY || + Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_LEFT_BRACE)) { + return ParseReExport(startLoc); + } - auto *id = AllocNode(compiler::Signatures::CCTOR, Allocator()); + ir::Statement *result = nullptr; + auto token = Lexer()->GetToken(); + switch (token.Type()) { + case lexer::TokenType::KEYW_FUNCTION: { + result = ParseFunctionDeclaration(false, memberModifiers); + result->SetStart(startLoc); + break; + } + case lexer::TokenType::KEYW_CONST: { + memberModifiers |= ir::ModifierFlags::CONST; + [[fallthrough]]; + } + case lexer::TokenType::KEYW_LET: { + result = ParseStatement(flags); + break; + } + case lexer::TokenType::KEYW_NAMESPACE: + case lexer::TokenType::KEYW_STATIC: + case lexer::TokenType::KEYW_ABSTRACT: + case lexer::TokenType::KEYW_FINAL: + case lexer::TokenType::KEYW_ENUM: + case lexer::TokenType::KEYW_INTERFACE: + case lexer::TokenType::KEYW_CLASS: { + result = ParseTypeDeclaration(false); + break; + } + case lexer::TokenType::LITERAL_IDENT: { + result = ParseIdentKeyword(); + break; + } + default: { + break; + } + } + if (result != nullptr) { + result->AddModifier(memberModifiers); + } + return result; +} - ArenaVector statements(Allocator()->Adapter()); +ir::Statement *ETSParser::ParseTopLevelStatement() +{ + const auto flags = StatementParsingFlags::ALLOW_LEXICAL; + static const std::unordered_set ALLOWED_TOP_LEVEL_STMTS = { + lexer::TokenType::PUNCTUATOR_LEFT_BRACE, + lexer::TokenType::PUNCTUATOR_SEMI_COLON, + lexer::TokenType::KEYW_ASSERT, + lexer::TokenType::KEYW_IF, + lexer::TokenType::KEYW_DO, + lexer::TokenType::KEYW_FOR, + lexer::TokenType::KEYW_TRY, + lexer::TokenType::KEYW_WHILE, + lexer::TokenType::KEYW_BREAK, + lexer::TokenType::KEYW_CONTINUE, + lexer::TokenType::KEYW_THROW, + lexer::TokenType::KEYW_SWITCH, + lexer::TokenType::KEYW_DEBUGGER, + lexer::TokenType::LITERAL_IDENT, + }; - // Add the call to special '_$init$_' method containing all the top-level variable initializations (as assignments) - // and statements to the end of static constructor of the global class. - if (inGlobalClass) { - if (auto const it = std::find_if(properties.begin(), properties.end(), - [](ir::AstNode const *const item) { - return item->IsMethodDefinition() && - item->AsMethodDefinition()->Id()->Name() == - compiler::Signatures::INIT_METHOD; - }); - it != properties.end()) { - if (!(*it)->AsMethodDefinition()->Function()->Body()->AsBlockStatement()->Statements().empty()) { - auto *const callee = AllocNode(compiler::Signatures::INIT_METHOD, Allocator()); - callee->SetReference(); - - auto *const callExpr = AllocNode( - callee, ArenaVector(Allocator()->Adapter()), nullptr, false, false); - - statements.emplace_back(AllocNode(callExpr)); - } + auto result = ParseTopLevelDeclStatement(flags); + if (result == nullptr) { + auto const tokenType = Lexer()->GetToken().Type(); + if (ALLOWED_TOP_LEVEL_STMTS.count(tokenType) != 0U) { + result = ParseStatement(flags); + } else { + ThrowUnexpectedToken(tokenType); } } + return result; +} - auto *body = AllocNode(Allocator(), std::move(statements)); - auto *func = AllocNode(ir::FunctionSignature(nullptr, std::move(params), nullptr), body, - ir::ScriptFunctionFlags::STATIC_BLOCK | ir::ScriptFunctionFlags::HIDDEN, - ir::ModifierFlags::STATIC, false, GetContext().GetLanguge()); - func->SetIdent(id); - - auto *funcExpr = AllocNode(func); - auto *staticBlock = AllocNode(funcExpr, Allocator()); - staticBlock->AddModifier(ir::ModifierFlags::STATIC); - staticBlock->SetRange({loc, loc}); - properties.push_back(staticBlock); +ArenaVector ETSParser::ParseTopLevelDeclaration() +{ + auto topStatements = ParseTopLevelStatements(); + Lexer()->NextToken(); + return topStatements; } static bool IsClassModifier(lexer::TokenType type) @@ -1063,6 +380,24 @@ static bool IsClassModifier(lexer::TokenType type) type == lexer::TokenType::KEYW_FINAL; } +ir::Statement *ETSParser::ParseIdentKeyword() +{ + const auto token = Lexer()->GetToken(); + ASSERT(token.Type() == lexer::TokenType::LITERAL_IDENT); + switch (token.KeywordType()) { + case lexer::TokenType::KEYW_STRUCT: { + return ParseTypeDeclaration(false); + } + case lexer::TokenType::KEYW_TYPE: { + return ParseTypeAliasDeclaration(); + } + default: { + break; + } + } + return nullptr; +} + ir::ModifierFlags ETSParser::ParseClassModifiers() { ir::ModifierFlags flags = ir::ModifierFlags::NONE; @@ -1324,10 +659,9 @@ ir::ModifierFlags ETSParser::ParseClassMethodModifiers(bool seenStatic) // NOLINTNEXTLINE(google-default-arguments) void ETSParser::ParseClassFieldDefinition(ir::Identifier *fieldName, ir::ModifierFlags modifiers, - ArenaVector *declarations, ir::ScriptFunction *initFunction, - lexer::SourcePosition *letLoc) + ArenaVector *declarations, lexer::SourcePosition *letLoc) { - lexer::SourcePosition startLoc = letLoc != nullptr ? *letLoc : Lexer()->GetToken().Start(); + lexer::SourcePosition startLoc = letLoc != nullptr ? *letLoc : fieldName->Start(); lexer::SourcePosition endLoc = startLoc; ir::TypeNode *typeAnnotation = nullptr; TypeAnnotationParsingOptions options = TypeAnnotationParsingOptions::THROW_ERROR; @@ -1344,21 +678,12 @@ void ETSParser::ParseClassFieldDefinition(ir::Identifier *fieldName, ir::Modifie } else if (typeAnnotation == nullptr) { ThrowSyntaxError("Field type annotation expected"); } - - // Add initialization of top-level (global) variables to a special '_$init$_' function so that it could be - // performed multiple times. - if (initFunction != nullptr && (modifiers & ir::ModifierFlags::CONST) == 0U && initializer != nullptr && - !initializer->IsArrowFunctionExpression()) { - endLoc = InitializeGlobalVariable(fieldName, initializer, initFunction, startLoc, typeAnnotation); - } - bool isDeclare = (modifiers & ir::ModifierFlags::DECLARE) != 0; if (isDeclare && initializer != nullptr) { ThrowSyntaxError("Initializers are not allowed in ambient contexts."); } auto *field = AllocNode(fieldName, initializer, typeAnnotation, modifiers, Allocator(), false); - startLoc = fieldName->Start(); if (initializer != nullptr) { endLoc = initializer->End(); } else { @@ -1366,7 +691,6 @@ void ETSParser::ParseClassFieldDefinition(ir::Identifier *fieldName, ir::Modifie } field->SetRange({startLoc, endLoc}); - fieldMap_.insert({fieldName->Name(), field}); declarations->push_back(field); if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_COMMA) { @@ -1443,9 +767,6 @@ ir::MethodDefinition *ETSParser::ParseClassMethodDefinition(ir::Identifier *meth } auto *method = AllocNode(methodKind, methodName, funcExpr, modifiers, Allocator(), false); method->SetRange(funcExpr->Range()); - - fieldMap_.insert({methodName->Name(), method}); - return method; } @@ -1915,12 +1236,10 @@ ir::TSTypeAliasDeclaration *ETSParser::ParseTypeAliasDeclaration() params->SetParent(typeAliasDecl); } - if (Lexer()->GetToken().Type() != lexer::TokenType::PUNCTUATOR_SUBSTITUTION) { + if (!Lexer()->TryEatTokenType(lexer::TokenType::PUNCTUATOR_SUBSTITUTION)) { ThrowSyntaxError("'=' expected"); } - Lexer()->NextToken(); // eat '=' - TypeAnnotationParsingOptions options = TypeAnnotationParsingOptions::THROW_ERROR; ir::TypeNode *typeAnnotation = ParseTypeAnnotation(&options); typeAliasDecl->SetTsTypeAnnotation(typeAnnotation); @@ -1962,7 +1281,7 @@ ir::TSInterfaceDeclaration *ETSParser::ParseInterfaceBody(ir::Identifier *name, auto *body = AllocNode(std::move(members)); body->SetRange({bodyStart, Lexer()->GetToken().End()}); - const auto isExternal = (GetContext().Status() & ParserStatus::IN_EXTERNAL); + const auto isExternal = IsExternal(); auto *interfaceDecl = AllocNode( Allocator(), name, typeParamDecl, body, std::move(extends), isStatic, isExternal, GetContext().GetLanguge()); @@ -2061,7 +1380,6 @@ ir::ClassDefinition *ETSParser::ParseClassDefinition(ir::ClassDefinitionModifier // Parse ClassBody auto [ctor, properties, bodyRange] = ParseClassBody(modifiers, flags, identNode); - CreateCCtor(properties, bodyRange.start); auto *classDefinition = AllocNode( util::StringView(), identNode, typeParamDecl, superTypeParams, std::move(implements), ctor, superClass, @@ -2125,17 +1443,16 @@ ir::ClassProperty *ETSParser::ParseInterfaceField() Lexer()->NextToken(); ir::TypeNode *typeAnnotation = nullptr; - if (Lexer()->GetToken().Type() != lexer::TokenType::PUNCTUATOR_COLON) { - ThrowSyntaxError("Interface fields must have typeannotation."); + if (!Lexer()->TryEatTokenType(lexer::TokenType::PUNCTUATOR_COLON)) { + ThrowSyntaxError("Interface fields must have type annotation."); } - Lexer()->NextToken(); // eat ':' TypeAnnotationParsingOptions options = TypeAnnotationParsingOptions::THROW_ERROR; typeAnnotation = ParseTypeAnnotation(&options); name->SetTsTypeAnnotation(typeAnnotation); if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_EQUAL) { - ThrowSyntaxError("Initializers are not allowed on interface propertys."); + ThrowSyntaxError("Initializers are not allowed on interface properties."); } ir::ModifierFlags fieldModifiers = ir::ModifierFlags::PUBLIC; @@ -2388,8 +1705,7 @@ ir::AstNode *ETSParser::ParseTypeLiteralOrInterfaceMember() return ParseInterfaceGetterSetterMethod(methodFlags); } - if (Lexer()->GetToken().KeywordType() == lexer::TokenType::KEYW_READONLY) { - Lexer()->NextToken(); // eat 'readonly' keyword + if (Lexer()->TryEatTokenKeyword(lexer::TokenType::KEYW_READONLY)) { auto *field = ParseInterfaceField(); field->SetStart(startLoc); field->AddModifier(ir::ModifierFlags::READONLY); @@ -2956,7 +2272,7 @@ ir::DebuggerStatement *ETSParser::ParseDebuggerStatement() ThrowUnexpectedToken(lexer::TokenType::KEYW_DEBUGGER); } -void ETSParser::ParseExport(lexer::SourcePosition startLoc) +ir::Statement *ETSParser::ParseReExport(lexer::SourcePosition startLoc) { ASSERT(Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_MULTIPLY || Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_LEFT_BRACE); @@ -2965,11 +2281,18 @@ void ETSParser::ParseExport(lexer::SourcePosition startLoc) if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_MULTIPLY) { ParseNameSpaceSpecifier(&specifiers, true); } else { - ParseNamedSpecifiers(&specifiers, true); + auto specs = ParseNamedSpecifiers(); - if (Lexer()->GetToken().KeywordType() != lexer::TokenType::KEYW_FROM) { - // selective export directive - return; + if (Lexer()->GetToken().KeywordType() == lexer::TokenType::KEYW_FROM) { + specifiers = util::Helpers::ConvertVector(specs); + } else { + ArenaVector exports(Allocator()->Adapter()); + for (auto spec : specs) { + exports.emplace_back(AllocNode(spec->Local(), spec->Imported())); + } + auto selectiveExport = AllocNode( + Allocator(), static_cast(nullptr), std::move(exports)); + return selectiveExport; } } @@ -2983,16 +2306,12 @@ void ETSParser::ParseExport(lexer::SourcePosition startLoc) auto *reExportDeclaration = AllocNode(reExportSource, specifiers); reExportDeclaration->SetRange({startLoc, endLoc}); - auto varbinder = GetProgram()->VarBinder()->AsETSBinder(); - if (reExportDeclaration->Language().IsDynamic()) { - varbinder->AddDynamicImport(reExportDeclaration); - } - ConsumeSemicolon(reExportDeclaration); - auto *reExport = Allocator()->New(reExportDeclaration, userPaths, - GetProgram()->SourceFilePath(), Allocator()); - varbinder->AddReExportImport(reExport); + auto *reExport = AllocNode(reExportDeclaration, userPaths, + GetProgram()->SourceFilePath(), Allocator()); + reExports_.emplace_back(reExport); + return reExport; } ir::Statement *ETSParser::ParseFunctionStatement([[maybe_unused]] const StatementParsingFlags flags) @@ -3001,13 +2320,13 @@ ir::Statement *ETSParser::ParseFunctionStatement([[maybe_unused]] const Statemen ThrowSyntaxError("Nested functions are not allowed"); } -void ETSParser::ParsePackageDeclaration(ArenaVector &statements) +ir::ETSPackageDeclaration *ETSParser::ParsePackageDeclaration() { auto startLoc = Lexer()->GetToken().Start(); if (Lexer()->GetToken().Type() != lexer::TokenType::KEYW_PACKAGE) { if (!IsETSModule() && GetProgram()->IsEntryPoint()) { - return; + return nullptr; } auto baseName = GetProgram()->SourceFilePath().Utf8(); @@ -3019,7 +2338,7 @@ void ETSParser::ParsePackageDeclaration(ArenaVector &statements GetProgram()->SetPackageName(baseName); - return; + return nullptr; } Lexer()->NextToken(); @@ -3030,13 +2349,13 @@ void ETSParser::ParsePackageDeclaration(ArenaVector &statements packageDeclaration->SetRange({startLoc, Lexer()->GetToken().End()}); ConsumeSemicolon(packageDeclaration); - statements.push_back(packageDeclaration); if (name->IsIdentifier()) { GetProgram()->SetPackageName(name->AsIdentifier()->Name()); } else { GetProgram()->SetPackageName(name->AsTSQualifiedName()->ToString(Allocator())); } + return packageDeclaration; } std::tuple> ETSParser::ParseFromClause(bool requireFrom) @@ -3057,8 +2376,7 @@ std::tuple> ETSParser::ParseFromCla std::vector userPaths; bool isModule = false; auto importPath = Lexer()->GetToken().Ident(); - auto resolvedImportPath = ResolveImportPath(importPath.Mutf8()); - resolvedParsedSources_.emplace(importPath.Mutf8(), resolvedImportPath); + auto resolvedImportPath = ValidatePathResolver(pathResolver_.ResolveImportPath(importPath.Mutf8(), GetProgram())); ir::StringLiteral *resolvedSource; if (*importPath.Bytes() == '/') { @@ -3067,7 +2385,7 @@ std::tuple> ETSParser::ParseFromCla resolvedSource = AllocNode(importPath); } - auto importData = GetImportData(resolvedImportPath); + auto importData = pathResolver_.GetImportData(resolvedImportPath); if ((GetContext().Status() & ParserStatus::IN_DEFAULT_IMPORTS) == 0) { std::tie(userPaths, isModule) = CollectUserSources(importPath.Mutf8()); @@ -3096,11 +2414,11 @@ std::tuple> ETSParser::ParseFromCla return {importSource, userPaths}; } -std::vector ETSParser::ParseImportDeclarations(ArenaVector &statements) +std::pair, std::vector> ETSParser::ParseImportDeclarations() { std::vector allUserPaths; std::vector userPaths; - ArenaVector imports(Allocator()->Adapter()); + ArenaVector statements(Allocator()->Adapter()); while (Lexer()->GetToken().Type() == lexer::TokenType::KEYW_IMPORT) { auto startLoc = Lexer()->GetToken().Start(); @@ -3112,7 +2430,8 @@ std::vector ETSParser::ParseImportDeclarations(ArenaVectorGetToken().Type() == lexer::TokenType::PUNCTUATOR_MULTIPLY) { ParseNameSpaceSpecifier(&specifiers); } else if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_LEFT_BRACE) { - ParseNamedSpecifiers(&specifiers); + auto specs = ParseNamedSpecifiers(); + specifiers = util::Helpers::ConvertVector(specs); } else { ParseImportDefaultSpecifier(&specifiers); } @@ -3127,37 +2446,28 @@ std::vector ETSParser::ParseImportDeclarations(ArenaVector bool { - return s1->IsETSImportDeclaration() && s2->IsETSImportDeclaration() && - s1->AsETSImportDeclaration()->Specifiers()[0]->IsImportNamespaceSpecifier() && - !s2->AsETSImportDeclaration()->Specifiers()[0]->IsImportNamespaceSpecifier(); + std::sort(statements.begin(), statements.end(), [](const auto *s1, const auto *s2) -> bool { + return s1->Specifiers()[0]->IsImportNamespaceSpecifier() && !s2->Specifiers()[0]->IsImportNamespaceSpecifier(); }); - if ((GetContext().Status() & ParserStatus::IN_DEFAULT_IMPORTS) != 0) { - static_cast(GetProgram()->VarBinder()) - ->SetDefaultImports(std::move(imports)); // get rid of it - } - - sort(allUserPaths.begin(), allUserPaths.end()); - allUserPaths.erase(unique(allUserPaths.begin(), allUserPaths.end()), allUserPaths.end()); + std::sort(allUserPaths.begin(), allUserPaths.end()); + allUserPaths.erase(std::unique(allUserPaths.begin(), allUserPaths.end()), allUserPaths.end()); - return allUserPaths; + return std::make_pair(statements, allUserPaths); } -void ETSParser::ParseNamedSpecifiers(ArenaVector *specifiers, bool isExport) +ArenaVector ETSParser::ParseNamedSpecifiers() { - lexer::SourcePosition startLoc = Lexer()->GetToken().Start(); // NOTE(user): handle qualifiedName in file bindings: qualifiedName '.' '*' - if (Lexer()->GetToken().Type() != lexer::TokenType::PUNCTUATOR_LEFT_BRACE) { + if (!Lexer()->TryEatTokenType(lexer::TokenType::PUNCTUATOR_LEFT_BRACE)) { ThrowExpectedToken(lexer::TokenType::PUNCTUATOR_LEFT_BRACE); } - Lexer()->NextToken(); // eat '{' auto fileName = GetProgram()->SourceFilePath().Mutf8(); - std::vector exportedIdents; + + ArenaVector result(Allocator()->Adapter()); while (Lexer()->GetToken().Type() != lexer::TokenType::PUNCTUATOR_RIGHT_BRACE) { if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_MULTIPLY) { @@ -3175,8 +2485,7 @@ void ETSParser::ParseNamedSpecifiers(ArenaVector *specifiers, boo Lexer()->NextToken(); // eat import/export name - if (CheckModuleAsModifier() && Lexer()->GetToken().Type() == lexer::TokenType::KEYW_AS) { - Lexer()->NextToken(); // eat `as` literal + if (CheckModuleAsModifier() && Lexer()->TryEatTokenType(lexer::TokenType::KEYW_AS)) { local = ParseNamedImport(Lexer()->GetToken()); Lexer()->NextToken(); // eat local name } else { @@ -3186,13 +2495,9 @@ void ETSParser::ParseNamedSpecifiers(ArenaVector *specifiers, boo auto *specifier = AllocNode(imported, local); specifier->SetRange({imported->Start(), local->End()}); - util::Helpers::CheckImportedName(specifiers, specifier, fileName); + util::Helpers::CheckImportedName(result, specifier, fileName); - if (isExport) { - util::StringView memberName = local->Name(); - exportedIdents.push_back(memberName); - } - specifiers->push_back(specifier); + result.emplace_back(specifier); if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_COMMA) { Lexer()->NextToken(lexer::NextTokenFlags::KEYWORD_TO_IDENT); // eat comma @@ -3201,12 +2506,7 @@ void ETSParser::ParseNamedSpecifiers(ArenaVector *specifiers, boo Lexer()->NextToken(); // eat '}' - if (isExport && Lexer()->GetToken().KeywordType() != lexer::TokenType::KEYW_FROM) { - // update exported idents to export name map when it is not the case of re-export - for (auto memberName : exportedIdents) { - exportNameMap_.insert({memberName, startLoc}); - } - } + return result; } void ETSParser::ParseNameSpaceSpecifier(ArenaVector *specifiers, bool isReExport) @@ -3314,40 +2614,37 @@ static constexpr char const ONLY_ARRAY_FOR_REST[] = "Rest parameter should be of static constexpr char const EXPLICIT_PARAM_TYPE[] = "Parameter declaration should have an explicit type annotation."; // NOLINTEND(modernize-avoid-c-arrays) -ir::Expression *ETSParser::ParseFunctionParameter() +std::pair ETSParser::TypeAnnotationValue(ir::TypeNode *typeAnnotation) { - ir::ETSParameterExpression *paramExpression; - auto *const paramIdent = GetAnnotatedExpressionFromParam(); - - bool defaultUndefined = false; - if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_QUESTION_MARK) { - if (paramIdent->IsRestElement()) { - ThrowSyntaxError(NO_DEFAULT_FOR_REST); - } - defaultUndefined = true; - Lexer()->NextToken(); // eat '?' + if (typeAnnotation == nullptr) { + return std::make_pair(nullptr, ""); } - - const bool isArrow = (GetContext().Status() & ParserStatus::ARROW_FUNCTION) != 0; - - if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_COLON) { - Lexer()->NextToken(); // eat ':' - - TypeAnnotationParsingOptions options = TypeAnnotationParsingOptions::THROW_ERROR; - ir::TypeNode *typeAnnotation = ParseTypeAnnotation(&options); - - if (paramIdent->IsRestElement() && !typeAnnotation->IsTSArrayType()) { - ThrowSyntaxError(ONLY_ARRAY_FOR_REST); + if (!typeAnnotation->IsETSPrimitiveType()) { + return std::make_pair(AllocNode(), "undefined"); + } + // NOTE(ttamas) : after nullable fix, fix this scope + switch (typeAnnotation->AsETSPrimitiveType()->GetPrimitiveType()) { + case ir::PrimitiveType::BYTE: + case ir::PrimitiveType::INT: + case ir::PrimitiveType::LONG: + case ir::PrimitiveType::SHORT: + case ir::PrimitiveType::FLOAT: + case ir::PrimitiveType::DOUBLE: + return std::make_pair(AllocNode(lexer::Number(0)), "0"); + case ir::PrimitiveType::BOOLEAN: + return std::make_pair(AllocNode(false), "false"); + case ir::PrimitiveType::CHAR: + return std::make_pair(AllocNode(), "c'\\u0000'"); + default: { + UNREACHABLE(); } - - typeAnnotation->SetParent(paramIdent); - paramIdent->SetTsTypeAnnotation(typeAnnotation); - paramIdent->SetEnd(typeAnnotation->End()); - - } else if (!isArrow && !defaultUndefined) { - ThrowSyntaxError(EXPLICIT_PARAM_TYPE); } +} +ir::ETSParameterExpression *ETSParser::ParseFunctionParameterTail(ir::AnnotatedExpression *paramIdent, + bool defaultUndefined) +{ + ir::ETSParameterExpression *paramExpression; if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_SUBSTITUTION) { if (paramIdent->IsRestElement()) { ThrowSyntaxError(NO_DEFAULT_FOR_REST); @@ -3379,42 +2676,16 @@ ir::Expression *ETSParser::ParseFunctionParameter() paramExpression->SetRange({paramIdent->Start(), paramExpression->Initializer()->End()}); } else if (paramIdent->IsIdentifier()) { auto *const typeAnnotation = paramIdent->AsIdentifier()->TypeAnnotation(); - - const auto typeAnnotationValue = [this, typeAnnotation]() -> std::pair { - if (typeAnnotation == nullptr) { - return std::make_pair(nullptr, ""); - } - if (!typeAnnotation->IsETSPrimitiveType()) { - return std::make_pair(AllocNode(), "undefined"); - } - // NOTE(ttamas) : after nullable fix, fix this scope - switch (typeAnnotation->AsETSPrimitiveType()->GetPrimitiveType()) { - case ir::PrimitiveType::BYTE: - case ir::PrimitiveType::INT: - case ir::PrimitiveType::LONG: - case ir::PrimitiveType::SHORT: - case ir::PrimitiveType::FLOAT: - case ir::PrimitiveType::DOUBLE: - return std::make_pair(AllocNode(lexer::Number(0)), "0"); - case ir::PrimitiveType::BOOLEAN: - return std::make_pair(AllocNode(false), "false"); - case ir::PrimitiveType::CHAR: - return std::make_pair(AllocNode(), "c'\\u0000'"); - default: { - UNREACHABLE(); - } - } - }(); - + auto [literal, defaultValue] = TypeAnnotationValue(typeAnnotation); if (defaultUndefined && !typeAnnotation->IsETSPrimitiveType()) { typeAnnotation->AddModifier(ir::ModifierFlags::UNDEFINED_ASSIGNABLE); } - paramExpression = AllocNode( - paramIdent->AsIdentifier(), defaultUndefined ? std::get<0>(typeAnnotationValue) : nullptr); + paramExpression = + AllocNode(paramIdent->AsIdentifier(), defaultUndefined ? literal : nullptr); if (defaultUndefined) { - paramExpression->SetLexerSaved(util::UString(std::get<1>(typeAnnotationValue), Allocator()).View()); + paramExpression->SetLexerSaved(util::UString(defaultValue, Allocator()).View()); } paramExpression->SetRange({paramIdent->Start(), paramIdent->End()}); @@ -3422,10 +2693,43 @@ ir::Expression *ETSParser::ParseFunctionParameter() paramExpression = AllocNode(paramIdent->AsRestElement(), nullptr); paramExpression->SetRange({paramIdent->Start(), paramIdent->End()}); } - return paramExpression; } +ir::Expression *ETSParser::ParseFunctionParameter() +{ + auto *const paramIdent = GetAnnotatedExpressionFromParam(); + + bool defaultUndefined = false; + if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_QUESTION_MARK) { + if (paramIdent->IsRestElement()) { + ThrowSyntaxError(NO_DEFAULT_FOR_REST); + } + defaultUndefined = true; + Lexer()->NextToken(); // eat '?' + } + + const bool isArrow = (GetContext().Status() & ParserStatus::ARROW_FUNCTION) != 0; + + if (Lexer()->TryEatTokenType(lexer::TokenType::PUNCTUATOR_COLON)) { + TypeAnnotationParsingOptions options = TypeAnnotationParsingOptions::THROW_ERROR; + ir::TypeNode *typeAnnotation = ParseTypeAnnotation(&options); + + if (paramIdent->IsRestElement() && !typeAnnotation->IsTSArrayType()) { + ThrowSyntaxError(ONLY_ARRAY_FOR_REST); + } + + typeAnnotation->SetParent(paramIdent); + paramIdent->SetTsTypeAnnotation(typeAnnotation); + paramIdent->SetEnd(typeAnnotation->End()); + + } else if (!isArrow && !defaultUndefined) { + ThrowSyntaxError(EXPLICIT_PARAM_TYPE); + } + + return ParseFunctionParameterTail(paramIdent, defaultUndefined); +} + ir::Expression *ETSParser::CreateParameterThis(const util::StringView className) { auto *paramIdent = AllocNode(varbinder::TypedBinder::MANDATORY_PARAM_THIS, Allocator()); @@ -4603,7 +3907,6 @@ bool ETSParser::ParsePotentialNonNullExpression(ir::Expression **expression, con const auto nonNullExpr = AllocNode(*expression); nonNullExpr->SetRange({startLoc, Lexer()->GetToken().End()}); - nonNullExpr->SetParent(*expression); *expression = nonNullExpr; @@ -4618,12 +3921,6 @@ bool ETSParser::IsStructKeyword() const Lexer()->GetToken().KeywordType() == lexer::TokenType::KEYW_STRUCT); } -bool ETSParser::IsTypeKeyword() const -{ - return (Lexer()->GetToken().Type() == lexer::TokenType::LITERAL_IDENT && - Lexer()->GetToken().KeywordType() == lexer::TokenType::KEYW_TYPE); -} - void ETSParser::ValidateInstanceOfExpression(ir::Expression *expr) { ValidateGroupedExpression(expr); @@ -5031,6 +4328,92 @@ ir::TypeNode *ETSParser::CreateTypeAnnotation(TypeAnnotationParsingOptions *opti return ParseTypeAnnotation(options); } +ir::FunctionDeclaration *ETSParser::ParseFunctionDeclaration(bool canBeAnonymous, ir::ModifierFlags modifiers) +{ + lexer::SourcePosition startLoc = Lexer()->GetToken().Start(); + + ASSERT(Lexer()->GetToken().Type() == lexer::TokenType::KEYW_FUNCTION); + Lexer()->NextToken(); + auto newStatus = ParserStatus::NEED_RETURN_TYPE | ParserStatus::ALLOW_SUPER; + + if ((modifiers & ir::ModifierFlags::ASYNC) != 0) { + newStatus |= ParserStatus::ASYNC_FUNCTION; + } + if (Lexer()->TryEatTokenType(lexer::TokenType::PUNCTUATOR_MULTIPLY)) { + newStatus |= ParserStatus::GENERATOR_FUNCTION; + } + + ir::Identifier *className = nullptr; + ir::Identifier *identNode = nullptr; + if (Lexer()->Lookahead() == lexer::LEX_CHAR_DOT) { + className = ExpectIdentifier(); + if (className != nullptr) { + newStatus |= ParserStatus::IN_EXTENSION_FUNCTION; + } + Lexer()->NextToken(); + identNode = ExpectIdentifier(); + } else if (Lexer()->GetToken().Type() == lexer::TokenType::LITERAL_IDENT) { + identNode = ExpectIdentifier(); + } else if (!canBeAnonymous) { + ThrowSyntaxError("Unexpected token, expected identifier after 'function' keyword"); + } + newStatus |= ParserStatus::FUNCTION_DECLARATION; + if (identNode != nullptr) { + CheckRestrictedBinding(identNode->Name(), identNode->Start()); + } + ir::ScriptFunction *func = ParseFunction(newStatus, className); + func->SetIdent(identNode); + auto *funcDecl = AllocNode(Allocator(), func); + if (func->IsOverload() && Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_SEMI_COLON) { + Lexer()->NextToken(); + } + funcDecl->SetRange(func->Range()); + func->AddModifier(modifiers); + func->SetStart(startLoc); + + if (className != nullptr) { + func->AddFlag(ir::ScriptFunctionFlags::INSTANCE_EXTENSION_METHOD); + } + + return funcDecl; +} + +std::pair ETSParser::ParseMemberModifiers() +{ + auto memberModifiers = ir::ModifierFlags::STATIC | ir::ModifierFlags::PUBLIC; + + if (Lexer()->TryEatTokenType(lexer::TokenType::KEYW_EXPORT)) { + memberModifiers |= ir::ModifierFlags::EXPORT; + if (Lexer()->TryEatTokenKeyword(lexer::TokenType::KEYW_DEFAULT)) { + memberModifiers |= ir::ModifierFlags::DEFAULT_EXPORT; + } + } + + lexer::SourcePosition startLoc = Lexer()->GetToken().Start(); + + if (Lexer()->GetToken().KeywordType() == lexer::TokenType::KEYW_DECLARE) { + CheckDeclare(); + memberModifiers |= ir::ModifierFlags::DECLARE; + } + const auto tokenType = Lexer()->GetToken().KeywordType(); + if (tokenType == lexer::TokenType::KEYW_ASYNC || tokenType == lexer::TokenType::KEYW_NATIVE) { + bool isAsync = tokenType == lexer::TokenType::KEYW_ASYNC; + + if (isAsync) { + memberModifiers |= ir::ModifierFlags::ASYNC; + } else { + memberModifiers |= ir::ModifierFlags::NATIVE; + } + Lexer()->NextToken(); + + if (Lexer()->GetToken().Type() != lexer::TokenType::KEYW_FUNCTION) { + ThrowSyntaxError( + {isAsync ? "'async'" : "'native'", " flags must be used for functions only at top-level."}); + } + } + return std::make_pair(memberModifiers, startLoc); +} + //================================================================================================// // ExternalSourceParser class //================================================================================================// @@ -5072,4 +4455,3 @@ InnerSourceParser::~InnerSourceParser() parser_->GetProgram()->SetSource(savedSourceCode_, savedSourceFile_, savedSourceFilePath_); } } // namespace panda::es2panda::parser -#undef USE_UNIX_SYSCALL diff --git a/ets2panda/parser/ETSparser.h b/ets2panda/parser/ETSparser.h index a7de8a807f..abb23f8f62 100644 --- a/ets2panda/parser/ETSparser.h +++ b/ets2panda/parser/ETSparser.h @@ -18,6 +18,8 @@ #include #include "parserFlags.h" +#include "ir/ets/etsReExportDeclaration.h" +#include "util/importPathResolver.h" #include "util/arktsconfig.h" #include "TypedParser.h" @@ -41,7 +43,10 @@ inline constexpr char const DEFAULT_SOURCE_FILE[] = ".ets"; class ETSParser final : public TypedParser { public: ETSParser(Program *program, const CompilerOptions &options, ParserStatus status = ParserStatus::NO_OPTS) - : TypedParser(program, options, status), globalProgram_(GetProgram()) + : TypedParser(program, options, status), + globalProgram_(GetProgram()), + pathResolver_(ArkTSConfig(), options.stdLib, Extension()), + reExports_(Allocator()->Adapter()) { } @@ -57,9 +62,6 @@ public: } // Methods to create AST node(s) from the specified string (part of valid ETS-code!) - // NOTE: the correct initial scope should be entered BEFORE calling any of these methods, - // and correct parent and, probably, variable set to the node(s) after obtaining - ir::Expression *CreateExpression(std::string_view sourceCode, ExpressionParseFlags flags = ExpressionParseFlags::NO_OPTS, std::string_view fileName = DEFAULT_SOURCE_FILE); @@ -93,64 +95,34 @@ public: return CreateFormattedStatements(sourceCode, insertingNodes, fileName); } + ArenaVector ParseDefaultSources(std::string_view srcFile, std::string_view importSrc, + const std::vector &paths); + private: - struct ImportData { - Language lang; - std::string module; - bool hasDecl; - }; - - std::map fieldMap_; - std::map exportNameMap_; void ParseProgram(ScriptKind kind) override; [[nodiscard]] std::unique_ptr InitLexer(const SourceFile &sourceFile) override; - void ParsePackageDeclaration(ArenaVector &statements); - ArenaVector ParseTopLevelStatements(ArenaVector &statements); - void ParseTopLevelType(ArenaVector &statements, bool &defaultExport, std::size_t currentPos, - std::function const &parserFunction); - void ParseTopLevelNextToken(ArenaVector &statements, ArenaVector &globalProperties, - ir::ScriptFunction *initFunction); - void ParseTopLevelNextTokenDefault(ArenaVector &statements, ir::ScriptFunction *initFunction, - size_t currentPos, lexer::TokenType tokenType, bool defaultExport); - ir::ModifierFlags ResolveMemberModifiers(); - lexer::SourcePosition ParseTopLevelNextTokenResolution(ArenaVector &statements, - ArenaVector &globalProperties, - ir::ScriptFunction *initFunction, size_t currentPos, - bool defaultExport); - void ParseTokenOfNative(panda::es2panda::lexer::TokenType tokenType, ir::ModifierFlags &memberModifiers); - void ParseTokenOfFunction(ir::ModifierFlags memberModifiers, lexer::SourcePosition startLoc, - ArenaVector &globalProperties); + ir::ETSPackageDeclaration *ParsePackageDeclaration(); + ArenaVector ParseTopLevelStatements(); + #ifdef USE_FTW static int NFTWCallBack(const char *fpath, const struct stat * /*unused*/, int tflag, struct FTW * /*unused*/); #endif - void ParseTopLevelDeclaration(ArenaVector &statements); - std::vector UnixApiDefaultSources(const std::vector &stdlib); - std::vector CollectDefaultSources(); - void CollectUserSourcesFromIndex(const std::string &path, const std::string &resolvedPath, - std::vector &userPaths); - std::string ResolveImportPath(const std::string &path); - std::string ResolveFullPathFromRelative(const std::string &path); - ImportData GetImportData(const std::string &path); + ArenaVector ParseTopLevelDeclaration(); std::tuple, bool> CollectUserSources(const std::string &path); - std::tuple GetSourceRegularPath(const std::string &path, const std::string &resolvedPath); - void ParseSources(const std::vector &paths, bool isExternal = true); + std::vector ParseSources(std::vector paths); std::tuple> ParseFromClause(bool requireFrom); - void ParseNamedSpecifiers(ArenaVector *specifiers, bool isExport = false); - void ParseNamedExportSpecifiers(ArenaVector *specifiers, bool defaultExport); - void ParseUserSources(std::vector userParths); - std::vector ParseImportDeclarations(ArenaVector &statements); - void ParseDefaultSources(); - void ParseSource(const SourceFile &sourceFile); - void CreateGlobalClass(); - ArenaVector PrepareGlobalClass(); - ArenaVector PrepareExternalGlobalClass(const SourceFile &sourceFile); - void ParseETSGlobalScript(lexer::SourcePosition startLoc, ArenaVector &statements); + ArenaVector ParseNamedSpecifiers(); + std::pair, std::vector> ParseImportDeclarations(); + parser::Program *ParseSource(const SourceFile &sourceFile); + void AddExternalSource(const std::vector &programs); + ir::ETSScript *ParseETSGlobalScript(lexer::SourcePosition startLoc, ArenaVector &statements); ir::AstNode *ParseImportDefaultSpecifier(ArenaVector *specifiers) override; ir::MethodDefinition *ParseClassGetterSetterMethod(const ArenaVector &properties, ir::ClassDefinitionModifiers modifiers, ir::ModifierFlags memberModifiers); ir::MethodDefinition *ParseInterfaceGetterSetterMethod(ir::ModifierFlags modifiers); + ir::Statement *ParseIdentKeyword(); ir::Statement *ParseTypeDeclaration(bool allowStatic = false); ir::Statement *ParseTypeDeclarationAbstractFinal(bool allowStatic, ir::ClassDefinitionModifiers modifiers); ir::ModifierFlags ParseClassModifiers(); @@ -177,8 +149,7 @@ private: // NOLINTNEXTLINE(google-default-arguments) void ParseClassFieldDefinition(ir::Identifier *fieldName, ir::ModifierFlags modifiers, - ArenaVector *declarations, ir::ScriptFunction *initFunction = nullptr, - lexer::SourcePosition *letLoc = nullptr); + ArenaVector *declarations, lexer::SourcePosition *letLoc = nullptr); lexer::SourcePosition InitializeGlobalVariable(ir::Identifier *fieldName, ir::Expression *&initializer, ir::ScriptFunction *initFunction, lexer::SourcePosition &startLoc, ir::TypeNode *typeAnnotation); @@ -217,6 +188,7 @@ private: ir::Statement *ParseTryStatement() override; ir::DebuggerStatement *ParseDebuggerStatement() override; void ParseExport(lexer::SourcePosition startLoc); + ir::Statement *ParseReExport(lexer::SourcePosition startLoc); ir::Statement *ParseImportDeclaration(StatementParsingFlags flags) override; ir::Statement *ParseExportDeclaration(StatementParsingFlags flags) override; ir::AnnotatedExpression *ParseVariableDeclaratorKey(VariableParsingFlags flags) override; @@ -227,6 +199,8 @@ private: ir::AstNode *ParseTypeLiteralOrInterfaceMember() override; void ParseNameSpaceSpecifier(ArenaVector *specifiers, bool isReExport = false); bool CheckModuleAsModifier(); + std::pair TypeAnnotationValue(ir::TypeNode *typeAnnotation); + ir::ETSParameterExpression *ParseFunctionParameterTail(ir::AnnotatedExpression *paramIdent, bool defaultUndefined); ir::Expression *ParseFunctionParameter() override; ir::AnnotatedExpression *GetAnnotatedExpressionFromParam(); // NOLINTNEXTLINE(google-default-arguments) @@ -284,6 +258,7 @@ private: ir::ThisExpression *ParseThisExpression() override; ir::TypeNode *ParseThisType(TypeAnnotationParsingOptions *options); ir::Statement *ParseFunctionStatement(StatementParsingFlags flags) override; + ir::FunctionDeclaration *ParseFunctionDeclaration(bool canBeAnonymous, ir::ModifierFlags modifiers); std::tuple ParseClassImplementsElement() override; ir::TypeNode *ParseInterfaceExtendsElement() override; // NOLINTNEXTLINE(google-default-arguments) @@ -298,17 +273,32 @@ private: bool CheckClassElement(ir::AstNode *property, ir::MethodDefinition *&ctor, ArenaVector &properties) override; - // NOLINTNEXTLINE(google-default-arguments) - void CreateCCtor(ArenaVector &properties, const lexer::SourcePosition &loc, - bool inGlobalClass = false) override; void CreateImplicitConstructor(ir::MethodDefinition *&ctor, ArenaVector &properties, ir::ClassDefinitionModifiers modifiers, const lexer::SourcePosition &startLoc) override; bool ParsePotentialGenericFunctionCall(ir::Expression *primaryExpr, ir::Expression **returnExpression, const lexer::SourcePosition &startLoc, bool ignoreCallExpression) override; bool ParsePotentialNonNullExpression(ir::Expression **expression, lexer::SourcePosition startLoc) override; - void MarkNodeAsExported(ir::AstNode *node, lexer::SourcePosition startPos, bool defaultExport, - std::size_t numOfElements = 1); + + std::pair ParseMemberModifiers(); + + template + Value ValidatePathResolver(util::ImportPathResolver::ResultT result) + { + if (result.IsError()) { + const auto &[code, error] = result.ExpectError(); + using ErrorCode = util::ImportPathResolver::ErrorCode; + switch (code) { + case ErrorCode::ARKTS_PREFIX_FAIL: + ThrowSyntaxError({"Can't find prefix for '", error, "' in ", ArkTSConfig()->ConfigPath()}); + case ErrorCode::INCORRECT_PATH: + ThrowSyntaxError("Incorrect path: " + error); + default: + UNREACHABLE(); + } + } + return std::move(*result); + } std::shared_ptr ArkTSConfig() const { @@ -321,7 +311,11 @@ private: } bool IsStructKeyword() const; - bool IsTypeKeyword() const; + + bool IsExternal() const override + { + return pathResolver_.IsStdLib(GetProgram()); + } // NOLINTNEXTLINE(google-default-arguments) ir::Expression *ParseExpression(ExpressionParseFlags flags = ExpressionParseFlags::NO_OPTS) override; @@ -330,16 +324,15 @@ private: ir::ModifierFlags ParseTypeVarianceModifier(TypeAnnotationParsingOptions *const options); - ir::ScriptFunction *AddInitMethod(ArenaVector &globalProperties); - ir::Statement *ParseTopLevelStatement(StatementParsingFlags flags = StatementParsingFlags::NONE); + ir::Statement *ParseTopLevelDeclStatement(StatementParsingFlags flags); + ir::Statement *ParseTopLevelStatement(); void ParseTrailingBlock([[maybe_unused]] ir::CallExpression *callExpr) override; void CheckDeclare(); // Methods to create AST node(s) from the specified string (part of valid ETS-code!) - // NOTE: the correct initial scope should be entered BEFORE calling any of these methods, - // and correct parent and, probably, variable set to the node(s) after obtaining + // NOTE: ScopeInitPhase, SetParent should be called on created subtree after calling any of these methods, // NOLINTBEGIN(modernize-avoid-c-arrays) inline static constexpr char const DEFAULT_SOURCE_FILE[] = ".ets"; // NOLINTEND(modernize-avoid-c-arrays) @@ -374,13 +367,14 @@ private: public: const std::unordered_map &ResolvedParsedSourcesMap() const { - return resolvedParsedSources_; + return pathResolver_.ResolvedParsedSourcesMap(); } private: parser::Program *globalProgram_; + util::ImportPathResolver pathResolver_; + ArenaVector reExports_; std::vector insertingNodes_ {}; - std::unordered_map resolvedParsedSources_; }; class ExternalSourceParser { diff --git a/ets2panda/parser/TypedParser.cpp b/ets2panda/parser/TypedParser.cpp index a3018356f2..9ba010c6ee 100644 --- a/ets2panda/parser/TypedParser.cpp +++ b/ets2panda/parser/TypedParser.cpp @@ -460,7 +460,7 @@ ir::Statement *TypedParser::ParseInterfaceDeclaration(bool isStatic) auto *body = AllocNode(std::move(members)); body->SetRange({bodyStart, Lexer()->GetToken().End()}); - const auto isExternal = (GetContext().Status() & ParserStatus::IN_EXTERNAL); + const auto isExternal = IsExternal(); auto *interfaceDecl = AllocNode( Allocator(), id, typeParamDecl, body, std::move(extends), isStatic, isExternal, GetContext().GetLanguge()); interfaceDecl->SetRange({interfaceStart, Lexer()->GetToken().End()}); diff --git a/ets2panda/parser/TypedParser.h b/ets2panda/parser/TypedParser.h index fc04ce492f..ab7f2fd145 100644 --- a/ets2panda/parser/TypedParser.h +++ b/ets2panda/parser/TypedParser.h @@ -144,13 +144,6 @@ protected: { return false; } - - // NOLINTNEXTLINE(google-default-arguments) - virtual void CreateCCtor([[maybe_unused]] ArenaVector &properties, - [[maybe_unused]] const lexer::SourcePosition &loc, - [[maybe_unused]] bool inGlobalClass = false) - { - } }; } // namespace panda::es2panda::parser diff --git a/ets2panda/parser/context/parserContext.h b/ets2panda/parser/context/parserContext.h index 926fc510f0..45df25c965 100644 --- a/ets2panda/parser/context/parserContext.h +++ b/ets2panda/parser/context/parserContext.h @@ -60,8 +60,6 @@ enum class ParserStatus : uint64_t { IN_CLASS_BODY = 1U << 25U, NEED_RETURN_TYPE = 1U << 26U, - IN_EXTERNAL = 1U << 27U, - IN_IMPORT = 1U << 28U, IN_DEFAULT_IMPORTS = 1U << 29U, IN_EXTENSION_FUNCTION = 1U << 30U, FUNCTION_HAS_RETURN_STATEMENT = 1U << 31U, diff --git a/ets2panda/parser/expressionParser.cpp b/ets2panda/parser/expressionParser.cpp index 5eaa24e774..752073c32e 100644 --- a/ets2panda/parser/expressionParser.cpp +++ b/ets2panda/parser/expressionParser.cpp @@ -1193,6 +1193,7 @@ void ParserImpl::CreateAmendedBinaryExpression(ir::Expression *const left, ir::E { auto *amended = GetAmendedChildExpression(right); + amended->SetParent(nullptr); // Next line overwrite parent auto *binaryExpr = AllocNode(left, amended, operatorType); binaryExpr->SetRange({left->Start(), amended->End()}); diff --git a/ets2panda/parser/parserImpl.cpp b/ets2panda/parser/parserImpl.cpp index 5f4d6b623c..00bd35c383 100644 --- a/ets2panda/parser/parserImpl.cpp +++ b/ets2panda/parser/parserImpl.cpp @@ -87,7 +87,6 @@ void ParserImpl::ParseProgram(ScriptKind kind) lexer::SourcePosition startLoc = lexer_->GetToken().Start(); lexer_->NextToken(); program_->SetKind(kind); - program_->VarBinder()->InitTopScope(); auto statements = ParseStatementList(StatementParsingFlags::STMT_GLOBAL_LEXICAL); @@ -945,13 +944,13 @@ ir::SpreadElement *ParserImpl::ParseSpreadElement(ExpressionParseFlags flags) return spreadElementNode; } -void ParserImpl::CheckRestrictedBinding() +void ParserImpl::CheckRestrictedBinding() const { ASSERT(lexer_->GetToken().Type() == lexer::TokenType::LITERAL_IDENT); CheckRestrictedBinding(lexer_->GetToken().KeywordType()); } -void ParserImpl::CheckRestrictedBinding(lexer::TokenType keywordType) +void ParserImpl::CheckRestrictedBinding(lexer::TokenType keywordType) const { if (keywordType == lexer::TokenType::KEYW_ARGUMENTS || keywordType == lexer::TokenType::KEYW_EVAL) { ThrowSyntaxError( @@ -961,7 +960,7 @@ void ParserImpl::CheckRestrictedBinding(lexer::TokenType keywordType) } } -void ParserImpl::CheckRestrictedBinding(const util::StringView &ident, const lexer::SourcePosition &pos) +void ParserImpl::CheckRestrictedBinding(const util::StringView &ident, const lexer::SourcePosition &pos) const { if (ident.Is("eval") || ident.Is("arguments")) { ThrowSyntaxError( diff --git a/ets2panda/parser/parserImpl.h b/ets2panda/parser/parserImpl.h index 7939cd0fcf..64760bba1b 100644 --- a/ets2panda/parser/parserImpl.h +++ b/ets2panda/parser/parserImpl.h @@ -30,6 +30,7 @@ #include "parser/program/program.h" #include "util/enumbitops.h" #include "util/ustring.h" +#include "util/helpers.h" #include #include @@ -199,6 +200,8 @@ public: return reinterpret_cast(this); } + [[noreturn]] void ThrowSyntaxError(std::string_view errorMessage, const lexer::SourcePosition &pos) const; + protected: virtual void ParseProgram(ScriptKind kind); static ExpressionParseFlags CarryExpressionParserFlag(ExpressionParseFlags origin, ExpressionParseFlags carry); @@ -277,25 +280,14 @@ protected: [[noreturn]] void ThrowSyntaxError(std::initializer_list list, const lexer::SourcePosition &pos) const; - [[noreturn]] void ThrowSyntaxError(std::string_view errorMessage, const lexer::SourcePosition &pos) const; - template - T *AllocNodeNoSetParent(Args &&...args) + T *AllocNode(Args &&...args) { - auto *ret = program_->Allocator()->New(std::forward(args)...); + auto *ret = util::NodeAllocator::ForceSetParent( + Allocator(), std::forward(args)...); // Note: replace with AllocNode if (ret == nullptr) { ThrowAllocationError("Unsuccessful allocation during parsing"); } - - return ret; - } - - template - T *AllocNode(Args &&...args) - { - auto *ret = AllocNodeNoSetParent(std::forward(args)...); - ret->Iterate([ret](auto *child) { child->SetParent(ret); }); - return ret; } @@ -306,6 +298,12 @@ protected: bool CheckModuleAsModifier(); + // ETS extension + virtual bool IsExternal() const + { + return false; + } + ir::Identifier *ExpectIdentifier(bool isReference = false, bool isUserDefinedType = false); void ExpectToken(lexer::TokenType tokenType, bool consumeToken = true); @@ -399,9 +397,9 @@ protected: ir::ExportNamedDeclaration *ParseExportNamedSpecifiers(const lexer::SourcePosition &startLoc); ir::Statement *ParseVariableDeclaration(VariableParsingFlags flags = VariableParsingFlags::NO_OPTS); void ValidateDeclaratorId(); - void CheckRestrictedBinding(); - void CheckRestrictedBinding(lexer::TokenType keywordType); - void CheckRestrictedBinding(const util::StringView &ident, const lexer::SourcePosition &pos); + void CheckRestrictedBinding() const; + void CheckRestrictedBinding(lexer::TokenType keywordType) const; + void CheckRestrictedBinding(const util::StringView &ident, const lexer::SourcePosition &pos) const; ir::VariableDeclarator *ParseVariableDeclarator(VariableParsingFlags flags); ir::FunctionDeclaration *ParseFunctionDeclaration(bool canBeAnonymous = false, diff --git a/ets2panda/parser/program/program.h b/ets2panda/parser/program/program.h index a289ac73b6..4f6f013d97 100644 --- a/ets2panda/parser/program/program.h +++ b/ets2panda/parser/program/program.h @@ -109,6 +109,11 @@ public: return sourceFileFolder_; } + std::string PackagePath() const + { + return SourceFileFolder().Mutf8() + panda::os::file::File::GetPathDelim().at(0) + GetPackageName().Mutf8(); + } + util::StringView ResolvedFilePath() const { return resolvedFilePath_; diff --git a/ets2panda/parser/statementParser.cpp b/ets2panda/parser/statementParser.cpp index e56be215f7..180ef5706f 100644 --- a/ets2panda/parser/statementParser.cpp +++ b/ets2panda/parser/statementParser.cpp @@ -268,7 +268,7 @@ ir::ETSStructDeclaration *ParserImpl::ParseStructDeclaration(ir::ClassDefinition { const lexer::SourcePosition startLoc = lexer_->GetToken().Start(); modifiers |= ir::ClassDefinitionModifiers::DECLARATION; - if ((GetContext().Status() & ParserStatus::IN_EXTERNAL) != 0) { + if (IsExternal()) { modifiers |= ir::ClassDefinitionModifiers::FROM_EXTERNAL; } @@ -292,7 +292,7 @@ ir::ClassDeclaration *ParserImpl::ParseClassDeclaration(ir::ClassDefinitionModif { const lexer::SourcePosition startLoc = lexer_->GetToken().Start(); modifiers |= ir::ClassDefinitionModifiers::DECLARATION; - if ((GetContext().Status() & ParserStatus::IN_EXTERNAL) != 0) { + if (IsExternal()) { modifiers |= ir::ClassDefinitionModifiers::FROM_EXTERNAL; } diff --git a/ets2panda/test/compiler/ets/FunctionType1-expected.txt b/ets2panda/test/compiler/ets/FunctionType1-expected.txt index eb64020f40..1350edd293 100644 --- a/ets2panda/test/compiler/ets/FunctionType1-expected.txt +++ b/ets2panda/test/compiler/ets/FunctionType1-expected.txt @@ -599,7 +599,7 @@ }, "end": { "line": 16, - "column": 35 + "column": 9 } } }, diff --git a/ets2panda/test/compiler/ets/FunctionType2-expected.txt b/ets2panda/test/compiler/ets/FunctionType2-expected.txt index 1dcaa7ce18..bc1ed8f6d6 100644 --- a/ets2panda/test/compiler/ets/FunctionType2-expected.txt +++ b/ets2panda/test/compiler/ets/FunctionType2-expected.txt @@ -258,7 +258,7 @@ }, "end": { "line": 16, - "column": 37 + "column": 9 } } }, diff --git a/ets2panda/test/compiler/ets/FunctionType3-expected.txt b/ets2panda/test/compiler/ets/FunctionType3-expected.txt index bbb4c6e27b..790eb2a096 100644 --- a/ets2panda/test/compiler/ets/FunctionType3-expected.txt +++ b/ets2panda/test/compiler/ets/FunctionType3-expected.txt @@ -286,7 +286,7 @@ }, "end": { "line": 16, - "column": 36 + "column": 9 } } }, diff --git a/ets2panda/test/compiler/ets/FunctionType4-expected.txt b/ets2panda/test/compiler/ets/FunctionType4-expected.txt index 8927a88069..13c0c3fbd0 100644 --- a/ets2panda/test/compiler/ets/FunctionType4-expected.txt +++ b/ets2panda/test/compiler/ets/FunctionType4-expected.txt @@ -119,11 +119,11 @@ "loc": { "start": { "line": 20, - "column": 1 + "column": 5 }, "end": { "line": 20, - "column": 25 + "column": 24 } } } @@ -505,7 +505,7 @@ "loc": { "start": { "line": 22, - "column": 14 + "column": 13 }, "end": { "line": 24, @@ -516,7 +516,7 @@ "loc": { "start": { "line": 22, - "column": 14 + "column": 13 }, "end": { "line": 24, diff --git a/ets2panda/test/compiler/ets/FunctionType5-expected.txt b/ets2panda/test/compiler/ets/FunctionType5-expected.txt index c6c23c17de..1a02058a93 100644 --- a/ets2panda/test/compiler/ets/FunctionType5-expected.txt +++ b/ets2panda/test/compiler/ets/FunctionType5-expected.txt @@ -119,11 +119,11 @@ "loc": { "start": { "line": 20, - "column": 1 + "column": 5 }, "end": { "line": 20, - "column": 14 + "column": 13 } } } diff --git a/ets2panda/test/compiler/ets/array_indexing_with_chaining_non_nullish-expected.txt b/ets2panda/test/compiler/ets/array_indexing_with_chaining_non_nullish-expected.txt index f0c0cc7404..095a52a35d 100644 --- a/ets2panda/test/compiler/ets/array_indexing_with_chaining_non_nullish-expected.txt +++ b/ets2panda/test/compiler/ets/array_indexing_with_chaining_non_nullish-expected.txt @@ -366,11 +366,11 @@ "loc": { "start": { "line": 18, - "column": 1 + "column": 5 }, "end": { "line": 18, - "column": 46 + "column": 45 } } }, @@ -452,11 +452,11 @@ "loc": { "start": { "line": 19, - "column": 1 + "column": 5 }, "end": { "line": 19, - "column": 42 + "column": 41 } } } @@ -593,7 +593,7 @@ }, "end": { "line": 18, - "column": 21 + "column": 45 } } }, @@ -670,7 +670,7 @@ }, "end": { "line": 19, - "column": 20 + "column": 41 } } } diff --git a/ets2panda/test/compiler/ets/array_indexing_with_chaining_nullish-expected.txt b/ets2panda/test/compiler/ets/array_indexing_with_chaining_nullish-expected.txt index d57bb4ddb5..391b654d2e 100644 --- a/ets2panda/test/compiler/ets/array_indexing_with_chaining_nullish-expected.txt +++ b/ets2panda/test/compiler/ets/array_indexing_with_chaining_nullish-expected.txt @@ -366,11 +366,11 @@ "loc": { "start": { "line": 18, - "column": 1 + "column": 5 }, "end": { "line": 18, - "column": 53 + "column": 52 } } }, @@ -452,11 +452,11 @@ "loc": { "start": { "line": 19, - "column": 1 + "column": 5 }, "end": { "line": 19, - "column": 42 + "column": 41 } } } @@ -593,7 +593,7 @@ }, "end": { "line": 18, - "column": 21 + "column": 52 } } }, @@ -670,7 +670,7 @@ }, "end": { "line": 19, - "column": 20 + "column": 41 } } } diff --git a/ets2panda/test/compiler/ets/array_indexing_without_chaining_non_nullish-expected.txt b/ets2panda/test/compiler/ets/array_indexing_without_chaining_non_nullish-expected.txt index f66a8a148e..e3d9e2b92f 100644 --- a/ets2panda/test/compiler/ets/array_indexing_without_chaining_non_nullish-expected.txt +++ b/ets2panda/test/compiler/ets/array_indexing_without_chaining_non_nullish-expected.txt @@ -366,11 +366,11 @@ "loc": { "start": { "line": 18, - "column": 1 + "column": 5 }, "end": { "line": 18, - "column": 46 + "column": 45 } } }, @@ -452,11 +452,11 @@ "loc": { "start": { "line": 19, - "column": 1 + "column": 5 }, "end": { "line": 19, - "column": 28 + "column": 27 } } } @@ -593,7 +593,7 @@ }, "end": { "line": 18, - "column": 21 + "column": 45 } } }, @@ -670,7 +670,7 @@ }, "end": { "line": 19, - "column": 20 + "column": 27 } } } diff --git a/ets2panda/test/compiler/ets/array_indexing_without_chaining_nullish-expected.txt b/ets2panda/test/compiler/ets/array_indexing_without_chaining_nullish-expected.txt index 771737bbd8..356739d3d5 100644 --- a/ets2panda/test/compiler/ets/array_indexing_without_chaining_nullish-expected.txt +++ b/ets2panda/test/compiler/ets/array_indexing_without_chaining_nullish-expected.txt @@ -366,11 +366,11 @@ "loc": { "start": { "line": 18, - "column": 1 + "column": 5 }, "end": { "line": 18, - "column": 53 + "column": 52 } } }, @@ -452,11 +452,11 @@ "loc": { "start": { "line": 19, - "column": 1 + "column": 5 }, "end": { "line": 19, - "column": 40 + "column": 39 } } } @@ -593,7 +593,7 @@ }, "end": { "line": 18, - "column": 21 + "column": 52 } } }, @@ -670,7 +670,7 @@ }, "end": { "line": 19, - "column": 20 + "column": 39 } } } diff --git a/ets2panda/test/compiler/ets/etsObjectToString4-expected.txt b/ets2panda/test/compiler/ets/etsObjectToString4-expected.txt index a92c603283..062a9fc0e7 100644 --- a/ets2panda/test/compiler/ets/etsObjectToString4-expected.txt +++ b/ets2panda/test/compiler/ets/etsObjectToString4-expected.txt @@ -298,11 +298,11 @@ "loc": { "start": { "line": 18, - "column": 1 + "column": 5 }, "end": { "line": 18, - "column": 31 + "column": 30 } } } diff --git a/ets2panda/test/compiler/ets/identifierReference2-expected.txt b/ets2panda/test/compiler/ets/identifierReference2-expected.txt index c0fb2875ea..3767a0035e 100644 --- a/ets2panda/test/compiler/ets/identifierReference2-expected.txt +++ b/ets2panda/test/compiler/ets/identifierReference2-expected.txt @@ -119,11 +119,11 @@ "loc": { "start": { "line": 16, - "column": 1 + "column": 5 }, "end": { "line": 16, - "column": 38 + "column": 37 } } } diff --git a/ets2panda/test/compiler/ets/identifierReference3-expected.txt b/ets2panda/test/compiler/ets/identifierReference3-expected.txt index f5c375d18a..a3d2d178bc 100644 --- a/ets2panda/test/compiler/ets/identifierReference3-expected.txt +++ b/ets2panda/test/compiler/ets/identifierReference3-expected.txt @@ -447,11 +447,11 @@ "loc": { "start": { "line": 16, - "column": 1 + "column": 5 }, "end": { "line": 16, - "column": 16 + "column": 15 } } } @@ -547,7 +547,7 @@ }, "end": { "line": 16, - "column": 11 + "column": 15 } } } diff --git a/ets2panda/test/compiler/ets/identifierReference4-expected.txt b/ets2panda/test/compiler/ets/identifierReference4-expected.txt index beb0f9de57..a1c5b3b57d 100644 --- a/ets2panda/test/compiler/ets/identifierReference4-expected.txt +++ b/ets2panda/test/compiler/ets/identifierReference4-expected.txt @@ -701,11 +701,11 @@ "loc": { "start": { "line": 16, - "column": 1 + "column": 5 }, "end": { "line": 16, - "column": 17 + "column": 16 } } } @@ -801,7 +801,7 @@ }, "end": { "line": 16, - "column": 11 + "column": 16 } } } diff --git a/ets2panda/test/compiler/ets/inferTypeOfArray-expected.txt b/ets2panda/test/compiler/ets/inferTypeOfArray-expected.txt index ed3c6dd87d..bd192ee2e3 100644 --- a/ets2panda/test/compiler/ets/inferTypeOfArray-expected.txt +++ b/ets2panda/test/compiler/ets/inferTypeOfArray-expected.txt @@ -118,7 +118,7 @@ "loc": { "start": { "line": 16, - "column": 1 + "column": 5 }, "end": { "line": 16, @@ -174,7 +174,7 @@ "loc": { "start": { "line": 17, - "column": 1 + "column": 5 }, "end": { "line": 17, @@ -245,7 +245,7 @@ "loc": { "start": { "line": 18, - "column": 1 + "column": 5 }, "end": { "line": 18, @@ -344,7 +344,7 @@ "loc": { "start": { "line": 19, - "column": 1 + "column": 5 }, "end": { "line": 19, @@ -513,7 +513,7 @@ "loc": { "start": { "line": 20, - "column": 1 + "column": 5 }, "end": { "line": 20, @@ -569,7 +569,7 @@ "loc": { "start": { "line": 21, - "column": 1 + "column": 5 }, "end": { "line": 21, @@ -683,7 +683,7 @@ "loc": { "start": { "line": 22, - "column": 1 + "column": 5 }, "end": { "line": 22, diff --git a/ets2panda/test/compiler/ets/inferTypeOfArrayNegative1-expected.txt b/ets2panda/test/compiler/ets/inferTypeOfArrayNegative1-expected.txt index 8f6bb0ae1d..7d12e35a6e 100644 --- a/ets2panda/test/compiler/ets/inferTypeOfArrayNegative1-expected.txt +++ b/ets2panda/test/compiler/ets/inferTypeOfArrayNegative1-expected.txt @@ -161,7 +161,7 @@ "loc": { "start": { "line": 16, - "column": 1 + "column": 5 }, "end": { "line": 16, diff --git a/ets2panda/test/compiler/ets/inferTypeOfArrayNegative2-expected.txt b/ets2panda/test/compiler/ets/inferTypeOfArrayNegative2-expected.txt index be6fbf6957..35a019dc88 100644 --- a/ets2panda/test/compiler/ets/inferTypeOfArrayNegative2-expected.txt +++ b/ets2panda/test/compiler/ets/inferTypeOfArrayNegative2-expected.txt @@ -118,7 +118,7 @@ "loc": { "start": { "line": 16, - "column": 1 + "column": 5 }, "end": { "line": 16, @@ -432,7 +432,7 @@ "loc": { "start": { "line": 19, - "column": 1 + "column": 5 }, "end": { "line": 19, diff --git a/ets2panda/test/compiler/ets/inferTypeOfArrayNegative3-expected.txt b/ets2panda/test/compiler/ets/inferTypeOfArrayNegative3-expected.txt index 50c685879a..054d89e7f5 100644 --- a/ets2panda/test/compiler/ets/inferTypeOfArrayNegative3-expected.txt +++ b/ets2panda/test/compiler/ets/inferTypeOfArrayNegative3-expected.txt @@ -161,7 +161,7 @@ "loc": { "start": { "line": 16, - "column": 1 + "column": 5 }, "end": { "line": 16, diff --git a/ets2panda/test/compiler/ets/lambdaFunction1-expected.txt b/ets2panda/test/compiler/ets/lambdaFunction1-expected.txt index 132a58cca8..61642d4c3b 100644 --- a/ets2panda/test/compiler/ets/lambdaFunction1-expected.txt +++ b/ets2panda/test/compiler/ets/lambdaFunction1-expected.txt @@ -795,11 +795,11 @@ "loc": { "start": { "line": 16, - "column": 1 + "column": 5 }, "end": { "line": 16, - "column": 16 + "column": 15 } } } @@ -895,7 +895,7 @@ }, "end": { "line": 16, - "column": 11 + "column": 15 } } }, diff --git a/ets2panda/test/compiler/ets/lambda_infer_type/lambda_cast_infer_type_void-expected.txt b/ets2panda/test/compiler/ets/lambda_infer_type/lambda_cast_infer_type_void-expected.txt index 66623064bb..0c0b964786 100644 --- a/ets2panda/test/compiler/ets/lambda_infer_type/lambda_cast_infer_type_void-expected.txt +++ b/ets2panda/test/compiler/ets/lambda_infer_type/lambda_cast_infer_type_void-expected.txt @@ -450,7 +450,7 @@ "loc": { "start": { "line": 16, - "column": 15 + "column": 14 }, "end": { "line": 19, @@ -461,7 +461,7 @@ "loc": { "start": { "line": 16, - "column": 15 + "column": 14 }, "end": { "line": 19, diff --git a/ets2panda/test/compiler/ets/lambda_infer_type/lambda_cast_type_has_pramas-expected.txt b/ets2panda/test/compiler/ets/lambda_infer_type/lambda_cast_type_has_pramas-expected.txt index 0d17b84dd6..27ff957b76 100644 --- a/ets2panda/test/compiler/ets/lambda_infer_type/lambda_cast_type_has_pramas-expected.txt +++ b/ets2panda/test/compiler/ets/lambda_infer_type/lambda_cast_type_has_pramas-expected.txt @@ -688,7 +688,7 @@ "loc": { "start": { "line": 16, - "column": 15 + "column": 14 }, "end": { "line": 19, @@ -699,7 +699,7 @@ "loc": { "start": { "line": 16, - "column": 15 + "column": 14 }, "end": { "line": 19, diff --git a/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_retrun_enum-expected.txt b/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_retrun_enum-expected.txt index ae8e7882a3..18ef5aa299 100644 --- a/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_retrun_enum-expected.txt +++ b/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_retrun_enum-expected.txt @@ -656,7 +656,7 @@ "loc": { "start": { "line": 17, - "column": 15 + "column": 14 }, "end": { "line": 23, @@ -667,7 +667,7 @@ "loc": { "start": { "line": 17, - "column": 15 + "column": 14 }, "end": { "line": 23, diff --git a/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_return_array-expected.txt b/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_return_array-expected.txt index a333dff5f0..a3aa7c7921 100644 --- a/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_return_array-expected.txt +++ b/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_return_array-expected.txt @@ -579,7 +579,7 @@ "loc": { "start": { "line": 16, - "column": 15 + "column": 14 }, "end": { "line": 20, @@ -590,7 +590,7 @@ "loc": { "start": { "line": 16, - "column": 15 + "column": 14 }, "end": { "line": 20, diff --git a/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_return_lambda_expression-expected.txt b/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_return_lambda_expression-expected.txt index 2237eae3ae..fea46aa2f9 100644 --- a/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_return_lambda_expression-expected.txt +++ b/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_return_lambda_expression-expected.txt @@ -134,7 +134,7 @@ "loc": { "start": { "line": 23, - "column": 1 + "column": 5 }, "end": { "line": 23, @@ -369,7 +369,7 @@ "loc": { "start": { "line": 16, - "column": 16 + "column": 15 }, "end": { "line": 22, @@ -380,7 +380,7 @@ "loc": { "start": { "line": 16, - "column": 16 + "column": 15 }, "end": { "line": 22, diff --git a/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_return_literal-expected.txt b/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_return_literal-expected.txt index 84d4b48482..904969d645 100644 --- a/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_return_literal-expected.txt +++ b/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_return_literal-expected.txt @@ -410,7 +410,7 @@ "loc": { "start": { "line": 16, - "column": 15 + "column": 14 }, "end": { "line": 21, @@ -421,7 +421,7 @@ "loc": { "start": { "line": 16, - "column": 15 + "column": 14 }, "end": { "line": 21, diff --git a/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_return_union-expected.txt b/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_return_union-expected.txt index 191ba526c8..0a5f2826a7 100644 --- a/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_return_union-expected.txt +++ b/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_return_union-expected.txt @@ -622,7 +622,7 @@ "loc": { "start": { "line": 16, - "column": 15 + "column": 14 }, "end": { "line": 22, @@ -633,7 +633,7 @@ "loc": { "start": { "line": 16, - "column": 15 + "column": 14 }, "end": { "line": 22, diff --git a/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_scope-expected.txt b/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_scope-expected.txt index 1034ff0fdf..a5cc56b6ac 100644 --- a/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_scope-expected.txt +++ b/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_scope-expected.txt @@ -118,11 +118,11 @@ "loc": { "start": { "line": 16, - "column": 1 + "column": 5 }, "end": { "line": 16, - "column": 11 + "column": 10 } } } @@ -554,7 +554,7 @@ "loc": { "start": { "line": 18, - "column": 15 + "column": 14 }, "end": { "line": 20, @@ -565,7 +565,7 @@ "loc": { "start": { "line": 18, - "column": 15 + "column": 14 }, "end": { "line": 20, diff --git a/ets2panda/test/compiler/ets/launch_expression-expected.txt b/ets2panda/test/compiler/ets/launch_expression-expected.txt index e0578ae161..b96b8b3e39 100644 --- a/ets2panda/test/compiler/ets/launch_expression-expected.txt +++ b/ets2panda/test/compiler/ets/launch_expression-expected.txt @@ -243,7 +243,7 @@ "loc": { "start": { "line": 16, - "column": 1 + "column": 5 }, "end": { "line": 16, @@ -299,7 +299,7 @@ "loc": { "start": { "line": 17, - "column": 1 + "column": 5 }, "end": { "line": 17, @@ -382,11 +382,11 @@ "loc": { "start": { "line": 18, - "column": 1 + "column": 5 }, "end": { "line": 18, - "column": 31 + "column": 30 } } }, @@ -465,11 +465,11 @@ "loc": { "start": { "line": 19, - "column": 1 + "column": 5 }, "end": { "line": 19, - "column": 31 + "column": 30 } } } @@ -678,7 +678,7 @@ }, "end": { "line": 18, - "column": 15 + "column": 30 } } }, @@ -740,7 +740,7 @@ }, "end": { "line": 19, - "column": 15 + "column": 30 } } }, diff --git a/ets2panda/test/compiler/ets/objectLiteralAbstract-expected.txt b/ets2panda/test/compiler/ets/objectLiteralAbstract-expected.txt index e4799e206c..5db12240c7 100644 --- a/ets2panda/test/compiler/ets/objectLiteralAbstract-expected.txt +++ b/ets2panda/test/compiler/ets/objectLiteralAbstract-expected.txt @@ -255,11 +255,11 @@ "loc": { "start": { "line": 18, - "column": 1 + "column": 5 }, "end": { "line": 18, - "column": 15 + "column": 14 } } } @@ -383,7 +383,7 @@ }, "end": { "line": 18, - "column": 11 + "column": 14 } } } diff --git a/ets2panda/test/compiler/ets/objectLiteralBadKey-expected.txt b/ets2panda/test/compiler/ets/objectLiteralBadKey-expected.txt index 37364fa25b..939b83aee6 100644 --- a/ets2panda/test/compiler/ets/objectLiteralBadKey-expected.txt +++ b/ets2panda/test/compiler/ets/objectLiteralBadKey-expected.txt @@ -301,11 +301,11 @@ "loc": { "start": { "line": 19, - "column": 1 + "column": 5 }, "end": { "line": 21, - "column": 3 + "column": 2 } } } @@ -428,8 +428,8 @@ "column": 5 }, "end": { - "line": 19, - "column": 11 + "line": 21, + "column": 2 } } } diff --git a/ets2panda/test/compiler/ets/objectLiteralInaccessibleKey-expected.txt b/ets2panda/test/compiler/ets/objectLiteralInaccessibleKey-expected.txt index 7d776f219a..169a5fc028 100644 --- a/ets2panda/test/compiler/ets/objectLiteralInaccessibleKey-expected.txt +++ b/ets2panda/test/compiler/ets/objectLiteralInaccessibleKey-expected.txt @@ -351,11 +351,11 @@ "loc": { "start": { "line": 20, - "column": 1 + "column": 5 }, "end": { "line": 22, - "column": 3 + "column": 2 } } } @@ -478,8 +478,8 @@ "column": 5 }, "end": { - "line": 20, - "column": 11 + "line": 22, + "column": 2 } } } diff --git a/ets2panda/test/compiler/ets/objectLiteralInterface-expected.txt b/ets2panda/test/compiler/ets/objectLiteralInterface-expected.txt index 368098ad83..5cd0f4bddf 100644 --- a/ets2panda/test/compiler/ets/objectLiteralInterface-expected.txt +++ b/ets2panda/test/compiler/ets/objectLiteralInterface-expected.txt @@ -161,11 +161,11 @@ "loc": { "start": { "line": 18, - "column": 1 + "column": 5 }, "end": { "line": 18, - "column": 15 + "column": 14 } } } @@ -289,7 +289,7 @@ }, "end": { "line": 18, - "column": 11 + "column": 14 } } } diff --git a/ets2panda/test/compiler/ets/objectLiteralNoContextType-expected.txt b/ets2panda/test/compiler/ets/objectLiteralNoContextType-expected.txt index ef22164be0..1d661df1c8 100644 --- a/ets2panda/test/compiler/ets/objectLiteralNoContextType-expected.txt +++ b/ets2panda/test/compiler/ets/objectLiteralNoContextType-expected.txt @@ -118,11 +118,11 @@ "loc": { "start": { "line": 16, - "column": 1 + "column": 5 }, "end": { "line": 16, - "column": 12 + "column": 11 } } } diff --git a/ets2panda/test/compiler/ets/objectLiteralNoParameterlessConstructor-expected.txt b/ets2panda/test/compiler/ets/objectLiteralNoParameterlessConstructor-expected.txt index 365d537e22..4ca426fbcd 100644 --- a/ets2panda/test/compiler/ets/objectLiteralNoParameterlessConstructor-expected.txt +++ b/ets2panda/test/compiler/ets/objectLiteralNoParameterlessConstructor-expected.txt @@ -298,11 +298,11 @@ "loc": { "start": { "line": 20, - "column": 1 + "column": 5 }, "end": { "line": 20, - "column": 15 + "column": 14 } } } @@ -426,7 +426,7 @@ }, "end": { "line": 20, - "column": 11 + "column": 14 } } } diff --git a/ets2panda/test/compiler/ets/objectLiteralNoSuchKey-expected.txt b/ets2panda/test/compiler/ets/objectLiteralNoSuchKey-expected.txt index d7eb3607ec..5af2594c5c 100644 --- a/ets2panda/test/compiler/ets/objectLiteralNoSuchKey-expected.txt +++ b/ets2panda/test/compiler/ets/objectLiteralNoSuchKey-expected.txt @@ -302,11 +302,11 @@ "loc": { "start": { "line": 19, - "column": 1 + "column": 5 }, "end": { "line": 21, - "column": 3 + "column": 2 } } } @@ -429,8 +429,8 @@ "column": 5 }, "end": { - "line": 19, - "column": 11 + "line": 21, + "column": 2 } } } diff --git a/ets2panda/test/compiler/ets/objectLiteralPrimitiveContextType-expected.txt b/ets2panda/test/compiler/ets/objectLiteralPrimitiveContextType-expected.txt index d4c28c364b..6113219ccd 100644 --- a/ets2panda/test/compiler/ets/objectLiteralPrimitiveContextType-expected.txt +++ b/ets2panda/test/compiler/ets/objectLiteralPrimitiveContextType-expected.txt @@ -118,11 +118,11 @@ "loc": { "start": { "line": 16, - "column": 1 + "column": 5 }, "end": { "line": 16, - "column": 17 + "column": 16 } } } @@ -218,7 +218,7 @@ }, "end": { "line": 16, - "column": 11 + "column": 16 } } } diff --git a/ets2panda/test/compiler/ets/objectLiteralPrivateConstructor-expected.txt b/ets2panda/test/compiler/ets/objectLiteralPrivateConstructor-expected.txt index 65af224bc8..47d07f348f 100644 --- a/ets2panda/test/compiler/ets/objectLiteralPrivateConstructor-expected.txt +++ b/ets2panda/test/compiler/ets/objectLiteralPrivateConstructor-expected.txt @@ -256,11 +256,11 @@ "loc": { "start": { "line": 20, - "column": 1 + "column": 5 }, "end": { "line": 20, - "column": 15 + "column": 14 } } } @@ -384,7 +384,7 @@ }, "end": { "line": 20, - "column": 11 + "column": 14 } } } diff --git a/ets2panda/test/compiler/ets/objectLiteralReadonlyKey-expected.txt b/ets2panda/test/compiler/ets/objectLiteralReadonlyKey-expected.txt index 277e55a111..b919165f8e 100644 --- a/ets2panda/test/compiler/ets/objectLiteralReadonlyKey-expected.txt +++ b/ets2panda/test/compiler/ets/objectLiteralReadonlyKey-expected.txt @@ -351,11 +351,11 @@ "loc": { "start": { "line": 20, - "column": 1 + "column": 5 }, "end": { "line": 22, - "column": 3 + "column": 2 } } } @@ -478,8 +478,8 @@ "column": 5 }, "end": { - "line": 20, - "column": 11 + "line": 22, + "column": 2 } } } diff --git a/ets2panda/test/compiler/ets/objectLiteralWrongValueType-expected.txt b/ets2panda/test/compiler/ets/objectLiteralWrongValueType-expected.txt index ba7bf8cb40..e741bd36d0 100644 --- a/ets2panda/test/compiler/ets/objectLiteralWrongValueType-expected.txt +++ b/ets2panda/test/compiler/ets/objectLiteralWrongValueType-expected.txt @@ -351,11 +351,11 @@ "loc": { "start": { "line": 20, - "column": 1 + "column": 5 }, "end": { "line": 22, - "column": 3 + "column": 2 } } } @@ -478,8 +478,8 @@ "column": 5 }, "end": { - "line": 20, - "column": 11 + "line": 22, + "column": 2 } } } diff --git a/ets2panda/test/compiler/ets/throwingFunctionCheck1-expected.txt b/ets2panda/test/compiler/ets/throwingFunctionCheck1-expected.txt index 14b1a16a40..ec00b6e667 100644 --- a/ets2panda/test/compiler/ets/throwingFunctionCheck1-expected.txt +++ b/ets2panda/test/compiler/ets/throwingFunctionCheck1-expected.txt @@ -134,11 +134,11 @@ "loc": { "start": { "line": 18, - "column": 1 + "column": 5 }, "end": { "line": 18, - "column": 28 + "column": 27 } } } diff --git a/ets2panda/test/compiler/ets/typeAlias-expected.txt b/ets2panda/test/compiler/ets/typeAlias-expected.txt index 4f17d69d03..2f9467386e 100644 --- a/ets2panda/test/compiler/ets/typeAlias-expected.txt +++ b/ets2panda/test/compiler/ets/typeAlias-expected.txt @@ -179,11 +179,11 @@ "loc": { "start": { "line": 17, - "column": 1 + "column": 5 }, "end": { "line": 17, - "column": 29 + "column": 28 } } } diff --git a/ets2panda/test/parser/ets/Dollar_dollar_1-expected.txt b/ets2panda/test/parser/ets/Dollar_dollar_1-expected.txt index b50e9e4867..e3d9bb2699 100644 --- a/ets2panda/test/parser/ets/Dollar_dollar_1-expected.txt +++ b/ets2panda/test/parser/ets/Dollar_dollar_1-expected.txt @@ -133,7 +133,7 @@ "loc": { "start": { "line": 16, - "column": 1 + "column": 5 }, "end": { "line": 16, diff --git a/ets2panda/test/parser/ets/Dollar_dollar_3-expected.txt b/ets2panda/test/parser/ets/Dollar_dollar_3-expected.txt index f981e5c354..d4d7953e1d 100644 --- a/ets2panda/test/parser/ets/Dollar_dollar_3-expected.txt +++ b/ets2panda/test/parser/ets/Dollar_dollar_3-expected.txt @@ -296,7 +296,7 @@ "loc": { "start": { "line": 17, - "column": 1 + "column": 5 }, "end": { "line": 18, @@ -368,7 +368,7 @@ "loc": { "start": { "line": 18, - "column": 1 + "column": 5 }, "end": { "line": 18, diff --git a/ets2panda/test/parser/ets/Dollar_dollar_4-expected.txt b/ets2panda/test/parser/ets/Dollar_dollar_4-expected.txt index f38a7fdcff..ad15034d81 100644 --- a/ets2panda/test/parser/ets/Dollar_dollar_4-expected.txt +++ b/ets2panda/test/parser/ets/Dollar_dollar_4-expected.txt @@ -118,7 +118,7 @@ "loc": { "start": { "line": 16, - "column": 1 + "column": 5 }, "end": { "line": 16, diff --git a/ets2panda/test/parser/ets/FunctionType-expected.txt b/ets2panda/test/parser/ets/FunctionType-expected.txt index 051ecf2aa9..dc021dada9 100644 --- a/ets2panda/test/parser/ets/FunctionType-expected.txt +++ b/ets2panda/test/parser/ets/FunctionType-expected.txt @@ -569,7 +569,7 @@ }, "end": { "line": 16, - "column": 32 + "column": 6 } } }, @@ -674,7 +674,7 @@ }, "end": { "line": 17, - "column": 26 + "column": 6 } } }, diff --git a/ets2panda/test/parser/ets/ambiguous_call_1-expected.txt b/ets2panda/test/parser/ets/ambiguous_call_1-expected.txt index 6c87709fc0..1484280686 100644 --- a/ets2panda/test/parser/ets/ambiguous_call_1-expected.txt +++ b/ets2panda/test/parser/ets/ambiguous_call_1-expected.txt @@ -621,7 +621,7 @@ "loc": { "start": { "line": 16, - "column": 14 + "column": 13 }, "end": { "line": 16, @@ -632,7 +632,7 @@ "loc": { "start": { "line": 16, - "column": 14 + "column": 13 }, "end": { "line": 16, @@ -814,7 +814,7 @@ "loc": { "start": { "line": 17, - "column": 14 + "column": 13 }, "end": { "line": 17, @@ -825,7 +825,7 @@ "loc": { "start": { "line": 17, - "column": 14 + "column": 13 }, "end": { "line": 17, @@ -1062,7 +1062,7 @@ "loc": { "start": { "line": 22, - "column": 15 + "column": 14 }, "end": { "line": 24, @@ -1073,7 +1073,7 @@ "loc": { "start": { "line": 22, - "column": 15 + "column": 14 }, "end": { "line": 24, diff --git a/ets2panda/test/parser/ets/ambiguous_call_2-expected.txt b/ets2panda/test/parser/ets/ambiguous_call_2-expected.txt index 6fb45ac9a5..d6d64da7f5 100644 --- a/ets2panda/test/parser/ets/ambiguous_call_2-expected.txt +++ b/ets2panda/test/parser/ets/ambiguous_call_2-expected.txt @@ -1022,7 +1022,7 @@ "loc": { "start": { "line": 16, - "column": 14 + "column": 13 }, "end": { "line": 16, @@ -1033,7 +1033,7 @@ "loc": { "start": { "line": 16, - "column": 14 + "column": 13 }, "end": { "line": 16, @@ -1325,7 +1325,7 @@ "loc": { "start": { "line": 17, - "column": 14 + "column": 13 }, "end": { "line": 17, @@ -1336,7 +1336,7 @@ "loc": { "start": { "line": 17, - "column": 14 + "column": 13 }, "end": { "line": 17, @@ -1640,7 +1640,7 @@ "loc": { "start": { "line": 18, - "column": 14 + "column": 13 }, "end": { "line": 18, @@ -1651,7 +1651,7 @@ "loc": { "start": { "line": 18, - "column": 14 + "column": 13 }, "end": { "line": 18, @@ -1916,7 +1916,7 @@ "loc": { "start": { "line": 26, - "column": 15 + "column": 14 }, "end": { "line": 28, @@ -1927,7 +1927,7 @@ "loc": { "start": { "line": 26, - "column": 15 + "column": 14 }, "end": { "line": 28, diff --git a/ets2panda/test/parser/ets/ambiguous_call_3-expected.txt b/ets2panda/test/parser/ets/ambiguous_call_3-expected.txt index eaca9b0b5c..b037238447 100644 --- a/ets2panda/test/parser/ets/ambiguous_call_3-expected.txt +++ b/ets2panda/test/parser/ets/ambiguous_call_3-expected.txt @@ -701,7 +701,7 @@ "loc": { "start": { "line": 16, - "column": 14 + "column": 13 }, "end": { "line": 16, @@ -712,7 +712,7 @@ "loc": { "start": { "line": 16, - "column": 14 + "column": 13 }, "end": { "line": 16, @@ -894,7 +894,7 @@ "loc": { "start": { "line": 17, - "column": 14 + "column": 13 }, "end": { "line": 17, @@ -905,7 +905,7 @@ "loc": { "start": { "line": 17, - "column": 14 + "column": 13 }, "end": { "line": 17, @@ -1142,7 +1142,7 @@ "loc": { "start": { "line": 22, - "column": 15 + "column": 14 }, "end": { "line": 24, @@ -1153,7 +1153,7 @@ "loc": { "start": { "line": 22, - "column": 15 + "column": 14 }, "end": { "line": 24, diff --git a/ets2panda/test/parser/ets/array-expected.txt b/ets2panda/test/parser/ets/array-expected.txt index 94a5bd22f3..3a3d657a17 100644 --- a/ets2panda/test/parser/ets/array-expected.txt +++ b/ets2panda/test/parser/ets/array-expected.txt @@ -161,11 +161,11 @@ "loc": { "start": { "line": 16, - "column": 1 + "column": 5 }, "end": { "line": 16, - "column": 24 + "column": 23 } } }, @@ -260,11 +260,11 @@ "loc": { "start": { "line": 17, - "column": 1 + "column": 5 }, "end": { "line": 17, - "column": 35 + "column": 34 } } } @@ -373,7 +373,7 @@ }, "end": { "line": 16, - "column": 15 + "column": 23 } } }, @@ -463,7 +463,7 @@ }, "end": { "line": 17, - "column": 18 + "column": 34 } } }, diff --git a/ets2panda/test/parser/ets/arrayHoldingNullValue-expected.txt b/ets2panda/test/parser/ets/arrayHoldingNullValue-expected.txt index d9ff0c65bc..7a2d431eb4 100644 --- a/ets2panda/test/parser/ets/arrayHoldingNullValue-expected.txt +++ b/ets2panda/test/parser/ets/arrayHoldingNullValue-expected.txt @@ -118,11 +118,11 @@ "loc": { "start": { "line": 16, - "column": 1 + "column": 5 }, "end": { "line": 16, - "column": 28 + "column": 27 } } }, @@ -174,11 +174,11 @@ "loc": { "start": { "line": 17, - "column": 1 + "column": 5 }, "end": { "line": 17, - "column": 31 + "column": 30 } } }, @@ -230,11 +230,11 @@ "loc": { "start": { "line": 18, - "column": 1 + "column": 5 }, "end": { "line": 18, - "column": 31 + "column": 30 } } } @@ -343,7 +343,7 @@ }, "end": { "line": 16, - "column": 15 + "column": 27 } } }, @@ -405,7 +405,7 @@ }, "end": { "line": 17, - "column": 18 + "column": 30 } } }, @@ -495,7 +495,7 @@ }, "end": { "line": 18, - "column": 18 + "column": 30 } } }, diff --git a/ets2panda/test/parser/ets/assign-expected.txt b/ets2panda/test/parser/ets/assign-expected.txt index 89ce3dbfca..1ee8a063a2 100644 --- a/ets2panda/test/parser/ets/assign-expected.txt +++ b/ets2panda/test/parser/ets/assign-expected.txt @@ -118,11 +118,11 @@ "loc": { "start": { "line": 16, - "column": 1 + "column": 5 }, "end": { "line": 16, - "column": 11 + "column": 10 } } } diff --git a/ets2panda/test/parser/ets/async_function_bad-expected.txt b/ets2panda/test/parser/ets/async_function_bad-expected.txt index 2e3d432ead..a993bdde6d 100644 --- a/ets2panda/test/parser/ets/async_function_bad-expected.txt +++ b/ets2panda/test/parser/ets/async_function_bad-expected.txt @@ -1 +1 @@ -SyntaxError: 'async' flags must be used for functions at top-level. [async_function_bad.ets:16:7] +SyntaxError: 'async' flags must be used for functions only at top-level. [async_function_bad.ets:16:7] diff --git a/ets2panda/test/parser/ets/async_with_lambda-expected.txt b/ets2panda/test/parser/ets/async_with_lambda-expected.txt index 657afa1714..5fa0aaafbb 100644 --- a/ets2panda/test/parser/ets/async_with_lambda-expected.txt +++ b/ets2panda/test/parser/ets/async_with_lambda-expected.txt @@ -161,7 +161,7 @@ }, "end": { "line": 16, - "column": 16 + "column": 11 } } }, diff --git a/ets2panda/test/parser/ets/await_keyword-expected.txt b/ets2panda/test/parser/ets/await_keyword-expected.txt index 2159d4df66..8eb07173bd 100644 --- a/ets2panda/test/parser/ets/await_keyword-expected.txt +++ b/ets2panda/test/parser/ets/await_keyword-expected.txt @@ -118,11 +118,11 @@ "loc": { "start": { "line": 38, - "column": 1 + "column": 5 }, "end": { "line": 38, - "column": 44 + "column": 43 } } }, @@ -188,7 +188,7 @@ "loc": { "start": { "line": 39, - "column": 1 + "column": 5 }, "end": { "line": 39, @@ -2296,7 +2296,7 @@ }, "end": { "line": 38, - "column": 31 + "column": 43 } } }, @@ -2373,7 +2373,7 @@ }, "end": { "line": 39, - "column": 18 + "column": 33 } } } diff --git a/ets2panda/test/parser/ets/binary_op-expected.txt b/ets2panda/test/parser/ets/binary_op-expected.txt index f491c8074d..91bcafa112 100644 --- a/ets2panda/test/parser/ets/binary_op-expected.txt +++ b/ets2panda/test/parser/ets/binary_op-expected.txt @@ -118,11 +118,11 @@ "loc": { "start": { "line": 17, - "column": 1 + "column": 5 }, "end": { "line": 17, - "column": 11 + "column": 10 } } }, @@ -174,11 +174,11 @@ "loc": { "start": { "line": 18, - "column": 1 + "column": 5 }, "end": { "line": 18, - "column": 11 + "column": 10 } } }, @@ -230,11 +230,11 @@ "loc": { "start": { "line": 19, - "column": 1 + "column": 5 }, "end": { "line": 19, - "column": 15 + "column": 14 } } }, @@ -286,11 +286,11 @@ "loc": { "start": { "line": 20, - "column": 1 + "column": 5 }, "end": { "line": 20, - "column": 16 + "column": 15 } } }, @@ -383,7 +383,7 @@ "loc": { "start": { "line": 21, - "column": 1 + "column": 5 }, "end": { "line": 21, @@ -439,11 +439,11 @@ "loc": { "start": { "line": 22, - "column": 1 + "column": 5 }, "end": { "line": 22, - "column": 30 + "column": 29 } } }, @@ -525,11 +525,11 @@ "loc": { "start": { "line": 25, - "column": 1 + "column": 5 }, "end": { "line": 25, - "column": 19 + "column": 18 } } }, @@ -640,11 +640,11 @@ "loc": { "start": { "line": 26, - "column": 1 + "column": 5 }, "end": { "line": 26, - "column": 25 + "column": 24 } } }, @@ -726,11 +726,11 @@ "loc": { "start": { "line": 29, - "column": 1 + "column": 5 }, "end": { "line": 29, - "column": 20 + "column": 19 } } }, @@ -812,11 +812,11 @@ "loc": { "start": { "line": 30, - "column": 1 + "column": 5 }, "end": { "line": 30, - "column": 20 + "column": 19 } } }, @@ -956,11 +956,11 @@ "loc": { "start": { "line": 31, - "column": 1 + "column": 5 }, "end": { "line": 31, - "column": 34 + "column": 33 } } }, @@ -1100,11 +1100,11 @@ "loc": { "start": { "line": 32, - "column": 1 + "column": 5 }, "end": { "line": 32, - "column": 34 + "column": 33 } } }, @@ -1244,11 +1244,11 @@ "loc": { "start": { "line": 33, - "column": 1 + "column": 5 }, "end": { "line": 33, - "column": 34 + "column": 33 } } }, @@ -1388,11 +1388,11 @@ "loc": { "start": { "line": 34, - "column": 1 + "column": 5 }, "end": { "line": 34, - "column": 34 + "column": 33 } } }, @@ -1474,11 +1474,11 @@ "loc": { "start": { "line": 37, - "column": 1 + "column": 5 }, "end": { "line": 37, - "column": 17 + "column": 16 } } }, @@ -1560,11 +1560,11 @@ "loc": { "start": { "line": 38, - "column": 1 + "column": 5 }, "end": { "line": 38, - "column": 17 + "column": 16 } } }, @@ -1646,11 +1646,11 @@ "loc": { "start": { "line": 39, - "column": 1 + "column": 5 }, "end": { "line": 39, - "column": 17 + "column": 16 } } }, @@ -1848,11 +1848,11 @@ "loc": { "start": { "line": 40, - "column": 1 + "column": 5 }, "end": { "line": 40, - "column": 33 + "column": 32 } } }, @@ -1934,11 +1934,11 @@ "loc": { "start": { "line": 43, - "column": 1 + "column": 5 }, "end": { "line": 43, - "column": 18 + "column": 17 } } }, @@ -2020,11 +2020,11 @@ "loc": { "start": { "line": 44, - "column": 1 + "column": 5 }, "end": { "line": 44, - "column": 18 + "column": 17 } } }, @@ -2106,11 +2106,11 @@ "loc": { "start": { "line": 45, - "column": 1 + "column": 5 }, "end": { "line": 45, - "column": 21 + "column": 20 } } }, @@ -2192,11 +2192,11 @@ "loc": { "start": { "line": 46, - "column": 1 + "column": 5 }, "end": { "line": 46, - "column": 21 + "column": 20 } } }, @@ -2278,11 +2278,11 @@ "loc": { "start": { "line": 49, - "column": 1 + "column": 5 }, "end": { "line": 49, - "column": 17 + "column": 16 } } }, @@ -2364,11 +2364,11 @@ "loc": { "start": { "line": 50, - "column": 1 + "column": 5 }, "end": { "line": 50, - "column": 17 + "column": 16 } } }, @@ -2450,11 +2450,11 @@ "loc": { "start": { "line": 51, - "column": 1 + "column": 5 }, "end": { "line": 51, - "column": 18 + "column": 17 } } }, @@ -2536,11 +2536,11 @@ "loc": { "start": { "line": 52, - "column": 1 + "column": 5 }, "end": { "line": 52, - "column": 18 + "column": 17 } } }, @@ -2622,11 +2622,11 @@ "loc": { "start": { "line": 53, - "column": 1 + "column": 5 }, "end": { "line": 53, - "column": 32 + "column": 31 } } }, @@ -2708,11 +2708,11 @@ "loc": { "start": { "line": 56, - "column": 1 + "column": 5 }, "end": { "line": 56, - "column": 18 + "column": 17 } } }, @@ -2794,11 +2794,11 @@ "loc": { "start": { "line": 57, - "column": 1 + "column": 5 }, "end": { "line": 57, - "column": 18 + "column": 17 } } }, @@ -2880,11 +2880,11 @@ "loc": { "start": { "line": 58, - "column": 1 + "column": 5 }, "end": { "line": 58, - "column": 19 + "column": 18 } } }, @@ -3024,11 +3024,11 @@ "loc": { "start": { "line": 59, - "column": 1 + "column": 5 }, "end": { "line": 59, - "column": 29 + "column": 28 } } }, @@ -3110,11 +3110,11 @@ "loc": { "start": { "line": 62, - "column": 1 + "column": 5 }, "end": { "line": 62, - "column": 17 + "column": 16 } } }, @@ -3196,11 +3196,11 @@ "loc": { "start": { "line": 63, - "column": 1 + "column": 5 }, "end": { "line": 63, - "column": 17 + "column": 16 } } }, @@ -3340,11 +3340,11 @@ "loc": { "start": { "line": 64, - "column": 1 + "column": 5 }, "end": { "line": 64, - "column": 25 + "column": 24 } } }, @@ -3426,11 +3426,11 @@ "loc": { "start": { "line": 67, - "column": 1 + "column": 5 }, "end": { "line": 67, - "column": 17 + "column": 16 } } }, @@ -3512,11 +3512,11 @@ "loc": { "start": { "line": 68, - "column": 1 + "column": 5 }, "end": { "line": 68, - "column": 17 + "column": 16 } } }, @@ -3598,11 +3598,11 @@ "loc": { "start": { "line": 69, - "column": 1 + "column": 5 }, "end": { "line": 69, - "column": 17 + "column": 16 } } }, @@ -3800,11 +3800,11 @@ "loc": { "start": { "line": 70, - "column": 1 + "column": 5 }, "end": { "line": 70, - "column": 33 + "column": 32 } } }, @@ -3944,11 +3944,11 @@ "loc": { "start": { "line": 73, - "column": 1 + "column": 5 }, "end": { "line": 73, - "column": 27 + "column": 26 } } }, @@ -4088,11 +4088,11 @@ "loc": { "start": { "line": 74, - "column": 1 + "column": 5 }, "end": { "line": 74, - "column": 29 + "column": 28 } } }, @@ -4435,11 +4435,11 @@ "loc": { "start": { "line": 75, - "column": 1 + "column": 5 }, "end": { "line": 75, - "column": 63 + "column": 62 } } }, @@ -4782,11 +4782,11 @@ "loc": { "start": { "line": 76, - "column": 1 + "column": 5 }, "end": { "line": 76, - "column": 64 + "column": 63 } } }, @@ -4955,11 +4955,11 @@ "loc": { "start": { "line": 77, - "column": 1 + "column": 5 }, "end": { "line": 77, - "column": 35 + "column": 34 } } } @@ -5374,7 +5374,7 @@ }, "end": { "line": 22, - "column": 17 + "column": 29 } } }, diff --git a/ets2panda/test/parser/ets/boolean-expected.txt b/ets2panda/test/parser/ets/boolean-expected.txt index ddbbcc7ffe..bb679ea24a 100644 --- a/ets2panda/test/parser/ets/boolean-expected.txt +++ b/ets2panda/test/parser/ets/boolean-expected.txt @@ -118,11 +118,11 @@ "loc": { "start": { "line": 16, - "column": 1 + "column": 5 }, "end": { "line": 16, - "column": 23 + "column": 22 } } } @@ -218,7 +218,7 @@ }, "end": { "line": 16, - "column": 15 + "column": 22 } } }, diff --git a/ets2panda/test/parser/ets/break-expected.txt b/ets2panda/test/parser/ets/break-expected.txt index c165861131..de23f03f7f 100644 --- a/ets2panda/test/parser/ets/break-expected.txt +++ b/ets2panda/test/parser/ets/break-expected.txt @@ -161,11 +161,11 @@ "loc": { "start": { "line": 16, - "column": 1 + "column": 5 }, "end": { "line": 16, - "column": 26 + "column": 25 } } } @@ -274,7 +274,7 @@ }, "end": { "line": 16, - "column": 15 + "column": 25 } } }, diff --git a/ets2panda/test/parser/ets/cast_expressions5-expected.txt b/ets2panda/test/parser/ets/cast_expressions5-expected.txt index d8a3a2b217..e68c5b2871 100644 --- a/ets2panda/test/parser/ets/cast_expressions5-expected.txt +++ b/ets2panda/test/parser/ets/cast_expressions5-expected.txt @@ -717,11 +717,11 @@ "loc": { "start": { "line": 16, - "column": 1 + "column": 5 }, "end": { "line": 16, - "column": 26 + "column": 25 } } } @@ -817,7 +817,7 @@ }, "end": { "line": 16, - "column": 21 + "column": 25 } } }, diff --git a/ets2panda/test/parser/ets/class_instance-expected.txt b/ets2panda/test/parser/ets/class_instance-expected.txt index a4e953fd73..ec3b1a26ab 100644 --- a/ets2panda/test/parser/ets/class_instance-expected.txt +++ b/ets2panda/test/parser/ets/class_instance-expected.txt @@ -118,11 +118,11 @@ "loc": { "start": { "line": 16, - "column": 1 + "column": 5 }, "end": { "line": 16, - "column": 11 + "column": 10 } } }, @@ -174,11 +174,11 @@ "loc": { "start": { "line": 17, - "column": 1 + "column": 5 }, "end": { "line": 17, - "column": 12 + "column": 11 } } }, @@ -256,11 +256,11 @@ "loc": { "start": { "line": 19, - "column": 1 + "column": 5 }, "end": { "line": 19, - "column": 21 + "column": 20 } } }, @@ -356,11 +356,11 @@ "loc": { "start": { "line": 20, - "column": 1 + "column": 5 }, "end": { "line": 20, - "column": 23 + "column": 22 } } }, @@ -500,11 +500,11 @@ "loc": { "start": { "line": 21, - "column": 1 + "column": 5 }, "end": { "line": 21, - "column": 30 + "column": 29 } } } diff --git a/ets2panda/test/parser/ets/const_enum-expected.txt b/ets2panda/test/parser/ets/const_enum-expected.txt index 512ed79e80..bfb000b710 100644 --- a/ets2panda/test/parser/ets/const_enum-expected.txt +++ b/ets2panda/test/parser/ets/const_enum-expected.txt @@ -1 +1 @@ -SyntaxError: Identifier expected. [const_enum.ets:16:7] +SyntaxError: Variable declaration expected. [const_enum.ets:16:7] diff --git a/ets2panda/test/parser/ets/continue-expected.txt b/ets2panda/test/parser/ets/continue-expected.txt index cd8cfe6fab..264fa69017 100644 --- a/ets2panda/test/parser/ets/continue-expected.txt +++ b/ets2panda/test/parser/ets/continue-expected.txt @@ -161,11 +161,11 @@ "loc": { "start": { "line": 16, - "column": 1 + "column": 5 }, "end": { "line": 16, - "column": 26 + "column": 25 } } } @@ -274,7 +274,7 @@ }, "end": { "line": 16, - "column": 15 + "column": 25 } } }, diff --git a/ets2panda/test/parser/ets/decl_infer-expected.txt b/ets2panda/test/parser/ets/decl_infer-expected.txt index 0455f4f8b2..effb99d39e 100644 --- a/ets2panda/test/parser/ets/decl_infer-expected.txt +++ b/ets2panda/test/parser/ets/decl_infer-expected.txt @@ -118,11 +118,11 @@ "loc": { "start": { "line": 16, - "column": 1 + "column": 5 }, "end": { "line": 16, - "column": 12 + "column": 11 } } }, @@ -174,11 +174,11 @@ "loc": { "start": { "line": 17, - "column": 1 + "column": 5 }, "end": { "line": 17, - "column": 14 + "column": 13 } } }, @@ -230,11 +230,11 @@ "loc": { "start": { "line": 18, - "column": 1 + "column": 5 }, "end": { "line": 18, - "column": 15 + "column": 14 } } }, @@ -286,11 +286,11 @@ "loc": { "start": { "line": 19, - "column": 1 + "column": 5 }, "end": { "line": 19, - "column": 15 + "column": 14 } } }, @@ -342,11 +342,11 @@ "loc": { "start": { "line": 20, - "column": 1 + "column": 5 }, "end": { "line": 20, - "column": 16 + "column": 15 } } } diff --git a/ets2panda/test/parser/ets/exports-expected.txt b/ets2panda/test/parser/ets/exports-expected.txt index aab03ca622..aaceffc96d 100644 --- a/ets2panda/test/parser/ets/exports-expected.txt +++ b/ets2panda/test/parser/ets/exports-expected.txt @@ -339,11 +339,11 @@ "loc": { "start": { "line": 16, - "column": 8 + "column": 12 }, "end": { "line": 16, - "column": 19 + "column": 18 } } } diff --git a/ets2panda/test/parser/ets/for_of-expected.txt b/ets2panda/test/parser/ets/for_of-expected.txt index d3446be05a..cef1c5eec2 100644 --- a/ets2panda/test/parser/ets/for_of-expected.txt +++ b/ets2panda/test/parser/ets/for_of-expected.txt @@ -161,11 +161,11 @@ "loc": { "start": { "line": 17, - "column": 1 + "column": 5 }, "end": { "line": 17, - "column": 26 + "column": 25 } } } @@ -274,7 +274,7 @@ }, "end": { "line": 17, - "column": 15 + "column": 25 } } }, diff --git a/ets2panda/test/parser/ets/for_of_02-expected.txt b/ets2panda/test/parser/ets/for_of_02-expected.txt index f7ae611379..adcd757016 100644 --- a/ets2panda/test/parser/ets/for_of_02-expected.txt +++ b/ets2panda/test/parser/ets/for_of_02-expected.txt @@ -161,11 +161,11 @@ "loc": { "start": { "line": 16, - "column": 1 + "column": 5 }, "end": { "line": 16, - "column": 26 + "column": 25 } } } @@ -274,7 +274,7 @@ }, "end": { "line": 16, - "column": 15 + "column": 25 } } }, diff --git a/ets2panda/test/parser/ets/functionTypeThrows-expected.txt b/ets2panda/test/parser/ets/functionTypeThrows-expected.txt index 2c3510eb60..db780fab06 100644 --- a/ets2panda/test/parser/ets/functionTypeThrows-expected.txt +++ b/ets2panda/test/parser/ets/functionTypeThrows-expected.txt @@ -259,7 +259,7 @@ }, "end": { "line": 16, - "column": 32 + "column": 6 } } } diff --git a/ets2panda/test/parser/ets/function_implicit_return_type3-expected.txt b/ets2panda/test/parser/ets/function_implicit_return_type3-expected.txt index 86af963d88..4735377d45 100644 --- a/ets2panda/test/parser/ets/function_implicit_return_type3-expected.txt +++ b/ets2panda/test/parser/ets/function_implicit_return_type3-expected.txt @@ -119,11 +119,11 @@ "loc": { "start": { "line": 18, - "column": 1 + "column": 5 }, "end": { "line": 18, - "column": 33 + "column": 32 } } } diff --git a/ets2panda/test/parser/ets/genericDefaultParam_1-expected.txt b/ets2panda/test/parser/ets/genericDefaultParam_1-expected.txt index 09b1fbae7a..8387f49f9a 100644 --- a/ets2panda/test/parser/ets/genericDefaultParam_1-expected.txt +++ b/ets2panda/test/parser/ets/genericDefaultParam_1-expected.txt @@ -1988,7 +1988,7 @@ "loc": { "start": { "line": 31, - "column": 1 + "column": 5 }, "end": { "line": 32, @@ -2182,7 +2182,7 @@ "loc": { "start": { "line": 32, - "column": 1 + "column": 5 }, "end": { "line": 33, @@ -2417,7 +2417,7 @@ "loc": { "start": { "line": 33, - "column": 1 + "column": 5 }, "end": { "line": 34, diff --git a/ets2panda/test/parser/ets/generics_type_param_constraint_3-expected.txt b/ets2panda/test/parser/ets/generics_type_param_constraint_3-expected.txt index 3b525585b9..8a94129e2a 100644 --- a/ets2panda/test/parser/ets/generics_type_param_constraint_3-expected.txt +++ b/ets2panda/test/parser/ets/generics_type_param_constraint_3-expected.txt @@ -458,7 +458,7 @@ "loc": { "start": { "line": 17, - "column": 12 + "column": 11 }, "end": { "line": 19, @@ -469,7 +469,7 @@ "loc": { "start": { "line": 17, - "column": 12 + "column": 11 }, "end": { "line": 19, diff --git a/ets2panda/test/parser/ets/identifier-expected.txt b/ets2panda/test/parser/ets/identifier-expected.txt index 79101bcf96..70df781844 100644 --- a/ets2panda/test/parser/ets/identifier-expected.txt +++ b/ets2panda/test/parser/ets/identifier-expected.txt @@ -118,11 +118,11 @@ "loc": { "start": { "line": 17, - "column": 1 + "column": 5 }, "end": { "line": 17, - "column": 27 + "column": 26 } } }, @@ -174,11 +174,11 @@ "loc": { "start": { "line": 18, - "column": 1 + "column": 5 }, "end": { "line": 18, - "column": 32 + "column": 31 } } }, @@ -230,11 +230,11 @@ "loc": { "start": { "line": 19, - "column": 1 + "column": 5 }, "end": { "line": 19, - "column": 28 + "column": 27 } } } @@ -330,7 +330,7 @@ }, "end": { "line": 17, - "column": 22 + "column": 26 } } }, @@ -379,7 +379,7 @@ }, "end": { "line": 18, - "column": 27 + "column": 31 } } }, @@ -428,7 +428,7 @@ }, "end": { "line": 19, - "column": 23 + "column": 27 } } } diff --git a/ets2panda/test/parser/ets/import_tests/diamond/test2-expected.txt b/ets2panda/test/parser/ets/import_tests/diamond/test2-expected.txt index 020e5e183a..029990a229 100644 --- a/ets2panda/test/parser/ets/import_tests/diamond/test2-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/diamond/test2-expected.txt @@ -191,11 +191,11 @@ "loc": { "start": { "line": 18, - "column": 8 + "column": 12 }, "end": { "line": 18, - "column": 22 + "column": 21 } } } diff --git a/ets2panda/test/parser/ets/import_tests/diamond/test3-expected.txt b/ets2panda/test/parser/ets/import_tests/diamond/test3-expected.txt index 41d64f40ed..aa59cba3ba 100644 --- a/ets2panda/test/parser/ets/import_tests/diamond/test3-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/diamond/test3-expected.txt @@ -191,11 +191,11 @@ "loc": { "start": { "line": 18, - "column": 8 + "column": 12 }, "end": { "line": 18, - "column": 22 + "column": 21 } } } diff --git a/ets2panda/test/parser/ets/import_tests/diamond/test4-expected.txt b/ets2panda/test/parser/ets/import_tests/diamond/test4-expected.txt index 49fc3015d8..96bbb0c8bb 100644 --- a/ets2panda/test/parser/ets/import_tests/diamond/test4-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/diamond/test4-expected.txt @@ -118,11 +118,11 @@ "loc": { "start": { "line": 16, - "column": 8 + "column": 12 }, "end": { "line": 16, - "column": 20 + "column": 19 } } } diff --git a/ets2panda/test/parser/ets/import_tests/import_alias/export-expected.txt b/ets2panda/test/parser/ets/import_tests/import_alias/export-expected.txt index 6f65df0476..03aa93b5c2 100644 --- a/ets2panda/test/parser/ets/import_tests/import_alias/export-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/import_alias/export-expected.txt @@ -580,11 +580,11 @@ "loc": { "start": { "line": 28, - "column": 1 + "column": 5 }, "end": { "line": 28, - "column": 15 + "column": 14 } } }, @@ -636,11 +636,11 @@ "loc": { "start": { "line": 30, - "column": 8 + "column": 12 }, "end": { "line": 30, - "column": 22 + "column": 21 } } } diff --git a/ets2panda/test/parser/ets/import_tests/import_all-expected.txt b/ets2panda/test/parser/ets/import_tests/import_all-expected.txt index a05f2eaec9..34fdeb2579 100755 --- a/ets2panda/test/parser/ets/import_tests/import_all-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/import_all-expected.txt @@ -264,11 +264,11 @@ "loc": { "start": { "line": 19, - "column": 1 + "column": 5 }, "end": { "line": 19, - "column": 47 + "column": 46 } } }, @@ -352,11 +352,11 @@ "loc": { "start": { "line": 20, - "column": 1 + "column": 5 }, "end": { "line": 20, - "column": 46 + "column": 45 } } }, @@ -439,11 +439,11 @@ "loc": { "start": { "line": 21, - "column": 1 + "column": 5 }, "end": { "line": 21, - "column": 49 + "column": 48 } } } diff --git a/ets2panda/test/parser/ets/import_tests/import_all_alias_1-expected.txt b/ets2panda/test/parser/ets/import_tests/import_all_alias_1-expected.txt index e105d8c13c..1079f0ac8a 100644 --- a/ets2panda/test/parser/ets/import_tests/import_all_alias_1-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/import_all_alias_1-expected.txt @@ -267,11 +267,11 @@ "loc": { "start": { "line": 18, - "column": 1 + "column": 5 }, "end": { "line": 18, - "column": 57 + "column": 56 } } }, @@ -415,11 +415,11 @@ "loc": { "start": { "line": 19, - "column": 1 + "column": 5 }, "end": { "line": 19, - "column": 56 + "column": 55 } } } diff --git a/ets2panda/test/parser/ets/import_tests/import_all_alias_2-expected.txt b/ets2panda/test/parser/ets/import_tests/import_all_alias_2-expected.txt index 18b018cd70..623e169b05 100755 --- a/ets2panda/test/parser/ets/import_tests/import_all_alias_2-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/import_all_alias_2-expected.txt @@ -207,11 +207,11 @@ "loc": { "start": { "line": 20, - "column": 1 + "column": 5 }, "end": { "line": 20, - "column": 47 + "column": 46 } } } diff --git a/ets2panda/test/parser/ets/import_tests/import_all_type_alias-expected.txt b/ets2panda/test/parser/ets/import_tests/import_all_type_alias-expected.txt index 20deb523cd..46f64d4417 100644 --- a/ets2panda/test/parser/ets/import_tests/import_all_type_alias-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/import_all_type_alias-expected.txt @@ -244,7 +244,7 @@ "loc": { "start": { "line": 22, - "column": 1 + "column": 5 }, "end": { "line": 22, diff --git a/ets2panda/test/parser/ets/import_tests/import_name_1-expected.txt b/ets2panda/test/parser/ets/import_tests/import_name_1-expected.txt index 77c11005f8..40e1725683 100755 --- a/ets2panda/test/parser/ets/import_tests/import_name_1-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/import_name_1-expected.txt @@ -308,11 +308,11 @@ "loc": { "start": { "line": 18, - "column": 1 + "column": 5 }, "end": { "line": 18, - "column": 47 + "column": 46 } } }, @@ -396,7 +396,7 @@ "loc": { "start": { "line": 19, - "column": 1 + "column": 5 }, "end": { "line": 19, diff --git a/ets2panda/test/parser/ets/import_tests/import_name_2-expected.txt b/ets2panda/test/parser/ets/import_tests/import_name_2-expected.txt index 4ce97a3c9b..f994a5367e 100755 --- a/ets2panda/test/parser/ets/import_tests/import_name_2-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/import_name_2-expected.txt @@ -265,11 +265,11 @@ "loc": { "start": { "line": 19, - "column": 1 + "column": 5 }, "end": { "line": 19, - "column": 18 + "column": 17 } } } diff --git a/ets2panda/test/parser/ets/import_tests/import_name_alias_1-expected.txt b/ets2panda/test/parser/ets/import_tests/import_name_alias_1-expected.txt index 8192941368..5206b86417 100755 --- a/ets2panda/test/parser/ets/import_tests/import_name_alias_1-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/import_name_alias_1-expected.txt @@ -308,11 +308,11 @@ "loc": { "start": { "line": 18, - "column": 1 + "column": 5 }, "end": { "line": 18, - "column": 47 + "column": 46 } } }, @@ -396,11 +396,11 @@ "loc": { "start": { "line": 19, - "column": 1 + "column": 5 }, "end": { "line": 19, - "column": 46 + "column": 45 } } } diff --git a/ets2panda/test/parser/ets/import_tests/import_name_alias_2-expected.txt b/ets2panda/test/parser/ets/import_tests/import_name_alias_2-expected.txt index 6c17455873..d072593243 100755 --- a/ets2panda/test/parser/ets/import_tests/import_name_alias_2-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/import_name_alias_2-expected.txt @@ -265,11 +265,11 @@ "loc": { "start": { "line": 19, - "column": 1 + "column": 5 }, "end": { "line": 19, - "column": 18 + "column": 17 } } } diff --git a/ets2panda/test/parser/ets/import_tests/import_relative_path-expected.txt b/ets2panda/test/parser/ets/import_tests/import_relative_path-expected.txt index c99810cb09..69ad61a034 100755 --- a/ets2panda/test/parser/ets/import_tests/import_relative_path-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/import_relative_path-expected.txt @@ -207,11 +207,11 @@ "loc": { "start": { "line": 18, - "column": 1 + "column": 5 }, "end": { "line": 18, - "column": 47 + "column": 46 } } }, @@ -295,11 +295,11 @@ "loc": { "start": { "line": 19, - "column": 1 + "column": 5 }, "end": { "line": 19, - "column": 46 + "column": 45 } } } diff --git a/ets2panda/test/parser/ets/import_tests/import_several_1-expected.txt b/ets2panda/test/parser/ets/import_tests/import_several_1-expected.txt index 7ceeda9725..f4fc0df83c 100755 --- a/ets2panda/test/parser/ets/import_tests/import_several_1-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/import_several_1-expected.txt @@ -366,11 +366,11 @@ "loc": { "start": { "line": 20, - "column": 1 + "column": 5 }, "end": { "line": 20, - "column": 47 + "column": 46 } } }, @@ -454,11 +454,11 @@ "loc": { "start": { "line": 21, - "column": 1 + "column": 5 }, "end": { "line": 21, - "column": 46 + "column": 45 } } } diff --git a/ets2panda/test/parser/ets/import_tests/import_several_2-expected.txt b/ets2panda/test/parser/ets/import_tests/import_several_2-expected.txt index a1118839c3..a6b9200056 100755 --- a/ets2panda/test/parser/ets/import_tests/import_several_2-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/import_several_2-expected.txt @@ -264,11 +264,11 @@ "loc": { "start": { "line": 19, - "column": 1 + "column": 5 }, "end": { "line": 19, - "column": 19 + "column": 18 } } } diff --git a/ets2panda/test/parser/ets/import_tests/import_several_3-expected.txt b/ets2panda/test/parser/ets/import_tests/import_several_3-expected.txt index bb89ff35a9..0c310d7017 100755 --- a/ets2panda/test/parser/ets/import_tests/import_several_3-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/import_several_3-expected.txt @@ -279,11 +279,11 @@ "loc": { "start": { "line": 19, - "column": 1 + "column": 5 }, "end": { "line": 19, - "column": 47 + "column": 46 } } }, @@ -367,11 +367,11 @@ "loc": { "start": { "line": 20, - "column": 1 + "column": 5 }, "end": { "line": 20, - "column": 46 + "column": 45 } } } diff --git a/ets2panda/test/parser/ets/import_tests/import_several_4-expected.txt b/ets2panda/test/parser/ets/import_tests/import_several_4-expected.txt index 614c31accb..6ea9c81dd2 100644 --- a/ets2panda/test/parser/ets/import_tests/import_several_4-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/import_several_4-expected.txt @@ -309,11 +309,11 @@ "loc": { "start": { "line": 19, - "column": 1 + "column": 5 }, "end": { "line": 19, - "column": 52 + "column": 51 } } }, @@ -457,11 +457,11 @@ "loc": { "start": { "line": 20, - "column": 1 + "column": 5 }, "end": { "line": 20, - "column": 56 + "column": 55 } } } diff --git a/ets2panda/test/parser/ets/import_tests/import_several_5-expected.txt b/ets2panda/test/parser/ets/import_tests/import_several_5-expected.txt index 3d619efbbe..eb8902b6de 100755 --- a/ets2panda/test/parser/ets/import_tests/import_several_5-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/import_several_5-expected.txt @@ -279,11 +279,11 @@ "loc": { "start": { "line": 19, - "column": 1 + "column": 5 }, "end": { "line": 19, - "column": 47 + "column": 46 } } }, @@ -367,11 +367,11 @@ "loc": { "start": { "line": 20, - "column": 1 + "column": 5 }, "end": { "line": 20, - "column": 46 + "column": 45 } } } diff --git a/ets2panda/test/parser/ets/import_tests/import_several_6-expected.txt b/ets2panda/test/parser/ets/import_tests/import_several_6-expected.txt index 08763cfb56..4f190cb5ec 100644 --- a/ets2panda/test/parser/ets/import_tests/import_several_6-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/import_several_6-expected.txt @@ -309,11 +309,11 @@ "loc": { "start": { "line": 19, - "column": 1 + "column": 5 }, "end": { "line": 19, - "column": 52 + "column": 51 } } }, @@ -457,11 +457,11 @@ "loc": { "start": { "line": 20, - "column": 1 + "column": 5 }, "end": { "line": 20, - "column": 56 + "column": 55 } } } diff --git a/ets2panda/test/parser/ets/import_tests/import_several_7-expected.txt b/ets2panda/test/parser/ets/import_tests/import_several_7-expected.txt index a522257b8f..d4d3958526 100755 --- a/ets2panda/test/parser/ets/import_tests/import_several_7-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/import_several_7-expected.txt @@ -351,11 +351,11 @@ "loc": { "start": { "line": 20, - "column": 1 + "column": 5 }, "end": { "line": 20, - "column": 47 + "column": 46 } } }, @@ -439,11 +439,11 @@ "loc": { "start": { "line": 21, - "column": 1 + "column": 5 }, "end": { "line": 21, - "column": 46 + "column": 45 } } } diff --git a/ets2panda/test/parser/ets/import_tests/modules/too_many_default_exports_2-expected.txt b/ets2panda/test/parser/ets/import_tests/modules/too_many_default_exports_2-expected.txt index 286371d4e6..f4b12fc8ce 100644 --- a/ets2panda/test/parser/ets/import_tests/modules/too_many_default_exports_2-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/modules/too_many_default_exports_2-expected.txt @@ -1 +1 @@ -SyntaxError: Only one default export is allowed in a module [too_many_default_exports_2.ets:16:16] +SyntaxError: Only one default export is allowed in a module [too_many_default_exports_2.ets:16:27] diff --git a/ets2panda/test/parser/ets/import_tests/relative_import/alias2-expected.txt b/ets2panda/test/parser/ets/import_tests/relative_import/alias2-expected.txt index 78b1a6b2bb..0ce3e4dd86 100644 --- a/ets2panda/test/parser/ets/import_tests/relative_import/alias2-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/relative_import/alias2-expected.txt @@ -349,11 +349,11 @@ "loc": { "start": { "line": 16, - "column": 8 + "column": 12 }, "end": { "line": 16, - "column": 20 + "column": 19 } } } diff --git a/ets2panda/test/parser/ets/index_expressions-expected.txt b/ets2panda/test/parser/ets/index_expressions-expected.txt index da4f144916..39fc2ad997 100644 --- a/ets2panda/test/parser/ets/index_expressions-expected.txt +++ b/ets2panda/test/parser/ets/index_expressions-expected.txt @@ -144,11 +144,11 @@ "loc": { "start": { "line": 17, - "column": 1 + "column": 5 }, "end": { "line": 17, - "column": 20 + "column": 19 } } }, @@ -230,11 +230,11 @@ "loc": { "start": { "line": 18, - "column": 1 + "column": 5 }, "end": { "line": 18, - "column": 14 + "column": 13 } } }, @@ -317,11 +317,11 @@ "loc": { "start": { "line": 19, - "column": 1 + "column": 5 }, "end": { "line": 19, - "column": 14 + "column": 13 } } }, @@ -434,11 +434,11 @@ "loc": { "start": { "line": 20, - "column": 1 + "column": 5 }, "end": { "line": 20, - "column": 17 + "column": 16 } } } diff --git a/ets2panda/test/parser/ets/lambda_import_alias_1-2-expected.txt b/ets2panda/test/parser/ets/lambda_import_alias_1-2-expected.txt index fce52818b7..6e14834c9b 100644 --- a/ets2panda/test/parser/ets/lambda_import_alias_1-2-expected.txt +++ b/ets2panda/test/parser/ets/lambda_import_alias_1-2-expected.txt @@ -303,7 +303,7 @@ "loc": { "start": { "line": 18, - "column": 8 + "column": 12 }, "end": { "line": 18, diff --git a/ets2panda/test/parser/ets/launch_with_call_expression-expected.txt b/ets2panda/test/parser/ets/launch_with_call_expression-expected.txt index d5c7850550..2e69814082 100644 --- a/ets2panda/test/parser/ets/launch_with_call_expression-expected.txt +++ b/ets2panda/test/parser/ets/launch_with_call_expression-expected.txt @@ -408,7 +408,7 @@ "loc": { "start": { "line": 21, - "column": 1 + "column": 5 }, "end": { "line": 21, diff --git a/ets2panda/test/parser/ets/null-expected.txt b/ets2panda/test/parser/ets/null-expected.txt index f069f5a6a6..6bef006c4d 100644 --- a/ets2panda/test/parser/ets/null-expected.txt +++ b/ets2panda/test/parser/ets/null-expected.txt @@ -255,11 +255,11 @@ "loc": { "start": { "line": 18, - "column": 1 + "column": 5 }, "end": { "line": 18, - "column": 27 + "column": 26 } } }, @@ -352,7 +352,7 @@ "loc": { "start": { "line": 19, - "column": 1 + "column": 5 }, "end": { "line": 19, @@ -480,7 +480,7 @@ }, "end": { "line": 18, - "column": 14 + "column": 26 } } }, @@ -557,7 +557,7 @@ }, "end": { "line": 19, - "column": 14 + "column": 25 } } }, diff --git a/ets2panda/test/parser/ets/null_invalid-expected.txt b/ets2panda/test/parser/ets/null_invalid-expected.txt index 4f1b9e0d7c..05a4724c5f 100644 --- a/ets2panda/test/parser/ets/null_invalid-expected.txt +++ b/ets2panda/test/parser/ets/null_invalid-expected.txt @@ -119,11 +119,11 @@ "loc": { "start": { "line": 17, - "column": 1 + "column": 5 }, "end": { "line": 17, - "column": 20 + "column": 19 } } } @@ -297,7 +297,7 @@ }, "end": { "line": 17, - "column": 17 + "column": 19 } } } diff --git a/ets2panda/test/parser/ets/null_valid-expected.txt b/ets2panda/test/parser/ets/null_valid-expected.txt index 1891cfc564..cae638039c 100644 --- a/ets2panda/test/parser/ets/null_valid-expected.txt +++ b/ets2panda/test/parser/ets/null_valid-expected.txt @@ -119,11 +119,11 @@ "loc": { "start": { "line": 17, - "column": 1 + "column": 5 }, "end": { "line": 17, - "column": 27 + "column": 26 } } } @@ -297,7 +297,7 @@ }, "end": { "line": 17, - "column": 17 + "column": 26 } } } diff --git a/ets2panda/test/parser/ets/object-expected.txt b/ets2panda/test/parser/ets/object-expected.txt index 9f1511caa9..caf59e7c60 100644 --- a/ets2panda/test/parser/ets/object-expected.txt +++ b/ets2panda/test/parser/ets/object-expected.txt @@ -189,7 +189,7 @@ }, "end": { "line": 16, - "column": 15 + "column": 6 } } } diff --git a/ets2panda/test/parser/ets/optional-chaining-array-expected.txt b/ets2panda/test/parser/ets/optional-chaining-array-expected.txt index 9fc7887951..9a02f3f966 100644 --- a/ets2panda/test/parser/ets/optional-chaining-array-expected.txt +++ b/ets2panda/test/parser/ets/optional-chaining-array-expected.txt @@ -161,11 +161,11 @@ "loc": { "start": { "line": 16, - "column": 1 + "column": 5 }, "end": { "line": 16, - "column": 35 + "column": 34 } } }, @@ -275,11 +275,11 @@ "loc": { "start": { "line": 17, - "column": 1 + "column": 5 }, "end": { "line": 17, - "column": 34 + "column": 33 } } }, @@ -389,11 +389,11 @@ "loc": { "start": { "line": 20, - "column": 1 + "column": 5 }, "end": { "line": 20, - "column": 39 + "column": 38 } } } @@ -530,7 +530,7 @@ }, "end": { "line": 16, - "column": 17 + "column": 34 } } }, @@ -728,7 +728,7 @@ }, "end": { "line": 19, - "column": 21 + "column": 9 } } }, diff --git a/ets2panda/test/parser/ets/optional_chaining_invalid_property-expected.txt b/ets2panda/test/parser/ets/optional_chaining_invalid_property-expected.txt index 2c046490ec..c357cbf4de 100644 --- a/ets2panda/test/parser/ets/optional_chaining_invalid_property-expected.txt +++ b/ets2panda/test/parser/ets/optional_chaining_invalid_property-expected.txt @@ -456,7 +456,7 @@ "loc": { "start": { "line": 22, - "column": 1 + "column": 5 }, "end": { "line": 24, @@ -543,11 +543,11 @@ "loc": { "start": { "line": 26, - "column": 1 + "column": 5 }, "end": { "line": 26, - "column": 30 + "column": 29 } } } @@ -670,8 +670,8 @@ "column": 5 }, "end": { - "line": 22, - "column": 15 + "line": 24, + "column": 2 } } }, diff --git a/ets2panda/test/parser/ets/optional_chaining_nested_property-expected.txt b/ets2panda/test/parser/ets/optional_chaining_nested_property-expected.txt index 1e67c713bc..120efe8f89 100644 --- a/ets2panda/test/parser/ets/optional_chaining_nested_property-expected.txt +++ b/ets2panda/test/parser/ets/optional_chaining_nested_property-expected.txt @@ -533,7 +533,7 @@ "loc": { "start": { "line": 23, - "column": 1 + "column": 5 }, "end": { "line": 25, @@ -650,11 +650,11 @@ "loc": { "start": { "line": 27, - "column": 1 + "column": 5 }, "end": { "line": 27, - "column": 42 + "column": 41 } } } @@ -777,8 +777,8 @@ "column": 5 }, "end": { - "line": 23, - "column": 15 + "line": 25, + "column": 2 } } }, diff --git a/ets2panda/test/parser/ets/optional_chaining_object_property-expected.txt b/ets2panda/test/parser/ets/optional_chaining_object_property-expected.txt index 3e7ff288e9..c97274831d 100644 --- a/ets2panda/test/parser/ets/optional_chaining_object_property-expected.txt +++ b/ets2panda/test/parser/ets/optional_chaining_object_property-expected.txt @@ -456,7 +456,7 @@ "loc": { "start": { "line": 22, - "column": 1 + "column": 5 }, "end": { "line": 24, @@ -571,11 +571,11 @@ "loc": { "start": { "line": 26, - "column": 1 + "column": 5 }, "end": { "line": 26, - "column": 33 + "column": 32 } } }, @@ -686,11 +686,11 @@ "loc": { "start": { "line": 27, - "column": 1 + "column": 5 }, "end": { "line": 27, - "column": 36 + "column": 35 } } } @@ -813,8 +813,8 @@ "column": 5 }, "end": { - "line": 22, - "column": 15 + "line": 24, + "column": 2 } } }, @@ -972,7 +972,7 @@ }, "end": { "line": 27, - "column": 18 + "column": 35 } } } diff --git a/ets2panda/test/parser/ets/optional_union_paramter-expected.txt b/ets2panda/test/parser/ets/optional_union_paramter-expected.txt index 3a880a2d53..f5caec4089 100644 --- a/ets2panda/test/parser/ets/optional_union_paramter-expected.txt +++ b/ets2panda/test/parser/ets/optional_union_paramter-expected.txt @@ -1216,7 +1216,7 @@ "loc": { "start": { "line": 21, - "column": 15 + "column": 14 }, "end": { "line": 23, @@ -1227,7 +1227,7 @@ "loc": { "start": { "line": 21, - "column": 15 + "column": 14 }, "end": { "line": 23, diff --git a/ets2panda/test/parser/ets/parentheses_expression_value-expected.txt b/ets2panda/test/parser/ets/parentheses_expression_value-expected.txt index 32bc14b3a4..38eb06e701 100644 --- a/ets2panda/test/parser/ets/parentheses_expression_value-expected.txt +++ b/ets2panda/test/parser/ets/parentheses_expression_value-expected.txt @@ -118,11 +118,11 @@ "loc": { "start": { "line": 17, - "column": 1 + "column": 5 }, "end": { "line": 17, - "column": 11 + "column": 10 } } }, @@ -174,11 +174,11 @@ "loc": { "start": { "line": 18, - "column": 1 + "column": 5 }, "end": { "line": 18, - "column": 13 + "column": 12 } } }, @@ -230,11 +230,11 @@ "loc": { "start": { "line": 19, - "column": 1 + "column": 5 }, "end": { "line": 19, - "column": 15 + "column": 14 } } }, @@ -287,11 +287,11 @@ "loc": { "start": { "line": 20, - "column": 1 + "column": 5 }, "end": { "line": 20, - "column": 13 + "column": 12 } } } diff --git a/ets2panda/test/parser/ets/predefined_types-expected.txt b/ets2panda/test/parser/ets/predefined_types-expected.txt index 1917db3b88..630c603172 100644 --- a/ets2panda/test/parser/ets/predefined_types-expected.txt +++ b/ets2panda/test/parser/ets/predefined_types-expected.txt @@ -161,7 +161,7 @@ }, "end": { "line": 17, - "column": 12 + "column": 6 } } }, @@ -210,7 +210,7 @@ }, "end": { "line": 18, - "column": 13 + "column": 6 } } }, @@ -259,7 +259,7 @@ }, "end": { "line": 19, - "column": 11 + "column": 6 } } }, @@ -308,7 +308,7 @@ }, "end": { "line": 20, - "column": 12 + "column": 6 } } }, @@ -357,7 +357,7 @@ }, "end": { "line": 22, - "column": 13 + "column": 6 } } }, @@ -406,7 +406,7 @@ }, "end": { "line": 23, - "column": 14 + "column": 6 } } }, @@ -455,7 +455,7 @@ }, "end": { "line": 25, - "column": 12 + "column": 6 } } } diff --git a/ets2panda/test/parser/ets/re_export/folder/re_export_6-expected.txt b/ets2panda/test/parser/ets/re_export/folder/re_export_6-expected.txt index 3120da76ac..ffe77aba60 100644 --- a/ets2panda/test/parser/ets/re_export/folder/re_export_6-expected.txt +++ b/ets2panda/test/parser/ets/re_export/folder/re_export_6-expected.txt @@ -1,6 +1,76 @@ { "type": "Program", "statements": [ + { + "type": "ETSReExportDeclaration", + "ets_import_declarations": { + "type": "ImportDeclaration", + "source": { + "type": "StringLiteral", + "value": "./", + "loc": { + "start": { + "line": 16, + "column": 15 + }, + "end": { + "line": 16, + "column": 25 + } + } + }, + "specifiers": [ + { + "type": "ImportNamespaceSpecifier", + "local": { + "type": "Identifier", + "name": "", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 8 + }, + "end": { + "line": 16, + "column": 14 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 8 + }, + "end": { + "line": 16, + "column": 25 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, { "type": "ClassDeclaration", "definition": { diff --git a/ets2panda/test/parser/ets/re_export/folder/re_export_7-expected.txt b/ets2panda/test/parser/ets/re_export/folder/re_export_7-expected.txt index 3120da76ac..120c86b0aa 100644 --- a/ets2panda/test/parser/ets/re_export/folder/re_export_7-expected.txt +++ b/ets2panda/test/parser/ets/re_export/folder/re_export_7-expected.txt @@ -1,6 +1,76 @@ { "type": "Program", "statements": [ + { + "type": "ETSReExportDeclaration", + "ets_import_declarations": { + "type": "ImportDeclaration", + "source": { + "type": "StringLiteral", + "value": "./folder2", + "loc": { + "start": { + "line": 16, + "column": 15 + }, + "end": { + "line": 16, + "column": 33 + } + } + }, + "specifiers": [ + { + "type": "ImportNamespaceSpecifier", + "local": { + "type": "Identifier", + "name": "", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 8 + }, + "end": { + "line": 16, + "column": 14 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 8 + }, + "end": { + "line": 16, + "column": 33 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, { "type": "ClassDeclaration", "definition": { diff --git a/ets2panda/test/parser/ets/re_export/folderIndex/index-expected.txt b/ets2panda/test/parser/ets/re_export/folderIndex/index-expected.txt index 3120da76ac..1e03074140 100644 --- a/ets2panda/test/parser/ets/re_export/folderIndex/index-expected.txt +++ b/ets2panda/test/parser/ets/re_export/folderIndex/index-expected.txt @@ -1,6 +1,91 @@ { "type": "Program", "statements": [ + { + "type": "ETSReExportDeclaration", + "ets_import_declarations": { + "type": "ImportDeclaration", + "source": { + "type": "StringLiteral", + "value": "./", + "loc": { + "start": { + "line": 16, + "column": 18 + }, + "end": { + "line": 16, + "column": 26 + } + } + }, + "specifiers": [ + { + "type": "ImportSpecifier", + "local": { + "type": "Identifier", + "name": "ad", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 11 + } + } + }, + "imported": { + "type": "Identifier", + "name": "ad", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 11 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 11 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 8 + }, + "end": { + "line": 16, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, { "type": "ClassDeclaration", "definition": { diff --git a/ets2panda/test/parser/ets/re_export/re_export-expected.txt b/ets2panda/test/parser/ets/re_export/re_export-expected.txt index 3120da76ac..ffe77aba60 100644 --- a/ets2panda/test/parser/ets/re_export/re_export-expected.txt +++ b/ets2panda/test/parser/ets/re_export/re_export-expected.txt @@ -1,6 +1,76 @@ { "type": "Program", "statements": [ + { + "type": "ETSReExportDeclaration", + "ets_import_declarations": { + "type": "ImportDeclaration", + "source": { + "type": "StringLiteral", + "value": "./", + "loc": { + "start": { + "line": 16, + "column": 15 + }, + "end": { + "line": 16, + "column": 25 + } + } + }, + "specifiers": [ + { + "type": "ImportNamespaceSpecifier", + "local": { + "type": "Identifier", + "name": "", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 8 + }, + "end": { + "line": 16, + "column": 14 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 8 + }, + "end": { + "line": 16, + "column": 25 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, { "type": "ClassDeclaration", "definition": { diff --git a/ets2panda/test/parser/ets/re_export/re_export_2-expected.txt b/ets2panda/test/parser/ets/re_export/re_export_2-expected.txt index 3120da76ac..99e93e2329 100644 --- a/ets2panda/test/parser/ets/re_export/re_export_2-expected.txt +++ b/ets2panda/test/parser/ets/re_export/re_export_2-expected.txt @@ -1,6 +1,91 @@ { "type": "Program", "statements": [ + { + "type": "ETSReExportDeclaration", + "ets_import_declarations": { + "type": "ImportDeclaration", + "source": { + "type": "StringLiteral", + "value": "./", + "loc": { + "start": { + "line": 16, + "column": 26 + }, + "end": { + "line": 16, + "column": 36 + } + } + }, + "specifiers": [ + { + "type": "ImportSpecifier", + "local": { + "type": "Identifier", + "name": "FOO", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 16 + }, + "end": { + "line": 16, + "column": 19 + } + } + }, + "imported": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 12 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 19 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 8 + }, + "end": { + "line": 16, + "column": 36 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, { "type": "ClassDeclaration", "definition": { diff --git a/ets2panda/test/parser/ets/re_export/re_export_3-expected.txt b/ets2panda/test/parser/ets/re_export/re_export_3-expected.txt index 3120da76ac..61ba5da592 100644 --- a/ets2panda/test/parser/ets/re_export/re_export_3-expected.txt +++ b/ets2panda/test/parser/ets/re_export/re_export_3-expected.txt @@ -1,6 +1,91 @@ { "type": "Program", "statements": [ + { + "type": "ETSReExportDeclaration", + "ets_import_declarations": { + "type": "ImportDeclaration", + "source": { + "type": "StringLiteral", + "value": "./", + "loc": { + "start": { + "line": 16, + "column": 19 + }, + "end": { + "line": 16, + "column": 29 + } + } + }, + "specifiers": [ + { + "type": "ImportSpecifier", + "local": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 12 + } + } + }, + "imported": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 12 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 12 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 8 + }, + "end": { + "line": 16, + "column": 29 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, { "type": "ClassDeclaration", "definition": { diff --git a/ets2panda/test/parser/ets/re_export/re_export_4-expected.txt b/ets2panda/test/parser/ets/re_export/re_export_4-expected.txt index 5d09166882..daf3fd0b18 100644 --- a/ets2panda/test/parser/ets/re_export/re_export_4-expected.txt +++ b/ets2panda/test/parser/ets/re_export/re_export_4-expected.txt @@ -1,6 +1,176 @@ { "type": "Program", "statements": [ + { + "type": "ETSReExportDeclaration", + "ets_import_declarations": { + "type": "ImportDeclaration", + "source": { + "type": "StringLiteral", + "value": "./", + "loc": { + "start": { + "line": 16, + "column": 19 + }, + "end": { + "line": 16, + "column": 29 + } + } + }, + "specifiers": [ + { + "type": "ImportSpecifier", + "local": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 12 + } + } + }, + "imported": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 12 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 12 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 8 + }, + "end": { + "line": 16, + "column": 29 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ETSReExportDeclaration", + "ets_import_declarations": { + "type": "ImportDeclaration", + "source": { + "type": "StringLiteral", + "value": "./", + "loc": { + "start": { + "line": 17, + "column": 19 + }, + "end": { + "line": 17, + "column": 31 + } + } + }, + "specifiers": [ + { + "type": "ImportSpecifier", + "local": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 9 + }, + "end": { + "line": 17, + "column": 12 + } + } + }, + "imported": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 9 + }, + "end": { + "line": 17, + "column": 12 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 9 + }, + "end": { + "line": 17, + "column": 12 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 8 + }, + "end": { + "line": 17, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, { "type": "ClassDeclaration", "definition": { diff --git a/ets2panda/test/parser/ets/re_export/re_export_5-expected.txt b/ets2panda/test/parser/ets/re_export/re_export_5-expected.txt index 5d09166882..94d968a131 100644 --- a/ets2panda/test/parser/ets/re_export/re_export_5-expected.txt +++ b/ets2panda/test/parser/ets/re_export/re_export_5-expected.txt @@ -1,6 +1,146 @@ { "type": "Program", "statements": [ + { + "type": "ETSReExportDeclaration", + "ets_import_declarations": { + "type": "ImportDeclaration", + "source": { + "type": "StringLiteral", + "value": "./", + "loc": { + "start": { + "line": 16, + "column": 15 + }, + "end": { + "line": 16, + "column": 25 + } + } + }, + "specifiers": [ + { + "type": "ImportNamespaceSpecifier", + "local": { + "type": "Identifier", + "name": "", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 8 + }, + "end": { + "line": 16, + "column": 14 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 8 + }, + "end": { + "line": 16, + "column": 25 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ETSReExportDeclaration", + "ets_import_declarations": { + "type": "ImportDeclaration", + "source": { + "type": "StringLiteral", + "value": "./", + "loc": { + "start": { + "line": 17, + "column": 15 + }, + "end": { + "line": 17, + "column": 27 + } + } + }, + "specifiers": [ + { + "type": "ImportNamespaceSpecifier", + "local": { + "type": "Identifier", + "name": "", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 8 + }, + "end": { + "line": 17, + "column": 14 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 8 + }, + "end": { + "line": 17, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, { "type": "ClassDeclaration", "definition": { diff --git a/ets2panda/test/parser/ets/rest_parameter_01-expected.txt b/ets2panda/test/parser/ets/rest_parameter_01-expected.txt index 19a0a0e6e6..537df9b4b0 100644 --- a/ets2panda/test/parser/ets/rest_parameter_01-expected.txt +++ b/ets2panda/test/parser/ets/rest_parameter_01-expected.txt @@ -302,7 +302,7 @@ "loc": { "start": { "line": 16, - "column": 14 + "column": 13 }, "end": { "line": 18, @@ -313,7 +313,7 @@ "loc": { "start": { "line": 16, - "column": 14 + "column": 13 }, "end": { "line": 18, @@ -534,7 +534,7 @@ "loc": { "start": { "line": 20, - "column": 14 + "column": 13 }, "end": { "line": 22, @@ -545,7 +545,7 @@ "loc": { "start": { "line": 20, - "column": 14 + "column": 13 }, "end": { "line": 22, diff --git a/ets2panda/test/parser/ets/rest_parameter_02-expected.txt b/ets2panda/test/parser/ets/rest_parameter_02-expected.txt index 5cb49ef973..5417cf1189 100644 --- a/ets2panda/test/parser/ets/rest_parameter_02-expected.txt +++ b/ets2panda/test/parser/ets/rest_parameter_02-expected.txt @@ -328,7 +328,7 @@ "loc": { "start": { "line": 16, - "column": 14 + "column": 13 }, "end": { "line": 18, @@ -339,7 +339,7 @@ "loc": { "start": { "line": 16, - "column": 14 + "column": 13 }, "end": { "line": 18, @@ -575,7 +575,7 @@ "loc": { "start": { "line": 20, - "column": 14 + "column": 13 }, "end": { "line": 22, @@ -586,7 +586,7 @@ "loc": { "start": { "line": 20, - "column": 14 + "column": 13 }, "end": { "line": 22, diff --git a/ets2panda/test/parser/ets/rest_parameter_03-expected.txt b/ets2panda/test/parser/ets/rest_parameter_03-expected.txt index bf94e31aa1..1799a3c9a3 100644 --- a/ets2panda/test/parser/ets/rest_parameter_03-expected.txt +++ b/ets2panda/test/parser/ets/rest_parameter_03-expected.txt @@ -1 +1 @@ -SyntaxError: Both optional and rest parameters are not allowed in function's parameter list. [rest_parameter_03.ets:16:14] +SyntaxError: Both optional and rest parameters are not allowed in function's parameter list. [rest_parameter_03.ets:16:13] diff --git a/ets2panda/test/parser/ets/return-expected.txt b/ets2panda/test/parser/ets/return-expected.txt index ee83fa8590..45f9c493e3 100644 --- a/ets2panda/test/parser/ets/return-expected.txt +++ b/ets2panda/test/parser/ets/return-expected.txt @@ -161,11 +161,11 @@ "loc": { "start": { "line": 16, - "column": 1 + "column": 5 }, "end": { "line": 16, - "column": 26 + "column": 25 } } } @@ -274,7 +274,7 @@ }, "end": { "line": 16, - "column": 15 + "column": 25 } } }, diff --git a/ets2panda/test/parser/ets/selective_export/selective_export_bad-expected.txt b/ets2panda/test/parser/ets/selective_export/selective_export_bad-expected.txt index dc09c9ecd8..840f7dbccf 100644 --- a/ets2panda/test/parser/ets/selective_export/selective_export_bad-expected.txt +++ b/ets2panda/test/parser/ets/selective_export/selective_export_bad-expected.txt @@ -1 +1 @@ -SyntaxError: Cannot find name 'foo' to export. [selective_export_bad.ets:16:8] +SyntaxError: Cannot find name 'foo' to export. [selective_export_bad.ets:16:10] diff --git a/ets2panda/test/parser/ets/simple_types-expected.txt b/ets2panda/test/parser/ets/simple_types-expected.txt index b75839eeb2..ce0e4dda7f 100644 --- a/ets2panda/test/parser/ets/simple_types-expected.txt +++ b/ets2panda/test/parser/ets/simple_types-expected.txt @@ -118,11 +118,11 @@ "loc": { "start": { "line": 16, - "column": 1 + "column": 5 }, "end": { "line": 16, - "column": 19 + "column": 18 } } }, @@ -189,11 +189,11 @@ "loc": { "start": { "line": 17, - "column": 1 + "column": 5 }, "end": { "line": 17, - "column": 23 + "column": 22 } } }, @@ -245,11 +245,11 @@ "loc": { "start": { "line": 18, - "column": 1 + "column": 5 }, "end": { "line": 18, - "column": 25 + "column": 24 } } }, @@ -316,11 +316,11 @@ "loc": { "start": { "line": 19, - "column": 1 + "column": 5 }, "end": { "line": 19, - "column": 36 + "column": 35 } } }, @@ -372,11 +372,11 @@ "loc": { "start": { "line": 21, - "column": 1 + "column": 5 }, "end": { "line": 21, - "column": 23 + "column": 22 } } }, @@ -428,11 +428,11 @@ "loc": { "start": { "line": 22, - "column": 1 + "column": 5 }, "end": { "line": 22, - "column": 20 + "column": 19 } } }, @@ -484,11 +484,11 @@ "loc": { "start": { "line": 26, - "column": 1 + "column": 5 }, "end": { "line": 26, - "column": 23 + "column": 22 } } }, @@ -540,11 +540,11 @@ "loc": { "start": { "line": 27, - "column": 1 + "column": 5 }, "end": { "line": 27, - "column": 24 + "column": 23 } } }, @@ -597,11 +597,11 @@ "loc": { "start": { "line": 29, - "column": 1 + "column": 5 }, "end": { "line": 29, - "column": 17 + "column": 16 } } } @@ -697,7 +697,7 @@ }, "end": { "line": 16, - "column": 12 + "column": 18 } } }, @@ -746,7 +746,7 @@ }, "end": { "line": 17, - "column": 13 + "column": 22 } } }, @@ -795,7 +795,7 @@ }, "end": { "line": 18, - "column": 11 + "column": 24 } } }, @@ -844,7 +844,7 @@ }, "end": { "line": 19, - "column": 12 + "column": 35 } } }, @@ -893,7 +893,7 @@ }, "end": { "line": 21, - "column": 15 + "column": 22 } } }, @@ -942,7 +942,7 @@ }, "end": { "line": 22, - "column": 12 + "column": 19 } } }, @@ -1019,7 +1019,7 @@ }, "end": { "line": 24, - "column": 13 + "column": 6 } } }, @@ -1068,7 +1068,7 @@ }, "end": { "line": 26, - "column": 13 + "column": 22 } } }, @@ -1117,7 +1117,7 @@ }, "end": { "line": 27, - "column": 14 + "column": 23 } } }, @@ -1166,7 +1166,7 @@ }, "end": { "line": 29, - "column": 12 + "column": 16 } } } diff --git a/ets2panda/test/parser/ets/string-expected.txt b/ets2panda/test/parser/ets/string-expected.txt index 657641c244..38083df2f9 100644 --- a/ets2panda/test/parser/ets/string-expected.txt +++ b/ets2panda/test/parser/ets/string-expected.txt @@ -118,11 +118,11 @@ "loc": { "start": { "line": 16, - "column": 1 + "column": 5 }, "end": { "line": 16, - "column": 25 + "column": 24 } } }, @@ -174,11 +174,11 @@ "loc": { "start": { "line": 17, - "column": 1 + "column": 5 }, "end": { "line": 17, - "column": 25 + "column": 24 } } } @@ -302,7 +302,7 @@ }, "end": { "line": 16, - "column": 16 + "column": 24 } } }, @@ -379,7 +379,7 @@ }, "end": { "line": 17, - "column": 16 + "column": 24 } } } diff --git a/ets2panda/test/parser/ets/ternary-expected.txt b/ets2panda/test/parser/ets/ternary-expected.txt index b80d1cd97c..f74401a8ee 100644 --- a/ets2panda/test/parser/ets/ternary-expected.txt +++ b/ets2panda/test/parser/ets/ternary-expected.txt @@ -118,11 +118,11 @@ "loc": { "start": { "line": 16, - "column": 1 + "column": 5 }, "end": { "line": 16, - "column": 11 + "column": 10 } } }, @@ -174,11 +174,11 @@ "loc": { "start": { "line": 17, - "column": 1 + "column": 5 }, "end": { "line": 17, - "column": 11 + "column": 10 } } }, @@ -303,11 +303,11 @@ "loc": { "start": { "line": 19, - "column": 1 + "column": 5 }, "end": { "line": 19, - "column": 23 + "column": 22 } } } diff --git a/ets2panda/test/parser/ets/test_jsvalue-expected.txt b/ets2panda/test/parser/ets/test_jsvalue-expected.txt index f172336108..ee9b4367bf 100644 --- a/ets2panda/test/parser/ets/test_jsvalue-expected.txt +++ b/ets2panda/test/parser/ets/test_jsvalue-expected.txt @@ -189,7 +189,7 @@ }, "end": { "line": 16, - "column": 16 + "column": 6 } } } diff --git a/ets2panda/test/parser/ets/test_jsvalue_get_double-expected.txt b/ets2panda/test/parser/ets/test_jsvalue_get_double-expected.txt index 59de21d316..e95785906d 100644 --- a/ets2panda/test/parser/ets/test_jsvalue_get_double-expected.txt +++ b/ets2panda/test/parser/ets/test_jsvalue_get_double-expected.txt @@ -119,11 +119,11 @@ "loc": { "start": { "line": 17, - "column": 1 + "column": 5 }, "end": { "line": 17, - "column": 23 + "column": 22 } } } @@ -247,7 +247,7 @@ }, "end": { "line": 16, - "column": 16 + "column": 6 } } }, @@ -296,7 +296,7 @@ }, "end": { "line": 17, - "column": 18 + "column": 22 } } } diff --git a/ets2panda/test/parser/ets/test_jsvalue_get_property_1-expected.txt b/ets2panda/test/parser/ets/test_jsvalue_get_property_1-expected.txt index dfd10c05a7..73bf02b622 100644 --- a/ets2panda/test/parser/ets/test_jsvalue_get_property_1-expected.txt +++ b/ets2panda/test/parser/ets/test_jsvalue_get_property_1-expected.txt @@ -149,11 +149,11 @@ "loc": { "start": { "line": 17, - "column": 1 + "column": 5 }, "end": { "line": 17, - "column": 33 + "column": 32 } } } @@ -277,7 +277,7 @@ }, "end": { "line": 16, - "column": 16 + "column": 6 } } }, @@ -354,7 +354,7 @@ }, "end": { "line": 17, - "column": 20 + "column": 32 } } } diff --git a/ets2panda/test/parser/ets/test_jsvalue_get_property_2-expected.txt b/ets2panda/test/parser/ets/test_jsvalue_get_property_2-expected.txt index b19aae6384..69a2a714c4 100644 --- a/ets2panda/test/parser/ets/test_jsvalue_get_property_2-expected.txt +++ b/ets2panda/test/parser/ets/test_jsvalue_get_property_2-expected.txt @@ -179,11 +179,11 @@ "loc": { "start": { "line": 17, - "column": 1 + "column": 5 }, "end": { "line": 17, - "column": 47 + "column": 46 } } } @@ -307,7 +307,7 @@ }, "end": { "line": 16, - "column": 16 + "column": 6 } } }, @@ -384,7 +384,7 @@ }, "end": { "line": 17, - "column": 20 + "column": 46 } } } diff --git a/ets2panda/test/parser/ets/test_type_alias9-expected.txt b/ets2panda/test/parser/ets/test_type_alias9-expected.txt index 20df64b662..f71a0b03d7 100644 --- a/ets2panda/test/parser/ets/test_type_alias9-expected.txt +++ b/ets2panda/test/parser/ets/test_type_alias9-expected.txt @@ -226,11 +226,11 @@ "loc": { "start": { "line": 19, - "column": 1 + "column": 5 }, "end": { "line": 19, - "column": 17 + "column": 16 } } }, @@ -397,11 +397,11 @@ "loc": { "start": { "line": 20, - "column": 1 + "column": 5 }, "end": { "line": 20, - "column": 52 + "column": 51 } } } @@ -525,7 +525,7 @@ }, "end": { "line": 19, - "column": 13 + "column": 16 } } }, @@ -602,7 +602,7 @@ }, "end": { "line": 20, - "column": 16 + "column": 51 } } } diff --git a/ets2panda/test/parser/ets/throwsRethrowsAsVariables-expected.txt b/ets2panda/test/parser/ets/throwsRethrowsAsVariables-expected.txt index 203a0147ad..f0c71fd715 100644 --- a/ets2panda/test/parser/ets/throwsRethrowsAsVariables-expected.txt +++ b/ets2panda/test/parser/ets/throwsRethrowsAsVariables-expected.txt @@ -118,11 +118,11 @@ "loc": { "start": { "line": 16, - "column": 1 + "column": 5 }, "end": { "line": 16, - "column": 16 + "column": 15 } } }, @@ -174,11 +174,11 @@ "loc": { "start": { "line": 17, - "column": 1 + "column": 5 }, "end": { "line": 17, - "column": 18 + "column": 17 } } } diff --git a/ets2panda/test/parser/ets/trailing_lambda_tests/trailing_lambda_mismatch_lambda_signature-expected.txt b/ets2panda/test/parser/ets/trailing_lambda_tests/trailing_lambda_mismatch_lambda_signature-expected.txt index fba13eb71c..f3e0754f7f 100644 --- a/ets2panda/test/parser/ets/trailing_lambda_tests/trailing_lambda_mismatch_lambda_signature-expected.txt +++ b/ets2panda/test/parser/ets/trailing_lambda_tests/trailing_lambda_mismatch_lambda_signature-expected.txt @@ -118,7 +118,7 @@ "loc": { "start": { "line": 16, - "column": 1 + "column": 5 }, "end": { "line": 16, diff --git a/ets2panda/test/parser/ets/tuple_type_1-expected.txt b/ets2panda/test/parser/ets/tuple_type_1-expected.txt index 101d5111ac..bca78f1e0e 100644 --- a/ets2panda/test/parser/ets/tuple_type_1-expected.txt +++ b/ets2panda/test/parser/ets/tuple_type_1-expected.txt @@ -359,11 +359,11 @@ "loc": { "start": { "line": 22, - "column": 1 + "column": 5 }, "end": { "line": 22, - "column": 34 + "column": 33 } } }, @@ -470,11 +470,11 @@ "loc": { "start": { "line": 23, - "column": 1 + "column": 5 }, "end": { "line": 23, - "column": 44 + "column": 43 } } }, @@ -569,11 +569,11 @@ "loc": { "start": { "line": 24, - "column": 1 + "column": 5 }, "end": { "line": 24, - "column": 50 + "column": 49 } } }, @@ -625,11 +625,11 @@ "loc": { "start": { "line": 25, - "column": 1 + "column": 5 }, "end": { "line": 25, - "column": 16 + "column": 15 } } }, @@ -710,11 +710,11 @@ "loc": { "start": { "line": 26, - "column": 1 + "column": 5 }, "end": { "line": 26, - "column": 42 + "column": 41 } } }, @@ -809,11 +809,11 @@ "loc": { "start": { "line": 27, - "column": 1 + "column": 5 }, "end": { "line": 27, - "column": 50 + "column": 49 } } } @@ -1342,7 +1342,7 @@ }, "end": { "line": 22, - "column": 26 + "column": 33 } } }, @@ -1476,7 +1476,7 @@ }, "end": { "line": 23, - "column": 26 + "column": 43 } } }, @@ -1663,7 +1663,7 @@ }, "end": { "line": 24, - "column": 39 + "column": 49 } } }, @@ -1713,7 +1713,7 @@ }, "end": { "line": 25, - "column": 12 + "column": 15 } } }, @@ -1847,7 +1847,7 @@ }, "end": { "line": 26, - "column": 34 + "column": 41 } } }, @@ -1994,7 +1994,7 @@ }, "end": { "line": 27, - "column": 39 + "column": 49 } } } diff --git a/ets2panda/test/parser/ets/unary_op-expected.txt b/ets2panda/test/parser/ets/unary_op-expected.txt index 9a9d965671..32aa0ba97d 100644 --- a/ets2panda/test/parser/ets/unary_op-expected.txt +++ b/ets2panda/test/parser/ets/unary_op-expected.txt @@ -118,11 +118,11 @@ "loc": { "start": { "line": 16, - "column": 1 + "column": 5 }, "end": { "line": 16, - "column": 11 + "column": 10 } } }, @@ -190,11 +190,11 @@ "loc": { "start": { "line": 17, - "column": 1 + "column": 5 }, "end": { "line": 17, - "column": 13 + "column": 12 } } }, @@ -262,11 +262,11 @@ "loc": { "start": { "line": 18, - "column": 1 + "column": 5 }, "end": { "line": 18, - "column": 13 + "column": 12 } } }, @@ -333,11 +333,11 @@ "loc": { "start": { "line": 19, - "column": 1 + "column": 5 }, "end": { "line": 19, - "column": 12 + "column": 11 } } }, @@ -405,11 +405,11 @@ "loc": { "start": { "line": 20, - "column": 1 + "column": 5 }, "end": { "line": 20, - "column": 12 + "column": 11 } } }, @@ -477,11 +477,11 @@ "loc": { "start": { "line": 21, - "column": 1 + "column": 5 }, "end": { "line": 21, - "column": 12 + "column": 11 } } }, @@ -533,11 +533,11 @@ "loc": { "start": { "line": 22, - "column": 1 + "column": 5 }, "end": { "line": 22, - "column": 14 + "column": 13 } } }, @@ -605,11 +605,11 @@ "loc": { "start": { "line": 23, - "column": 1 + "column": 5 }, "end": { "line": 23, - "column": 12 + "column": 11 } } }, @@ -677,11 +677,11 @@ "loc": { "start": { "line": 25, - "column": 1 + "column": 5 }, "end": { "line": 25, - "column": 12 + "column": 11 } } } diff --git a/ets2panda/test/parser/ets/user_defined_22-expected.txt b/ets2panda/test/parser/ets/user_defined_22-expected.txt index 6b33f24143..f61d047d2f 100644 --- a/ets2panda/test/parser/ets/user_defined_22-expected.txt +++ b/ets2panda/test/parser/ets/user_defined_22-expected.txt @@ -456,7 +456,7 @@ "loc": { "start": { "line": 20, - "column": 1 + "column": 5 }, "end": { "line": 21, @@ -570,7 +570,7 @@ "loc": { "start": { "line": 22, - "column": 1 + "column": 5 }, "end": { "line": 22, @@ -789,7 +789,7 @@ }, "end": { "line": 22, - "column": 11 + "column": 14 } } } diff --git a/ets2panda/test/parser/ets/user_defined_3-expected.txt b/ets2panda/test/parser/ets/user_defined_3-expected.txt index 18603423f6..4ed6dec988 100644 --- a/ets2panda/test/parser/ets/user_defined_3-expected.txt +++ b/ets2panda/test/parser/ets/user_defined_3-expected.txt @@ -161,7 +161,7 @@ }, "end": { "line": 16, - "column": 22 + "column": 14 } } }, @@ -210,7 +210,7 @@ }, "end": { "line": 17, - "column": 26 + "column": 16 } } }, @@ -259,7 +259,7 @@ }, "end": { "line": 18, - "column": 24 + "column": 15 } } }, @@ -308,7 +308,7 @@ }, "end": { "line": 19, - "column": 20 + "column": 13 } } }, @@ -357,7 +357,7 @@ }, "end": { "line": 20, - "column": 22 + "column": 14 } } }, @@ -406,7 +406,7 @@ }, "end": { "line": 21, - "column": 18 + "column": 12 } } }, @@ -455,7 +455,7 @@ }, "end": { "line": 22, - "column": 20 + "column": 13 } } }, @@ -504,7 +504,7 @@ }, "end": { "line": 23, - "column": 20 + "column": 13 } } }, diff --git a/ets2panda/test/unit/public/es2panda_public_test.cpp b/ets2panda/test/unit/public/es2panda_public_test.cpp index 2987e79dc3..d0b8c83d6c 100644 --- a/ets2panda/test/unit/public/es2panda_public_test.cpp +++ b/ets2panda/test/unit/public/es2panda_public_test.cpp @@ -94,9 +94,8 @@ function main() { impl_->AstNodeForEach(impl_->ProgramAst(impl_->ContextProgram(ctx)), func, &arg); - std::vector expected {"C", "n", "string", "constructor", "constructor", "ETSGLOBAL", - "_$init$_", "_$init$_", "main", "main", "c", "C", - "console", "log", "c", "n", ""}; + std::vector expected {"C", "n", "string", "constructor", "constructor", "main", + "c", "C", "console", "log", "c", "n"}; ASSERT_EQ(arg.ids, expected); impl_->DestroyContext(ctx); diff --git a/ets2panda/test/unit/public/plugin_test.expected.txt b/ets2panda/test/unit/public/plugin_test.expected.txt index f578824e84..b1a9b406b0 100644 --- a/ets2panda/test/unit/public/plugin_test.expected.txt +++ b/ets2panda/test/unit/public/plugin_test.expected.txt @@ -1,9 +1,5 @@ Hi there! After parse -ETSGLOBAL -_$init$_ -_$init$_ -main main m n @@ -11,6 +7,5 @@ console log m n - After check After lowerings diff --git a/ets2panda/test/unit/union_normalization_test.cpp b/ets2panda/test/unit/union_normalization_test.cpp index 0c680764b0..f55635c059 100644 --- a/ets2panda/test/unit/union_normalization_test.cpp +++ b/ets2panda/test/unit/union_normalization_test.cpp @@ -122,10 +122,6 @@ public: publicContext_->emitter = context.GetEmitter(); parser.ParseScript(unit.input, unit.options.compilationMode == CompilationMode::GEN_STD_LIB); - if constexpr (std::is_same_v && std::is_same_v) { - reinterpret_cast(varbinder)->FillResolvedImportPathes( - parser.ResolvedParsedSourcesMap(), allocator_.get()); - } for (auto *phase : getPhases) { if (!phase->Apply(publicContext_.get(), program)) { return; diff --git a/ets2panda/util/arktsconfig.cpp b/ets2panda/util/arktsconfig.cpp index 3e84f1fd05..2c87edc444 100644 --- a/ets2panda/util/arktsconfig.cpp +++ b/ets2panda/util/arktsconfig.cpp @@ -321,7 +321,7 @@ static std::string TrimPath(const std::string &path) return trimmedPath; } -std::string ArkTsConfig::ResolvePath(const std::string &path) +std::optional ArkTsConfig::ResolvePath(const std::string &path) const { for (const auto &[alias, paths] : paths_) { auto trimmedAlias = TrimPath(alias); @@ -334,7 +334,7 @@ std::string ArkTsConfig::ResolvePath(const std::string &path) return resolved; } } - return ""; + return std::nullopt; } #ifdef ARKTSCONFIG_USE_FILESYSTEM diff --git a/ets2panda/util/arktsconfig.h b/ets2panda/util/arktsconfig.h index e7c697eaa2..1ebb1a2527 100644 --- a/ets2panda/util/arktsconfig.h +++ b/ets2panda/util/arktsconfig.h @@ -80,7 +80,7 @@ public: explicit ArkTsConfig(std::string configPath) : configPath_(std::move(configPath)) {} bool Parse(); - std::string ResolvePath(const std::string &path); + std::optional ResolvePath(const std::string &path) const; std::string ConfigPath() const { diff --git a/ets2panda/util/error_handler.cpp b/ets2panda/util/error_handler.cpp new file mode 100644 index 0000000000..e8554ce8bf --- /dev/null +++ b/ets2panda/util/error_handler.cpp @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2021 - 2023 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. + */ + +#include "util/error_handler.h" + +namespace panda::es2panda::util { + +void ErrorHandler::ThrowSyntaxError(std::string_view errorMessage, const lexer::SourcePosition &pos) const +{ + lexer::LineIndex index(program_->SourceCode()); + lexer::SourceLocation loc = index.GetLocation(pos); + + throw Error {ErrorType::SYNTAX, program_->SourceFilePath().Utf8(), errorMessage, loc.line, loc.col}; +} + +void ErrorHandler::ThrowSyntaxError(const parser::Program *program, std::string_view errorMessage, + const lexer::SourcePosition &pos) +{ + ErrorHandler(program).ThrowSyntaxError(errorMessage, pos); +} + +} // namespace panda::es2panda::util diff --git a/ets2panda/util/error_handler.h b/ets2panda/util/error_handler.h new file mode 100644 index 0000000000..547ee62dab --- /dev/null +++ b/ets2panda/util/error_handler.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2021 - 2023 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. + */ + +#ifndef PANDA_ERRORHANDLER_H +#define PANDA_ERRORHANDLER_H + +#include +#include "parser/program/program.h" +#include "lexer/token/sourceLocation.h" + +namespace panda::es2panda::util { + +class ErrorHandler { +public: + explicit ErrorHandler(const parser::Program *program) : program_(program) {} + + [[noreturn]] void ThrowSyntaxError(std::string_view errorMessage, const lexer::SourcePosition &pos) const; + + [[noreturn]] static void ThrowSyntaxError(const parser::Program *program, std::string_view errorMessage, + const lexer::SourcePosition &pos); + +private: + const parser::Program *program_; +}; +} // namespace panda::es2panda::util + +#endif // PANDA_ERRORHANDLER_H diff --git a/ets2panda/util/helpers.cpp b/ets2panda/util/helpers.cpp index c1b73175b8..262a2009bb 100644 --- a/ets2panda/util/helpers.cpp +++ b/ets2panda/util/helpers.cpp @@ -487,20 +487,16 @@ std::vector Helpers::CollectBindingNames(ir::AstNode *node) return bindings; } -void Helpers::CheckImportedName(ArenaVector *specifiers, const ir::ImportSpecifier *specifier, - const std::string &fileName) +void Helpers::CheckImportedName(const ArenaVector &specifiers, + const ir::ImportSpecifier *specifier, const std::string &fileName) { auto newIdentName = specifier->Imported()->Name(); auto newAliasName = specifier->Local()->Name(); std::stringstream message {}; - for (auto *it : *specifiers) { - if (!it->IsImportSpecifier()) { - continue; - } - - auto savedIdentName = it->AsImportSpecifier()->Imported()->Name(); - auto savedAliasName = it->AsImportSpecifier()->Local()->Name(); + for (auto *it : specifiers) { + auto savedIdentName = it->Imported()->Name(); + auto savedAliasName = it->Local()->Name(); if (savedIdentName == savedAliasName && savedAliasName == newIdentName) { message << "Warning: '" << newIdentName << "' has already imported "; diff --git a/ets2panda/util/helpers.h b/ets2panda/util/helpers.h index f3f0b927de..447096d4a2 100644 --- a/ets2panda/util/helpers.h +++ b/ets2panda/util/helpers.h @@ -63,6 +63,40 @@ enum class LogLevel : std::uint8_t { FATAL, }; +class NodeAllocator { +public: + template + static T *NoSetParent(ArenaAllocator *alloc, Args &&...args) + { + return alloc->New(std::forward(args)...); + } + + template + static T *ForceSetParent(ArenaAllocator *alloc, Args &&...args) + { + auto *ret = NoSetParent(alloc, std::forward(args)...); + if (ret == nullptr) { + return nullptr; + } + ret->Iterate([ret](ir::AstNode *child) { child->SetParent(ret); }); + return ret; + } + + template + static T *Alloc(ArenaAllocator *alloc, Args &&...args) + { + auto *ret = NoSetParent(alloc, std::forward(args)...); + if (ret == nullptr) { + return nullptr; + } + ret->Iterate([ret](ir::AstNode *child) { + ASSERT(child->Parent() == nullptr); + child->SetParent(ret); + }); + return ret; + } +}; + class Helpers { public: Helpers() = delete; @@ -122,11 +156,18 @@ public: static bool IsPattern(const ir::AstNode *node); static std::vector CollectBindingNames(ir::AstNode *node); static util::StringView FunctionName(ArenaAllocator *allocator, const ir::ScriptFunction *func); - static void CheckImportedName(ArenaVector *specifiers, const ir::ImportSpecifier *specifier, - const std::string &fileName); + static void CheckImportedName(const ArenaVector &specifiers, + const ir::ImportSpecifier *specifier, const std::string &fileName); static std::tuple ParamName(ArenaAllocator *allocator, const ir::AstNode *param, uint32_t index); + template + static ArenaVector ConvertVector(const ArenaVector &src) + { + ArenaVector dst(src.begin(), src.end(), src.get_allocator()); + return dst; + } + template static bool IsTargetFitInSourceRange(Target target) { diff --git a/ets2panda/util/importPathResolver.cpp b/ets2panda/util/importPathResolver.cpp new file mode 100644 index 0000000000..156024b96f --- /dev/null +++ b/ets2panda/util/importPathResolver.cpp @@ -0,0 +1,354 @@ +/** + * Copyright (c) 2021 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. + */ + +#include "util/importPathResolver.h" +#include "util/error_handler.h" + +#if defined PANDA_TARGET_MOBILE +#define USE_UNIX_SYSCALL +#endif + +#ifdef USE_UNIX_SYSCALL +#include +#include +#include +#else +#if __has_include() +#include +namespace fs = std::filesystem; +#elif __has_include() +#include +namespace fs = std::experimental::filesystem; +#endif +#endif + +namespace panda::es2panda::util { + +std::string ImportPathResolver::ResolveFullPathFromRelative(const std::string &path, const parser::Program *program) +{ + const auto resolvedFp = program->ResolvedFilePath().Mutf8(); + const auto sourceFp = program->SourceFileFolder().Mutf8(); + if (resolvedFp.empty()) { + auto fp = JoinPaths(sourceFp, path); + return util::Helpers::IsRealPath(fp) ? fp : path; + } + auto fp = JoinPaths(resolvedFp, path); + if (util::Helpers::IsRealPath(fp)) { + return fp; + } + if (path.find(sourceFp) == 0) { + return JoinPaths(resolvedFp, path.substr(sourceFp.size())); + } + return path; +} + +ImportPathResolver::ResultPath ImportPathResolver::GetImportPath(const PathT &path, + const parser::Program *program) const +{ + ResultPath resolvedPath; + if (util::Helpers::IsRelativePath(path)) { + resolvedPath = ResultPath::Ok(util::Helpers::GetAbsPath(ResolveFullPathFromRelative(path, program))); + } else if (path.find(PATH_DELIM) == 0) { + resolvedPath = ResultPath::Ok(config_->BaseUrl()); + resolvedPath->append(path, 0, path.length()); + } else { + auto &dynamicPaths = config_->DynamicPaths(); + auto it = dynamicPaths.find(path); + if (it != dynamicPaths.cend() && !it->second.HasDecl()) { + resolvedPath = ResultPath::Ok(path); + } else { + resolvedPath = ResolveRootPath(path); + } + } + return resolvedPath; +} + +ImportPathResolver::ResultPath ImportPathResolver::ResolveImportPath(const PathT &path, const parser::Program *program) +{ + auto importPath = GetImportPath(path, program); + if (importPath) { + AddResolved(path, *importPath); + } + return importPath; +} + +std::pair ImportPathResolver::GetSourceRegularPath( + const PathT &path, const PathT &resolvedPath) const +{ + if (!panda::os::file::File::IsRegularFile(resolvedPath)) { + for (const auto &ext : allowedExts_) { + if (panda::os::file::File::IsRegularFile(resolvedPath + ext)) { + return std::make_pair(ResultPath::Ok(path + ext), true); + } + } + return std::make_pair(ResultPath::Error(ErrorCode::INCORRECT_PATH, resolvedPath), false); + } + return std::make_pair(ResultPath::Ok(path), false); +} + +ImportPathResolver::ImportData ImportPathResolver::GetImportData(const PathT &path) const +{ + auto &dynamicPaths = config_->DynamicPaths(); + auto key = panda::os::NormalizePath(path); + + auto it = dynamicPaths.find(key); + if (it == dynamicPaths.cend()) { + key = panda::os::RemoveExtension(key); + } + + while (it == dynamicPaths.cend() && !key.empty()) { + it = dynamicPaths.find(key); + if (it != dynamicPaths.cend()) { + break; + } + key = panda::os::GetParentDir(key); + } + + if (it != dynamicPaths.cend()) { + return {it->second.GetLanguage(), key, it->second.HasDecl()}; + } + return {ToLanguage(extension_), path, true}; +} + +ImportPathResolver::ResultSources ImportPathResolver::CollectUserSources(const PathT &path, + const parser::Program *program) +{ + const auto maybeResolvedPath = ResolveImportPath(path, program); + if (!maybeResolvedPath) { + return ResultSources::Error(maybeResolvedPath); + } + const auto &resolvedPath = *maybeResolvedPath; + const auto data = GetImportData(resolvedPath); + if (!data.hasDecl) { + return ResultSources::Ok(std::vector {}, false); + } + + if (!panda::os::file::File::IsDirectory(resolvedPath)) { + auto [regular_path, is_module] = GetSourceRegularPath(path, resolvedPath); + return std::move(regular_path).Transform([module = is_module](PathT &&resPath) { + return UserSources {std::vector {resPath}, module}; + }); + } + + auto newPaths = CollectUserSourcesFromIndex(path, resolvedPath); + return std::move(newPaths).Transform([](std::vector &&paths) { + return UserSources {std::move(paths), false}; + }); +} + +ImportPathResolver::ResultT> ImportPathResolver::CollectUserSourcesFromIndex( + const std::string &path, const std::string &resolvedPath) +{ + std::vector userPaths; + + auto files = ListFiles(resolvedPath); + if (!files) { + return files.ExpectError(); + } + for (const auto &filename : files.ExpectOk()) { + std::string filePath = JoinPaths(path, filename); + + if (IsIndexFile(filename)) { + userPaths.clear(); + userPaths.emplace_back(filePath); + break; + } + if (filename == "Object.ets") { + userPaths.emplace(userPaths.begin(), filePath); + } else { + userPaths.emplace_back(filePath); + } + } + return ResultT>::Ok(userPaths); +} + +ImportPathResolver::ResultT> ImportPathResolver::CollectDefaultSources( + const std::vector &stdlib, const parser::Program *program) +{ + std::vector paths; + std::vector defaultSources; + + for (auto const &path : stdlib) { + const auto maybeResolvedPath = ResolveImportPath(path, program); + if (!maybeResolvedPath) { + return maybeResolvedPath.ExpectError(); + } + auto files = ListFiles(maybeResolvedPath.ExpectOk()); + if (!files) { + return files.ExpectError(); + } + for (const auto &filename : files.ExpectOk()) { + const PathT filePath = JoinPaths(path, filename); + if (filename == "Object.ets") { + defaultSources.emplace(defaultSources.begin(), filePath); + } else { + defaultSources.emplace_back(filePath); + } + } + } + return ResultT>::Ok(defaultSources); +} + +ImportPathResolver::ResultT> ImportPathResolver::ParseSources( + const std::vector &paths, const parser::Program *program) +{ + std::vector sources; + + for (const auto &path : paths) { + auto resolvedPath = ResolveImportPath(path, program); + if (!resolvedPath) { + return resolvedPath.ExpectError(); + } + + const auto data = GetImportData(resolvedPath.ExpectOk()); + if (!data.hasDecl) { + continue; + } + sources.emplace_back(SourceInfo {path, resolvedPath.ExpectOk(), false, data.lang}); + } + return ResultT>::Ok(sources); +} + +void ImportPathResolver::FilterParsedSources(std::vector &sources, const parser::Program *program) +{ + auto condition = [this, program](auto x) { + auto resolved = GetImportPath(x, program).ExpectOk(); + auto found = std::count_if(resolvedParsedSources_.begin(), resolvedParsedSources_.end(), + [resolved](const auto &p) { return p.second == resolved; }); + if (found != 0) { + AddResolved(x, resolved); + } + return found; + }; + + // erase_if - c++20 ext + for (auto it = sources.begin(); it != sources.end();) { + if (condition(*it) != 0) { + it = sources.erase(it); + } else { + ++it; + } + } +} + +ImportPathResolver::ResultPath ImportPathResolver::ResolveRootPath(const ImportPathResolver::PathT &path) const +{ + std::string::size_type pos = path.find(PATH_DELIM); + bool containsDelim = (pos != std::string::npos); + std::string rootPart = containsDelim ? path.substr(0, pos) : path; + + static const std::unordered_set STDLIB_PARTS = {"std", "escompat"}; + + PathT resolvedPath; + if (STDLIB_PARTS.count(rootPart) != 0 && !stdlibPath_.empty()) { + resolvedPath = JoinPaths(stdlibPath_, rootPart); + if (containsDelim) { + resolvedPath.append(1, PATH_DELIM).append(path, rootPart.length() + 1, path.length()); + } + } else { + auto resolved = config_->ResolvePath(path); + if (resolved) { + resolvedPath = *resolved; + } else { + return ResultPath::Error(ErrorCode::ARKTS_PREFIX_FAIL, path); + } + } + return ResultPath::Ok(resolvedPath); +} + +std::vector ImportPathResolver::ReExportPaths( + const ArenaVector &reExports, const std::vector &alreadyExported) +{ + std::vector result; + for (auto reExport : reExports) { + auto progPath = reExport->GetProgramPath().Mutf8(); + if (std::count(alreadyExported.begin(), alreadyExported.end(), progPath) == 0U) { + continue; + } + auto path = progPath.substr(0, progPath.find_last_of(PATH_DELIM)); + for (auto item : reExport->GetUserPaths()) { + const auto reExPath = item.Mutf8(); + result.push_back( + JoinPaths(path, reExPath.substr(reExPath.find_first_of(PATH_DELIM) + 1, reExPath.length()))); + } + } + return result; +} + +bool ImportPathResolver::IsCompatibleExtension(const std::string &extension) const +{ + return allowedExts_.count(extension) != 0U; +} + +bool ImportPathResolver::IsCompatibleFile(const std::string &fileName) const +{ + std::string::size_type pos = fileName.find_last_of('.'); + if (pos == std::string::npos) { + return false; + } + return IsCompatibleExtension(fileName.substr(pos)); +} + +bool ImportPathResolver::IsStdLib(const parser::Program *program) const +{ + const auto &stdlib = StdLib(); + return std::count(stdlib.begin(), stdlib.end(), std::string(program->SourceFileFolder())) != 0; +} + +ImportPathResolver::ResultT> ImportPathResolver::ListFiles( + const PathT &resolvedPath) const +{ + std::vector files; +#ifdef USE_UNIX_SYSCALL + DIR *dir = opendir(resolvedPath.c_str()); + + if (dir == nullptr) { + return ResultT>::Error(ErrorCode::INCORRECT_PATH, resolvedPath); + } + + struct dirent *entry; + while ((entry = readdir(dir)) != nullptr) { + if (entry->d_type != DT_REG) { + continue; + } + + std::string fileName = entry->d_name; + if (!IsCompatibleFile(fileName)) { + continue; + } + + files.emplace_back(fileName); + } + + closedir(dir); +#else + for (auto const &entry : fs::directory_iterator(resolvedPath)) { + if (!fs::is_regular_file(entry) || !IsCompatibleExtension(entry.path().extension().string())) { + continue; + } + files.emplace_back(entry.path().filename().string()); + } +#endif + std::sort(files.begin(), files.end()); + return ResultT>::Ok(files); +} + +bool ImportPathResolver::IsIndexFile(const std::string &fileName) +{ + return fileName == "index.ets" || fileName == "index.ts"; +} + +} // namespace panda::es2panda::util +#undef USE_UNIX_SYSCALL diff --git a/ets2panda/util/importPathResolver.h b/ets2panda/util/importPathResolver.h new file mode 100644 index 0000000000..e10d6e26f2 --- /dev/null +++ b/ets2panda/util/importPathResolver.h @@ -0,0 +1,154 @@ +/** + * Copyright (c) 2021 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. + */ + +#ifndef PANDA_IMPORTPATHRESOLVER_H +#define PANDA_IMPORTPATHRESOLVER_H + +#include +#include +#include "util/helpers.h" +#include "util/arktsconfig.h" +#include "ir/ets/etsReExportDeclaration.h" +#include "parser/program/program.h" +#include "es2panda.h" +#include "os/filesystem.h" +#include "util/error_handler.h" +#include "util/result.h" + +namespace panda::es2panda::util { + +class ImportPathResolver { +public: + enum class ErrorCode { + INCORRECT_PATH, + ARKTS_PREFIX_FAIL, + }; + + template + using ResultT = Result; + +private: + using PathT = std::string; + + using ResultPath = ResultT; + + struct UserSources { + std::vector sources; + bool isModule {false}; + }; + using ResultSources = ResultT; + + const std::unordered_set allowedExts_ = {".ets", ".ts"}; + +public: + struct ImportData { + Language lang; + std::string module; + bool hasDecl; + }; + + ImportPathResolver(std::shared_ptr config, PathT stdlibPath, ScriptExtension extension) + : config_(std::move(config)), stdlibPath_(std::move(stdlibPath)), extension_(extension) + { + } + + static std::vector ReExportPaths(const ArenaVector &reExports, + const std::vector &alreadyExported); + + void AddResolved(const PathT &path, const PathT &realPath) + { + resolvedParsedSources_.emplace(path, realPath); + } + + ResultPath ResolveImportPath(const PathT &path, const parser::Program *program); + + ImportData GetImportData(const PathT &path) const; + + const std::unordered_map &ResolvedParsedSourcesMap() const + { + return resolvedParsedSources_; + } + + static std::vector &StdLib() + { + static std::vector stdlib {"std/core", "std/math", "std/containers", + "std/time", "std/interop/js", "escompat"}; + return stdlib; + } + + bool IsStdLib(const parser::Program *program) const; + + ResultSources CollectUserSources(const PathT &path, const parser::Program *program); + + ResultT> CollectDefaultSources(const std::vector &stdlib, const parser::Program *program); + + struct SourceInfo { + PathT filePath; + PathT resolvedPath; + bool isModule; + Language lang; + }; + + ResultT> ParseSources(const std::vector &paths, const parser::Program *program); + + /** + * Removes from `sources` already parsed files, and mark this paths as resolved + * @param sources + * @param resolved_fp + * @param source_fp + */ + void FilterParsedSources(std::vector &sources, const parser::Program *program); + + /** + * Resolves root path. E.g. rel_dir/file.ets -> absolute_path/rel_dir + * @param path + * @return root path + */ + ResultPath ResolveRootPath(const PathT &path) const; + +private: + ResultT> CollectUserSourcesFromIndex(const PathT &path, const PathT &resolvedPath); + + /** + * @param path + * @param resolved_path + * @return (src path, is_module) + */ + std::pair GetSourceRegularPath(const PathT &path, const PathT &resolvedPath) const; + static PathT ResolveFullPathFromRelative(const PathT &path, const parser::Program *program); + ResultPath GetImportPath(const PathT &path, const parser::Program *program) const; + + /** + * @param resolvedPath directory absolute path + * @return alphabetically ordered ts/ets files in directory + */ + ResultT> ListFiles(const PathT &resolvedPath) const; + + bool IsCompatibleExtension(const std::string &extension) const; + + bool IsCompatibleFile(const std::string &fileName) const; + + static bool IsIndexFile(const std::string &fileName); + +private: + std::shared_ptr config_; + std::unordered_map resolvedParsedSources_; + const PathT stdlibPath_; + const ScriptExtension extension_; + static constexpr char PATH_DELIM = panda::os::file::File::GetPathDelim().at(0); +}; +} // namespace panda::es2panda::util + +#endif // PANDA_IMPORTPATHRESOLVER_H diff --git a/ets2panda/util/result.h b/ets2panda/util/result.h new file mode 100644 index 0000000000..c73a76fe7a --- /dev/null +++ b/ets2panda/util/result.h @@ -0,0 +1,149 @@ +/** + * Copyright (c) 2021-2022 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. + */ + +#ifndef PANDA_RESULT_H +#define PANDA_RESULT_H + +#include +#include + +namespace panda::es2panda::util { + +/** + * Class to handle errors + * @tparam SuccessT type in case of success + * @tparam ErrorStatus error code, should be enum + * @tparam ErrorV error value to provide detail about error + * NOTE: `ErrorV = void` not allowed yet. + */ +template +class Result { + using ErrorT = std::pair; + + class Tag {}; + template + explicit Result(Tag /*tag*/, Args... args) : value_ {SuccessT {std::forward(args)...}} + { + } + +public: + Result() = default; + + template + static Result Ok(Args... args) + { + return Result(Tag {}, std::forward(args)...); + } + + static Result Error(ErrorStatus status, ErrorV value) + { + return Result(std::make_pair(status, value)); + } + + template + static Result Error(Result result) + { + return Result(result.ExpectError()); + } + + Result(ErrorStatus status, ErrorV errorVal) : value_(std::make_pair(std::move(status), std::move(errorVal))) {} + + // NOLINTNEXTLINE(google-explicit-constructor) + Result(std::pair error) : value_(std::move(error)) {} + + explicit Result(SuccessT success) : value_(success) {} + + explicit operator bool() const + { + return IsOk(); + } + + SuccessT &operator*() + { + return std::get(value_); + } + + const SuccessT &operator*() const + { + return std::get(value_); + } + + SuccessT *operator->() + { + return &std::get(value_); + } + + const SuccessT *operator->() const + { + return &std::get(value_); + } + + bool IsOk() const + { + return std::holds_alternative(value_); + } + + bool IsError() const + { + return !IsOk(); + } + + const std::pair &ExpectError() const + { + return std::get(value_); + } + + const SuccessT &ExpectOk() const & + { + return std::get(value_); + } + + SuccessT ExpectOk() && + { + return std::move(std::get(value_)); + } + + template + Result Transform(std::function cb) + { + Result result; + if (IsError()) { + result = Result::Error(this); + } else { + result = Result::Ok(cb(ExpectOk())); + } + return result; + } + + template + Result Transform(std::function cb) && + { + using ReturnT = Result; + ReturnT result; + if (IsError()) { + result = ReturnT::Error(*this); + } else { + result = ReturnT::Ok(cb(std::move(*this).ExpectOk())); + } + return result; + } + +private: + std::variant value_; +}; + +} // namespace panda::es2panda::util + +#endif // PANDA_RESULT_H diff --git a/ets2panda/varbinder/ETSBinder.cpp b/ets2panda/varbinder/ETSBinder.cpp index 06d08f3553..b60c1e5f1e 100644 --- a/ets2panda/varbinder/ETSBinder.cpp +++ b/ets2panda/varbinder/ETSBinder.cpp @@ -1040,7 +1040,7 @@ void ETSBinder::BuildImportDeclaration(ir::ETSImportDeclaration *decl) return; } - auto specifiers = decl->Specifiers(); + const auto &specifiers = decl->Specifiers(); for (auto specifier : specifiers) { AddSpecifiersToTopBindings(specifier, decl, decl->Source()); diff --git a/ets2panda/varbinder/ETSBinder.h b/ets2panda/varbinder/ETSBinder.h index edd27f9a43..bbaaad08f6 100644 --- a/ets2panda/varbinder/ETSBinder.h +++ b/ets2panda/varbinder/ETSBinder.h @@ -46,7 +46,7 @@ public: lambdaObjects_(Allocator()->Adapter()), dynamicImportVars_(Allocator()->Adapter()), importSpecifiers_(Allocator()->Adapter()), - resolvedImportPathesMap_(Allocator()->Adapter()) + resolvedImportPathsMap_(Allocator()->Adapter()) { InitImplicitThisParam(); } @@ -202,23 +202,18 @@ public: defaultExport_ = defaultExport; } - const ArenaUnorderedMap &ResolvedImportPathesMap() const - { - return resolvedImportPathesMap_; - } - const util::StringView &GetResolvedImportPath(const util::StringView &path) const { - ASSERT(resolvedImportPathesMap_.find(path) != resolvedImportPathesMap_.end()); + ASSERT(resolvedImportPathsMap_.find(path) != resolvedImportPathsMap_.end()); - return resolvedImportPathesMap_.find(path)->second; + return resolvedImportPathsMap_.find(path)->second; } - void FillResolvedImportPathes(const std::unordered_map &map, ArenaAllocator *allocator) + void FillResolvedImportPaths(const std::unordered_map &map, ArenaAllocator *allocator) { for (const auto &path : map) { - resolvedImportPathesMap_.emplace(util::UString(path.first, allocator).View(), - util::UString(path.second, allocator).View()); + resolvedImportPathsMap_.emplace(util::UString(path.first, allocator).View(), + util::UString(path.second, allocator).View()); } } @@ -226,16 +221,6 @@ public: bool IsDynamicNamespaceVariable(const Variable *var) const; const DynamicImportData *DynamicImportDataForVar(const Variable *var) const; - static constexpr std::string_view DEFAULT_IMPORT_SOURCE_FILE = ".ets"; - static constexpr std::string_view DEFAULT_IMPORT_SOURCE = R"( -import * from "std/core"; -import * from "std/math"; -import * from "std/containers"; -import * from "std/time"; -import * from "std/interop/js"; -import * from "escompat"; -)"; - void ResolveReferenceForScope(ir::AstNode *node, Scope *scope); void ResolveReferencesForScope(ir::AstNode const *parent, Scope *scope); @@ -262,7 +247,7 @@ private: DynamicImportVariables dynamicImportVars_; ir::Identifier *thisParam_ {}; ArenaVector> importSpecifiers_; - ArenaUnorderedMap resolvedImportPathesMap_; + ArenaUnorderedMap resolvedImportPathsMap_; ir::AstNode *defaultExport_ {}; }; diff --git a/ets2panda/varbinder/varbinder.h b/ets2panda/varbinder/varbinder.h index 48aa8c7166..0d38ce15be 100644 --- a/ets2panda/varbinder/varbinder.h +++ b/ets2panda/varbinder/varbinder.h @@ -129,6 +129,11 @@ public: return varScope_; } + bool IsETSBinder() const + { + return Extension() == ScriptExtension::ETS; + } + ETSBinder *AsETSBinder() { ASSERT(Extension() == ScriptExtension::ETS); -- Gitee