diff --git a/ets2panda/checker/ETSchecker.h b/ets2panda/checker/ETSchecker.h index b3ced7b7d372663b02d01071966e28c29a3ef118..2bccab94fd1ec4023ba0d4ced36b1535c33456a2 100644 --- a/ets2panda/checker/ETSchecker.h +++ b/ets2panda/checker/ETSchecker.h @@ -18,6 +18,7 @@ #include #include +#include #include "checker/checker.h" @@ -467,6 +468,8 @@ public: bool IsValidRestArgument(ir::Expression *argument, Signature *substitutedSig, TypeRelationFlag flags, std::size_t index); bool SetPreferredTypeForArrayArgument(ir::ArrayExpression *arrayExpr, Signature *substitutedSig); + bool ValidateSpreadArgument(ir::SpreadElement *argument, Signature *substitutedSig, + const std::tuple &info); bool ValidateSignatureRestParams(Signature *substitutedSig, const ArenaVector &arguments, TypeRelationFlag flags, bool reportError, bool unique); void ThrowSignatureMismatch(ArenaVector &signatures, const ArenaVector &arguments, diff --git a/ets2panda/checker/ets/function.cpp b/ets2panda/checker/ets/function.cpp index ea80a961c377bad8c0774150bebde324fc61cc1b..11872971f7928419d005d2037bebb4515856a8b4 100644 --- a/ets2panda/checker/ets/function.cpp +++ b/ets2panda/checker/ets/function.cpp @@ -60,6 +60,42 @@ namespace ark::es2panda::checker { +// Helper function to recursively check for empty array literals at any nesting level +static bool ContainsEmptyArrayLiteral(ir::Expression *expr) +{ + if (!expr->IsArrayExpression()) { + return false; + } + auto *arrayExpr = expr->AsArrayExpression(); + if (arrayExpr->Elements().empty()) { + return true; // Found an empty array literal + } + // Recursively check each element + for (auto *element : arrayExpr->Elements()) { + if (ContainsEmptyArrayLiteral(element)) { + return true; + } + } + return false; +} + +// Helper function to check if a type is a union of multiple array types +static bool IsUnionOfMultipleArrayTypes(Type *type) +{ + if (!type->IsETSUnionType()) { + return false; + } + + int arrayTypeCount = 0; + for (auto *constituent : type->AsETSUnionType()->ConstituentTypes()) { + if (constituent->IsETSArrayType() || constituent->IsETSResizableArrayType()) { + arrayTypeCount++; + } + } + + return arrayTypeCount > 1; +} + // NOTE: #14993 merge with InstantiationContext::ValidateTypeArg bool ETSChecker::IsCompatibleTypeArgument(ETSTypeParameter *typeParam, Type *typeArgument, const Substitution *substitution) @@ -431,9 +467,15 @@ bool ETSChecker::ValidateSignatureRequiredParams(Signature *substitutedSig, } for (size_t index = 0; index < commonArity; ++index) { auto &argument = arguments[index]; - // #22952: infer optional parameter heuristics auto const paramType = GetNonNullishType(substitutedSig->Params()[index]->TsType()); + if (argument->IsArrayExpression() && IsUnionOfMultipleArrayTypes(paramType) && + ContainsEmptyArrayLiteral(argument)) { + if (reportError) { + LogError(diagnostic::UNRESOLVABLE_ARRAY, {}, argument->Start()); + } + return false; + } if (argument->IsObjectExpression()) { if (!paramType->IsETSObjectType()) { return false; @@ -443,7 +485,7 @@ bool ETSChecker::ValidateSignatureRequiredParams(Signature *substitutedSig, } argument->SetPreferredType(paramType); } - + // #22952: infer optional parameter heuristics if (argument->IsMemberExpression()) { SetArrayPreferredTypeForNestedMemberExpressions(argument->AsMemberExpression(), paramType); } else if (argument->IsSpreadElement()) { @@ -455,7 +497,6 @@ bool ETSChecker::ValidateSignatureRequiredParams(Signature *substitutedSig, argument->SetTsType(nullptr); argument->SetPreferredType(paramType); } - if (argTypeInferenceRequired[index]) { ES2PANDA_ASSERT(argument->IsArrowFunctionExpression()); // Note: If the signatures are from lambdas, then they have no `Function`. @@ -468,12 +509,10 @@ bool ETSChecker::ValidateSignatureRequiredParams(Signature *substitutedSig, } ClearPreferredTypeForArray(this, argument, paramType, flags, false); - if (argument->IsIdentifier() && ValidateArgumentAsIdentifier(argument->AsIdentifier())) { LogError(diagnostic::ARG_IS_CLASS_ID, {}, argument->Start()); return false; } - // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) if (!ValidateSignatureInvocationContext(substitutedSig, argument, index, flags)) { return false; @@ -504,11 +543,23 @@ bool ETSChecker::IsValidRestArgument(ir::Expression *const argument, Signature * { auto *restParamType = substitutedSig->RestVar()->TsType(); if (argument->IsObjectExpression()) { - argument->SetPreferredType(GetElementTypeOfArray(restParamType)); + if (restParamType->IsETSArrayType() || restParamType->IsETSResizableArrayType()) { + argument->SetPreferredType(GetElementTypeOfArray(restParamType)); + } // Object literals should be checked separately afterwards after call resolution return true; } + if (argument->IsArrayExpression()) { + if (restParamType->IsETSArrayType() || restParamType->IsETSResizableArrayType()) { + auto targetType = GetElementTypeOfArray(restParamType); + if (IsUnionOfMultipleArrayTypes(targetType) && ContainsEmptyArrayLiteral(argument)) { + LogError(diagnostic::UNRESOLVABLE_ARRAY, {}, argument->Start()); + return false; + } + } + } + // Set preferred type for array expressions before checking, similar to spread elements if (argument->IsArrayExpression()) { if (!SetPreferredTypeForArrayArgument(argument->AsArrayExpression(), substitutedSig)) { @@ -563,6 +614,44 @@ bool ETSChecker::SetPreferredTypeForArrayArgument(ir::ArrayExpression *arrayExpr return true; } +bool ETSChecker::ValidateSpreadArgument(ir::SpreadElement *argument, Signature *substitutedSig, + const std::tuple &info) +{ + auto [flags, reportError, index, restCount] = info; + if (restCount > 1U) { + if (reportError) { + LogError(diagnostic::MULTIPLE_SPREADS, {}, argument->Start()); + } + return false; + } + + auto *const restArgument = argument->Argument(); + Type *targetType = substitutedSig->RestVar()->TsType(); + // backing out of check that results in a signature mismatch would be difficult + // so only attempt it if there is only one candidate signature + if (restArgument->IsArrayExpression()) { + if (IsUnionOfMultipleArrayTypes(targetType) && ContainsEmptyArrayLiteral(restArgument)) { + if (reportError) { + LogError(diagnostic::UNRESOLVABLE_ARRAY, {}, restArgument->Start()); + } + return false; + } + restArgument->AsArrayExpression()->SetPreferredType(targetType); + } + auto const argumentType = restArgument->Check(this); + + auto const invocationCtx = checker::InvocationContext( + Relation(), restArgument, argumentType, substitutedSig->RestVar()->TsType(), argument->Start(), + {{diagnostic::REST_PARAM_INCOMPAT_AT, {argumentType, substitutedSig->RestVar()->TsType(), index + 1}}}, flags); + if (!invocationCtx.IsInvocable()) { + if (restArgument->IsArrayExpression()) { + ModifyPreferredType(restArgument->AsArrayExpression(), nullptr); + } + return false; + } + return true; +} + bool ETSChecker::ValidateSignatureRestParams(Signature *substitutedSig, const ArenaVector &arguments, TypeRelationFlag flags, bool reportError, [[maybe_unused]] const bool unique) @@ -574,6 +663,9 @@ bool ETSChecker::ValidateSignatureRestParams(Signature *substitutedSig, const Ar if (argumentCount == commonArity && substitutedSig->RestVar()->TsType()->IsETSTupleType()) { return false; } + + constexpr size_t INDEX_TUPLE_INDEX = 2; + auto spreadInfo = std::make_tuple(flags, reportError, 0, restCount); for (size_t index = commonArity; index < argumentCount; ++index) { auto &argument = arguments[index]; @@ -584,28 +676,8 @@ bool ETSChecker::ValidateSignatureRestParams(Signature *substitutedSig, const Ar continue; } - if (restCount > 1U) { - if (reportError) { - LogError(diagnostic::MULTIPLE_SPREADS, {}, argument->Start()); - } - return false; - } - - auto *const restArgument = argument->AsSpreadElement()->Argument(); - Type *targetType = substitutedSig->RestVar()->TsType(); - // backing out of check that results in a signature mismatch would be difficult - // so only attempt it if there is only one candidate signature - restArgument->SetPreferredType(targetType); - auto const argumentType = restArgument->Check(this); - - auto const invocationCtx = checker::InvocationContext( - Relation(), restArgument, argumentType, substitutedSig->RestVar()->TsType(), argument->Start(), - {{diagnostic::REST_PARAM_INCOMPAT_AT, {argumentType, substitutedSig->RestVar()->TsType(), index + 1}}}, - flags); - if (!invocationCtx.IsInvocable()) { - if (restArgument->IsArrayExpression()) { - ModifyPreferredType(restArgument->AsArrayExpression(), nullptr); - } + std::get(spreadInfo) = index; + if (!ValidateSpreadArgument(argument->AsSpreadElement(), substitutedSig, spreadInfo)) { return false; } } @@ -809,6 +881,8 @@ Signature *ETSChecker::GetMostSpecificSignature(ArenaVector &compat return nullptr; } + CheckObjectLiteralArguments(mostSpecificSignature, arguments); + // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) if (!TypeInference(mostSpecificSignature, arguments, resolveFlags)) { return nullptr; diff --git a/ets2panda/checker/ets/helpers.cpp b/ets2panda/checker/ets/helpers.cpp index 553abd66e2047e601d4e4440b62db65fc8eadec5..3ea313adfd2ab5f60b46816b01c3a5ac2362fb2d 100644 --- a/ets2panda/checker/ets/helpers.cpp +++ b/ets2panda/checker/ets/helpers.cpp @@ -688,6 +688,9 @@ bool ETSChecker::CheckInit(ir::Identifier *ident, ir::TypeNode *typeAnnotation, { if (typeAnnotation == nullptr) { if (init->IsArrayExpression()) { + if (init->AsArrayExpression()->Elements().empty()) { + LogError(diagnostic::UNRESOLVABLE_ARRAY, {}, ident->Start()); + } annotationType = CheckArrayElements(init->AsArrayExpression()); } else if (init->IsETSNewArrayInstanceExpression()) { annotationType = init->AsETSNewArrayInstanceExpression()->TypeReference()->GetType(this); diff --git a/ets2panda/test/ast/compiler/ets/inferTypeOfArrayNegative2.ets b/ets2panda/test/ast/compiler/ets/inferTypeOfArrayNegative2.ets index b0f2d51def4648f80f50a76557359097f32c0c7a..8a802a3df6ed72371e0d6ceb71e7bff512006d6d 100644 --- a/ets2panda/test/ast/compiler/ets/inferTypeOfArrayNegative2.ets +++ b/ets2panda/test/ast/compiler/ets/inferTypeOfArrayNegative2.ets @@ -13,9 +13,10 @@ * limitations under the License. */ -let a = [] +let a = [] // Cant determine type of array a[0] = 1 a[1] = "1" let b = a[0] + a[1] +/* @@? 16:5 Error TypeError: Can't resolve array type */ /* @@? 19:9 Error TypeError: Bad operand type, the types of the operands must be numeric type, enum or String. */ diff --git a/ets2panda/test/compiler/ets/inferTypeOfArray-expected.txt b/ets2panda/test/compiler/ets/inferTypeOfArray-expected.txt index 760183394c72cfc72f60a15adf4ce811237c4708..cf92b98585fef2664bfedea8455fb41daedd169f 100644 --- a/ets2panda/test/compiler/ets/inferTypeOfArray-expected.txt +++ b/ets2panda/test/compiler/ets/inferTypeOfArray-expected.txt @@ -253,7 +253,7 @@ "operator": "=", "left": { "type": "Identifier", - "name": "b", + "name": "c", "decorators": [], "loc": { "start": { @@ -268,70 +268,6 @@ } } }, - "right": { - "type": "ArrayExpression", - "elements": [], - "loc": { - "start": { - "line": 17, - "column": 9, - "program": "inferTypeOfArray.ets" - }, - "end": { - "line": 17, - "column": 11, - "program": "inferTypeOfArray.ets" - } - } - }, - "loc": { - "start": { - "line": 17, - "column": 5, - "program": "inferTypeOfArray.ets" - }, - "end": { - "line": 17, - "column": 11, - "program": "inferTypeOfArray.ets" - } - } - }, - "loc": { - "start": { - "line": 17, - "column": 5, - "program": "inferTypeOfArray.ets" - }, - "end": { - "line": 17, - "column": 11, - "program": "inferTypeOfArray.ets" - } - } - }, - { - "type": "ExpressionStatement", - "expression": { - "type": "AssignmentExpression", - "operator": "=", - "left": { - "type": "Identifier", - "name": "c", - "decorators": [], - "loc": { - "start": { - "line": 18, - "column": 5, - "program": "inferTypeOfArray.ets" - }, - "end": { - "line": 18, - "column": 6, - "program": "inferTypeOfArray.ets" - } - } - }, "right": { "type": "ArrayExpression", "elements": [ @@ -340,12 +276,12 @@ "value": "a", "loc": { "start": { - "line": 18, + "line": 17, "column": 10, "program": "inferTypeOfArray.ets" }, "end": { - "line": 18, + "line": 17, "column": 13, "program": "inferTypeOfArray.ets" } @@ -354,12 +290,12 @@ ], "loc": { "start": { - "line": 18, + "line": 17, "column": 9, "program": "inferTypeOfArray.ets" }, "end": { - "line": 18, + "line": 17, "column": 14, "program": "inferTypeOfArray.ets" } @@ -367,12 +303,12 @@ }, "loc": { "start": { - "line": 18, + "line": 17, "column": 5, "program": "inferTypeOfArray.ets" }, "end": { - "line": 18, + "line": 17, "column": 14, "program": "inferTypeOfArray.ets" } @@ -380,12 +316,12 @@ }, "loc": { "start": { - "line": 18, + "line": 17, "column": 5, "program": "inferTypeOfArray.ets" }, "end": { - "line": 18, + "line": 17, "column": 14, "program": "inferTypeOfArray.ets" } @@ -402,12 +338,12 @@ "decorators": [], "loc": { "start": { - "line": 19, + "line": 18, "column": 5, "program": "inferTypeOfArray.ets" }, "end": { - "line": 19, + "line": 18, "column": 6, "program": "inferTypeOfArray.ets" } @@ -421,12 +357,12 @@ "value": 1, "loc": { "start": { - "line": 19, + "line": 18, "column": 10, "program": "inferTypeOfArray.ets" }, "end": { - "line": 19, + "line": 18, "column": 11, "program": "inferTypeOfArray.ets" } @@ -437,12 +373,12 @@ "value": 2, "loc": { "start": { - "line": 19, + "line": 18, "column": 13, "program": "inferTypeOfArray.ets" }, "end": { - "line": 19, + "line": 18, "column": 14, "program": "inferTypeOfArray.ets" } @@ -453,12 +389,12 @@ "value": 3, "loc": { "start": { - "line": 19, + "line": 18, "column": 16, "program": "inferTypeOfArray.ets" }, "end": { - "line": 19, + "line": 18, "column": 17, "program": "inferTypeOfArray.ets" } @@ -467,12 +403,12 @@ ], "loc": { "start": { - "line": 19, + "line": 18, "column": 9, "program": "inferTypeOfArray.ets" }, "end": { - "line": 19, + "line": 18, "column": 18, "program": "inferTypeOfArray.ets" } @@ -480,12 +416,12 @@ }, "loc": { "start": { - "line": 19, + "line": 18, "column": 5, "program": "inferTypeOfArray.ets" }, "end": { - "line": 19, + "line": 18, "column": 18, "program": "inferTypeOfArray.ets" } @@ -493,12 +429,12 @@ }, "loc": { "start": { - "line": 19, + "line": 18, "column": 5, "program": "inferTypeOfArray.ets" }, "end": { - "line": 19, + "line": 18, "column": 18, "program": "inferTypeOfArray.ets" } @@ -515,12 +451,12 @@ "decorators": [], "loc": { "start": { - "line": 20, + "line": 19, "column": 5, "program": "inferTypeOfArray.ets" }, "end": { - "line": 20, + "line": 19, "column": 6, "program": "inferTypeOfArray.ets" } @@ -534,12 +470,12 @@ "value": 1, "loc": { "start": { - "line": 20, + "line": 19, "column": 10, "program": "inferTypeOfArray.ets" }, "end": { - "line": 20, + "line": 19, "column": 11, "program": "inferTypeOfArray.ets" } @@ -550,12 +486,12 @@ "value": 2.8, "loc": { "start": { - "line": 20, + "line": 19, "column": 13, "program": "inferTypeOfArray.ets" }, "end": { - "line": 20, + "line": 19, "column": 16, "program": "inferTypeOfArray.ets" } @@ -566,12 +502,12 @@ "value": 3, "loc": { "start": { - "line": 20, + "line": 19, "column": 18, "program": "inferTypeOfArray.ets" }, "end": { - "line": 20, + "line": 19, "column": 19, "program": "inferTypeOfArray.ets" } @@ -583,12 +519,12 @@ "decorators": [], "loc": { "start": { - "line": 20, + "line": 19, "column": 21, "program": "inferTypeOfArray.ets" }, "end": { - "line": 20, + "line": 19, "column": 22, "program": "inferTypeOfArray.ets" } @@ -606,12 +542,12 @@ "decorators": [], "loc": { "start": { - "line": 20, + "line": 19, "column": 28, "program": "inferTypeOfArray.ets" }, "end": { - "line": 20, + "line": 19, "column": 31, "program": "inferTypeOfArray.ets" } @@ -619,12 +555,12 @@ }, "loc": { "start": { - "line": 20, + "line": 19, "column": 28, "program": "inferTypeOfArray.ets" }, "end": { - "line": 20, + "line": 19, "column": 32, "program": "inferTypeOfArray.ets" } @@ -632,12 +568,12 @@ }, "loc": { "start": { - "line": 20, + "line": 19, "column": 28, "program": "inferTypeOfArray.ets" }, "end": { - "line": 20, + "line": 19, "column": 32, "program": "inferTypeOfArray.ets" } @@ -646,12 +582,12 @@ "arguments": [], "loc": { "start": { - "line": 20, + "line": 19, "column": 24, "program": "inferTypeOfArray.ets" }, "end": { - "line": 20, + "line": 19, "column": 34, "program": "inferTypeOfArray.ets" } @@ -660,12 +596,12 @@ ], "loc": { "start": { - "line": 20, + "line": 19, "column": 9, "program": "inferTypeOfArray.ets" }, "end": { - "line": 20, + "line": 19, "column": 34, "program": "inferTypeOfArray.ets" } @@ -673,12 +609,12 @@ }, "loc": { "start": { - "line": 20, + "line": 19, "column": 5, "program": "inferTypeOfArray.ets" }, "end": { - "line": 20, + "line": 19, "column": 34, "program": "inferTypeOfArray.ets" } @@ -686,81 +622,17 @@ }, "loc": { "start": { - "line": 20, + "line": 19, "column": 5, "program": "inferTypeOfArray.ets" }, "end": { - "line": 20, + "line": 19, "column": 34, "program": "inferTypeOfArray.ets" } } }, - { - "type": "ExpressionStatement", - "expression": { - "type": "AssignmentExpression", - "operator": "=", - "left": { - "type": "Identifier", - "name": "f", - "decorators": [], - "loc": { - "start": { - "line": 21, - "column": 5, - "program": "inferTypeOfArray.ets" - }, - "end": { - "line": 21, - "column": 6, - "program": "inferTypeOfArray.ets" - } - } - }, - "right": { - "type": "ArrayExpression", - "elements": [], - "loc": { - "start": { - "line": 21, - "column": 9, - "program": "inferTypeOfArray.ets" - }, - "end": { - "line": 21, - "column": 11, - "program": "inferTypeOfArray.ets" - } - } - }, - "loc": { - "start": { - "line": 21, - "column": 5, - "program": "inferTypeOfArray.ets" - }, - "end": { - "line": 21, - "column": 11, - "program": "inferTypeOfArray.ets" - } - } - }, - "loc": { - "start": { - "line": 21, - "column": 5, - "program": "inferTypeOfArray.ets" - }, - "end": { - "line": 21, - "column": 11, - "program": "inferTypeOfArray.ets" - } - } - }, { "type": "ExpressionStatement", "expression": { @@ -772,12 +644,12 @@ "decorators": [], "loc": { "start": { - "line": 22, + "line": 20, "column": 5, "program": "inferTypeOfArray.ets" }, "end": { - "line": 22, + "line": 20, "column": 6, "program": "inferTypeOfArray.ets" } @@ -794,12 +666,12 @@ "decorators": [], "loc": { "start": { - "line": 22, + "line": 20, "column": 9, "program": "inferTypeOfArray.ets" }, "end": { - "line": 22, + "line": 20, "column": 10, "program": "inferTypeOfArray.ets" } @@ -810,277 +682,83 @@ "value": 2, "loc": { "start": { - "line": 22, - "column": 11, - "program": "inferTypeOfArray.ets" - }, - "end": { - "line": 22, - "column": 12, - "program": "inferTypeOfArray.ets" - } - } - }, - "computed": true, - "optional": false, - "loc": { - "start": { - "line": 22, - "column": 9, - "program": "inferTypeOfArray.ets" - }, - "end": { - "line": 22, - "column": 13, - "program": "inferTypeOfArray.ets" - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 1.2, - "loc": { - "start": { - "line": 22, - "column": 16, - "program": "inferTypeOfArray.ets" - }, - "end": { - "line": 22, - "column": 19, - "program": "inferTypeOfArray.ets" - } - } - }, - "loc": { - "start": { - "line": 22, - "column": 9, - "program": "inferTypeOfArray.ets" - }, - "end": { - "line": 22, - "column": 19, - "program": "inferTypeOfArray.ets" - } - } - }, - "loc": { - "start": { - "line": 22, - "column": 5, - "program": "inferTypeOfArray.ets" - }, - "end": { - "line": 22, - "column": 19, - "program": "inferTypeOfArray.ets" - } - } - }, - "loc": { - "start": { - "line": 22, - "column": 5, - "program": "inferTypeOfArray.ets" - }, - "end": { - "line": 22, - "column": 19, - "program": "inferTypeOfArray.ets" - } - } - }, - { - "type": "ExpressionStatement", - "expression": { - "type": "AssignmentExpression", - "operator": "=", - "left": { - "type": "MemberExpression", - "object": { - "type": "Identifier", - "name": "f", - "decorators": [], - "loc": { - "start": { - "line": 23, - "column": 1, - "program": "inferTypeOfArray.ets" - }, - "end": { - "line": 23, - "column": 2, - "program": "inferTypeOfArray.ets" - } - } - }, - "property": { - "type": "NumberLiteral", - "value": 0, - "loc": { - "start": { - "line": 23, - "column": 3, - "program": "inferTypeOfArray.ets" - }, - "end": { - "line": 23, - "column": 4, - "program": "inferTypeOfArray.ets" - } - } - }, - "computed": true, - "optional": false, - "loc": { - "start": { - "line": 23, - "column": 1, - "program": "inferTypeOfArray.ets" - }, - "end": { - "line": 23, - "column": 5, - "program": "inferTypeOfArray.ets" - } - } - }, - "right": { - "type": "StringLiteral", - "value": "1", - "loc": { - "start": { - "line": 23, - "column": 8, - "program": "inferTypeOfArray.ets" + "line": 20, + "column": 11, + "program": "inferTypeOfArray.ets" + }, + "end": { + "line": 20, + "column": 12, + "program": "inferTypeOfArray.ets" + } + } }, - "end": { - "line": 23, - "column": 11, - "program": "inferTypeOfArray.ets" - } - } - }, - "loc": { - "start": { - "line": 23, - "column": 1, - "program": "inferTypeOfArray.ets" - }, - "end": { - "line": 23, - "column": 11, - "program": "inferTypeOfArray.ets" - } - } - }, - "loc": { - "start": { - "line": 23, - "column": 1, - "program": "inferTypeOfArray.ets" - }, - "end": { - "line": 23, - "column": 11, - "program": "inferTypeOfArray.ets" - } - } - }, - { - "type": "ExpressionStatement", - "expression": { - "type": "AssignmentExpression", - "operator": "=", - "left": { - "type": "MemberExpression", - "object": { - "type": "Identifier", - "name": "f", - "decorators": [], + "computed": true, + "optional": false, "loc": { "start": { - "line": 24, - "column": 1, + "line": 20, + "column": 9, "program": "inferTypeOfArray.ets" }, "end": { - "line": 24, - "column": 2, + "line": 20, + "column": 13, "program": "inferTypeOfArray.ets" } } }, - "property": { + "right": { "type": "NumberLiteral", - "value": 1, + "value": 1.2, "loc": { "start": { - "line": 24, - "column": 3, + "line": 20, + "column": 16, "program": "inferTypeOfArray.ets" }, "end": { - "line": 24, - "column": 4, + "line": 20, + "column": 19, "program": "inferTypeOfArray.ets" } } }, - "computed": true, - "optional": false, - "loc": { - "start": { - "line": 24, - "column": 1, - "program": "inferTypeOfArray.ets" - }, - "end": { - "line": 24, - "column": 5, - "program": "inferTypeOfArray.ets" - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 1, "loc": { "start": { - "line": 24, - "column": 8, + "line": 20, + "column": 9, "program": "inferTypeOfArray.ets" }, "end": { - "line": 24, - "column": 9, + "line": 20, + "column": 19, "program": "inferTypeOfArray.ets" } } }, "loc": { "start": { - "line": 24, - "column": 1, + "line": 20, + "column": 5, "program": "inferTypeOfArray.ets" }, "end": { - "line": 24, - "column": 9, + "line": 20, + "column": 19, "program": "inferTypeOfArray.ets" } } }, "loc": { "start": { - "line": 24, - "column": 1, + "line": 20, + "column": 5, "program": "inferTypeOfArray.ets" }, "end": { - "line": 24, - "column": 9, + "line": 20, + "column": 19, "program": "inferTypeOfArray.ets" } } @@ -1200,7 +878,7 @@ "type": "ClassProperty", "key": { "type": "Identifier", - "name": "b", + "name": "c", "decorators": [], "loc": { "start": { @@ -1215,62 +893,6 @@ } } }, - "value": { - "type": "ArrayExpression", - "elements": [], - "loc": { - "start": { - "line": 17, - "column": 9, - "program": "inferTypeOfArray.ets" - }, - "end": { - "line": 17, - "column": 11, - "program": "inferTypeOfArray.ets" - } - } - }, - "accessibility": "public", - "static": true, - "readonly": false, - "declare": false, - "optional": false, - "computed": false, - "definite": false, - "decorators": [], - "loc": { - "start": { - "line": 17, - "column": 5, - "program": "inferTypeOfArray.ets" - }, - "end": { - "line": 17, - "column": 11, - "program": "inferTypeOfArray.ets" - } - } - }, - { - "type": "ClassProperty", - "key": { - "type": "Identifier", - "name": "c", - "decorators": [], - "loc": { - "start": { - "line": 18, - "column": 5, - "program": "inferTypeOfArray.ets" - }, - "end": { - "line": 18, - "column": 6, - "program": "inferTypeOfArray.ets" - } - } - }, "value": { "type": "ArrayExpression", "elements": [ @@ -1279,12 +901,12 @@ "value": "a", "loc": { "start": { - "line": 18, + "line": 17, "column": 10, "program": "inferTypeOfArray.ets" }, "end": { - "line": 18, + "line": 17, "column": 13, "program": "inferTypeOfArray.ets" } @@ -1293,12 +915,12 @@ ], "loc": { "start": { - "line": 18, + "line": 17, "column": 9, "program": "inferTypeOfArray.ets" }, "end": { - "line": 18, + "line": 17, "column": 14, "program": "inferTypeOfArray.ets" } @@ -1314,12 +936,12 @@ "decorators": [], "loc": { "start": { - "line": 18, + "line": 17, "column": 5, "program": "inferTypeOfArray.ets" }, "end": { - "line": 18, + "line": 17, "column": 14, "program": "inferTypeOfArray.ets" } @@ -1333,12 +955,12 @@ "decorators": [], "loc": { "start": { - "line": 19, + "line": 18, "column": 5, "program": "inferTypeOfArray.ets" }, "end": { - "line": 19, + "line": 18, "column": 6, "program": "inferTypeOfArray.ets" } @@ -1352,12 +974,12 @@ "value": 1, "loc": { "start": { - "line": 19, + "line": 18, "column": 10, "program": "inferTypeOfArray.ets" }, "end": { - "line": 19, + "line": 18, "column": 11, "program": "inferTypeOfArray.ets" } @@ -1368,12 +990,12 @@ "value": 2, "loc": { "start": { - "line": 19, + "line": 18, "column": 13, "program": "inferTypeOfArray.ets" }, "end": { - "line": 19, + "line": 18, "column": 14, "program": "inferTypeOfArray.ets" } @@ -1384,12 +1006,12 @@ "value": 3, "loc": { "start": { - "line": 19, + "line": 18, "column": 16, "program": "inferTypeOfArray.ets" }, "end": { - "line": 19, + "line": 18, "column": 17, "program": "inferTypeOfArray.ets" } @@ -1398,12 +1020,12 @@ ], "loc": { "start": { - "line": 19, + "line": 18, "column": 9, "program": "inferTypeOfArray.ets" }, "end": { - "line": 19, + "line": 18, "column": 18, "program": "inferTypeOfArray.ets" } @@ -1419,12 +1041,12 @@ "decorators": [], "loc": { "start": { - "line": 19, + "line": 18, "column": 5, "program": "inferTypeOfArray.ets" }, "end": { - "line": 19, + "line": 18, "column": 18, "program": "inferTypeOfArray.ets" } @@ -1438,12 +1060,12 @@ "decorators": [], "loc": { "start": { - "line": 20, + "line": 19, "column": 5, "program": "inferTypeOfArray.ets" }, "end": { - "line": 20, + "line": 19, "column": 6, "program": "inferTypeOfArray.ets" } @@ -1457,12 +1079,12 @@ "value": 1, "loc": { "start": { - "line": 20, + "line": 19, "column": 10, "program": "inferTypeOfArray.ets" }, "end": { - "line": 20, + "line": 19, "column": 11, "program": "inferTypeOfArray.ets" } @@ -1473,12 +1095,12 @@ "value": 2.8, "loc": { "start": { - "line": 20, + "line": 19, "column": 13, "program": "inferTypeOfArray.ets" }, "end": { - "line": 20, + "line": 19, "column": 16, "program": "inferTypeOfArray.ets" } @@ -1489,12 +1111,12 @@ "value": 3, "loc": { "start": { - "line": 20, + "line": 19, "column": 18, "program": "inferTypeOfArray.ets" }, "end": { - "line": 20, + "line": 19, "column": 19, "program": "inferTypeOfArray.ets" } @@ -1506,12 +1128,12 @@ "decorators": [], "loc": { "start": { - "line": 20, + "line": 19, "column": 21, "program": "inferTypeOfArray.ets" }, "end": { - "line": 20, + "line": 19, "column": 22, "program": "inferTypeOfArray.ets" } @@ -1529,12 +1151,12 @@ "decorators": [], "loc": { "start": { - "line": 20, + "line": 19, "column": 28, "program": "inferTypeOfArray.ets" }, "end": { - "line": 20, + "line": 19, "column": 31, "program": "inferTypeOfArray.ets" } @@ -1542,12 +1164,12 @@ }, "loc": { "start": { - "line": 20, + "line": 19, "column": 28, "program": "inferTypeOfArray.ets" }, "end": { - "line": 20, + "line": 19, "column": 32, "program": "inferTypeOfArray.ets" } @@ -1555,12 +1177,12 @@ }, "loc": { "start": { - "line": 20, + "line": 19, "column": 28, "program": "inferTypeOfArray.ets" }, "end": { - "line": 20, + "line": 19, "column": 32, "program": "inferTypeOfArray.ets" } @@ -1569,12 +1191,12 @@ "arguments": [], "loc": { "start": { - "line": 20, + "line": 19, "column": 24, "program": "inferTypeOfArray.ets" }, "end": { - "line": 20, + "line": 19, "column": 34, "program": "inferTypeOfArray.ets" } @@ -1583,12 +1205,12 @@ ], "loc": { "start": { - "line": 20, + "line": 19, "column": 9, "program": "inferTypeOfArray.ets" }, "end": { - "line": 20, + "line": 19, "column": 34, "program": "inferTypeOfArray.ets" } @@ -1604,73 +1226,17 @@ "decorators": [], "loc": { "start": { - "line": 20, + "line": 19, "column": 5, "program": "inferTypeOfArray.ets" }, "end": { - "line": 20, + "line": 19, "column": 34, "program": "inferTypeOfArray.ets" } } }, - { - "type": "ClassProperty", - "key": { - "type": "Identifier", - "name": "f", - "decorators": [], - "loc": { - "start": { - "line": 21, - "column": 5, - "program": "inferTypeOfArray.ets" - }, - "end": { - "line": 21, - "column": 6, - "program": "inferTypeOfArray.ets" - } - } - }, - "value": { - "type": "ArrayExpression", - "elements": [], - "loc": { - "start": { - "line": 21, - "column": 9, - "program": "inferTypeOfArray.ets" - }, - "end": { - "line": 21, - "column": 11, - "program": "inferTypeOfArray.ets" - } - } - }, - "accessibility": "public", - "static": true, - "readonly": false, - "declare": false, - "optional": false, - "computed": false, - "definite": false, - "decorators": [], - "loc": { - "start": { - "line": 21, - "column": 5, - "program": "inferTypeOfArray.ets" - }, - "end": { - "line": 21, - "column": 11, - "program": "inferTypeOfArray.ets" - } - } - }, { "type": "ClassProperty", "key": { @@ -1679,12 +1245,12 @@ "decorators": [], "loc": { "start": { - "line": 22, + "line": 20, "column": 5, "program": "inferTypeOfArray.ets" }, "end": { - "line": 22, + "line": 20, "column": 6, "program": "inferTypeOfArray.ets" } @@ -1701,12 +1267,12 @@ "decorators": [], "loc": { "start": { - "line": 22, + "line": 20, "column": 9, "program": "inferTypeOfArray.ets" }, "end": { - "line": 22, + "line": 20, "column": 10, "program": "inferTypeOfArray.ets" } @@ -1717,12 +1283,12 @@ "value": 2, "loc": { "start": { - "line": 22, + "line": 20, "column": 11, "program": "inferTypeOfArray.ets" }, "end": { - "line": 22, + "line": 20, "column": 12, "program": "inferTypeOfArray.ets" } @@ -1732,12 +1298,12 @@ "optional": false, "loc": { "start": { - "line": 22, + "line": 20, "column": 9, "program": "inferTypeOfArray.ets" }, "end": { - "line": 22, + "line": 20, "column": 13, "program": "inferTypeOfArray.ets" } @@ -1748,12 +1314,12 @@ "value": 1.2, "loc": { "start": { - "line": 22, + "line": 20, "column": 16, "program": "inferTypeOfArray.ets" }, "end": { - "line": 22, + "line": 20, "column": 19, "program": "inferTypeOfArray.ets" } @@ -1761,12 +1327,12 @@ }, "loc": { "start": { - "line": 22, + "line": 20, "column": 9, "program": "inferTypeOfArray.ets" }, "end": { - "line": 22, + "line": 20, "column": 19, "program": "inferTypeOfArray.ets" } @@ -1782,12 +1348,12 @@ "decorators": [], "loc": { "start": { - "line": 22, + "line": 20, "column": 5, "program": "inferTypeOfArray.ets" }, "end": { - "line": 22, + "line": 20, "column": 19, "program": "inferTypeOfArray.ets" } @@ -1828,8 +1394,8 @@ "program": "inferTypeOfArray.ets" }, "end": { - "line": 25, - "column": 1, + "line": 20, + "column": 19, "program": "inferTypeOfArray.ets" } } diff --git a/ets2panda/test/compiler/ets/inferTypeOfArray.ets b/ets2panda/test/compiler/ets/inferTypeOfArray.ets index ca4ed9c3b411c8fd61cd92cdc445daebfa60528e..39bad69dbdf9489c5e970d7506537849d5a439f6 100644 --- a/ets2panda/test/compiler/ets/inferTypeOfArray.ets +++ b/ets2panda/test/compiler/ets/inferTypeOfArray.ets @@ -14,11 +14,7 @@ */ let a = 5 -let b = [] let c = ["a"] let d = [1, 2, 3] let e = [1, 2.8, 3, a, new Int()] -let f = [] -let g = d[2] + 1.2 -f[0] = "1" -f[1] = 1 +let g = d[2] + 1.2 \ No newline at end of file diff --git a/ets2panda/test/parser/ets/literals-expected.txt b/ets2panda/test/parser/ets/literals-expected.txt index 5dffbbbbf62629a9dc45140ad69982e1902a4991..8f653a865eb1bafd893bc91a28dc75a0060e638d 100644 --- a/ets2panda/test/parser/ets/literals-expected.txt +++ b/ets2panda/test/parser/ets/literals-expected.txt @@ -1192,7 +1192,7 @@ "type": "ClassProperty", "key": { "type": "Identifier", - "name": "lit18", + "name": "lit19", "decorators": [], "loc": { "start": { @@ -1207,62 +1207,6 @@ } } }, - "value": { - "type": "ArrayExpression", - "elements": [], - "loc": { - "start": { - "line": 35, - "column": 15, - "program": "literals.ets" - }, - "end": { - "line": 35, - "column": 17, - "program": "literals.ets" - } - } - }, - "accessibility": "public", - "static": true, - "readonly": false, - "declare": false, - "optional": false, - "computed": false, - "definite": false, - "decorators": [], - "loc": { - "start": { - "line": 35, - "column": 7, - "program": "literals.ets" - }, - "end": { - "line": 35, - "column": 17, - "program": "literals.ets" - } - } - }, - { - "type": "ClassProperty", - "key": { - "type": "Identifier", - "name": "lit19", - "decorators": [], - "loc": { - "start": { - "line": 36, - "column": 7, - "program": "literals.ets" - }, - "end": { - "line": 36, - "column": 12, - "program": "literals.ets" - } - } - }, "value": { "type": "ArrayExpression", "elements": [ @@ -1271,12 +1215,12 @@ "value": 1, "loc": { "start": { - "line": 36, + "line": 35, "column": 16, "program": "literals.ets" }, "end": { - "line": 36, + "line": 35, "column": 17, "program": "literals.ets" } @@ -1287,12 +1231,12 @@ "value": 2, "loc": { "start": { - "line": 36, + "line": 35, "column": 18, "program": "literals.ets" }, "end": { - "line": 36, + "line": 35, "column": 19, "program": "literals.ets" } @@ -1303,12 +1247,12 @@ "value": 3, "loc": { "start": { - "line": 36, + "line": 35, "column": 20, "program": "literals.ets" }, "end": { - "line": 36, + "line": 35, "column": 21, "program": "literals.ets" } @@ -1317,12 +1261,12 @@ ], "loc": { "start": { - "line": 36, + "line": 35, "column": 15, "program": "literals.ets" }, "end": { - "line": 36, + "line": 35, "column": 22, "program": "literals.ets" } @@ -1338,12 +1282,12 @@ "decorators": [], "loc": { "start": { - "line": 36, + "line": 35, "column": 7, "program": "literals.ets" }, "end": { - "line": 36, + "line": 35, "column": 22, "program": "literals.ets" } @@ -1357,12 +1301,12 @@ "decorators": [], "loc": { "start": { - "line": 37, + "line": 36, "column": 7, "program": "literals.ets" }, "end": { - "line": 37, + "line": 36, "column": 12, "program": "literals.ets" } @@ -1376,12 +1320,12 @@ "value": "1", "loc": { "start": { - "line": 37, + "line": 36, "column": 16, "program": "literals.ets" }, "end": { - "line": 37, + "line": 36, "column": 19, "program": "literals.ets" } @@ -1392,12 +1336,12 @@ "value": "2", "loc": { "start": { - "line": 37, + "line": 36, "column": 20, "program": "literals.ets" }, "end": { - "line": 37, + "line": 36, "column": 23, "program": "literals.ets" } @@ -1408,12 +1352,12 @@ "value": "3", "loc": { "start": { - "line": 37, + "line": 36, "column": 24, "program": "literals.ets" }, "end": { - "line": 37, + "line": 36, "column": 27, "program": "literals.ets" } @@ -1422,12 +1366,12 @@ ], "loc": { "start": { - "line": 37, + "line": 36, "column": 15, "program": "literals.ets" }, "end": { - "line": 37, + "line": 36, "column": 28, "program": "literals.ets" } @@ -1443,12 +1387,12 @@ "decorators": [], "loc": { "start": { - "line": 37, + "line": 36, "column": 7, "program": "literals.ets" }, "end": { - "line": 37, + "line": 36, "column": 28, "program": "literals.ets" } @@ -1462,12 +1406,12 @@ "decorators": [], "loc": { "start": { - "line": 38, + "line": 37, "column": 7, "program": "literals.ets" }, "end": { - "line": 38, + "line": 37, "column": 12, "program": "literals.ets" } @@ -1481,12 +1425,12 @@ "value": 1, "loc": { "start": { - "line": 38, + "line": 37, "column": 16, "program": "literals.ets" }, "end": { - "line": 38, + "line": 37, "column": 19, "program": "literals.ets" } @@ -1497,12 +1441,12 @@ "value": 2, "loc": { "start": { - "line": 38, + "line": 37, "column": 20, "program": "literals.ets" }, "end": { - "line": 38, + "line": 37, "column": 23, "program": "literals.ets" } @@ -1513,12 +1457,12 @@ "value": 3, "loc": { "start": { - "line": 38, + "line": 37, "column": 24, "program": "literals.ets" }, "end": { - "line": 38, + "line": 37, "column": 27, "program": "literals.ets" } @@ -1527,12 +1471,12 @@ ], "loc": { "start": { - "line": 38, + "line": 37, "column": 15, "program": "literals.ets" }, "end": { - "line": 38, + "line": 37, "column": 28, "program": "literals.ets" } @@ -1548,12 +1492,12 @@ "decorators": [], "loc": { "start": { - "line": 38, + "line": 37, "column": 7, "program": "literals.ets" }, "end": { - "line": 38, + "line": 37, "column": 28, "program": "literals.ets" } @@ -1594,7 +1538,7 @@ "program": "literals.ets" }, "end": { - "line": 40, + "line": 39, "column": 1, "program": "literals.ets" } diff --git a/ets2panda/test/parser/ets/literals.ets b/ets2panda/test/parser/ets/literals.ets index bc1c123010edadfd1bc6288fa0849b433130df18..365d376f412e133b036b8d1e67cedeca083809fb 100644 --- a/ets2panda/test/parser/ets/literals.ets +++ b/ets2panda/test/parser/ets/literals.ets @@ -32,7 +32,6 @@ const lit14 = 123.45f; // equivalent to (123.45 as float) const lit15 = 123.45e10f; const lit16 = -123.45f; // equivalent to -(123.45 as float) const lit17 = -123.45e10f; -const lit18 = []; const lit19 = [1,2,3]; const lit20 = ["1","2","3"]; const lit21 = [1.0,2.0,3.0];