From 2d1647485cfb33a7ae1d84a6bc08ced6f952a552 Mon Sep 17 00:00:00 2001 From: Jason Freeman Date: Wed, 4 Feb 2015 19:18:54 -0800 Subject: [PATCH] Fix expression checking for symbols --- src/compiler/checker.ts | 72 ++++++++-- .../diagnosticInformationMap.generated.ts | 3 +- src/compiler/diagnosticMessages.json | 6 +- .../inOperatorWithInvalidOperands.errors.txt | 32 ++--- .../reference/symbolProperty54.errors.txt | 9 ++ .../reference/symbolType1.errors.txt | 7 +- tests/baselines/reference/symbolType1.js | 6 +- tests/baselines/reference/symbolType11.types | 37 +++++ .../reference/symbolType12.errors.txt | 136 ++++++++++++++++++ tests/baselines/reference/symbolType12.js | 5 +- .../reference/symbolType13.errors.txt | 18 +++ .../reference/symbolType2.errors.txt | 8 ++ .../reference/symbolType3.errors.txt | 33 +++++ tests/baselines/reference/symbolType3.js | 5 +- .../reference/symbolType6.errors.txt | 57 ++++++++ tests/baselines/reference/symbolType6.js | 13 +- .../reference/symbolType8.errors.txt | 45 ++++++ tests/baselines/reference/symbolType8.js | 7 +- .../reference/widenedTypes.errors.txt | 4 +- .../conformance/es6/Symbols/symbolType1.ts | 4 +- .../conformance/es6/Symbols/symbolType12.ts | 4 +- .../conformance/es6/Symbols/symbolType3.ts | 4 +- .../conformance/es6/Symbols/symbolType6.ts | 8 +- .../conformance/es6/Symbols/symbolType8.ts | 5 +- 24 files changed, 484 insertions(+), 44 deletions(-) create mode 100644 tests/baselines/reference/symbolProperty54.errors.txt create mode 100644 tests/baselines/reference/symbolType11.types create mode 100644 tests/baselines/reference/symbolType12.errors.txt create mode 100644 tests/baselines/reference/symbolType13.errors.txt create mode 100644 tests/baselines/reference/symbolType2.errors.txt create mode 100644 tests/baselines/reference/symbolType3.errors.txt create mode 100644 tests/baselines/reference/symbolType6.errors.txt create mode 100644 tests/baselines/reference/symbolType8.errors.txt diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 4973dd374500d..d513066cc040f 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -6856,6 +6856,9 @@ module ts { case SyntaxKind.PlusToken: case SyntaxKind.MinusToken: case SyntaxKind.TildeToken: + if (hasSomeTypeOfKind(operandType, TypeFlags.ESSymbol)) { + error(node.operand, Diagnostics.The_0_operator_cannot_be_applied_to_a_value_of_type_symbol, tokenToString(node.operator)); + } return numberType; case SyntaxKind.ExclamationToken: return booleanType; @@ -6891,6 +6894,24 @@ module ts { return numberType; } + // Just like isTypeOfKind below, except that it returns true if *any* constituent + // has this kind. + function hasSomeTypeOfKind(type: Type, kind: TypeFlags): boolean { + if (type.flags & kind) { + return true; + } + if (type.flags & TypeFlags.Union) { + var types = (type).types; + for (var i = 0; i < types.length; i++) { + if (types[i].flags & kind) { + return true; + } + } + return false; + } + return false; + } + // Return true if type has the given flags, or is a union type composed of types that all have those flags. function isTypeOfKind(type: Type, kind: TypeFlags): boolean { if (type.flags & kind) { @@ -6938,7 +6959,7 @@ module ts { // and the right operand to be of type Any, an object type, or a type parameter type. // The result is always of the Boolean primitive type. if (!isTypeOfKind(leftType, TypeFlags.Any | TypeFlags.StringLike | TypeFlags.NumberLike | TypeFlags.ESSymbol)) { - error(node.left, Diagnostics.The_left_hand_side_of_an_in_expression_must_be_of_types_any_string_or_number); + error(node.left, Diagnostics.The_left_hand_side_of_an_in_expression_must_be_of_type_any_string_number_or_symbol); } if (!isTypeOfKind(rightType, TypeFlags.Any | TypeFlags.ObjectType | TypeFlags.TypeParameter)) { error(node.right, Diagnostics.The_right_hand_side_of_an_in_expression_must_be_of_type_any_an_object_type_or_a_type_parameter); @@ -7106,14 +7127,21 @@ module ts { // If both operands are of the Number primitive type, the result is of the Number primitive type. resultType = numberType; } - else if (isTypeOfKind(leftType, TypeFlags.StringLike) || isTypeOfKind(rightType, TypeFlags.StringLike)) { - // If one or both operands are of the String primitive type, the result is of the String primitive type. - resultType = stringType; - } - else if (leftType.flags & TypeFlags.Any || rightType.flags & TypeFlags.Any) { - // Otherwise, the result is of type Any. - // NOTE: unknown type here denotes error type. Old compiler treated this case as any type so do we. - resultType = anyType; + else { + if (isTypeOfKind(leftType, TypeFlags.StringLike) || isTypeOfKind(rightType, TypeFlags.StringLike)) { + // If one or both operands are of the String primitive type, the result is of the String primitive type. + resultType = stringType; + } + else if (leftType.flags & TypeFlags.Any || rightType.flags & TypeFlags.Any) { + // Otherwise, the result is of type Any. + // NOTE: unknown type here denotes error type. Old compiler treated this case as any type so do we. + resultType = anyType; + } + + // Symbols are not allowed at all in arithmetic expressions + if (resultType && !checkForDisallowedESSymbolOperand(operator)) { + return resultType; + } } if (!resultType) { @@ -7125,14 +7153,18 @@ module ts { checkAssignmentOperator(resultType); } return resultType; - case SyntaxKind.EqualsEqualsToken: - case SyntaxKind.ExclamationEqualsToken: - case SyntaxKind.EqualsEqualsEqualsToken: - case SyntaxKind.ExclamationEqualsEqualsToken: case SyntaxKind.LessThanToken: case SyntaxKind.GreaterThanToken: case SyntaxKind.LessThanEqualsToken: case SyntaxKind.GreaterThanEqualsToken: + if (!checkForDisallowedESSymbolOperand(operator)) { + return booleanType; + } + // Fall through + case SyntaxKind.EqualsEqualsToken: + case SyntaxKind.ExclamationEqualsToken: + case SyntaxKind.EqualsEqualsEqualsToken: + case SyntaxKind.ExclamationEqualsEqualsToken: if (!isTypeAssignableTo(leftType, rightType) && !isTypeAssignableTo(rightType, leftType)) { reportOperatorError(); } @@ -7152,6 +7184,20 @@ module ts { return rightType; } + // Return type is true if there was no error, false if there was an error. + function checkForDisallowedESSymbolOperand(operator: SyntaxKind): boolean { + var offendingSymbolOperand = + hasSomeTypeOfKind(leftType, TypeFlags.ESSymbol) ? node.left : + hasSomeTypeOfKind(rightType, TypeFlags.ESSymbol) ? node.right : + undefined; + if (offendingSymbolOperand) { + error(offendingSymbolOperand, Diagnostics.The_0_operator_cannot_be_applied_to_a_value_of_type_symbol, tokenToString(operator)); + return false; + } + + return true; + } + function getSuggestedBooleanOperator(operator: SyntaxKind): SyntaxKind { switch (operator) { case SyntaxKind.BarToken: diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index e16130a0ecdda..922044bdaf59a 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -205,7 +205,7 @@ module ts { The_operand_of_an_increment_or_decrement_operator_must_be_a_variable_property_or_indexer: { code: 2357, category: DiagnosticCategory.Error, key: "The operand of an increment or decrement operator must be a variable, property or indexer." }, The_left_hand_side_of_an_instanceof_expression_must_be_of_type_any_an_object_type_or_a_type_parameter: { code: 2358, category: DiagnosticCategory.Error, key: "The left-hand side of an 'instanceof' expression must be of type 'any', an object type or a type parameter." }, The_right_hand_side_of_an_instanceof_expression_must_be_of_type_any_or_of_a_type_assignable_to_the_Function_interface_type: { code: 2359, category: DiagnosticCategory.Error, key: "The right-hand side of an 'instanceof' expression must be of type 'any' or of a type assignable to the 'Function' interface type." }, - The_left_hand_side_of_an_in_expression_must_be_of_types_any_string_or_number: { code: 2360, category: DiagnosticCategory.Error, key: "The left-hand side of an 'in' expression must be of types 'any', 'string' or 'number'." }, + The_left_hand_side_of_an_in_expression_must_be_of_type_any_string_number_or_symbol: { code: 2360, category: DiagnosticCategory.Error, key: "The left-hand side of an 'in' expression must be of type 'any', 'string', 'number', or 'symbol'." }, The_right_hand_side_of_an_in_expression_must_be_of_type_any_an_object_type_or_a_type_parameter: { code: 2361, category: DiagnosticCategory.Error, key: "The right-hand side of an 'in' expression must be of type 'any', an object type or a type parameter" }, The_left_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_or_an_enum_type: { code: 2362, category: DiagnosticCategory.Error, key: "The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type." }, The_right_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_or_an_enum_type: { code: 2363, category: DiagnosticCategory.Error, key: "The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type." }, @@ -305,6 +305,7 @@ module ts { super_cannot_be_referenced_in_a_computed_property_name: { code: 2466, category: DiagnosticCategory.Error, key: "'super' cannot be referenced in a computed property name." }, A_computed_property_name_cannot_reference_a_type_parameter_from_its_containing_type: { code: 2467, category: DiagnosticCategory.Error, key: "A computed property name cannot reference a type parameter from its containing type." }, Cannot_find_global_value_0: { code: 2468, category: DiagnosticCategory.Error, key: "Cannot find global value '{0}'." }, + The_0_operator_cannot_be_applied_to_a_value_of_type_symbol: { code: 2469, category: DiagnosticCategory.Error, key: "The '{0}' operator cannot be applied to a value of type 'symbol'." }, Import_declaration_0_is_using_private_name_1: { code: 4000, category: DiagnosticCategory.Error, key: "Import declaration '{0}' is using private name '{1}'." }, Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: { code: 4002, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported class has or is using private name '{1}'." }, Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1: { code: 4004, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported interface has or is using private name '{1}'." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 876f3184d1507..fb170548614a9 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -813,7 +813,7 @@ "category": "Error", "code": 2359 }, - "The left-hand side of an 'in' expression must be of types 'any', 'string' or 'number'.": { + "The left-hand side of an 'in' expression must be of type 'any', 'string', 'number', or 'symbol'.": { "category": "Error", "code": 2360 }, @@ -1213,6 +1213,10 @@ "category": "Error", "code": 2468 }, + "The '{0}' operator cannot be applied to a value of type 'symbol'.": { + "category": "Error", + "code": 2469 + }, "Import declaration '{0}' is using private name '{1}'.": { "category": "Error", diff --git a/tests/baselines/reference/inOperatorWithInvalidOperands.errors.txt b/tests/baselines/reference/inOperatorWithInvalidOperands.errors.txt index 9df5357767f17..0985157e0da73 100644 --- a/tests/baselines/reference/inOperatorWithInvalidOperands.errors.txt +++ b/tests/baselines/reference/inOperatorWithInvalidOperands.errors.txt @@ -1,10 +1,10 @@ -tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInvalidOperands.ts(12,11): error TS2360: The left-hand side of an 'in' expression must be of types 'any', 'string' or 'number'. -tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInvalidOperands.ts(13,11): error TS2360: The left-hand side of an 'in' expression must be of types 'any', 'string' or 'number'. -tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInvalidOperands.ts(14,11): error TS2360: The left-hand side of an 'in' expression must be of types 'any', 'string' or 'number'. -tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInvalidOperands.ts(16,11): error TS2360: The left-hand side of an 'in' expression must be of types 'any', 'string' or 'number'. -tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInvalidOperands.ts(17,11): error TS2360: The left-hand side of an 'in' expression must be of types 'any', 'string' or 'number'. -tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInvalidOperands.ts(19,11): error TS2360: The left-hand side of an 'in' expression must be of types 'any', 'string' or 'number'. -tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInvalidOperands.ts(20,11): error TS2360: The left-hand side of an 'in' expression must be of types 'any', 'string' or 'number'. +tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInvalidOperands.ts(12,11): error TS2360: The left-hand side of an 'in' expression must be of type 'any', 'string', 'number', or 'symbol'. +tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInvalidOperands.ts(13,11): error TS2360: The left-hand side of an 'in' expression must be of type 'any', 'string', 'number', or 'symbol'. +tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInvalidOperands.ts(14,11): error TS2360: The left-hand side of an 'in' expression must be of type 'any', 'string', 'number', or 'symbol'. +tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInvalidOperands.ts(16,11): error TS2360: The left-hand side of an 'in' expression must be of type 'any', 'string', 'number', or 'symbol'. +tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInvalidOperands.ts(17,11): error TS2360: The left-hand side of an 'in' expression must be of type 'any', 'string', 'number', or 'symbol'. +tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInvalidOperands.ts(19,11): error TS2360: The left-hand side of an 'in' expression must be of type 'any', 'string', 'number', or 'symbol'. +tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInvalidOperands.ts(20,11): error TS2360: The left-hand side of an 'in' expression must be of type 'any', 'string', 'number', or 'symbol'. tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInvalidOperands.ts(30,16): error TS2361: The right-hand side of an 'in' expression must be of type 'any', an object type or a type parameter tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInvalidOperands.ts(31,16): error TS2361: The right-hand side of an 'in' expression must be of type 'any', an object type or a type parameter tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInvalidOperands.ts(32,16): error TS2361: The right-hand side of an 'in' expression must be of type 'any', an object type or a type parameter @@ -15,7 +15,7 @@ tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInv tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInvalidOperands.ts(37,16): error TS2361: The right-hand side of an 'in' expression must be of type 'any', an object type or a type parameter tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInvalidOperands.ts(38,16): error TS2361: The right-hand side of an 'in' expression must be of type 'any', an object type or a type parameter tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInvalidOperands.ts(39,17): error TS2361: The right-hand side of an 'in' expression must be of type 'any', an object type or a type parameter -tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInvalidOperands.ts(43,11): error TS2360: The left-hand side of an 'in' expression must be of types 'any', 'string' or 'number'. +tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInvalidOperands.ts(43,11): error TS2360: The left-hand side of an 'in' expression must be of type 'any', 'string', 'number', or 'symbol'. tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInvalidOperands.ts(43,17): error TS2361: The right-hand side of an 'in' expression must be of type 'any', an object type or a type parameter @@ -33,27 +33,27 @@ tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInv var ra1 = a1 in x; ~~ -!!! error TS2360: The left-hand side of an 'in' expression must be of types 'any', 'string' or 'number'. +!!! error TS2360: The left-hand side of an 'in' expression must be of type 'any', 'string', 'number', or 'symbol'. var ra2 = a2 in x; ~~ -!!! error TS2360: The left-hand side of an 'in' expression must be of types 'any', 'string' or 'number'. +!!! error TS2360: The left-hand side of an 'in' expression must be of type 'any', 'string', 'number', or 'symbol'. var ra3 = a3 in x; ~~ -!!! error TS2360: The left-hand side of an 'in' expression must be of types 'any', 'string' or 'number'. +!!! error TS2360: The left-hand side of an 'in' expression must be of type 'any', 'string', 'number', or 'symbol'. var ra4 = a4 in x; var ra5 = null in x; ~~~~ -!!! error TS2360: The left-hand side of an 'in' expression must be of types 'any', 'string' or 'number'. +!!! error TS2360: The left-hand side of an 'in' expression must be of type 'any', 'string', 'number', or 'symbol'. var ra6 = undefined in x; ~~~~~~~~~ -!!! error TS2360: The left-hand side of an 'in' expression must be of types 'any', 'string' or 'number'. +!!! error TS2360: The left-hand side of an 'in' expression must be of type 'any', 'string', 'number', or 'symbol'. var ra7 = E.a in x; var ra8 = false in x; ~~~~~ -!!! error TS2360: The left-hand side of an 'in' expression must be of types 'any', 'string' or 'number'. +!!! error TS2360: The left-hand side of an 'in' expression must be of type 'any', 'string', 'number', or 'symbol'. var ra9 = {} in x; ~~ -!!! error TS2360: The left-hand side of an 'in' expression must be of types 'any', 'string' or 'number'. +!!! error TS2360: The left-hand side of an 'in' expression must be of type 'any', 'string', 'number', or 'symbol'. // invalid right operands // the right operand is required to be of type Any, an object type, or a type parameter type @@ -98,6 +98,6 @@ tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInv // both operands are invalid var rc1 = {} in ''; ~~ -!!! error TS2360: The left-hand side of an 'in' expression must be of types 'any', 'string' or 'number'. +!!! error TS2360: The left-hand side of an 'in' expression must be of type 'any', 'string', 'number', or 'symbol'. ~~ !!! error TS2361: The right-hand side of an 'in' expression must be of type 'any', an object type or a type parameter \ No newline at end of file diff --git a/tests/baselines/reference/symbolProperty54.errors.txt b/tests/baselines/reference/symbolProperty54.errors.txt new file mode 100644 index 0000000000000..b634b4edb0f94 --- /dev/null +++ b/tests/baselines/reference/symbolProperty54.errors.txt @@ -0,0 +1,9 @@ +tests/cases/conformance/es6/Symbols/symbolProperty54.ts(2,5): error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'. + + +==== tests/cases/conformance/es6/Symbols/symbolProperty54.ts (1 errors) ==== + var obj = { + [Symbol.prototype]: 0 + ~~~~~~~~~~~~~~~~~~ +!!! error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'. + }; \ No newline at end of file diff --git a/tests/baselines/reference/symbolType1.errors.txt b/tests/baselines/reference/symbolType1.errors.txt index db535f57625d7..00873ccc87179 100644 --- a/tests/baselines/reference/symbolType1.errors.txt +++ b/tests/baselines/reference/symbolType1.errors.txt @@ -1,11 +1,16 @@ tests/cases/conformance/es6/Symbols/symbolType1.ts(1,1): error TS2358: The left-hand side of an 'instanceof' expression must be of type 'any', an object type or a type parameter. tests/cases/conformance/es6/Symbols/symbolType1.ts(2,19): error TS2359: The right-hand side of an 'instanceof' expression must be of type 'any' or of a type assignable to the 'Function' interface type. +tests/cases/conformance/es6/Symbols/symbolType1.ts(4,19): error TS2359: The right-hand side of an 'instanceof' expression must be of type 'any' or of a type assignable to the 'Function' interface type. -==== tests/cases/conformance/es6/Symbols/symbolType1.ts (2 errors) ==== +==== tests/cases/conformance/es6/Symbols/symbolType1.ts (3 errors) ==== Symbol() instanceof Symbol; ~~~~~~~~ !!! error TS2358: The left-hand side of an 'instanceof' expression must be of type 'any', an object type or a type parameter. Symbol instanceof Symbol(); ~~~~~~~~ +!!! error TS2359: The right-hand side of an 'instanceof' expression must be of type 'any' or of a type assignable to the 'Function' interface type. + (Symbol() || {}) instanceof Object; // This one should be okay, it's a valid way of distinguishing types + Symbol instanceof (Symbol() || {}); + ~~~~~~~~~~~~~~~~ !!! error TS2359: The right-hand side of an 'instanceof' expression must be of type 'any' or of a type assignable to the 'Function' interface type. \ No newline at end of file diff --git a/tests/baselines/reference/symbolType1.js b/tests/baselines/reference/symbolType1.js index a3b00871c4eee..90fb540516228 100644 --- a/tests/baselines/reference/symbolType1.js +++ b/tests/baselines/reference/symbolType1.js @@ -1,7 +1,11 @@ //// [symbolType1.ts] Symbol() instanceof Symbol; -Symbol instanceof Symbol(); +Symbol instanceof Symbol(); +(Symbol() || {}) instanceof Object; // This one should be okay, it's a valid way of distinguishing types +Symbol instanceof (Symbol() || {}); //// [symbolType1.js] Symbol() instanceof Symbol; Symbol instanceof Symbol(); +(Symbol() || {}) instanceof Object; // This one should be okay, it's a valid way of distinguishing types +Symbol instanceof (Symbol() || {}); diff --git a/tests/baselines/reference/symbolType11.types b/tests/baselines/reference/symbolType11.types new file mode 100644 index 0000000000000..ba3a2fec36451 --- /dev/null +++ b/tests/baselines/reference/symbolType11.types @@ -0,0 +1,37 @@ +=== tests/cases/conformance/es6/Symbols/symbolType11.ts === +var s = Symbol.for("logical"); +>s : symbol +>Symbol.for("logical") : symbol +>Symbol.for : (key: string) => symbol +>Symbol : SymbolConstructor +>for : (key: string) => symbol + +s && s; +>s && s : symbol +>s : symbol +>s : symbol + +s && []; +>s && [] : undefined[] +>s : symbol +>[] : undefined[] + +0 && s; +>0 && s : symbol +>s : symbol + +s || s; +>s || s : symbol +>s : symbol +>s : symbol + +s || 1; +>s || 1 : number | symbol +>s : symbol + +({}) || s; +>({}) || s : symbol | {} +>({}) : {} +>{} : {} +>s : symbol + diff --git a/tests/baselines/reference/symbolType12.errors.txt b/tests/baselines/reference/symbolType12.errors.txt new file mode 100644 index 0000000000000..85db01ff5d235 --- /dev/null +++ b/tests/baselines/reference/symbolType12.errors.txt @@ -0,0 +1,136 @@ +tests/cases/conformance/es6/Symbols/symbolType12.ts(3,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/Symbols/symbolType12.ts(3,6): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/Symbols/symbolType12.ts(4,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/Symbols/symbolType12.ts(5,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/Symbols/symbolType12.ts(5,6): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/Symbols/symbolType12.ts(6,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/Symbols/symbolType12.ts(7,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/Symbols/symbolType12.ts(7,6): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/Symbols/symbolType12.ts(8,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/Symbols/symbolType12.ts(9,1): error TS2365: Operator '+=' cannot be applied to types 'symbol' and 'symbol'. +tests/cases/conformance/es6/Symbols/symbolType12.ts(10,1): error TS2365: Operator '+=' cannot be applied to types 'symbol' and 'number'. +tests/cases/conformance/es6/Symbols/symbolType12.ts(11,1): error TS2469: The '+=' operator cannot be applied to a value of type 'symbol'. +tests/cases/conformance/es6/Symbols/symbolType12.ts(12,8): error TS2469: The '+=' operator cannot be applied to a value of type 'symbol'. +tests/cases/conformance/es6/Symbols/symbolType12.ts(13,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/Symbols/symbolType12.ts(13,6): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/Symbols/symbolType12.ts(14,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/Symbols/symbolType12.ts(15,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/Symbols/symbolType12.ts(15,7): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/Symbols/symbolType12.ts(16,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/Symbols/symbolType12.ts(17,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/Symbols/symbolType12.ts(17,7): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/Symbols/symbolType12.ts(18,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/Symbols/symbolType12.ts(19,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/Symbols/symbolType12.ts(19,8): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/Symbols/symbolType12.ts(20,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/Symbols/symbolType12.ts(21,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/Symbols/symbolType12.ts(21,6): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/Symbols/symbolType12.ts(22,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/Symbols/symbolType12.ts(23,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/Symbols/symbolType12.ts(23,6): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/Symbols/symbolType12.ts(24,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/Symbols/symbolType12.ts(25,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/Symbols/symbolType12.ts(25,6): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/Symbols/symbolType12.ts(26,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/Symbols/symbolType12.ts(28,8): error TS2469: The '+=' operator cannot be applied to a value of type 'symbol'. + + +==== tests/cases/conformance/es6/Symbols/symbolType12.ts (35 errors) ==== + var s = Symbol.for("assign"); + var str = ""; + s *= s; + ~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + ~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + s *= 0; + ~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + s /= s; + ~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + ~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + s /= 0; + ~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + s %= s; + ~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + ~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + s %= 0; + ~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + s += s; + ~~~~~~ +!!! error TS2365: Operator '+=' cannot be applied to types 'symbol' and 'symbol'. + s += 0; + ~~~~~~ +!!! error TS2365: Operator '+=' cannot be applied to types 'symbol' and 'number'. + s += ""; + ~ +!!! error TS2469: The '+=' operator cannot be applied to a value of type 'symbol'. + str += s; + ~ +!!! error TS2469: The '+=' operator cannot be applied to a value of type 'symbol'. + s -= s; + ~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + ~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + s -= 0; + ~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + s <<= s; + ~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + ~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + s <<= 0; + ~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + s >>= s; + ~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + ~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + s >>= 0; + ~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + s >>>= s; + ~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + ~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + s >>>= 0; + ~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + s &= s; + ~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + ~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + s &= 0; + ~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + s ^= s; + ~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + ~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + s ^= 0; + ~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + s |= s; + ~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + ~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + s |= 0; + ~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + + str += (s || str); + ~~~~~~~~~~ +!!! error TS2469: The '+=' operator cannot be applied to a value of type 'symbol'. \ No newline at end of file diff --git a/tests/baselines/reference/symbolType12.js b/tests/baselines/reference/symbolType12.js index 05d7fa03eb695..069846e136fdf 100644 --- a/tests/baselines/reference/symbolType12.js +++ b/tests/baselines/reference/symbolType12.js @@ -24,7 +24,9 @@ s &= 0; s ^= s; s ^= 0; s |= s; -s |= 0; +s |= 0; + +str += (s || str); //// [symbolType12.js] var s = Symbol.for("assign"); @@ -53,3 +55,4 @@ s ^= s; s ^= 0; s |= s; s |= 0; +str += (s || str); diff --git a/tests/baselines/reference/symbolType13.errors.txt b/tests/baselines/reference/symbolType13.errors.txt new file mode 100644 index 0000000000000..68981d0072bb9 --- /dev/null +++ b/tests/baselines/reference/symbolType13.errors.txt @@ -0,0 +1,18 @@ +tests/cases/conformance/es6/Symbols/symbolType13.ts(4,6): error TS2405: The left-hand side of a 'for...in' statement must be of type 'string' or 'any'. +tests/cases/conformance/es6/Symbols/symbolType13.ts(5,11): error TS2407: The right-hand side of a 'for...in' statement must be of type 'any', an object type or a type parameter. +tests/cases/conformance/es6/Symbols/symbolType13.ts(6,15): error TS2407: The right-hand side of a 'for...in' statement must be of type 'any', an object type or a type parameter. + + +==== tests/cases/conformance/es6/Symbols/symbolType13.ts (3 errors) ==== + var s = Symbol(); + var x: any; + + for (s in {}) { } + ~ +!!! error TS2405: The left-hand side of a 'for...in' statement must be of type 'string' or 'any'. + for (x in s) { } + ~ +!!! error TS2407: The right-hand side of a 'for...in' statement must be of type 'any', an object type or a type parameter. + for (var y in s) { } + ~ +!!! error TS2407: The right-hand side of a 'for...in' statement must be of type 'any', an object type or a type parameter. \ No newline at end of file diff --git a/tests/baselines/reference/symbolType2.errors.txt b/tests/baselines/reference/symbolType2.errors.txt new file mode 100644 index 0000000000000..441db91771833 --- /dev/null +++ b/tests/baselines/reference/symbolType2.errors.txt @@ -0,0 +1,8 @@ +tests/cases/conformance/es6/Symbols/symbolType2.ts(2,7): error TS2361: The right-hand side of an 'in' expression must be of type 'any', an object type or a type parameter + + +==== tests/cases/conformance/es6/Symbols/symbolType2.ts (1 errors) ==== + Symbol.isConcatSpreadable in {}; + "" in Symbol.toPrimitive; + ~~~~~~~~~~~~~~~~~~ +!!! error TS2361: The right-hand side of an 'in' expression must be of type 'any', an object type or a type parameter \ No newline at end of file diff --git a/tests/baselines/reference/symbolType3.errors.txt b/tests/baselines/reference/symbolType3.errors.txt new file mode 100644 index 0000000000000..384ccb06c0505 --- /dev/null +++ b/tests/baselines/reference/symbolType3.errors.txt @@ -0,0 +1,33 @@ +tests/cases/conformance/es6/Symbols/symbolType3.ts(5,3): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/Symbols/symbolType3.ts(6,3): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/Symbols/symbolType3.ts(7,3): error TS2469: The '+' operator cannot be applied to a value of type 'symbol'. +tests/cases/conformance/es6/Symbols/symbolType3.ts(8,3): error TS2469: The '-' operator cannot be applied to a value of type 'symbol'. +tests/cases/conformance/es6/Symbols/symbolType3.ts(9,3): error TS2469: The '~' operator cannot be applied to a value of type 'symbol'. +tests/cases/conformance/es6/Symbols/symbolType3.ts(12,2): error TS2469: The '+' operator cannot be applied to a value of type 'symbol'. + + +==== tests/cases/conformance/es6/Symbols/symbolType3.ts (6 errors) ==== + var s = Symbol(); + delete Symbol.iterator; + void Symbol.toPrimitive; + typeof Symbol.toStringTag; + ++s; + ~ +!!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. + --s; + ~ +!!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. + + Symbol(); + ~~~~~~~~ +!!! error TS2469: The '+' operator cannot be applied to a value of type 'symbol'. + - Symbol(); + ~~~~~~~~ +!!! error TS2469: The '-' operator cannot be applied to a value of type 'symbol'. + ~ Symbol(); + ~~~~~~~~ +!!! error TS2469: The '~' operator cannot be applied to a value of type 'symbol'. + ! Symbol(); + + +(Symbol() || 0); + ~~~~~~~~~~~~~~~ +!!! error TS2469: The '+' operator cannot be applied to a value of type 'symbol'. \ No newline at end of file diff --git a/tests/baselines/reference/symbolType3.js b/tests/baselines/reference/symbolType3.js index 088449a3a8910..4f599dacbe0a1 100644 --- a/tests/baselines/reference/symbolType3.js +++ b/tests/baselines/reference/symbolType3.js @@ -8,7 +8,9 @@ typeof Symbol.toStringTag; + Symbol(); - Symbol(); ~ Symbol(); -! Symbol(); +! Symbol(); + ++(Symbol() || 0); //// [symbolType3.js] var s = Symbol(); @@ -21,3 +23,4 @@ typeof Symbol.toStringTag; -Symbol(); ~Symbol(); !Symbol(); ++(Symbol() || 0); diff --git a/tests/baselines/reference/symbolType6.errors.txt b/tests/baselines/reference/symbolType6.errors.txt new file mode 100644 index 0000000000000..9ad7321063f42 --- /dev/null +++ b/tests/baselines/reference/symbolType6.errors.txt @@ -0,0 +1,57 @@ +tests/cases/conformance/es6/Symbols/symbolType6.ts(3,1): error TS2365: Operator '+' cannot be applied to types 'symbol' and 'symbol'. +tests/cases/conformance/es6/Symbols/symbolType6.ts(4,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/Symbols/symbolType6.ts(4,5): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/Symbols/symbolType6.ts(5,1): error TS2469: The '+' operator cannot be applied to a value of type 'symbol'. +tests/cases/conformance/es6/Symbols/symbolType6.ts(6,1): error TS2469: The '+' operator cannot be applied to a value of type 'symbol'. +tests/cases/conformance/es6/Symbols/symbolType6.ts(7,1): error TS2365: Operator '+' cannot be applied to types 'symbol' and 'number'. +tests/cases/conformance/es6/Symbols/symbolType6.ts(8,6): error TS2469: The '+' operator cannot be applied to a value of type 'symbol'. +tests/cases/conformance/es6/Symbols/symbolType6.ts(9,5): error TS2469: The '+' operator cannot be applied to a value of type 'symbol'. +tests/cases/conformance/es6/Symbols/symbolType6.ts(10,1): error TS2365: Operator '+' cannot be applied to types 'number' and 'symbol'. +tests/cases/conformance/es6/Symbols/symbolType6.ts(11,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/Symbols/symbolType6.ts(12,5): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/es6/Symbols/symbolType6.ts(14,1): error TS2469: The '+' operator cannot be applied to a value of type 'symbol'. +tests/cases/conformance/es6/Symbols/symbolType6.ts(15,6): error TS2469: The '+' operator cannot be applied to a value of type 'symbol'. + + +==== tests/cases/conformance/es6/Symbols/symbolType6.ts (13 errors) ==== + var s = Symbol.for("add"); + var a: any; + s + s; + ~~~~~ +!!! error TS2365: Operator '+' cannot be applied to types 'symbol' and 'symbol'. + s - s; + ~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + ~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + s + ""; + ~ +!!! error TS2469: The '+' operator cannot be applied to a value of type 'symbol'. + s + a; + ~ +!!! error TS2469: The '+' operator cannot be applied to a value of type 'symbol'. + s + 0; + ~~~~~ +!!! error TS2365: Operator '+' cannot be applied to types 'symbol' and 'number'. + "" + s; + ~ +!!! error TS2469: The '+' operator cannot be applied to a value of type 'symbol'. + a + s; + ~ +!!! error TS2469: The '+' operator cannot be applied to a value of type 'symbol'. + 0 + s; + ~~~~~ +!!! error TS2365: Operator '+' cannot be applied to types 'number' and 'symbol'. + s - 0; + ~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + 0 - s; + ~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + + (s || "") + ""; + ~~~~~~~~~ +!!! error TS2469: The '+' operator cannot be applied to a value of type 'symbol'. + "" + (s || ""); + ~~~~~~~~~ +!!! error TS2469: The '+' operator cannot be applied to a value of type 'symbol'. \ No newline at end of file diff --git a/tests/baselines/reference/symbolType6.js b/tests/baselines/reference/symbolType6.js index ad16baa28b4ec..b316f48cf0346 100644 --- a/tests/baselines/reference/symbolType6.js +++ b/tests/baselines/reference/symbolType6.js @@ -1,21 +1,32 @@ //// [symbolType6.ts] var s = Symbol.for("add"); +var a: any; s + s; s - s; s + ""; +s + a; s + 0; "" + s; +a + s; 0 + s; s - 0; -0 - s; +0 - s; + +(s || "") + ""; +"" + (s || ""); //// [symbolType6.js] var s = Symbol.for("add"); +var a; s + s; s - s; s + ""; +s + a; s + 0; "" + s; +a + s; 0 + s; s - 0; 0 - s; +(s || "") + ""; +"" + (s || ""); diff --git a/tests/baselines/reference/symbolType8.errors.txt b/tests/baselines/reference/symbolType8.errors.txt new file mode 100644 index 0000000000000..e72d0d619e437 --- /dev/null +++ b/tests/baselines/reference/symbolType8.errors.txt @@ -0,0 +1,45 @@ +tests/cases/conformance/es6/Symbols/symbolType8.ts(2,1): error TS2469: The '<' operator cannot be applied to a value of type 'symbol'. +tests/cases/conformance/es6/Symbols/symbolType8.ts(3,1): error TS2469: The '<' operator cannot be applied to a value of type 'symbol'. +tests/cases/conformance/es6/Symbols/symbolType8.ts(4,1): error TS2469: The '>' operator cannot be applied to a value of type 'symbol'. +tests/cases/conformance/es6/Symbols/symbolType8.ts(5,1): error TS2469: The '>' operator cannot be applied to a value of type 'symbol'. +tests/cases/conformance/es6/Symbols/symbolType8.ts(6,1): error TS2469: The '<=' operator cannot be applied to a value of type 'symbol'. +tests/cases/conformance/es6/Symbols/symbolType8.ts(7,1): error TS2469: The '<=' operator cannot be applied to a value of type 'symbol'. +tests/cases/conformance/es6/Symbols/symbolType8.ts(8,1): error TS2469: The '>=' operator cannot be applied to a value of type 'symbol'. +tests/cases/conformance/es6/Symbols/symbolType8.ts(9,1): error TS2469: The '>=' operator cannot be applied to a value of type 'symbol'. +tests/cases/conformance/es6/Symbols/symbolType8.ts(11,6): error TS2469: The '>=' operator cannot be applied to a value of type 'symbol'. +tests/cases/conformance/es6/Symbols/symbolType8.ts(12,1): error TS2469: The '>=' operator cannot be applied to a value of type 'symbol'. + + +==== tests/cases/conformance/es6/Symbols/symbolType8.ts (10 errors) ==== + var s = Symbol.for("compare"); + s < s; + ~ +!!! error TS2469: The '<' operator cannot be applied to a value of type 'symbol'. + s < 0; + ~ +!!! error TS2469: The '<' operator cannot be applied to a value of type 'symbol'. + s > s; + ~ +!!! error TS2469: The '>' operator cannot be applied to a value of type 'symbol'. + s > 0; + ~ +!!! error TS2469: The '>' operator cannot be applied to a value of type 'symbol'. + s <= s; + ~ +!!! error TS2469: The '<=' operator cannot be applied to a value of type 'symbol'. + s <= 0; + ~ +!!! error TS2469: The '<=' operator cannot be applied to a value of type 'symbol'. + s >= s; + ~ +!!! error TS2469: The '>=' operator cannot be applied to a value of type 'symbol'. + s >= 0; + ~ +!!! error TS2469: The '>=' operator cannot be applied to a value of type 'symbol'. + + 0 >= (s || 0); + ~~~~~~~~ +!!! error TS2469: The '>=' operator cannot be applied to a value of type 'symbol'. + (s || 0) >= s; + ~~~~~~~~ +!!! error TS2469: The '>=' operator cannot be applied to a value of type 'symbol'. \ No newline at end of file diff --git a/tests/baselines/reference/symbolType8.js b/tests/baselines/reference/symbolType8.js index e80dea220b908..7e56416ca841d 100644 --- a/tests/baselines/reference/symbolType8.js +++ b/tests/baselines/reference/symbolType8.js @@ -7,7 +7,10 @@ s > 0; s <= s; s <= 0; s >= s; -s >= 0; +s >= 0; + +0 >= (s || 0); +(s || 0) >= s; //// [symbolType8.js] var s = Symbol.for("compare"); @@ -19,3 +22,5 @@ s <= s; s <= 0; s >= s; s >= 0; +0 >= (s || 0); +(s || 0) >= s; diff --git a/tests/baselines/reference/widenedTypes.errors.txt b/tests/baselines/reference/widenedTypes.errors.txt index 7374bd23b7799..2277ef6eea75a 100644 --- a/tests/baselines/reference/widenedTypes.errors.txt +++ b/tests/baselines/reference/widenedTypes.errors.txt @@ -1,5 +1,5 @@ tests/cases/compiler/widenedTypes.ts(2,1): error TS2358: The left-hand side of an 'instanceof' expression must be of type 'any', an object type or a type parameter. -tests/cases/compiler/widenedTypes.ts(5,1): error TS2360: The left-hand side of an 'in' expression must be of types 'any', 'string' or 'number'. +tests/cases/compiler/widenedTypes.ts(5,1): error TS2360: The left-hand side of an 'in' expression must be of type 'any', 'string', 'number', or 'symbol'. tests/cases/compiler/widenedTypes.ts(6,7): error TS2361: The right-hand side of an 'in' expression must be of type 'any', an object type or a type parameter tests/cases/compiler/widenedTypes.ts(8,15): error TS2407: The right-hand side of a 'for...in' statement must be of type 'any', an object type or a type parameter. tests/cases/compiler/widenedTypes.ts(11,1): error TS2322: Type 'string' is not assignable to type 'number'. @@ -20,7 +20,7 @@ tests/cases/compiler/widenedTypes.ts(24,5): error TS2322: Type '{ [x: string]: n null in {}; ~~~~ -!!! error TS2360: The left-hand side of an 'in' expression must be of types 'any', 'string' or 'number'. +!!! error TS2360: The left-hand side of an 'in' expression must be of type 'any', 'string', 'number', or 'symbol'. "" in null; ~~~~ !!! error TS2361: The right-hand side of an 'in' expression must be of type 'any', an object type or a type parameter diff --git a/tests/cases/conformance/es6/Symbols/symbolType1.ts b/tests/cases/conformance/es6/Symbols/symbolType1.ts index 3945ecc76e8e6..3a7339fbeb7aa 100644 --- a/tests/cases/conformance/es6/Symbols/symbolType1.ts +++ b/tests/cases/conformance/es6/Symbols/symbolType1.ts @@ -1,3 +1,5 @@ //@target: ES6 Symbol() instanceof Symbol; -Symbol instanceof Symbol(); \ No newline at end of file +Symbol instanceof Symbol(); +(Symbol() || {}) instanceof Object; // This one should be okay, it's a valid way of distinguishing types +Symbol instanceof (Symbol() || {}); \ No newline at end of file diff --git a/tests/cases/conformance/es6/Symbols/symbolType12.ts b/tests/cases/conformance/es6/Symbols/symbolType12.ts index 7197c13497da5..44852bc10e6f7 100644 --- a/tests/cases/conformance/es6/Symbols/symbolType12.ts +++ b/tests/cases/conformance/es6/Symbols/symbolType12.ts @@ -24,4 +24,6 @@ s &= 0; s ^= s; s ^= 0; s |= s; -s |= 0; \ No newline at end of file +s |= 0; + +str += (s || str); \ No newline at end of file diff --git a/tests/cases/conformance/es6/Symbols/symbolType3.ts b/tests/cases/conformance/es6/Symbols/symbolType3.ts index ca098fe069523..b5855ecab41bd 100644 --- a/tests/cases/conformance/es6/Symbols/symbolType3.ts +++ b/tests/cases/conformance/es6/Symbols/symbolType3.ts @@ -8,4 +8,6 @@ typeof Symbol.toStringTag; + Symbol(); - Symbol(); ~ Symbol(); -! Symbol(); \ No newline at end of file +! Symbol(); + ++(Symbol() || 0); \ No newline at end of file diff --git a/tests/cases/conformance/es6/Symbols/symbolType6.ts b/tests/cases/conformance/es6/Symbols/symbolType6.ts index b6f58ac5b2904..2efa682b98fa6 100644 --- a/tests/cases/conformance/es6/Symbols/symbolType6.ts +++ b/tests/cases/conformance/es6/Symbols/symbolType6.ts @@ -1,10 +1,16 @@ //@target: ES6 var s = Symbol.for("add"); +var a: any; s + s; s - s; s + ""; +s + a; s + 0; "" + s; +a + s; 0 + s; s - 0; -0 - s; \ No newline at end of file +0 - s; + +(s || "") + ""; +"" + (s || ""); \ No newline at end of file diff --git a/tests/cases/conformance/es6/Symbols/symbolType8.ts b/tests/cases/conformance/es6/Symbols/symbolType8.ts index 4970ae0a9ca81..b3bc68094c7c4 100644 --- a/tests/cases/conformance/es6/Symbols/symbolType8.ts +++ b/tests/cases/conformance/es6/Symbols/symbolType8.ts @@ -7,4 +7,7 @@ s > 0; s <= s; s <= 0; s >= s; -s >= 0; \ No newline at end of file +s >= 0; + +0 >= (s || 0); +(s || 0) >= s; \ No newline at end of file