From 549c2f5b603de2b27ce795aa0b66ae0b80f0dbc6 Mon Sep 17 00:00:00 2001 From: Isabel Duan Date: Tue, 21 May 2024 13:55:22 -0700 Subject: [PATCH 01/15] add BigIntLiteral to PropertyName --- src/compiler/diagnosticMessages.json | 4 ++++ src/compiler/parser.ts | 10 +++++++++- src/compiler/transformers/destructuring.ts | 3 ++- src/compiler/types.ts | 14 +++++++++++--- src/compiler/utilities.ts | 2 ++ tests/baselines/reference/api/typescript.d.ts | 4 ++-- .../baselines/reference/bigintIndex.errors.txt | 16 +++++++--------- tests/baselines/reference/bigintIndex.js | 10 ++++++---- tests/baselines/reference/bigintIndex.symbols | 4 ++++ tests/baselines/reference/bigintIndex.types | 18 ++++++++++++++---- tests/cases/compiler/bigintIndex.ts | 1 + 11 files changed, 62 insertions(+), 24 deletions(-) diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 725a6b73aa450..3e68260659565 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -8309,5 +8309,9 @@ "Enum member following a non-literal numeric member must have an initializer when 'isolatedModules' is enabled.": { "category": "Error", "code": 18056 + }, + "A bigint literal cannot be used as a property name.": { + "category": "Error", + "code": 18057 } } diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index a63735ad6bfa2..edcdef7f7c9e1 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -14,6 +14,7 @@ import { attachFileToDiagnostics, AwaitExpression, BaseNodeFactory, + BigIntLiteral, BinaryExpression, BinaryOperatorToken, BindingElement, @@ -2697,7 +2698,8 @@ namespace Parser { function isLiteralPropertyName(): boolean { return tokenIsIdentifierOrKeyword(token()) || token() === SyntaxKind.StringLiteral || - token() === SyntaxKind.NumericLiteral; + token() === SyntaxKind.NumericLiteral || + token() === SyntaxKind.BigIntLiteral; } function isImportAttributeName(): boolean { @@ -2710,6 +2712,12 @@ namespace Parser { node.text = internIdentifier(node.text); return node; } + if (token() === SyntaxKind.BigIntLiteral) { + parseErrorAtCurrentToken(Diagnostics.A_bigint_literal_cannot_be_used_as_a_property_name); + const node = parseLiteralNode() as BigIntLiteral; + node.text = internIdentifier(node.text); + return node; + } if (allowComputedPropertyNames && token() === SyntaxKind.OpenBracketToken) { return parseComputedPropertyName(); } diff --git a/src/compiler/transformers/destructuring.ts b/src/compiler/transformers/destructuring.ts index aa61d9f64787b..cca1f2b9e6fba 100644 --- a/src/compiler/transformers/destructuring.ts +++ b/src/compiler/transformers/destructuring.ts @@ -23,6 +23,7 @@ import { isArrayBindingElement, isArrayBindingOrAssignmentElement, isArrayBindingOrAssignmentPattern, + isBigIntLiteral, isBindingElement, isBindingName, isBindingOrAssignmentElement, @@ -558,7 +559,7 @@ function createDestructuringPropertyAccess(flattenContext: FlattenContext, value const argumentExpression = ensureIdentifier(flattenContext, Debug.checkDefined(visitNode(propertyName.expression, flattenContext.visitor, isExpression)), /*reuseIdentifierExpressions*/ false, /*location*/ propertyName); return flattenContext.context.factory.createElementAccessExpression(value, argumentExpression); } - else if (isStringOrNumericLiteralLike(propertyName)) { + else if (isStringOrNumericLiteralLike(propertyName) || isBigIntLiteral(propertyName)) { const argumentExpression = factory.cloneNode(propertyName); return flattenContext.context.factory.createElementAccessExpression(value, argumentExpression); } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index aae7c5494a17d..16f4b2bd6ac3f 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1719,7 +1719,14 @@ export interface QualifiedName extends Node, FlowContainer { export type EntityName = Identifier | QualifiedName; -export type PropertyName = Identifier | StringLiteral | NoSubstitutionTemplateLiteral | NumericLiteral | ComputedPropertyName | PrivateIdentifier; +export type PropertyName = + | Identifier + | StringLiteral + | NoSubstitutionTemplateLiteral + | NumericLiteral + | ComputedPropertyName + | PrivateIdentifier + | BigIntLiteral; export type MemberName = Identifier | PrivateIdentifier; @@ -2338,7 +2345,8 @@ export interface LiteralTypeNode extends TypeNode { export interface StringLiteral extends LiteralExpression, Declaration { readonly kind: SyntaxKind.StringLiteral; - /** @internal */ readonly textSourceNode?: Identifier | StringLiteralLike | NumericLiteral | PrivateIdentifier | JsxNamespacedName; // Allows a StringLiteral to get its text from another node (used by transforms). + /** @internal */ + readonly textSourceNode?: Identifier | StringLiteralLike | NumericLiteral | PrivateIdentifier | JsxNamespacedName | BigIntLiteral; // Allows a StringLiteral to get its text from another node (used by transforms). /** * Note: this is only set when synthesizing a node, not during parsing. * @@ -2348,7 +2356,7 @@ export interface StringLiteral extends LiteralExpression, Declaration { } export type StringLiteralLike = StringLiteral | NoSubstitutionTemplateLiteral; -export type PropertyNameLiteral = Identifier | StringLiteralLike | NumericLiteral | JsxNamespacedName; +export type PropertyNameLiteral = Identifier | StringLiteralLike | NumericLiteral | JsxNamespacedName | BigIntLiteral; export interface TemplateLiteralTypeNode extends TypeNode { kind: SyntaxKind.TemplateLiteralType; diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 4cf5f0082cd20..03406e84e5478 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -2088,6 +2088,7 @@ export function tryGetTextOfPropertyName(name: PropertyName | NoSubstitutionTemp return name.emitNode?.autoGenerate ? undefined : name.escapedText; case SyntaxKind.StringLiteral: case SyntaxKind.NumericLiteral: + case SyntaxKind.BigIntLiteral: case SyntaxKind.NoSubstitutionTemplateLiteral: return escapeLeadingUnderscores(name.text); case SyntaxKind.ComputedPropertyName: @@ -5170,6 +5171,7 @@ export function getPropertyNameForPropertyNameNode(name: PropertyName | JsxAttri case SyntaxKind.StringLiteral: case SyntaxKind.NoSubstitutionTemplateLiteral: case SyntaxKind.NumericLiteral: + case SyntaxKind.BigIntLiteral: return escapeLeadingUnderscores(name.text); case SyntaxKind.ComputedPropertyName: const nameExpression = name.expression; diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index 59692349afdc9..6d75c6196e852 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -4418,7 +4418,7 @@ declare namespace ts { readonly right: Identifier; } type EntityName = Identifier | QualifiedName; - type PropertyName = Identifier | StringLiteral | NoSubstitutionTemplateLiteral | NumericLiteral | ComputedPropertyName | PrivateIdentifier; + type PropertyName = Identifier | StringLiteral | NoSubstitutionTemplateLiteral | NumericLiteral | ComputedPropertyName | PrivateIdentifier | BigIntLiteral; type MemberName = Identifier | PrivateIdentifier; type DeclarationName = PropertyName | JsxAttributeName | StringLiteralLike | ElementAccessExpression | BindingPattern | EntityNameExpression; interface Declaration extends Node { @@ -4769,7 +4769,7 @@ declare namespace ts { readonly kind: SyntaxKind.StringLiteral; } type StringLiteralLike = StringLiteral | NoSubstitutionTemplateLiteral; - type PropertyNameLiteral = Identifier | StringLiteralLike | NumericLiteral | JsxNamespacedName; + type PropertyNameLiteral = Identifier | StringLiteralLike | NumericLiteral | JsxNamespacedName | BigIntLiteral; interface TemplateLiteralTypeNode extends TypeNode { kind: SyntaxKind.TemplateLiteralType; readonly head: TemplateHead; diff --git a/tests/baselines/reference/bigintIndex.errors.txt b/tests/baselines/reference/bigintIndex.errors.txt index 9b96f74377c49..cbf2383d4e486 100644 --- a/tests/baselines/reference/bigintIndex.errors.txt +++ b/tests/baselines/reference/bigintIndex.errors.txt @@ -2,11 +2,10 @@ a.ts(2,6): error TS1268: An index signature parameter type must be 'string', 'nu a.ts(8,11): error TS2538: Type '1n' cannot be used as an index type. a.ts(14,1): error TS2322: Type 'bigint' is not assignable to type 'string | number | symbol'. a.ts(19,12): error TS2538: Type 'bigint' cannot be used as an index type. -b.ts(2,12): error TS1136: Property assignment expected. -b.ts(2,14): error TS1005: ';' expected. -b.ts(2,19): error TS1128: Declaration or statement expected. +b.ts(2,12): error TS18057: A bigint literal cannot be used as a property name. b.ts(3,12): error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'. b.ts(4,12): error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'. +b.ts(5,5): error TS18057: A bigint literal cannot be used as a property name. ==== a.ts (4 errors) ==== @@ -42,19 +41,18 @@ b.ts(4,12): error TS2464: A computed property name must be of type 'string', 'nu typedArray[2] = 0xCC; // {1n: 123} is a syntax error; must go in separate file so BigIntIndex error is shown -==== b.ts (5 errors) ==== +==== b.ts (4 errors) ==== // BigInt cannot be used as an object literal property const a = {1n: 123}; ~~ -!!! error TS1136: Property assignment expected. - ~ -!!! error TS1005: ';' expected. - ~ -!!! error TS1128: Declaration or statement expected. +!!! error TS18057: A bigint literal cannot be used as a property name. const b = {[1n]: 456}; ~~~~ !!! error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'. const c = {[bigNum]: 789}; ~~~~~~~~ !!! error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'. + { ({1n: 123}); }; + ~~ +!!! error TS18057: A bigint literal cannot be used as a property name. \ No newline at end of file diff --git a/tests/baselines/reference/bigintIndex.js b/tests/baselines/reference/bigintIndex.js index e24aee68dcfb1..cb9811271a505 100644 --- a/tests/baselines/reference/bigintIndex.js +++ b/tests/baselines/reference/bigintIndex.js @@ -30,6 +30,7 @@ typedArray[2] = 0xCC; const a = {1n: 123}; const b = {[1n]: 456}; const c = {[bigNum]: 789}; +{ ({1n: 123}); }; //// [a.js] @@ -52,9 +53,10 @@ typedArray[2] = 0xCC; // {1n: 123} is a syntax error; must go in separate file so BigIntIndex error is shown //// [b.js] // BigInt cannot be used as an object literal property -const a = {}; -1n; -123; -; +const a = { 1n: 123 }; const b = { [1n]: 456 }; const c = { [bigNum]: 789 }; +{ + ({ 1n: 123 }); +} +; diff --git a/tests/baselines/reference/bigintIndex.symbols b/tests/baselines/reference/bigintIndex.symbols index 77dbc2cb6f4eb..2f842431e7889 100644 --- a/tests/baselines/reference/bigintIndex.symbols +++ b/tests/baselines/reference/bigintIndex.symbols @@ -69,6 +69,7 @@ typedArray[2] = 0xCC; // BigInt cannot be used as an object literal property const a = {1n: 123}; >a : Symbol(a, Decl(b.ts, 1, 5)) +>1n : Symbol(1n, Decl(b.ts, 1, 11)) const b = {[1n]: 456}; >b : Symbol(b, Decl(b.ts, 2, 5)) @@ -79,3 +80,6 @@ const c = {[bigNum]: 789}; >[bigNum] : Symbol([bigNum], Decl(b.ts, 3, 11)) >bigNum : Symbol(bigNum, Decl(a.ts, 16, 5)) +{ ({1n: 123}); }; +>1n : Symbol(1n, Decl(b.ts, 4, 4)) + diff --git a/tests/baselines/reference/bigintIndex.types b/tests/baselines/reference/bigintIndex.types index 16e26728c7c8f..ba00bfecb12ae 100644 --- a/tests/baselines/reference/bigintIndex.types +++ b/tests/baselines/reference/bigintIndex.types @@ -166,10 +166,10 @@ typedArray[2] = 0xCC; const a = {1n: 123}; >a : {} > : ^^ ->{ : {} -> : ^^ ->1n : 1n -> : ^^ +>{1n: 123} : {} +> : ^^ +>1n : number +> : ^^^^^^ >123 : 123 > : ^^^ @@ -197,3 +197,13 @@ const c = {[bigNum]: 789}; >789 : 789 > : ^^^ +{ ({1n: 123}); }; +>({1n: 123}) : {} +> : ^^ +>{1n: 123} : {} +> : ^^ +>1n : number +> : ^^^^^^ +>123 : 123 +> : ^^^ + diff --git a/tests/cases/compiler/bigintIndex.ts b/tests/cases/compiler/bigintIndex.ts index a959eac590f05..db7ec6747ccc1 100644 --- a/tests/cases/compiler/bigintIndex.ts +++ b/tests/cases/compiler/bigintIndex.ts @@ -30,3 +30,4 @@ typedArray[2] = 0xCC; const a = {1n: 123}; const b = {[1n]: 456}; const c = {[bigNum]: 789}; +{ ({1n: 123}); }; From dc4fa17b0872041409764846ac8cd89c9e7023e3 Mon Sep 17 00:00:00 2001 From: Isabel Duan Date: Tue, 21 May 2024 14:15:21 -0700 Subject: [PATCH 02/15] change error wording --- src/compiler/diagnosticMessages.json | 2 +- src/compiler/parser.ts | 2 +- tests/baselines/reference/bigintIndex.errors.txt | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 3e68260659565..5d9989a58e563 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -8310,7 +8310,7 @@ "category": "Error", "code": 18056 }, - "A bigint literal cannot be used as a property name.": { + "A bigint literal may not be used as a property name.": { "category": "Error", "code": 18057 } diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index edcdef7f7c9e1..c5710c66e8df9 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -2713,7 +2713,7 @@ namespace Parser { return node; } if (token() === SyntaxKind.BigIntLiteral) { - parseErrorAtCurrentToken(Diagnostics.A_bigint_literal_cannot_be_used_as_a_property_name); + parseErrorAtCurrentToken(Diagnostics.A_bigint_literal_may_not_be_used_as_a_property_name); const node = parseLiteralNode() as BigIntLiteral; node.text = internIdentifier(node.text); return node; diff --git a/tests/baselines/reference/bigintIndex.errors.txt b/tests/baselines/reference/bigintIndex.errors.txt index cbf2383d4e486..07eafaba39783 100644 --- a/tests/baselines/reference/bigintIndex.errors.txt +++ b/tests/baselines/reference/bigintIndex.errors.txt @@ -2,10 +2,10 @@ a.ts(2,6): error TS1268: An index signature parameter type must be 'string', 'nu a.ts(8,11): error TS2538: Type '1n' cannot be used as an index type. a.ts(14,1): error TS2322: Type 'bigint' is not assignable to type 'string | number | symbol'. a.ts(19,12): error TS2538: Type 'bigint' cannot be used as an index type. -b.ts(2,12): error TS18057: A bigint literal cannot be used as a property name. +b.ts(2,12): error TS18057: A bigint literal may not be used as a property name. b.ts(3,12): error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'. b.ts(4,12): error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'. -b.ts(5,5): error TS18057: A bigint literal cannot be used as a property name. +b.ts(5,5): error TS18057: A bigint literal may not be used as a property name. ==== a.ts (4 errors) ==== @@ -45,7 +45,7 @@ b.ts(5,5): error TS18057: A bigint literal cannot be used as a property name. // BigInt cannot be used as an object literal property const a = {1n: 123}; ~~ -!!! error TS18057: A bigint literal cannot be used as a property name. +!!! error TS18057: A bigint literal may not be used as a property name. const b = {[1n]: 456}; ~~~~ !!! error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'. @@ -54,5 +54,5 @@ b.ts(5,5): error TS18057: A bigint literal cannot be used as a property name. !!! error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'. { ({1n: 123}); }; ~~ -!!! error TS18057: A bigint literal cannot be used as a property name. +!!! error TS18057: A bigint literal may not be used as a property name. \ No newline at end of file From fadbf1399492f3f610372d36fcb2da6ac83ce293 Mon Sep 17 00:00:00 2001 From: Isabel Duan Date: Thu, 23 May 2024 14:36:21 -0700 Subject: [PATCH 03/15] change error to be a grammar error, add index error --- src/compiler/checker.ts | 10 +++++- src/compiler/diagnosticMessages.json | 12 ++++--- src/compiler/parser.ts | 10 ++---- .../reference/bigintIndex.errors.txt | 18 +++++++--- tests/baselines/reference/bigintIndex.js | 12 +++++++ tests/baselines/reference/bigintIndex.symbols | 17 ++++++++++ tests/baselines/reference/bigintIndex.types | 33 +++++++++++++++++++ tests/cases/compiler/bigintIndex.ts | 7 ++++ 8 files changed, 102 insertions(+), 17 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index bb73721914db8..5d04e0e2b5baa 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -18366,7 +18366,12 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { if (accessNode) { const indexNode = getIndexNodeForAccessExpression(accessNode); if (indexType.flags & (TypeFlags.StringLiteral | TypeFlags.NumberLiteral)) { - error(indexNode, Diagnostics.Property_0_does_not_exist_on_type_1, "" + (indexType as StringLiteralType | NumberLiteralType).value, typeToString(objectType)); + if (indexNode.kind === SyntaxKind.BigIntLiteral) { + error(indexNode, Diagnostics.A_bigint_literal_may_not_be_used_as_an_index); + } + else { + error(indexNode, Diagnostics.Property_0_does_not_exist_on_type_1, "" + (indexType as StringLiteralType | NumberLiteralType).value, typeToString(objectType)); + } } else if (indexType.flags & (TypeFlags.String | TypeFlags.Number)) { error(indexNode, Diagnostics.Type_0_has_no_matching_index_signature_for_type_1, typeToString(objectType), typeToString(indexType)); @@ -50412,6 +50417,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { if (name.kind === SyntaxKind.NumericLiteral) { checkGrammarNumericLiteral(name); } + if (name.kind === SyntaxKind.BigIntLiteral) { + addErrorOrSuggestion(/*isError*/ true, createDiagnosticForNode(name, Diagnostics.A_bigint_literal_may_not_be_used_as_a_property_name)); + } currentKind = DeclarationMeaning.PropertyAssignment; break; case SyntaxKind.MethodDeclaration: diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 5d9989a58e563..25cdeb3f7cfcd 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1797,6 +1797,14 @@ "category": "Error", "code": 1535 }, + "A bigint literal may not be used as a property name.": { + "category": "Error", + "code": 1536 + }, + "A bigint literal may not be used as an index.": { + "category": "Error", + "code": 1537 + }, "The types of '{0}' are incompatible between these types.": { "category": "Error", @@ -8309,9 +8317,5 @@ "Enum member following a non-literal numeric member must have an initializer when 'isolatedModules' is enabled.": { "category": "Error", "code": 18056 - }, - "A bigint literal may not be used as a property name.": { - "category": "Error", - "code": 18057 } } diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index c5710c66e8df9..cc06839f7a898 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -2707,14 +2707,8 @@ namespace Parser { } function parsePropertyNameWorker(allowComputedPropertyNames: boolean): PropertyName { - if (token() === SyntaxKind.StringLiteral || token() === SyntaxKind.NumericLiteral) { - const node = parseLiteralNode() as StringLiteral | NumericLiteral; - node.text = internIdentifier(node.text); - return node; - } - if (token() === SyntaxKind.BigIntLiteral) { - parseErrorAtCurrentToken(Diagnostics.A_bigint_literal_may_not_be_used_as_a_property_name); - const node = parseLiteralNode() as BigIntLiteral; + if (token() === SyntaxKind.StringLiteral || token() === SyntaxKind.NumericLiteral || token() === SyntaxKind.BigIntLiteral) { + const node = parseLiteralNode() as StringLiteral | NumericLiteral | BigIntLiteral; node.text = internIdentifier(node.text); return node; } diff --git a/tests/baselines/reference/bigintIndex.errors.txt b/tests/baselines/reference/bigintIndex.errors.txt index 07eafaba39783..13fccb1157485 100644 --- a/tests/baselines/reference/bigintIndex.errors.txt +++ b/tests/baselines/reference/bigintIndex.errors.txt @@ -2,10 +2,11 @@ a.ts(2,6): error TS1268: An index signature parameter type must be 'string', 'nu a.ts(8,11): error TS2538: Type '1n' cannot be used as an index type. a.ts(14,1): error TS2322: Type 'bigint' is not assignable to type 'string | number | symbol'. a.ts(19,12): error TS2538: Type 'bigint' cannot be used as an index type. -b.ts(2,12): error TS18057: A bigint literal may not be used as a property name. +b.ts(2,12): error TS1536: A bigint literal may not be used as a property name. b.ts(3,12): error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'. b.ts(4,12): error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'. -b.ts(5,5): error TS18057: A bigint literal may not be used as a property name. +b.ts(5,5): error TS1536: A bigint literal may not be used as a property name. +c.ts(3,9): error TS1537: A bigint literal may not be used as an index. ==== a.ts (4 errors) ==== @@ -45,7 +46,7 @@ b.ts(5,5): error TS18057: A bigint literal may not be used as a property name. // BigInt cannot be used as an object literal property const a = {1n: 123}; ~~ -!!! error TS18057: A bigint literal may not be used as a property name. +!!! error TS1536: A bigint literal may not be used as a property name. const b = {[1n]: 456}; ~~~~ !!! error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'. @@ -54,5 +55,14 @@ b.ts(5,5): error TS18057: A bigint literal may not be used as a property name. !!! error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'. { ({1n: 123}); }; ~~ -!!! error TS18057: A bigint literal may not be used as a property name. +!!! error TS1536: A bigint literal may not be used as a property name. + +==== c.ts (1 errors) ==== + const crr = [1, 2, 3] as const; + + const { 0n: f } = crr; // bigint should give an index error + ~~ +!!! error TS1537: A bigint literal may not be used as an index. + const { 0: d } = crr; + const { "0": e } = crr; \ No newline at end of file diff --git a/tests/baselines/reference/bigintIndex.js b/tests/baselines/reference/bigintIndex.js index cb9811271a505..b8d9828ae5728 100644 --- a/tests/baselines/reference/bigintIndex.js +++ b/tests/baselines/reference/bigintIndex.js @@ -32,6 +32,13 @@ const b = {[1n]: 456}; const c = {[bigNum]: 789}; { ({1n: 123}); }; +//// [c.ts] +const crr = [1, 2, 3] as const; + +const { 0n: f } = crr; // bigint should give an index error +const { 0: d } = crr; +const { "0": e } = crr; + //// [a.js] const arr = [1, 2, 3]; @@ -60,3 +67,8 @@ const c = { [bigNum]: 789 }; ({ 1n: 123 }); } ; +//// [c.js] +const crr = [1, 2, 3]; +const { 0n: f } = crr; // bigint should give an index error +const { 0: d } = crr; +const { "0": e } = crr; diff --git a/tests/baselines/reference/bigintIndex.symbols b/tests/baselines/reference/bigintIndex.symbols index 2f842431e7889..c240122a3df2b 100644 --- a/tests/baselines/reference/bigintIndex.symbols +++ b/tests/baselines/reference/bigintIndex.symbols @@ -83,3 +83,20 @@ const c = {[bigNum]: 789}; { ({1n: 123}); }; >1n : Symbol(1n, Decl(b.ts, 4, 4)) +=== c.ts === +const crr = [1, 2, 3] as const; +>crr : Symbol(crr, Decl(c.ts, 0, 5)) +>const : Symbol(const) + +const { 0n: f } = crr; // bigint should give an index error +>f : Symbol(f, Decl(c.ts, 2, 7)) +>crr : Symbol(crr, Decl(c.ts, 0, 5)) + +const { 0: d } = crr; +>d : Symbol(d, Decl(c.ts, 3, 7)) +>crr : Symbol(crr, Decl(c.ts, 0, 5)) + +const { "0": e } = crr; +>e : Symbol(e, Decl(c.ts, 4, 7)) +>crr : Symbol(crr, Decl(c.ts, 0, 5)) + diff --git a/tests/baselines/reference/bigintIndex.types b/tests/baselines/reference/bigintIndex.types index ba00bfecb12ae..2e7dc0d0ce3bb 100644 --- a/tests/baselines/reference/bigintIndex.types +++ b/tests/baselines/reference/bigintIndex.types @@ -207,3 +207,36 @@ const c = {[bigNum]: 789}; >123 : 123 > : ^^^ +=== c.ts === +const crr = [1, 2, 3] as const; +>crr : readonly [1, 2, 3] +> : ^^^^^^^^^^^^^^^^^^ +>[1, 2, 3] as const : readonly [1, 2, 3] +> : ^^^^^^^^^^^^^^^^^^ +>[1, 2, 3] : readonly [1, 2, 3] +> : ^^^^^^^^^^^^^^^^^^ +>1 : 1 +> : ^ +>2 : 2 +> : ^ +>3 : 3 +> : ^ + +const { 0n: f } = crr; // bigint should give an index error +>f : any +> : ^^^ +>crr : readonly [1, 2, 3] +> : ^^^^^^^^^^^^^^^^^^ + +const { 0: d } = crr; +>d : 1 +> : ^ +>crr : readonly [1, 2, 3] +> : ^^^^^^^^^^^^^^^^^^ + +const { "0": e } = crr; +>e : 1 +> : ^ +>crr : readonly [1, 2, 3] +> : ^^^^^^^^^^^^^^^^^^ + diff --git a/tests/cases/compiler/bigintIndex.ts b/tests/cases/compiler/bigintIndex.ts index db7ec6747ccc1..9b41ef64881fc 100644 --- a/tests/cases/compiler/bigintIndex.ts +++ b/tests/cases/compiler/bigintIndex.ts @@ -31,3 +31,10 @@ const a = {1n: 123}; const b = {[1n]: 456}; const c = {[bigNum]: 789}; { ({1n: 123}); }; + +// @filename: c.ts +const crr = [1, 2, 3] as const; + +const { 0n: f } = crr; // bigint should give an index error +const { 0: d } = crr; +const { "0": e } = crr; From 262c6b18a283508c5b5bda22028e1104f706125e Mon Sep 17 00:00:00 2001 From: Isabel Duan Date: Thu, 23 May 2024 16:20:24 -0700 Subject: [PATCH 04/15] more specific index error --- src/compiler/checker.ts | 12 +++++------- tests/baselines/reference/bigintIndex.errors.txt | 4 ++-- tests/cases/compiler/bigintIndex.ts | 1 + 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 5d04e0e2b5baa..28fa91eca21a7 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -18365,13 +18365,11 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { } if (accessNode) { const indexNode = getIndexNodeForAccessExpression(accessNode); - if (indexType.flags & (TypeFlags.StringLiteral | TypeFlags.NumberLiteral)) { - if (indexNode.kind === SyntaxKind.BigIntLiteral) { - error(indexNode, Diagnostics.A_bigint_literal_may_not_be_used_as_an_index); - } - else { - error(indexNode, Diagnostics.Property_0_does_not_exist_on_type_1, "" + (indexType as StringLiteralType | NumberLiteralType).value, typeToString(objectType)); - } + if (indexNode.kind === SyntaxKind.BigIntLiteral) { + error(indexNode, Diagnostics.A_bigint_literal_may_not_be_used_as_an_index); + } + else if (indexType.flags & (TypeFlags.StringLiteral | TypeFlags.NumberLiteral)) { + error(indexNode, Diagnostics.Property_0_does_not_exist_on_type_1, "" + (indexType as StringLiteralType | NumberLiteralType).value, typeToString(objectType)); } else if (indexType.flags & (TypeFlags.String | TypeFlags.Number)) { error(indexNode, Diagnostics.Type_0_has_no_matching_index_signature_for_type_1, typeToString(objectType), typeToString(indexType)); diff --git a/tests/baselines/reference/bigintIndex.errors.txt b/tests/baselines/reference/bigintIndex.errors.txt index 13fccb1157485..98dab6631dcc7 100644 --- a/tests/baselines/reference/bigintIndex.errors.txt +++ b/tests/baselines/reference/bigintIndex.errors.txt @@ -1,5 +1,5 @@ a.ts(2,6): error TS1268: An index signature parameter type must be 'string', 'number', 'symbol', or a template literal type. -a.ts(8,11): error TS2538: Type '1n' cannot be used as an index type. +a.ts(8,11): error TS1537: A bigint literal may not be used as an index. a.ts(14,1): error TS2322: Type 'bigint' is not assignable to type 'string | number | symbol'. a.ts(19,12): error TS2538: Type 'bigint' cannot be used as an index type. b.ts(2,12): error TS1536: A bigint literal may not be used as a property name. @@ -21,7 +21,7 @@ c.ts(3,9): error TS1537: A bigint literal may not be used as an index. num = arr["1"]; num = arr[1n]; // should error ~~ -!!! error TS2538: Type '1n' cannot be used as an index type. +!!! error TS1537: A bigint literal may not be used as an index. let key: keyof any; // should be type "string | number | symbol" key = 123; diff --git a/tests/cases/compiler/bigintIndex.ts b/tests/cases/compiler/bigintIndex.ts index 9b41ef64881fc..e34e47124c2b2 100644 --- a/tests/cases/compiler/bigintIndex.ts +++ b/tests/cases/compiler/bigintIndex.ts @@ -9,6 +9,7 @@ const arr: number[] = [1, 2, 3]; let num: number = arr[1]; num = arr["1"]; num = arr[1n]; // should error +num = [1, 2, 3][1n]; // should error let key: keyof any; // should be type "string | number | symbol" key = 123; From 026f259b9ba862ca08eb506a065148cc05cb8798 Mon Sep 17 00:00:00 2001 From: Isabel Duan Date: Thu, 23 May 2024 16:52:41 -0700 Subject: [PATCH 05/15] update baselines again? --- .../reference/bigintIndex.errors.txt | 10 ++++-- tests/baselines/reference/bigintIndex.js | 2 ++ tests/baselines/reference/bigintIndex.symbols | 31 ++++++++++--------- tests/baselines/reference/bigintIndex.types | 18 +++++++++++ 4 files changed, 44 insertions(+), 17 deletions(-) diff --git a/tests/baselines/reference/bigintIndex.errors.txt b/tests/baselines/reference/bigintIndex.errors.txt index 98dab6631dcc7..c09c5bf225c18 100644 --- a/tests/baselines/reference/bigintIndex.errors.txt +++ b/tests/baselines/reference/bigintIndex.errors.txt @@ -1,7 +1,8 @@ a.ts(2,6): error TS1268: An index signature parameter type must be 'string', 'number', 'symbol', or a template literal type. a.ts(8,11): error TS1537: A bigint literal may not be used as an index. -a.ts(14,1): error TS2322: Type 'bigint' is not assignable to type 'string | number | symbol'. -a.ts(19,12): error TS2538: Type 'bigint' cannot be used as an index type. +a.ts(9,17): error TS1537: A bigint literal may not be used as an index. +a.ts(15,1): error TS2322: Type 'bigint' is not assignable to type 'string | number | symbol'. +a.ts(20,12): error TS2538: Type 'bigint' cannot be used as an index type. b.ts(2,12): error TS1536: A bigint literal may not be used as a property name. b.ts(3,12): error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'. b.ts(4,12): error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'. @@ -9,7 +10,7 @@ b.ts(5,5): error TS1536: A bigint literal may not be used as a property name. c.ts(3,9): error TS1537: A bigint literal may not be used as an index. -==== a.ts (4 errors) ==== +==== a.ts (5 errors) ==== interface BigIntIndex { [index: bigint]: E; // should error ~~~~~ @@ -22,6 +23,9 @@ c.ts(3,9): error TS1537: A bigint literal may not be used as an index. num = arr[1n]; // should error ~~ !!! error TS1537: A bigint literal may not be used as an index. + num = [1, 2, 3][1n]; // should error + ~~ +!!! error TS1537: A bigint literal may not be used as an index. let key: keyof any; // should be type "string | number | symbol" key = 123; diff --git a/tests/baselines/reference/bigintIndex.js b/tests/baselines/reference/bigintIndex.js index b8d9828ae5728..e2c2129619ac2 100644 --- a/tests/baselines/reference/bigintIndex.js +++ b/tests/baselines/reference/bigintIndex.js @@ -9,6 +9,7 @@ const arr: number[] = [1, 2, 3]; let num: number = arr[1]; num = arr["1"]; num = arr[1n]; // should error +num = [1, 2, 3][1n]; // should error let key: keyof any; // should be type "string | number | symbol" key = 123; @@ -45,6 +46,7 @@ const arr = [1, 2, 3]; let num = arr[1]; num = arr["1"]; num = arr[1n]; // should error +num = [1, 2, 3][1n]; // should error let key; // should be type "string | number | symbol" key = 123; key = "abc"; diff --git a/tests/baselines/reference/bigintIndex.symbols b/tests/baselines/reference/bigintIndex.symbols index c240122a3df2b..99eb6851f8372 100644 --- a/tests/baselines/reference/bigintIndex.symbols +++ b/tests/baselines/reference/bigintIndex.symbols @@ -25,44 +25,47 @@ num = arr[1n]; // should error >num : Symbol(num, Decl(a.ts, 5, 3)) >arr : Symbol(arr, Decl(a.ts, 4, 5)) +num = [1, 2, 3][1n]; // should error +>num : Symbol(num, Decl(a.ts, 5, 3)) + let key: keyof any; // should be type "string | number | symbol" ->key : Symbol(key, Decl(a.ts, 9, 3)) +>key : Symbol(key, Decl(a.ts, 10, 3)) key = 123; ->key : Symbol(key, Decl(a.ts, 9, 3)) +>key : Symbol(key, Decl(a.ts, 10, 3)) key = "abc"; ->key : Symbol(key, Decl(a.ts, 9, 3)) +>key : Symbol(key, Decl(a.ts, 10, 3)) key = Symbol(); ->key : Symbol(key, Decl(a.ts, 9, 3)) +>key : Symbol(key, Decl(a.ts, 10, 3)) >Symbol : Symbol(Symbol, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2019.symbol.d.ts, --, --)) key = 123n; // should error ->key : Symbol(key, Decl(a.ts, 9, 3)) +>key : Symbol(key, Decl(a.ts, 10, 3)) // Show correct usage of bigint index: explicitly convert to string const bigNum: bigint = 0n; ->bigNum : Symbol(bigNum, Decl(a.ts, 16, 5)) +>bigNum : Symbol(bigNum, Decl(a.ts, 17, 5)) const typedArray = new Uint8Array(3); ->typedArray : Symbol(typedArray, Decl(a.ts, 17, 5)) +>typedArray : Symbol(typedArray, Decl(a.ts, 18, 5)) >Uint8Array : Symbol(Uint8Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --) ... and 1 more) typedArray[bigNum] = 0xAA; // should error ->typedArray : Symbol(typedArray, Decl(a.ts, 17, 5)) ->bigNum : Symbol(bigNum, Decl(a.ts, 16, 5)) +>typedArray : Symbol(typedArray, Decl(a.ts, 18, 5)) +>bigNum : Symbol(bigNum, Decl(a.ts, 17, 5)) typedArray[String(bigNum)] = 0xAA; ->typedArray : Symbol(typedArray, Decl(a.ts, 17, 5)) +>typedArray : Symbol(typedArray, Decl(a.ts, 18, 5)) >String : Symbol(String, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --) ... and 4 more) ->bigNum : Symbol(bigNum, Decl(a.ts, 16, 5)) +>bigNum : Symbol(bigNum, Decl(a.ts, 17, 5)) typedArray["1"] = 0xBB; ->typedArray : Symbol(typedArray, Decl(a.ts, 17, 5)) +>typedArray : Symbol(typedArray, Decl(a.ts, 18, 5)) typedArray[2] = 0xCC; ->typedArray : Symbol(typedArray, Decl(a.ts, 17, 5)) +>typedArray : Symbol(typedArray, Decl(a.ts, 18, 5)) // {1n: 123} is a syntax error; must go in separate file so BigIntIndex error is shown === b.ts === @@ -78,7 +81,7 @@ const b = {[1n]: 456}; const c = {[bigNum]: 789}; >c : Symbol(c, Decl(b.ts, 3, 5)) >[bigNum] : Symbol([bigNum], Decl(b.ts, 3, 11)) ->bigNum : Symbol(bigNum, Decl(a.ts, 16, 5)) +>bigNum : Symbol(bigNum, Decl(a.ts, 17, 5)) { ({1n: 123}); }; >1n : Symbol(1n, Decl(b.ts, 4, 4)) diff --git a/tests/baselines/reference/bigintIndex.types b/tests/baselines/reference/bigintIndex.types index 2e7dc0d0ce3bb..71d0d2c2592dd 100644 --- a/tests/baselines/reference/bigintIndex.types +++ b/tests/baselines/reference/bigintIndex.types @@ -53,6 +53,24 @@ num = arr[1n]; // should error >1n : 1n > : ^^ +num = [1, 2, 3][1n]; // should error +>num = [1, 2, 3][1n] : any +> : ^^^ +>num : number +> : ^^^^^^ +>[1, 2, 3][1n] : any +> : ^^^ +>[1, 2, 3] : number[] +> : ^^^^^^^^ +>1 : 1 +> : ^ +>2 : 2 +> : ^ +>3 : 3 +> : ^ +>1n : 1n +> : ^^ + let key: keyof any; // should be type "string | number | symbol" >key : string | number | symbol > : ^^^^^^^^^^^^^^^^^^^^^^^^ From f2da07f9e36d57c3d723b0492cdc7454679352cd Mon Sep 17 00:00:00 2001 From: Isabel Duan Date: Fri, 24 May 2024 19:24:50 -0700 Subject: [PATCH 06/15] suggested changes --- src/compiler/checker.ts | 8 +++----- src/compiler/diagnosticMessages.json | 6 +----- .../reference/bigintIndex.errors.txt | 20 +++++++++---------- 3 files changed, 14 insertions(+), 20 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 28fa91eca21a7..fcb3b12f3f672 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -18365,17 +18365,15 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { } if (accessNode) { const indexNode = getIndexNodeForAccessExpression(accessNode); - if (indexNode.kind === SyntaxKind.BigIntLiteral) { - error(indexNode, Diagnostics.A_bigint_literal_may_not_be_used_as_an_index); - } - else if (indexType.flags & (TypeFlags.StringLiteral | TypeFlags.NumberLiteral)) { + if (indexNode.kind !== SyntaxKind.BigIntLiteral && indexType.flags & (TypeFlags.StringLiteral | TypeFlags.NumberLiteral)) { error(indexNode, Diagnostics.Property_0_does_not_exist_on_type_1, "" + (indexType as StringLiteralType | NumberLiteralType).value, typeToString(objectType)); } else if (indexType.flags & (TypeFlags.String | TypeFlags.Number)) { error(indexNode, Diagnostics.Type_0_has_no_matching_index_signature_for_type_1, typeToString(objectType), typeToString(indexType)); } else { - error(indexNode, Diagnostics.Type_0_cannot_be_used_as_an_index_type, typeToString(indexType)); + const typeString = indexNode.kind === SyntaxKind.BigIntLiteral ? `bigint literal`: typeToString(indexType); + error(indexNode, Diagnostics.Type_0_cannot_be_used_as_an_index_type, typeString); } } if (isTypeAny(indexType)) { diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 25cdeb3f7cfcd..de6584fc8da53 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1797,14 +1797,10 @@ "category": "Error", "code": 1535 }, - "A bigint literal may not be used as a property name.": { + "A `bigint` literal may not be used as a property name.": { "category": "Error", "code": 1536 }, - "A bigint literal may not be used as an index.": { - "category": "Error", - "code": 1537 - }, "The types of '{0}' are incompatible between these types.": { "category": "Error", diff --git a/tests/baselines/reference/bigintIndex.errors.txt b/tests/baselines/reference/bigintIndex.errors.txt index c09c5bf225c18..eab6aade3d37b 100644 --- a/tests/baselines/reference/bigintIndex.errors.txt +++ b/tests/baselines/reference/bigintIndex.errors.txt @@ -1,13 +1,13 @@ a.ts(2,6): error TS1268: An index signature parameter type must be 'string', 'number', 'symbol', or a template literal type. -a.ts(8,11): error TS1537: A bigint literal may not be used as an index. -a.ts(9,17): error TS1537: A bigint literal may not be used as an index. +a.ts(8,11): error TS2538: Type 'bigint literal' cannot be used as an index type. +a.ts(9,17): error TS2538: Type 'bigint literal' cannot be used as an index type. a.ts(15,1): error TS2322: Type 'bigint' is not assignable to type 'string | number | symbol'. a.ts(20,12): error TS2538: Type 'bigint' cannot be used as an index type. -b.ts(2,12): error TS1536: A bigint literal may not be used as a property name. +b.ts(2,12): error TS1536: A `bigint` literal may not be used as a property name. b.ts(3,12): error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'. b.ts(4,12): error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'. -b.ts(5,5): error TS1536: A bigint literal may not be used as a property name. -c.ts(3,9): error TS1537: A bigint literal may not be used as an index. +b.ts(5,5): error TS1536: A `bigint` literal may not be used as a property name. +c.ts(3,9): error TS2538: Type 'bigint literal' cannot be used as an index type. ==== a.ts (5 errors) ==== @@ -22,10 +22,10 @@ c.ts(3,9): error TS1537: A bigint literal may not be used as an index. num = arr["1"]; num = arr[1n]; // should error ~~ -!!! error TS1537: A bigint literal may not be used as an index. +!!! error TS2538: Type 'bigint literal' cannot be used as an index type. num = [1, 2, 3][1n]; // should error ~~ -!!! error TS1537: A bigint literal may not be used as an index. +!!! error TS2538: Type 'bigint literal' cannot be used as an index type. let key: keyof any; // should be type "string | number | symbol" key = 123; @@ -50,7 +50,7 @@ c.ts(3,9): error TS1537: A bigint literal may not be used as an index. // BigInt cannot be used as an object literal property const a = {1n: 123}; ~~ -!!! error TS1536: A bigint literal may not be used as a property name. +!!! error TS1536: A `bigint` literal may not be used as a property name. const b = {[1n]: 456}; ~~~~ !!! error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'. @@ -59,14 +59,14 @@ c.ts(3,9): error TS1537: A bigint literal may not be used as an index. !!! error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'. { ({1n: 123}); }; ~~ -!!! error TS1536: A bigint literal may not be used as a property name. +!!! error TS1536: A `bigint` literal may not be used as a property name. ==== c.ts (1 errors) ==== const crr = [1, 2, 3] as const; const { 0n: f } = crr; // bigint should give an index error ~~ -!!! error TS1537: A bigint literal may not be used as an index. +!!! error TS2538: Type 'bigint literal' cannot be used as an index type. const { 0: d } = crr; const { "0": e } = crr; \ No newline at end of file From 544d4a33de4400c6a197273b46b55b4e969ae78d Mon Sep 17 00:00:00 2001 From: Isabel Duan Date: Tue, 28 May 2024 10:50:26 -0700 Subject: [PATCH 07/15] fix errors --- src/compiler/checker.ts | 2 +- tests/baselines/reference/bigintIndex.errors.txt | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index fcb3b12f3f672..cd6c5a489318d 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -18372,7 +18372,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { error(indexNode, Diagnostics.Type_0_has_no_matching_index_signature_for_type_1, typeToString(objectType), typeToString(indexType)); } else { - const typeString = indexNode.kind === SyntaxKind.BigIntLiteral ? `bigint literal`: typeToString(indexType); + const typeString = typeToString(indexNode.kind === SyntaxKind.BigIntLiteral ? getBaseTypeOfLiteralType(getContextFreeTypeOfExpression(indexNode)) : indexType); error(indexNode, Diagnostics.Type_0_cannot_be_used_as_an_index_type, typeString); } } diff --git a/tests/baselines/reference/bigintIndex.errors.txt b/tests/baselines/reference/bigintIndex.errors.txt index eab6aade3d37b..22b3f8fb9e192 100644 --- a/tests/baselines/reference/bigintIndex.errors.txt +++ b/tests/baselines/reference/bigintIndex.errors.txt @@ -1,13 +1,13 @@ a.ts(2,6): error TS1268: An index signature parameter type must be 'string', 'number', 'symbol', or a template literal type. -a.ts(8,11): error TS2538: Type 'bigint literal' cannot be used as an index type. -a.ts(9,17): error TS2538: Type 'bigint literal' cannot be used as an index type. +a.ts(8,11): error TS2538: Type 'bigint' cannot be used as an index type. +a.ts(9,17): error TS2538: Type 'bigint' cannot be used as an index type. a.ts(15,1): error TS2322: Type 'bigint' is not assignable to type 'string | number | symbol'. a.ts(20,12): error TS2538: Type 'bigint' cannot be used as an index type. b.ts(2,12): error TS1536: A `bigint` literal may not be used as a property name. b.ts(3,12): error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'. b.ts(4,12): error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'. b.ts(5,5): error TS1536: A `bigint` literal may not be used as a property name. -c.ts(3,9): error TS2538: Type 'bigint literal' cannot be used as an index type. +c.ts(3,9): error TS2538: Type 'bigint' cannot be used as an index type. ==== a.ts (5 errors) ==== @@ -22,10 +22,10 @@ c.ts(3,9): error TS2538: Type 'bigint literal' cannot be used as an index type. num = arr["1"]; num = arr[1n]; // should error ~~ -!!! error TS2538: Type 'bigint literal' cannot be used as an index type. +!!! error TS2538: Type 'bigint' cannot be used as an index type. num = [1, 2, 3][1n]; // should error ~~ -!!! error TS2538: Type 'bigint literal' cannot be used as an index type. +!!! error TS2538: Type 'bigint' cannot be used as an index type. let key: keyof any; // should be type "string | number | symbol" key = 123; @@ -66,7 +66,7 @@ c.ts(3,9): error TS2538: Type 'bigint literal' cannot be used as an index type. const { 0n: f } = crr; // bigint should give an index error ~~ -!!! error TS2538: Type 'bigint literal' cannot be used as an index type. +!!! error TS2538: Type 'bigint' cannot be used as an index type. const { 0: d } = crr; const { "0": e } = crr; \ No newline at end of file From 42c91501f3e8deaf70e9ad02a562f03fc7fea57c Mon Sep 17 00:00:00 2001 From: Isabel Duan Date: Tue, 18 Jun 2024 13:54:51 -0700 Subject: [PATCH 08/15] merge/change error number --- src/compiler/diagnosticMessages.json | 2 +- tests/baselines/reference/bigintIndex.errors.txt | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index de6584fc8da53..c3d496730a09e 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1799,7 +1799,7 @@ }, "A `bigint` literal may not be used as a property name.": { "category": "Error", - "code": 1536 + "code": 1538 }, "The types of '{0}' are incompatible between these types.": { diff --git a/tests/baselines/reference/bigintIndex.errors.txt b/tests/baselines/reference/bigintIndex.errors.txt index 22b3f8fb9e192..10d3df41a1408 100644 --- a/tests/baselines/reference/bigintIndex.errors.txt +++ b/tests/baselines/reference/bigintIndex.errors.txt @@ -3,10 +3,10 @@ a.ts(8,11): error TS2538: Type 'bigint' cannot be used as an index type. a.ts(9,17): error TS2538: Type 'bigint' cannot be used as an index type. a.ts(15,1): error TS2322: Type 'bigint' is not assignable to type 'string | number | symbol'. a.ts(20,12): error TS2538: Type 'bigint' cannot be used as an index type. -b.ts(2,12): error TS1536: A `bigint` literal may not be used as a property name. +b.ts(2,12): error TS1538: A `bigint` literal may not be used as a property name. b.ts(3,12): error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'. b.ts(4,12): error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'. -b.ts(5,5): error TS1536: A `bigint` literal may not be used as a property name. +b.ts(5,5): error TS1538: A `bigint` literal may not be used as a property name. c.ts(3,9): error TS2538: Type 'bigint' cannot be used as an index type. @@ -50,7 +50,7 @@ c.ts(3,9): error TS2538: Type 'bigint' cannot be used as an index type. // BigInt cannot be used as an object literal property const a = {1n: 123}; ~~ -!!! error TS1536: A `bigint` literal may not be used as a property name. +!!! error TS1538: A `bigint` literal may not be used as a property name. const b = {[1n]: 456}; ~~~~ !!! error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'. @@ -59,7 +59,7 @@ c.ts(3,9): error TS2538: Type 'bigint' cannot be used as an index type. !!! error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'. { ({1n: 123}); }; ~~ -!!! error TS1536: A `bigint` literal may not be used as a property name. +!!! error TS1538: A `bigint` literal may not be used as a property name. ==== c.ts (1 errors) ==== const crr = [1, 2, 3] as const; From 49b13695f8892e355aa08a2ceb2ae1b2e0376d24 Mon Sep 17 00:00:00 2001 From: Isabel Duan Date: Thu, 11 Jul 2024 17:24:57 -0700 Subject: [PATCH 09/15] add tests --- .../bigintArbirtraryIdentifier.errors.txt | 69 +++++++++++++++++++ .../reference/bigintArbirtraryIdentifier.js | 44 ++++++++++++ .../bigintArbirtraryIdentifier.symbols | 34 +++++++++ .../bigintArbirtraryIdentifier.types | 64 +++++++++++++++++ .../reference/bigintIndex.errors.txt | 16 +---- tests/baselines/reference/bigintIndex.js | 17 ----- tests/baselines/reference/bigintIndex.symbols | 20 ------ tests/baselines/reference/bigintIndex.types | 43 ------------ .../reference/bigintPropertyName.errors.txt | 16 +++++ .../baselines/reference/bigintPropertyName.js | 20 ++++++ .../reference/bigintPropertyName.symbols | 22 ++++++ .../reference/bigintPropertyName.types | 45 ++++++++++++ .../compiler/bigintArbirtraryIdentifier.ts | 22 ++++++ tests/cases/compiler/bigintIndex.ts | 8 --- tests/cases/compiler/bigintPropertyName.ts | 8 +++ 15 files changed, 345 insertions(+), 103 deletions(-) create mode 100644 tests/baselines/reference/bigintArbirtraryIdentifier.errors.txt create mode 100644 tests/baselines/reference/bigintArbirtraryIdentifier.js create mode 100644 tests/baselines/reference/bigintArbirtraryIdentifier.symbols create mode 100644 tests/baselines/reference/bigintArbirtraryIdentifier.types create mode 100644 tests/baselines/reference/bigintPropertyName.errors.txt create mode 100644 tests/baselines/reference/bigintPropertyName.js create mode 100644 tests/baselines/reference/bigintPropertyName.symbols create mode 100644 tests/baselines/reference/bigintPropertyName.types create mode 100644 tests/cases/compiler/bigintArbirtraryIdentifier.ts create mode 100644 tests/cases/compiler/bigintPropertyName.ts diff --git a/tests/baselines/reference/bigintArbirtraryIdentifier.errors.txt b/tests/baselines/reference/bigintArbirtraryIdentifier.errors.txt new file mode 100644 index 0000000000000..5a959d4e04b62 --- /dev/null +++ b/tests/baselines/reference/bigintArbirtraryIdentifier.errors.txt @@ -0,0 +1,69 @@ +badExport.ts(1,10): error TS2304: Cannot find name 'foo'. +badExport.ts(1,17): error TS1003: Identifier expected. +badExport.ts(1,20): error TS1128: Declaration or statement expected. +badExport2.ts(1,10): error TS1003: Identifier expected. +badExport2.ts(1,16): error TS2304: Cannot find name 'foo'. +badExport2.ts(1,20): error TS1128: Declaration or statement expected. +badImport.ts(1,10): error TS1003: Identifier expected. +badImport.ts(1,10): error TS1141: String literal expected. +badImport.ts(1,20): error TS1128: Declaration or statement expected. +badImport.ts(1,22): error TS1434: Unexpected keyword or identifier. +badImport.ts(1,22): error TS2304: Cannot find name 'from'. +badImport2.ts(1,17): error TS1003: Identifier expected. +badImport2.ts(1,17): error TS1141: String literal expected. +badImport2.ts(1,20): error TS1128: Declaration or statement expected. +badImport2.ts(1,22): error TS1434: Unexpected keyword or identifier. +badImport2.ts(1,22): error TS2304: Cannot find name 'from'. + + +==== foo.ts (0 errors) ==== + const foo = 0n; + export { foo as "0n" }; + +==== correctUse.ts (0 errors) ==== + import { "0n" as foo } from "./foo"; + export { foo as "0n" }; + +==== badImport.ts (5 errors) ==== + import { 0n as foo } from "./foo"; + ~~ +!!! error TS1003: Identifier expected. + ~~~~~~~~~ +!!! error TS1141: String literal expected. + ~ +!!! error TS1128: Declaration or statement expected. + ~~~~ +!!! error TS1434: Unexpected keyword or identifier. + ~~~~ +!!! error TS2304: Cannot find name 'from'. + +==== badImport2.ts (5 errors) ==== + import { foo as 0n } from "./foo"; + ~~ +!!! error TS1003: Identifier expected. + ~~ +!!! error TS1141: String literal expected. + ~ +!!! error TS1128: Declaration or statement expected. + ~~~~ +!!! error TS1434: Unexpected keyword or identifier. + ~~~~ +!!! error TS2304: Cannot find name 'from'. + +==== badExport.ts (3 errors) ==== + export { foo as 0n }; + ~~~ +!!! error TS2304: Cannot find name 'foo'. + ~~ +!!! error TS1003: Identifier expected. + ~ +!!! error TS1128: Declaration or statement expected. + +==== badExport2.ts (3 errors) ==== + export { 0n as foo }; + ~~ +!!! error TS1003: Identifier expected. + ~~~ +!!! error TS2304: Cannot find name 'foo'. + ~ +!!! error TS1128: Declaration or statement expected. \ No newline at end of file diff --git a/tests/baselines/reference/bigintArbirtraryIdentifier.js b/tests/baselines/reference/bigintArbirtraryIdentifier.js new file mode 100644 index 0000000000000..139c1991c8c3f --- /dev/null +++ b/tests/baselines/reference/bigintArbirtraryIdentifier.js @@ -0,0 +1,44 @@ +//// [tests/cases/compiler/bigintArbirtraryIdentifier.ts] //// + +//// [foo.ts] +const foo = 0n; +export { foo as "0n" }; + +//// [correctUse.ts] +import { "0n" as foo } from "./foo"; +export { foo as "0n" }; + +//// [badImport.ts] +import { 0n as foo } from "./foo"; + +//// [badImport2.ts] +import { foo as 0n } from "./foo"; + +//// [badExport.ts] +export { foo as 0n }; + +//// [badExport2.ts] +export { 0n as foo }; + +//// [foo.js] +const foo = 0n; +export { foo as "0n" }; +//// [correctUse.js] +import { "0n" as foo } from "./foo"; +export { foo as "0n" }; +//// [badImport.js] +from; +"./foo"; +export {}; +//// [badImport2.js] +from; +"./foo"; +export {}; +//// [badExport.js] +export { foo as }; +0n; +; +//// [badExport2.js] +0n; +; +export {}; diff --git a/tests/baselines/reference/bigintArbirtraryIdentifier.symbols b/tests/baselines/reference/bigintArbirtraryIdentifier.symbols new file mode 100644 index 0000000000000..8ef83a9eaec97 --- /dev/null +++ b/tests/baselines/reference/bigintArbirtraryIdentifier.symbols @@ -0,0 +1,34 @@ +//// [tests/cases/compiler/bigintArbirtraryIdentifier.ts] //// + +=== foo.ts === +const foo = 0n; +>foo : Symbol(foo, Decl(foo.ts, 0, 5)) + +export { foo as "0n" }; +>foo : Symbol(foo, Decl(foo.ts, 0, 5)) +>"0n" : Symbol("0n", Decl(foo.ts, 1, 8)) + +=== correctUse.ts === +import { "0n" as foo } from "./foo"; +>foo : Symbol(foo, Decl(correctUse.ts, 0, 8)) + +export { foo as "0n" }; +>foo : Symbol(foo, Decl(correctUse.ts, 0, 8)) +>"0n" : Symbol("0n", Decl(correctUse.ts, 1, 8)) + +=== badImport.ts === +import { 0n as foo } from "./foo"; +>foo : Symbol(foo) + +=== badImport2.ts === +import { foo as 0n } from "./foo"; +> : Symbol((Missing), Decl(badImport2.ts, 0, 8)) + +=== badExport.ts === +export { foo as 0n }; +> : Symbol((Missing), Decl(badExport.ts, 0, 8)) + +=== badExport2.ts === +export { 0n as foo }; +>foo : Symbol(foo) + diff --git a/tests/baselines/reference/bigintArbirtraryIdentifier.types b/tests/baselines/reference/bigintArbirtraryIdentifier.types new file mode 100644 index 0000000000000..722fb9a9f0644 --- /dev/null +++ b/tests/baselines/reference/bigintArbirtraryIdentifier.types @@ -0,0 +1,64 @@ +//// [tests/cases/compiler/bigintArbirtraryIdentifier.ts] //// + +=== foo.ts === +const foo = 0n; +>foo : 0n +> : ^^ +>0n : 0n +> : ^^ + +export { foo as "0n" }; +>foo : 0n +> : ^^ +>"0n" : 0n +> : ^^ + +=== correctUse.ts === +import { "0n" as foo } from "./foo"; +>foo : 0n +> : ^^ + +export { foo as "0n" }; +>foo : 0n +> : ^^ +>"0n" : 0n +> : ^^ + +=== badImport.ts === +import { 0n as foo } from "./foo"; +>0n as foo : foo +> : ^^^ +>0n : 0n +> : ^^ +>from : any +> : ^^^ +>"./foo" : "./foo" +> : ^^^^^^^ + +=== badImport2.ts === +import { foo as 0n } from "./foo"; +>foo : any +> : ^^^ +> : any +> : ^^^ +>from : any +> : ^^^ +>"./foo" : "./foo" +> : ^^^^^^^ + +=== badExport.ts === +export { foo as 0n }; +>foo : any +> : ^^^ +> : any +> : ^^^ +>0n : 0n +> : ^^ + +=== badExport2.ts === +export { 0n as foo }; +>0n as foo : foo +> : ^^^ +>0n : 0n +> : ^^ + diff --git a/tests/baselines/reference/bigintIndex.errors.txt b/tests/baselines/reference/bigintIndex.errors.txt index 10d3df41a1408..bb5c897798540 100644 --- a/tests/baselines/reference/bigintIndex.errors.txt +++ b/tests/baselines/reference/bigintIndex.errors.txt @@ -6,8 +6,6 @@ a.ts(20,12): error TS2538: Type 'bigint' cannot be used as an index type. b.ts(2,12): error TS1538: A `bigint` literal may not be used as a property name. b.ts(3,12): error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'. b.ts(4,12): error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'. -b.ts(5,5): error TS1538: A `bigint` literal may not be used as a property name. -c.ts(3,9): error TS2538: Type 'bigint' cannot be used as an index type. ==== a.ts (5 errors) ==== @@ -46,7 +44,7 @@ c.ts(3,9): error TS2538: Type 'bigint' cannot be used as an index type. typedArray[2] = 0xCC; // {1n: 123} is a syntax error; must go in separate file so BigIntIndex error is shown -==== b.ts (4 errors) ==== +==== b.ts (3 errors) ==== // BigInt cannot be used as an object literal property const a = {1n: 123}; ~~ @@ -57,16 +55,4 @@ c.ts(3,9): error TS2538: Type 'bigint' cannot be used as an index type. const c = {[bigNum]: 789}; ~~~~~~~~ !!! error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'. - { ({1n: 123}); }; - ~~ -!!! error TS1538: A `bigint` literal may not be used as a property name. - -==== c.ts (1 errors) ==== - const crr = [1, 2, 3] as const; - - const { 0n: f } = crr; // bigint should give an index error - ~~ -!!! error TS2538: Type 'bigint' cannot be used as an index type. - const { 0: d } = crr; - const { "0": e } = crr; \ No newline at end of file diff --git a/tests/baselines/reference/bigintIndex.js b/tests/baselines/reference/bigintIndex.js index e2c2129619ac2..429f6402d1cbc 100644 --- a/tests/baselines/reference/bigintIndex.js +++ b/tests/baselines/reference/bigintIndex.js @@ -31,14 +31,6 @@ typedArray[2] = 0xCC; const a = {1n: 123}; const b = {[1n]: 456}; const c = {[bigNum]: 789}; -{ ({1n: 123}); }; - -//// [c.ts] -const crr = [1, 2, 3] as const; - -const { 0n: f } = crr; // bigint should give an index error -const { 0: d } = crr; -const { "0": e } = crr; //// [a.js] @@ -65,12 +57,3 @@ typedArray[2] = 0xCC; const a = { 1n: 123 }; const b = { [1n]: 456 }; const c = { [bigNum]: 789 }; -{ - ({ 1n: 123 }); -} -; -//// [c.js] -const crr = [1, 2, 3]; -const { 0n: f } = crr; // bigint should give an index error -const { 0: d } = crr; -const { "0": e } = crr; diff --git a/tests/baselines/reference/bigintIndex.symbols b/tests/baselines/reference/bigintIndex.symbols index 99eb6851f8372..3f3779d3edbd3 100644 --- a/tests/baselines/reference/bigintIndex.symbols +++ b/tests/baselines/reference/bigintIndex.symbols @@ -83,23 +83,3 @@ const c = {[bigNum]: 789}; >[bigNum] : Symbol([bigNum], Decl(b.ts, 3, 11)) >bigNum : Symbol(bigNum, Decl(a.ts, 17, 5)) -{ ({1n: 123}); }; ->1n : Symbol(1n, Decl(b.ts, 4, 4)) - -=== c.ts === -const crr = [1, 2, 3] as const; ->crr : Symbol(crr, Decl(c.ts, 0, 5)) ->const : Symbol(const) - -const { 0n: f } = crr; // bigint should give an index error ->f : Symbol(f, Decl(c.ts, 2, 7)) ->crr : Symbol(crr, Decl(c.ts, 0, 5)) - -const { 0: d } = crr; ->d : Symbol(d, Decl(c.ts, 3, 7)) ->crr : Symbol(crr, Decl(c.ts, 0, 5)) - -const { "0": e } = crr; ->e : Symbol(e, Decl(c.ts, 4, 7)) ->crr : Symbol(crr, Decl(c.ts, 0, 5)) - diff --git a/tests/baselines/reference/bigintIndex.types b/tests/baselines/reference/bigintIndex.types index 71d0d2c2592dd..c12295c10e1de 100644 --- a/tests/baselines/reference/bigintIndex.types +++ b/tests/baselines/reference/bigintIndex.types @@ -215,46 +215,3 @@ const c = {[bigNum]: 789}; >789 : 789 > : ^^^ -{ ({1n: 123}); }; ->({1n: 123}) : {} -> : ^^ ->{1n: 123} : {} -> : ^^ ->1n : number -> : ^^^^^^ ->123 : 123 -> : ^^^ - -=== c.ts === -const crr = [1, 2, 3] as const; ->crr : readonly [1, 2, 3] -> : ^^^^^^^^^^^^^^^^^^ ->[1, 2, 3] as const : readonly [1, 2, 3] -> : ^^^^^^^^^^^^^^^^^^ ->[1, 2, 3] : readonly [1, 2, 3] -> : ^^^^^^^^^^^^^^^^^^ ->1 : 1 -> : ^ ->2 : 2 -> : ^ ->3 : 3 -> : ^ - -const { 0n: f } = crr; // bigint should give an index error ->f : any -> : ^^^ ->crr : readonly [1, 2, 3] -> : ^^^^^^^^^^^^^^^^^^ - -const { 0: d } = crr; ->d : 1 -> : ^ ->crr : readonly [1, 2, 3] -> : ^^^^^^^^^^^^^^^^^^ - -const { "0": e } = crr; ->e : 1 -> : ^ ->crr : readonly [1, 2, 3] -> : ^^^^^^^^^^^^^^^^^^ - diff --git a/tests/baselines/reference/bigintPropertyName.errors.txt b/tests/baselines/reference/bigintPropertyName.errors.txt new file mode 100644 index 0000000000000..b425ff79de8ee --- /dev/null +++ b/tests/baselines/reference/bigintPropertyName.errors.txt @@ -0,0 +1,16 @@ +bigintPropertyName.ts(1,5): error TS1538: A `bigint` literal may not be used as a property name. +bigintPropertyName.ts(4,9): error TS2538: Type 'bigint' cannot be used as an index type. + + +==== bigintPropertyName.ts (2 errors) ==== + { ({1n: 123}); }; + ~~ +!!! error TS1538: A `bigint` literal may not be used as a property name. + const arr = [1, 2, 3] as const; + + const { 0n: f } = arr; // bigint should give an index error + ~~ +!!! error TS2538: Type 'bigint' cannot be used as an index type. + const { 0: d } = arr; + const { "0": e } = arr; + \ No newline at end of file diff --git a/tests/baselines/reference/bigintPropertyName.js b/tests/baselines/reference/bigintPropertyName.js new file mode 100644 index 0000000000000..fef9bdd66d11c --- /dev/null +++ b/tests/baselines/reference/bigintPropertyName.js @@ -0,0 +1,20 @@ +//// [tests/cases/compiler/bigintPropertyName.ts] //// + +//// [bigintPropertyName.ts] +{ ({1n: 123}); }; +const arr = [1, 2, 3] as const; + +const { 0n: f } = arr; // bigint should give an index error +const { 0: d } = arr; +const { "0": e } = arr; + + +//// [bigintPropertyName.js] +{ + ({ 1n: 123 }); +} +; +const arr = [1, 2, 3]; +const { 0n: f } = arr; // bigint should give an index error +const { 0: d } = arr; +const { "0": e } = arr; diff --git a/tests/baselines/reference/bigintPropertyName.symbols b/tests/baselines/reference/bigintPropertyName.symbols new file mode 100644 index 0000000000000..716a9a84a4cec --- /dev/null +++ b/tests/baselines/reference/bigintPropertyName.symbols @@ -0,0 +1,22 @@ +//// [tests/cases/compiler/bigintPropertyName.ts] //// + +=== bigintPropertyName.ts === +{ ({1n: 123}); }; +>1n : Symbol(1n, Decl(bigintPropertyName.ts, 0, 4)) + +const arr = [1, 2, 3] as const; +>arr : Symbol(arr, Decl(bigintPropertyName.ts, 1, 5)) +>const : Symbol(const) + +const { 0n: f } = arr; // bigint should give an index error +>f : Symbol(f, Decl(bigintPropertyName.ts, 3, 7)) +>arr : Symbol(arr, Decl(bigintPropertyName.ts, 1, 5)) + +const { 0: d } = arr; +>d : Symbol(d, Decl(bigintPropertyName.ts, 4, 7)) +>arr : Symbol(arr, Decl(bigintPropertyName.ts, 1, 5)) + +const { "0": e } = arr; +>e : Symbol(e, Decl(bigintPropertyName.ts, 5, 7)) +>arr : Symbol(arr, Decl(bigintPropertyName.ts, 1, 5)) + diff --git a/tests/baselines/reference/bigintPropertyName.types b/tests/baselines/reference/bigintPropertyName.types new file mode 100644 index 0000000000000..b7557bb21fbf3 --- /dev/null +++ b/tests/baselines/reference/bigintPropertyName.types @@ -0,0 +1,45 @@ +//// [tests/cases/compiler/bigintPropertyName.ts] //// + +=== bigintPropertyName.ts === +{ ({1n: 123}); }; +>({1n: 123}) : {} +> : ^^ +>{1n: 123} : {} +> : ^^ +>1n : number +> : ^^^^^^ +>123 : 123 +> : ^^^ + +const arr = [1, 2, 3] as const; +>arr : readonly [1, 2, 3] +> : ^^^^^^^^^^^^^^^^^^ +>[1, 2, 3] as const : readonly [1, 2, 3] +> : ^^^^^^^^^^^^^^^^^^ +>[1, 2, 3] : readonly [1, 2, 3] +> : ^^^^^^^^^^^^^^^^^^ +>1 : 1 +> : ^ +>2 : 2 +> : ^ +>3 : 3 +> : ^ + +const { 0n: f } = arr; // bigint should give an index error +>f : any +> : ^^^ +>arr : readonly [1, 2, 3] +> : ^^^^^^^^^^^^^^^^^^ + +const { 0: d } = arr; +>d : 1 +> : ^ +>arr : readonly [1, 2, 3] +> : ^^^^^^^^^^^^^^^^^^ + +const { "0": e } = arr; +>e : 1 +> : ^ +>arr : readonly [1, 2, 3] +> : ^^^^^^^^^^^^^^^^^^ + diff --git a/tests/cases/compiler/bigintArbirtraryIdentifier.ts b/tests/cases/compiler/bigintArbirtraryIdentifier.ts new file mode 100644 index 0000000000000..9b281534212e8 --- /dev/null +++ b/tests/cases/compiler/bigintArbirtraryIdentifier.ts @@ -0,0 +1,22 @@ +// @target: esnext +// @module: esnext + +// @filename: foo.ts +const foo = 0n; +export { foo as "0n" }; + +// @filename: correctUse.ts +import { "0n" as foo } from "./foo"; +export { foo as "0n" }; + +// @filename: badImport.ts +import { 0n as foo } from "./foo"; + +// @filename: badImport2.ts +import { foo as 0n } from "./foo"; + +// @filename: badExport.ts +export { foo as 0n }; + +// @filename: badExport2.ts +export { 0n as foo }; \ No newline at end of file diff --git a/tests/cases/compiler/bigintIndex.ts b/tests/cases/compiler/bigintIndex.ts index e34e47124c2b2..7c24b77f55e16 100644 --- a/tests/cases/compiler/bigintIndex.ts +++ b/tests/cases/compiler/bigintIndex.ts @@ -31,11 +31,3 @@ typedArray[2] = 0xCC; const a = {1n: 123}; const b = {[1n]: 456}; const c = {[bigNum]: 789}; -{ ({1n: 123}); }; - -// @filename: c.ts -const crr = [1, 2, 3] as const; - -const { 0n: f } = crr; // bigint should give an index error -const { 0: d } = crr; -const { "0": e } = crr; diff --git a/tests/cases/compiler/bigintPropertyName.ts b/tests/cases/compiler/bigintPropertyName.ts new file mode 100644 index 0000000000000..2158e7d8eeaae --- /dev/null +++ b/tests/cases/compiler/bigintPropertyName.ts @@ -0,0 +1,8 @@ +// @target: esnext + +{ ({1n: 123}); }; +const arr = [1, 2, 3] as const; + +const { 0n: f } = arr; // bigint should give an index error +const { 0: d } = arr; +const { "0": e } = arr; From 2b1bafa1b6255f9e7e4865212b91e158f013bc2a Mon Sep 17 00:00:00 2001 From: Isabel Duan Date: Fri, 12 Jul 2024 13:17:40 -0700 Subject: [PATCH 10/15] add even more tests + fix crashes --- src/compiler/checker.ts | 4 + src/compiler/parser.ts | 1 + .../reference/bigintIndex.errors.txt | 16 -- tests/baselines/reference/bigintIndex.js | 13 - tests/baselines/reference/bigintIndex.symbols | 16 -- tests/baselines/reference/bigintIndex.types | 37 --- .../reference/bigintPropertyName.errors.txt | 139 +++++++++- .../baselines/reference/bigintPropertyName.js | 93 ++++++- .../reference/bigintPropertyName.symbols | 147 +++++++++- .../reference/bigintPropertyName.types | 258 +++++++++++++++++- tests/cases/compiler/bigintIndex.ts | 7 - tests/cases/compiler/bigintPropertyName.ts | 55 +++- 12 files changed, 666 insertions(+), 120 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 0f3b0f5fd26e6..a9eb91ff4445e 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -43773,6 +43773,10 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { return; } + if (node.name.kind === SyntaxKind.BigIntLiteral) { + error(node.name, Diagnostics.A_bigint_literal_may_not_be_used_as_a_property_name); + } + const type = convertAutoToAny(getTypeOfSymbol(symbol)); if (node === symbol.valueDeclaration) { // Node is the primary declaration of the symbol, just validate the initializer diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index dec8cb3c54b17..cc77808ec9b2e 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -8058,6 +8058,7 @@ namespace Parser { tokenIsIdentifierOrKeyword(token()) || token() === SyntaxKind.StringLiteral || token() === SyntaxKind.NumericLiteral || + token() === SyntaxKind.BigIntLiteral || token() === SyntaxKind.AsteriskToken || token() === SyntaxKind.OpenBracketToken ) { diff --git a/tests/baselines/reference/bigintIndex.errors.txt b/tests/baselines/reference/bigintIndex.errors.txt index bb5c897798540..9d74c569211d7 100644 --- a/tests/baselines/reference/bigintIndex.errors.txt +++ b/tests/baselines/reference/bigintIndex.errors.txt @@ -3,9 +3,6 @@ a.ts(8,11): error TS2538: Type 'bigint' cannot be used as an index type. a.ts(9,17): error TS2538: Type 'bigint' cannot be used as an index type. a.ts(15,1): error TS2322: Type 'bigint' is not assignable to type 'string | number | symbol'. a.ts(20,12): error TS2538: Type 'bigint' cannot be used as an index type. -b.ts(2,12): error TS1538: A `bigint` literal may not be used as a property name. -b.ts(3,12): error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'. -b.ts(4,12): error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'. ==== a.ts (5 errors) ==== @@ -42,17 +39,4 @@ b.ts(4,12): error TS2464: A computed property name must be of type 'string', 'nu typedArray[String(bigNum)] = 0xAA; typedArray["1"] = 0xBB; typedArray[2] = 0xCC; - - // {1n: 123} is a syntax error; must go in separate file so BigIntIndex error is shown -==== b.ts (3 errors) ==== - // BigInt cannot be used as an object literal property - const a = {1n: 123}; - ~~ -!!! error TS1538: A `bigint` literal may not be used as a property name. - const b = {[1n]: 456}; - ~~~~ -!!! error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'. - const c = {[bigNum]: 789}; - ~~~~~~~~ -!!! 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/bigintIndex.js b/tests/baselines/reference/bigintIndex.js index 429f6402d1cbc..0ee392380df41 100644 --- a/tests/baselines/reference/bigintIndex.js +++ b/tests/baselines/reference/bigintIndex.js @@ -24,13 +24,6 @@ typedArray[bigNum] = 0xAA; // should error typedArray[String(bigNum)] = 0xAA; typedArray["1"] = 0xBB; typedArray[2] = 0xCC; - -// {1n: 123} is a syntax error; must go in separate file so BigIntIndex error is shown -//// [b.ts] -// BigInt cannot be used as an object literal property -const a = {1n: 123}; -const b = {[1n]: 456}; -const c = {[bigNum]: 789}; //// [a.js] @@ -51,9 +44,3 @@ typedArray[bigNum] = 0xAA; // should error typedArray[String(bigNum)] = 0xAA; typedArray["1"] = 0xBB; typedArray[2] = 0xCC; -// {1n: 123} is a syntax error; must go in separate file so BigIntIndex error is shown -//// [b.js] -// BigInt cannot be used as an object literal property -const a = { 1n: 123 }; -const b = { [1n]: 456 }; -const c = { [bigNum]: 789 }; diff --git a/tests/baselines/reference/bigintIndex.symbols b/tests/baselines/reference/bigintIndex.symbols index 3f3779d3edbd3..a16ac17f82f25 100644 --- a/tests/baselines/reference/bigintIndex.symbols +++ b/tests/baselines/reference/bigintIndex.symbols @@ -67,19 +67,3 @@ typedArray["1"] = 0xBB; typedArray[2] = 0xCC; >typedArray : Symbol(typedArray, Decl(a.ts, 18, 5)) -// {1n: 123} is a syntax error; must go in separate file so BigIntIndex error is shown -=== b.ts === -// BigInt cannot be used as an object literal property -const a = {1n: 123}; ->a : Symbol(a, Decl(b.ts, 1, 5)) ->1n : Symbol(1n, Decl(b.ts, 1, 11)) - -const b = {[1n]: 456}; ->b : Symbol(b, Decl(b.ts, 2, 5)) ->[1n] : Symbol([1n], Decl(b.ts, 2, 11)) - -const c = {[bigNum]: 789}; ->c : Symbol(c, Decl(b.ts, 3, 5)) ->[bigNum] : Symbol([bigNum], Decl(b.ts, 3, 11)) ->bigNum : Symbol(bigNum, Decl(a.ts, 17, 5)) - diff --git a/tests/baselines/reference/bigintIndex.types b/tests/baselines/reference/bigintIndex.types index c12295c10e1de..028ab79a0f77e 100644 --- a/tests/baselines/reference/bigintIndex.types +++ b/tests/baselines/reference/bigintIndex.types @@ -178,40 +178,3 @@ typedArray[2] = 0xCC; >0xCC : 204 > : ^^^ -// {1n: 123} is a syntax error; must go in separate file so BigIntIndex error is shown -=== b.ts === -// BigInt cannot be used as an object literal property -const a = {1n: 123}; ->a : {} -> : ^^ ->{1n: 123} : {} -> : ^^ ->1n : number -> : ^^^^^^ ->123 : 123 -> : ^^^ - -const b = {[1n]: 456}; ->b : {} -> : ^^ ->{[1n]: 456} : {} -> : ^^ ->[1n] : number -> : ^^^^^^ ->1n : 1n -> : ^^ ->456 : 456 -> : ^^^ - -const c = {[bigNum]: 789}; ->c : {} -> : ^^ ->{[bigNum]: 789} : {} -> : ^^ ->[bigNum] : number -> : ^^^^^^ ->bigNum : bigint -> : ^^^^^^ ->789 : 789 -> : ^^^ - diff --git a/tests/baselines/reference/bigintPropertyName.errors.txt b/tests/baselines/reference/bigintPropertyName.errors.txt index b425ff79de8ee..79d2175d6d64f 100644 --- a/tests/baselines/reference/bigintPropertyName.errors.txt +++ b/tests/baselines/reference/bigintPropertyName.errors.txt @@ -1,16 +1,143 @@ -bigintPropertyName.ts(1,5): error TS1538: A `bigint` literal may not be used as a property name. -bigintPropertyName.ts(4,9): error TS2538: Type 'bigint' cannot be used as an index type. +a.ts(2,5): error TS1538: A `bigint` literal may not be used as a property name. +a.ts(5,13): error TS1538: A `bigint` literal may not be used as a property name. +a.ts(6,13): error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'. +a.ts(7,13): error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'. +a.ts(12,9): error TS2538: Type 'bigint' cannot be used as an index type. +a.ts(15,13): error TS1538: A `bigint` literal may not be used as a property name. +g.ts(2,5): error TS1538: A `bigint` literal may not be used as a property name. +g.ts(8,5): error TS1538: A `bigint` literal may not be used as a property name. +g.ts(15,17): error TS1538: A `bigint` literal may not be used as a property name. +g.ts(17,3): error TS2538: Type 'bigint' cannot be used as an index type. +g.ts(18,4): error TS2538: Type 'bigint' cannot be used as an index type. +g.ts(20,7): error TS2741: Property '"3n"' is missing in type '{}' but required in type 'H'. +g.ts(20,17): error TS1538: A `bigint` literal may not be used as a property name. +g.ts(22,3): error TS2538: Type 'bigint' cannot be used as an index type. +g.ts(23,4): error TS2538: Type 'bigint' cannot be used as an index type. +g.ts(25,17): error TS1538: A `bigint` literal may not be used as a property name. +g.ts(27,3): error TS2538: Type 'bigint' cannot be used as an index type. +g.ts(28,4): error TS2538: Type 'bigint' cannot be used as an index type. +g.ts(30,7): error TS2741: Property '"5n"' is missing in type '{}' but required in type 'L'. +g.ts(30,17): error TS1538: A `bigint` literal may not be used as a property name. +g.ts(31,18): error TS2322: Type 'string' is not assignable to type 'number'. +g.ts(32,3): error TS2538: Type 'bigint' cannot be used as an index type. +g.ts(33,4): error TS2538: Type 'bigint' cannot be used as an index type. +g.ts(35,1): error TS1434: Unexpected keyword or identifier. +g.ts(35,2): error TS1353: A bigint literal must be an integer. +q.ts(2,19): error TS2322: Type 'bigint' is not assignable to type 'string | number | symbol'. + Type 'bigint' is not assignable to type 'string | number | symbol'. -==== bigintPropertyName.ts (2 errors) ==== +==== a.ts (6 errors) ==== + // BigInt cannot be used as an object literal property { ({1n: 123}); }; ~~ !!! error TS1538: A `bigint` literal may not be used as a property name. - const arr = [1, 2, 3] as const; + const bigNum: bigint = 0n; + const a = { 1n: 123 }; + ~~ +!!! error TS1538: A `bigint` literal may not be used as a property name. + const b = { [1n]: 456 }; + ~~~~ +!!! error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'. + const c = { [bigNum]: 789 }; + ~~~~~~~~ +!!! error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'. + + const arr = [1, 2, 3] as const; + const { 0: d } = arr; + const { "0": e } = arr; const { 0n: f } = arr; // bigint should give an index error ~~ !!! error TS2538: Type 'bigint' cannot be used as an index type. - const { 0: d } = arr; - const { "0": e } = arr; + + // BigInt cannot be used as an property name + const x = { 0n: 123 }; + ~~ +!!! error TS1538: A `bigint` literal may not be used as a property name. + +==== g.ts (19 errors) ==== + interface G { + 2n: string; + ~~ +!!! error TS1538: A `bigint` literal may not be used as a property name. + } + interface H { + "3n": string; + } + class K { + 4n = 0; + ~~ +!!! error TS1538: A `bigint` literal may not be used as a property name. + } + + class L { + "5n" = 0; + } + + const g : G = { 2n: "hello" }; + ~~ +!!! error TS1538: A `bigint` literal may not be used as a property name. + const g2 : G = { "2n": "hello2" }; + g[2n]; + ~~ +!!! error TS2538: Type 'bigint' cannot be used as an index type. + g2[2n]; + ~~ +!!! error TS2538: Type 'bigint' cannot be used as an index type. + + const h : H = { 3n: "hello2" }; + ~ +!!! error TS2741: Property '"3n"' is missing in type '{}' but required in type 'H'. +!!! related TS2728 g.ts:5:5: '"3n"' is declared here. + ~~ +!!! error TS1538: A `bigint` literal may not be used as a property name. + const h2 : H = { "3n": "hello2" }; + h[3n]; + ~~ +!!! error TS2538: Type 'bigint' cannot be used as an index type. + h2[3n]; + ~~ +!!! error TS2538: Type 'bigint' cannot be used as an index type. + + const k : K = { 4n: "hello" }; + ~~ +!!! error TS1538: A `bigint` literal may not be used as a property name. + const k2 : K = { "4n": "hello2" }; + k[4n]; + ~~ +!!! error TS2538: Type 'bigint' cannot be used as an index type. + k2[4n]; + ~~ +!!! error TS2538: Type 'bigint' cannot be used as an index type. + + const l : L = { 5n: "hello2" }; + ~ +!!! error TS2741: Property '"5n"' is missing in type '{}' but required in type 'L'. +!!! related TS2728 g.ts:12:5: '"5n"' is declared here. + ~~ +!!! error TS1538: A `bigint` literal may not be used as a property name. + const l2 : L = { "5n": "hello2" }; + ~~~~ +!!! error TS2322: Type 'string' is not assignable to type 'number'. +!!! related TS6500 g.ts:12:5: The expected type comes from property '5n' which is declared here on type 'L' + l[5n]; + ~~ +!!! error TS2538: Type 'bigint' cannot be used as an index type. + l2[5n]; + ~~ +!!! error TS2538: Type 'bigint' cannot be used as an index type. + + g.2n; // not valid JS + ~ +!!! error TS1434: Unexpected keyword or identifier. + ~~~ +!!! error TS1353: A bigint literal must be an integer. + +==== q.ts (1 errors) ==== + type Q = 6n | 7n | 8n; + type T = { [t in Q]: string }; + ~ +!!! error TS2322: Type 'bigint' is not assignable to type 'string | number | symbol'. +!!! error TS2322: Type 'bigint' is not assignable to type 'string | number | symbol'. \ No newline at end of file diff --git a/tests/baselines/reference/bigintPropertyName.js b/tests/baselines/reference/bigintPropertyName.js index fef9bdd66d11c..4280802b784a0 100644 --- a/tests/baselines/reference/bigintPropertyName.js +++ b/tests/baselines/reference/bigintPropertyName.js @@ -1,20 +1,103 @@ //// [tests/cases/compiler/bigintPropertyName.ts] //// -//// [bigintPropertyName.ts] +//// [a.ts] +// BigInt cannot be used as an object literal property { ({1n: 123}); }; -const arr = [1, 2, 3] as const; -const { 0n: f } = arr; // bigint should give an index error +const bigNum: bigint = 0n; +const a = { 1n: 123 }; +const b = { [1n]: 456 }; +const c = { [bigNum]: 789 }; + +const arr = [1, 2, 3] as const; const { 0: d } = arr; const { "0": e } = arr; +const { 0n: f } = arr; // bigint should give an index error + +// BigInt cannot be used as an property name +const x = { 0n: 123 }; + +//// [g.ts] +interface G { + 2n: string; +} +interface H { + "3n": string; +} +class K { + 4n = 0; +} + +class L { + "5n" = 0; +} + +const g : G = { 2n: "hello" }; +const g2 : G = { "2n": "hello2" }; +g[2n]; +g2[2n]; + +const h : H = { 3n: "hello2" }; +const h2 : H = { "3n": "hello2" }; +h[3n]; +h2[3n]; + +const k : K = { 4n: "hello" }; +const k2 : K = { "4n": "hello2" }; +k[4n]; +k2[4n]; + +const l : L = { 5n: "hello2" }; +const l2 : L = { "5n": "hello2" }; +l[5n]; +l2[5n]; + +g.2n; // not valid JS + +//// [q.ts] +type Q = 6n | 7n | 8n; +type T = { [t in Q]: string }; -//// [bigintPropertyName.js] +//// [a.js] +// BigInt cannot be used as an object literal property { ({ 1n: 123 }); } ; +const bigNum = 0n; +const a = { 1n: 123 }; +const b = { [1n]: 456 }; +const c = { [bigNum]: 789 }; const arr = [1, 2, 3]; -const { 0n: f } = arr; // bigint should give an index error const { 0: d } = arr; const { "0": e } = arr; +const { 0n: f } = arr; // bigint should give an index error +// BigInt cannot be used as an property name +const x = { 0n: 123 }; +//// [g.js] +class K { + 4n = 0; +} +class L { + "5n" = 0; +} +const g = { 2n: "hello" }; +const g2 = { "2n": "hello2" }; +g[2n]; +g2[2n]; +const h = { 3n: "hello2" }; +const h2 = { "3n": "hello2" }; +h[3n]; +h2[3n]; +const k = { 4n: "hello" }; +const k2 = { "4n": "hello2" }; +k[4n]; +k2[4n]; +const l = { 5n: "hello2" }; +const l2 = { "5n": "hello2" }; +l[5n]; +l2[5n]; +g; +.2n; // not valid JS +//// [q.js] diff --git a/tests/baselines/reference/bigintPropertyName.symbols b/tests/baselines/reference/bigintPropertyName.symbols index 716a9a84a4cec..e3622dffa9c34 100644 --- a/tests/baselines/reference/bigintPropertyName.symbols +++ b/tests/baselines/reference/bigintPropertyName.symbols @@ -1,22 +1,147 @@ //// [tests/cases/compiler/bigintPropertyName.ts] //// -=== bigintPropertyName.ts === +=== a.ts === +// BigInt cannot be used as an object literal property { ({1n: 123}); }; ->1n : Symbol(1n, Decl(bigintPropertyName.ts, 0, 4)) +>1n : Symbol(1n, Decl(a.ts, 1, 4)) + +const bigNum: bigint = 0n; +>bigNum : Symbol(bigNum, Decl(a.ts, 3, 5)) + +const a = { 1n: 123 }; +>a : Symbol(a, Decl(a.ts, 4, 5)) +>1n : Symbol(1n, Decl(a.ts, 4, 11)) + +const b = { [1n]: 456 }; +>b : Symbol(b, Decl(a.ts, 5, 5)) +>[1n] : Symbol([1n], Decl(a.ts, 5, 11)) + +const c = { [bigNum]: 789 }; +>c : Symbol(c, Decl(a.ts, 6, 5)) +>[bigNum] : Symbol([bigNum], Decl(a.ts, 6, 11)) +>bigNum : Symbol(bigNum, Decl(a.ts, 3, 5)) const arr = [1, 2, 3] as const; ->arr : Symbol(arr, Decl(bigintPropertyName.ts, 1, 5)) +>arr : Symbol(arr, Decl(a.ts, 8, 5)) >const : Symbol(const) -const { 0n: f } = arr; // bigint should give an index error ->f : Symbol(f, Decl(bigintPropertyName.ts, 3, 7)) ->arr : Symbol(arr, Decl(bigintPropertyName.ts, 1, 5)) - const { 0: d } = arr; ->d : Symbol(d, Decl(bigintPropertyName.ts, 4, 7)) ->arr : Symbol(arr, Decl(bigintPropertyName.ts, 1, 5)) +>d : Symbol(d, Decl(a.ts, 9, 7)) +>arr : Symbol(arr, Decl(a.ts, 8, 5)) const { "0": e } = arr; ->e : Symbol(e, Decl(bigintPropertyName.ts, 5, 7)) ->arr : Symbol(arr, Decl(bigintPropertyName.ts, 1, 5)) +>e : Symbol(e, Decl(a.ts, 10, 7)) +>arr : Symbol(arr, Decl(a.ts, 8, 5)) + +const { 0n: f } = arr; // bigint should give an index error +>f : Symbol(f, Decl(a.ts, 11, 7)) +>arr : Symbol(arr, Decl(a.ts, 8, 5)) + +// BigInt cannot be used as an property name +const x = { 0n: 123 }; +>x : Symbol(x, Decl(a.ts, 14, 5)) +>0n : Symbol(0n, Decl(a.ts, 14, 11)) + +=== g.ts === +interface G { +>G : Symbol(G, Decl(g.ts, 0, 0)) + + 2n: string; +>2n : Symbol(G[2n], Decl(g.ts, 0, 13)) +} +interface H { +>H : Symbol(H, Decl(g.ts, 2, 1)) + + "3n": string; +>"3n" : Symbol(H["3n"], Decl(g.ts, 3, 13)) +} +class K { +>K : Symbol(K, Decl(g.ts, 5, 1)) + + 4n = 0; +>4n : Symbol(K[4n], Decl(g.ts, 6, 9)) +} + +class L { +>L : Symbol(L, Decl(g.ts, 8, 1)) + + "5n" = 0; +>"5n" : Symbol(L["5n"], Decl(g.ts, 10, 9)) +} + +const g : G = { 2n: "hello" }; +>g : Symbol(g, Decl(g.ts, 14, 5)) +>G : Symbol(G, Decl(g.ts, 0, 0)) +>2n : Symbol(2n, Decl(g.ts, 14, 15)) + +const g2 : G = { "2n": "hello2" }; +>g2 : Symbol(g2, Decl(g.ts, 15, 5)) +>G : Symbol(G, Decl(g.ts, 0, 0)) +>"2n" : Symbol("2n", Decl(g.ts, 15, 16)) + +g[2n]; +>g : Symbol(g, Decl(g.ts, 14, 5)) + +g2[2n]; +>g2 : Symbol(g2, Decl(g.ts, 15, 5)) + +const h : H = { 3n: "hello2" }; +>h : Symbol(h, Decl(g.ts, 19, 5)) +>H : Symbol(H, Decl(g.ts, 2, 1)) +>3n : Symbol(3n, Decl(g.ts, 19, 15)) + +const h2 : H = { "3n": "hello2" }; +>h2 : Symbol(h2, Decl(g.ts, 20, 5)) +>H : Symbol(H, Decl(g.ts, 2, 1)) +>"3n" : Symbol("3n", Decl(g.ts, 20, 16)) + +h[3n]; +>h : Symbol(h, Decl(g.ts, 19, 5)) + +h2[3n]; +>h2 : Symbol(h2, Decl(g.ts, 20, 5)) + +const k : K = { 4n: "hello" }; +>k : Symbol(k, Decl(g.ts, 24, 5)) +>K : Symbol(K, Decl(g.ts, 5, 1)) +>4n : Symbol(4n, Decl(g.ts, 24, 15)) + +const k2 : K = { "4n": "hello2" }; +>k2 : Symbol(k2, Decl(g.ts, 25, 5)) +>K : Symbol(K, Decl(g.ts, 5, 1)) +>"4n" : Symbol("4n", Decl(g.ts, 25, 16)) + +k[4n]; +>k : Symbol(k, Decl(g.ts, 24, 5)) + +k2[4n]; +>k2 : Symbol(k2, Decl(g.ts, 25, 5)) + +const l : L = { 5n: "hello2" }; +>l : Symbol(l, Decl(g.ts, 29, 5)) +>L : Symbol(L, Decl(g.ts, 8, 1)) +>5n : Symbol(5n, Decl(g.ts, 29, 15)) + +const l2 : L = { "5n": "hello2" }; +>l2 : Symbol(l2, Decl(g.ts, 30, 5)) +>L : Symbol(L, Decl(g.ts, 8, 1)) +>"5n" : Symbol("5n", Decl(g.ts, 30, 16)) + +l[5n]; +>l : Symbol(l, Decl(g.ts, 29, 5)) + +l2[5n]; +>l2 : Symbol(l2, Decl(g.ts, 30, 5)) + +g.2n; // not valid JS +>g : Symbol(g, Decl(g.ts, 14, 5)) + +=== q.ts === +type Q = 6n | 7n | 8n; +>Q : Symbol(Q, Decl(q.ts, 0, 0)) + +type T = { [t in Q]: string }; +>T : Symbol(T, Decl(q.ts, 0, 22)) +>t : Symbol(t, Decl(q.ts, 1, 12)) +>Q : Symbol(Q, Decl(q.ts, 0, 0)) diff --git a/tests/baselines/reference/bigintPropertyName.types b/tests/baselines/reference/bigintPropertyName.types index b7557bb21fbf3..e1c421f542584 100644 --- a/tests/baselines/reference/bigintPropertyName.types +++ b/tests/baselines/reference/bigintPropertyName.types @@ -1,6 +1,7 @@ //// [tests/cases/compiler/bigintPropertyName.ts] //// -=== bigintPropertyName.ts === +=== a.ts === +// BigInt cannot be used as an object literal property { ({1n: 123}); }; >({1n: 123}) : {} > : ^^ @@ -11,6 +12,46 @@ >123 : 123 > : ^^^ +const bigNum: bigint = 0n; +>bigNum : bigint +> : ^^^^^^ +>0n : 0n +> : ^^ + +const a = { 1n: 123 }; +>a : {} +> : ^^ +>{ 1n: 123 } : {} +> : ^^ +>1n : number +> : ^^^^^^ +>123 : 123 +> : ^^^ + +const b = { [1n]: 456 }; +>b : {} +> : ^^ +>{ [1n]: 456 } : {} +> : ^^ +>[1n] : number +> : ^^^^^^ +>1n : 1n +> : ^^ +>456 : 456 +> : ^^^ + +const c = { [bigNum]: 789 }; +>c : {} +> : ^^ +>{ [bigNum]: 789 } : {} +> : ^^ +>[bigNum] : number +> : ^^^^^^ +>bigNum : bigint +> : ^^^^^^ +>789 : 789 +> : ^^^ + const arr = [1, 2, 3] as const; >arr : readonly [1, 2, 3] > : ^^^^^^^^^^^^^^^^^^ @@ -25,12 +66,6 @@ const arr = [1, 2, 3] as const; >3 : 3 > : ^ -const { 0n: f } = arr; // bigint should give an index error ->f : any -> : ^^^ ->arr : readonly [1, 2, 3] -> : ^^^^^^^^^^^^^^^^^^ - const { 0: d } = arr; >d : 1 > : ^ @@ -43,3 +78,212 @@ const { "0": e } = arr; >arr : readonly [1, 2, 3] > : ^^^^^^^^^^^^^^^^^^ +const { 0n: f } = arr; // bigint should give an index error +>f : any +> : ^^^ +>arr : readonly [1, 2, 3] +> : ^^^^^^^^^^^^^^^^^^ + +// BigInt cannot be used as an property name +const x = { 0n: 123 }; +>x : {} +> : ^^ +>{ 0n: 123 } : {} +> : ^^ +>0n : number +> : ^^^^^^ +>123 : 123 +> : ^^^ + +=== g.ts === +interface G { + 2n: string; +>2n : string +> : ^^^^^^ +} +interface H { + "3n": string; +>"3n" : string +> : ^^^^^^ +} +class K { +>K : K +> : ^ + + 4n = 0; +>4n : number +> : ^^^^^^ +>0 : 0 +> : ^ +} + +class L { +>L : L +> : ^ + + "5n" = 0; +>"5n" : number +> : ^^^^^^ +>0 : 0 +> : ^ +} + +const g : G = { 2n: "hello" }; +>g : G +> : ^ +>{ 2n: "hello" } : {} +> : ^^ +>2n : string +> : ^^^^^^ +>"hello" : "hello" +> : ^^^^^^^ + +const g2 : G = { "2n": "hello2" }; +>g2 : G +> : ^ +>{ "2n": "hello2" } : { "2n": string; } +> : ^^^^^^^^^^^^^^^^^ +>"2n" : string +> : ^^^^^^ +>"hello2" : "hello2" +> : ^^^^^^^^ + +g[2n]; +>g[2n] : any +> : ^^^ +>g : G +> : ^ +>2n : 2n +> : ^^ + +g2[2n]; +>g2[2n] : any +> : ^^^ +>g2 : G +> : ^ +>2n : 2n +> : ^^ + +const h : H = { 3n: "hello2" }; +>h : H +> : ^ +>{ 3n: "hello2" } : {} +> : ^^ +>3n : string +> : ^^^^^^ +>"hello2" : "hello2" +> : ^^^^^^^^ + +const h2 : H = { "3n": "hello2" }; +>h2 : H +> : ^ +>{ "3n": "hello2" } : { "3n": string; } +> : ^^^^^^^^^^^^^^^^^ +>"3n" : string +> : ^^^^^^ +>"hello2" : "hello2" +> : ^^^^^^^^ + +h[3n]; +>h[3n] : any +> : ^^^ +>h : H +> : ^ +>3n : 3n +> : ^^ + +h2[3n]; +>h2[3n] : any +> : ^^^ +>h2 : H +> : ^ +>3n : 3n +> : ^^ + +const k : K = { 4n: "hello" }; +>k : K +> : ^ +>{ 4n: "hello" } : {} +> : ^^ +>4n : string +> : ^^^^^^ +>"hello" : "hello" +> : ^^^^^^^ + +const k2 : K = { "4n": "hello2" }; +>k2 : K +> : ^ +>{ "4n": "hello2" } : { "4n": string; } +> : ^^^^^^^^^^^^^^^^^ +>"4n" : string +> : ^^^^^^ +>"hello2" : "hello2" +> : ^^^^^^^^ + +k[4n]; +>k[4n] : any +> : ^^^ +>k : K +> : ^ +>4n : 4n +> : ^^ + +k2[4n]; +>k2[4n] : any +> : ^^^ +>k2 : K +> : ^ +>4n : 4n +> : ^^ + +const l : L = { 5n: "hello2" }; +>l : L +> : ^ +>{ 5n: "hello2" } : {} +> : ^^ +>5n : string +> : ^^^^^^ +>"hello2" : "hello2" +> : ^^^^^^^^ + +const l2 : L = { "5n": "hello2" }; +>l2 : L +> : ^ +>{ "5n": "hello2" } : { "5n": string; } +> : ^^^^^^^^^^^^^^^^^ +>"5n" : string +> : ^^^^^^ +>"hello2" : "hello2" +> : ^^^^^^^^ + +l[5n]; +>l[5n] : any +> : ^^^ +>l : L +> : ^ +>5n : 5n +> : ^^ + +l2[5n]; +>l2[5n] : any +> : ^^^ +>l2 : L +> : ^ +>5n : 5n +> : ^^ + +g.2n; // not valid JS +>g : G +> : ^ +>.2n : 0.2 +> : ^^^ + +=== q.ts === +type Q = 6n | 7n | 8n; +>Q : Q +> : ^ + +type T = { [t in Q]: string }; +>T : T +> : ^ + diff --git a/tests/cases/compiler/bigintIndex.ts b/tests/cases/compiler/bigintIndex.ts index 7c24b77f55e16..cb70721f464a3 100644 --- a/tests/cases/compiler/bigintIndex.ts +++ b/tests/cases/compiler/bigintIndex.ts @@ -24,10 +24,3 @@ typedArray[bigNum] = 0xAA; // should error typedArray[String(bigNum)] = 0xAA; typedArray["1"] = 0xBB; typedArray[2] = 0xCC; - -// {1n: 123} is a syntax error; must go in separate file so BigIntIndex error is shown -// @filename: b.ts -// BigInt cannot be used as an object literal property -const a = {1n: 123}; -const b = {[1n]: 456}; -const c = {[bigNum]: 789}; diff --git a/tests/cases/compiler/bigintPropertyName.ts b/tests/cases/compiler/bigintPropertyName.ts index 2158e7d8eeaae..b1927b885cde0 100644 --- a/tests/cases/compiler/bigintPropertyName.ts +++ b/tests/cases/compiler/bigintPropertyName.ts @@ -1,8 +1,59 @@ // @target: esnext +// @fileName: a.ts +// BigInt cannot be used as an object literal property { ({1n: 123}); }; -const arr = [1, 2, 3] as const; -const { 0n: f } = arr; // bigint should give an index error +const bigNum: bigint = 0n; +const a = { 1n: 123 }; +const b = { [1n]: 456 }; +const c = { [bigNum]: 789 }; + +const arr = [1, 2, 3] as const; const { 0: d } = arr; const { "0": e } = arr; +const { 0n: f } = arr; // bigint should give an index error + +// BigInt cannot be used as an property name +const x = { 0n: 123 }; + +// @filename: g.ts +interface G { + 2n: string; +} +interface H { + "3n": string; +} +class K { + 4n = 0; +} + +class L { + "5n" = 0; +} + +const g : G = { 2n: "hello" }; +const g2 : G = { "2n": "hello2" }; +g[2n]; +g2[2n]; + +const h : H = { 3n: "hello2" }; +const h2 : H = { "3n": "hello2" }; +h[3n]; +h2[3n]; + +const k : K = { 4n: "hello" }; +const k2 : K = { "4n": "hello2" }; +k[4n]; +k2[4n]; + +const l : L = { 5n: "hello2" }; +const l2 : L = { "5n": "hello2" }; +l[5n]; +l2[5n]; + +g.2n; // not valid JS + +// @filename: q.ts +type Q = 6n | 7n | 8n; +type T = { [t in Q]: string }; From bcd60232b16e47acd8a2b523ea291954ffe8d749 Mon Sep 17 00:00:00 2001 From: Isabel Duan Date: Fri, 12 Jul 2024 13:25:55 -0700 Subject: [PATCH 11/15] fix tests --- .../reference/bigintPropertyName.errors.txt | 16 ++-- .../baselines/reference/bigintPropertyName.js | 32 ++++---- .../reference/bigintPropertyName.symbols | 16 ++-- .../reference/bigintPropertyName.types | 80 +++++++++---------- tests/cases/compiler/bigintPropertyName.ts | 16 ++-- 5 files changed, 80 insertions(+), 80 deletions(-) diff --git a/tests/baselines/reference/bigintPropertyName.errors.txt b/tests/baselines/reference/bigintPropertyName.errors.txt index 79d2175d6d64f..7a52f0325dc00 100644 --- a/tests/baselines/reference/bigintPropertyName.errors.txt +++ b/tests/baselines/reference/bigintPropertyName.errors.txt @@ -75,10 +75,10 @@ q.ts(2,19): error TS2322: Type 'bigint' is not assignable to type 'string | numb "5n" = 0; } - const g : G = { 2n: "hello" }; + const g : G = { 2n: "propertyNameError2" }; ~~ !!! error TS1538: A `bigint` literal may not be used as a property name. - const g2 : G = { "2n": "hello2" }; + const g2 : G = { "2n": "ok2" }; g[2n]; ~~ !!! error TS2538: Type 'bigint' cannot be used as an index type. @@ -86,13 +86,13 @@ q.ts(2,19): error TS2322: Type 'bigint' is not assignable to type 'string | numb ~~ !!! error TS2538: Type 'bigint' cannot be used as an index type. - const h : H = { 3n: "hello2" }; + const h : H = { 3n: "propertyNameErrorAndMissingProperty3" }; ~ !!! error TS2741: Property '"3n"' is missing in type '{}' but required in type 'H'. !!! related TS2728 g.ts:5:5: '"3n"' is declared here. ~~ !!! error TS1538: A `bigint` literal may not be used as a property name. - const h2 : H = { "3n": "hello2" }; + const h2 : H = { "3n": "ok3" }; h[3n]; ~~ !!! error TS2538: Type 'bigint' cannot be used as an index type. @@ -100,10 +100,10 @@ q.ts(2,19): error TS2322: Type 'bigint' is not assignable to type 'string | numb ~~ !!! error TS2538: Type 'bigint' cannot be used as an index type. - const k : K = { 4n: "hello" }; + const k : K = { 4n: "propertyNameError4" }; ~~ !!! error TS1538: A `bigint` literal may not be used as a property name. - const k2 : K = { "4n": "hello2" }; + const k2 : K = { "4n": "ok4" }; k[4n]; ~~ !!! error TS2538: Type 'bigint' cannot be used as an index type. @@ -111,13 +111,13 @@ q.ts(2,19): error TS2322: Type 'bigint' is not assignable to type 'string | numb ~~ !!! error TS2538: Type 'bigint' cannot be used as an index type. - const l : L = { 5n: "hello2" }; + const l : L = { 5n: "propertyNameErrorAndMissingProperty5" }; ~ !!! error TS2741: Property '"5n"' is missing in type '{}' but required in type 'L'. !!! related TS2728 g.ts:12:5: '"5n"' is declared here. ~~ !!! error TS1538: A `bigint` literal may not be used as a property name. - const l2 : L = { "5n": "hello2" }; + const l2 : L = { "5n": "ok4" }; ~~~~ !!! error TS2322: Type 'string' is not assignable to type 'number'. !!! related TS6500 g.ts:12:5: The expected type comes from property '5n' which is declared here on type 'L' diff --git a/tests/baselines/reference/bigintPropertyName.js b/tests/baselines/reference/bigintPropertyName.js index 4280802b784a0..baf37339f1b7d 100644 --- a/tests/baselines/reference/bigintPropertyName.js +++ b/tests/baselines/reference/bigintPropertyName.js @@ -32,23 +32,23 @@ class L { "5n" = 0; } -const g : G = { 2n: "hello" }; -const g2 : G = { "2n": "hello2" }; +const g : G = { 2n: "propertyNameError2" }; +const g2 : G = { "2n": "ok2" }; g[2n]; g2[2n]; -const h : H = { 3n: "hello2" }; -const h2 : H = { "3n": "hello2" }; +const h : H = { 3n: "propertyNameErrorAndMissingProperty3" }; +const h2 : H = { "3n": "ok3" }; h[3n]; h2[3n]; -const k : K = { 4n: "hello" }; -const k2 : K = { "4n": "hello2" }; +const k : K = { 4n: "propertyNameError4" }; +const k2 : K = { "4n": "ok4" }; k[4n]; k2[4n]; -const l : L = { 5n: "hello2" }; -const l2 : L = { "5n": "hello2" }; +const l : L = { 5n: "propertyNameErrorAndMissingProperty5" }; +const l2 : L = { "5n": "ok4" }; l[5n]; l2[5n]; @@ -82,20 +82,20 @@ class K { class L { "5n" = 0; } -const g = { 2n: "hello" }; -const g2 = { "2n": "hello2" }; +const g = { 2n: "propertyNameError2" }; +const g2 = { "2n": "ok2" }; g[2n]; g2[2n]; -const h = { 3n: "hello2" }; -const h2 = { "3n": "hello2" }; +const h = { 3n: "propertyNameErrorAndMissingProperty3" }; +const h2 = { "3n": "ok3" }; h[3n]; h2[3n]; -const k = { 4n: "hello" }; -const k2 = { "4n": "hello2" }; +const k = { 4n: "propertyNameError4" }; +const k2 = { "4n": "ok4" }; k[4n]; k2[4n]; -const l = { 5n: "hello2" }; -const l2 = { "5n": "hello2" }; +const l = { 5n: "propertyNameErrorAndMissingProperty5" }; +const l2 = { "5n": "ok4" }; l[5n]; l2[5n]; g; diff --git a/tests/baselines/reference/bigintPropertyName.symbols b/tests/baselines/reference/bigintPropertyName.symbols index e3622dffa9c34..0eafa57074f70 100644 --- a/tests/baselines/reference/bigintPropertyName.symbols +++ b/tests/baselines/reference/bigintPropertyName.symbols @@ -69,12 +69,12 @@ class L { >"5n" : Symbol(L["5n"], Decl(g.ts, 10, 9)) } -const g : G = { 2n: "hello" }; +const g : G = { 2n: "propertyNameError2" }; >g : Symbol(g, Decl(g.ts, 14, 5)) >G : Symbol(G, Decl(g.ts, 0, 0)) >2n : Symbol(2n, Decl(g.ts, 14, 15)) -const g2 : G = { "2n": "hello2" }; +const g2 : G = { "2n": "ok2" }; >g2 : Symbol(g2, Decl(g.ts, 15, 5)) >G : Symbol(G, Decl(g.ts, 0, 0)) >"2n" : Symbol("2n", Decl(g.ts, 15, 16)) @@ -85,12 +85,12 @@ g[2n]; g2[2n]; >g2 : Symbol(g2, Decl(g.ts, 15, 5)) -const h : H = { 3n: "hello2" }; +const h : H = { 3n: "propertyNameErrorAndMissingProperty3" }; >h : Symbol(h, Decl(g.ts, 19, 5)) >H : Symbol(H, Decl(g.ts, 2, 1)) >3n : Symbol(3n, Decl(g.ts, 19, 15)) -const h2 : H = { "3n": "hello2" }; +const h2 : H = { "3n": "ok3" }; >h2 : Symbol(h2, Decl(g.ts, 20, 5)) >H : Symbol(H, Decl(g.ts, 2, 1)) >"3n" : Symbol("3n", Decl(g.ts, 20, 16)) @@ -101,12 +101,12 @@ h[3n]; h2[3n]; >h2 : Symbol(h2, Decl(g.ts, 20, 5)) -const k : K = { 4n: "hello" }; +const k : K = { 4n: "propertyNameError4" }; >k : Symbol(k, Decl(g.ts, 24, 5)) >K : Symbol(K, Decl(g.ts, 5, 1)) >4n : Symbol(4n, Decl(g.ts, 24, 15)) -const k2 : K = { "4n": "hello2" }; +const k2 : K = { "4n": "ok4" }; >k2 : Symbol(k2, Decl(g.ts, 25, 5)) >K : Symbol(K, Decl(g.ts, 5, 1)) >"4n" : Symbol("4n", Decl(g.ts, 25, 16)) @@ -117,12 +117,12 @@ k[4n]; k2[4n]; >k2 : Symbol(k2, Decl(g.ts, 25, 5)) -const l : L = { 5n: "hello2" }; +const l : L = { 5n: "propertyNameErrorAndMissingProperty5" }; >l : Symbol(l, Decl(g.ts, 29, 5)) >L : Symbol(L, Decl(g.ts, 8, 1)) >5n : Symbol(5n, Decl(g.ts, 29, 15)) -const l2 : L = { "5n": "hello2" }; +const l2 : L = { "5n": "ok4" }; >l2 : Symbol(l2, Decl(g.ts, 30, 5)) >L : Symbol(L, Decl(g.ts, 8, 1)) >"5n" : Symbol("5n", Decl(g.ts, 30, 16)) diff --git a/tests/baselines/reference/bigintPropertyName.types b/tests/baselines/reference/bigintPropertyName.types index e1c421f542584..71d982757a5de 100644 --- a/tests/baselines/reference/bigintPropertyName.types +++ b/tests/baselines/reference/bigintPropertyName.types @@ -128,25 +128,25 @@ class L { > : ^ } -const g : G = { 2n: "hello" }; +const g : G = { 2n: "propertyNameError2" }; >g : G > : ^ ->{ 2n: "hello" } : {} -> : ^^ +>{ 2n: "propertyNameError2" } : {} +> : ^^ >2n : string > : ^^^^^^ ->"hello" : "hello" -> : ^^^^^^^ +>"propertyNameError2" : "propertyNameError2" +> : ^^^^^^^^^^^^^^^^^^^^ -const g2 : G = { "2n": "hello2" }; +const g2 : G = { "2n": "ok2" }; >g2 : G > : ^ ->{ "2n": "hello2" } : { "2n": string; } -> : ^^^^^^^^^^^^^^^^^ +>{ "2n": "ok2" } : { "2n": string; } +> : ^^^^^^^^^^^^^^^^^ >"2n" : string > : ^^^^^^ ->"hello2" : "hello2" -> : ^^^^^^^^ +>"ok2" : "ok2" +> : ^^^^^ g[2n]; >g[2n] : any @@ -164,25 +164,25 @@ g2[2n]; >2n : 2n > : ^^ -const h : H = { 3n: "hello2" }; +const h : H = { 3n: "propertyNameErrorAndMissingProperty3" }; >h : H > : ^ ->{ 3n: "hello2" } : {} -> : ^^ +>{ 3n: "propertyNameErrorAndMissingProperty3" } : {} +> : ^^ >3n : string > : ^^^^^^ ->"hello2" : "hello2" -> : ^^^^^^^^ +>"propertyNameErrorAndMissingProperty3" : "propertyNameErrorAndMissingProperty3" +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -const h2 : H = { "3n": "hello2" }; +const h2 : H = { "3n": "ok3" }; >h2 : H > : ^ ->{ "3n": "hello2" } : { "3n": string; } -> : ^^^^^^^^^^^^^^^^^ +>{ "3n": "ok3" } : { "3n": string; } +> : ^^^^^^^^^^^^^^^^^ >"3n" : string > : ^^^^^^ ->"hello2" : "hello2" -> : ^^^^^^^^ +>"ok3" : "ok3" +> : ^^^^^ h[3n]; >h[3n] : any @@ -200,25 +200,25 @@ h2[3n]; >3n : 3n > : ^^ -const k : K = { 4n: "hello" }; +const k : K = { 4n: "propertyNameError4" }; >k : K > : ^ ->{ 4n: "hello" } : {} -> : ^^ +>{ 4n: "propertyNameError4" } : {} +> : ^^ >4n : string > : ^^^^^^ ->"hello" : "hello" -> : ^^^^^^^ +>"propertyNameError4" : "propertyNameError4" +> : ^^^^^^^^^^^^^^^^^^^^ -const k2 : K = { "4n": "hello2" }; +const k2 : K = { "4n": "ok4" }; >k2 : K > : ^ ->{ "4n": "hello2" } : { "4n": string; } -> : ^^^^^^^^^^^^^^^^^ +>{ "4n": "ok4" } : { "4n": string; } +> : ^^^^^^^^^^^^^^^^^ >"4n" : string > : ^^^^^^ ->"hello2" : "hello2" -> : ^^^^^^^^ +>"ok4" : "ok4" +> : ^^^^^ k[4n]; >k[4n] : any @@ -236,25 +236,25 @@ k2[4n]; >4n : 4n > : ^^ -const l : L = { 5n: "hello2" }; +const l : L = { 5n: "propertyNameErrorAndMissingProperty5" }; >l : L > : ^ ->{ 5n: "hello2" } : {} -> : ^^ +>{ 5n: "propertyNameErrorAndMissingProperty5" } : {} +> : ^^ >5n : string > : ^^^^^^ ->"hello2" : "hello2" -> : ^^^^^^^^ +>"propertyNameErrorAndMissingProperty5" : "propertyNameErrorAndMissingProperty5" +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -const l2 : L = { "5n": "hello2" }; +const l2 : L = { "5n": "ok4" }; >l2 : L > : ^ ->{ "5n": "hello2" } : { "5n": string; } -> : ^^^^^^^^^^^^^^^^^ +>{ "5n": "ok4" } : { "5n": string; } +> : ^^^^^^^^^^^^^^^^^ >"5n" : string > : ^^^^^^ ->"hello2" : "hello2" -> : ^^^^^^^^ +>"ok4" : "ok4" +> : ^^^^^ l[5n]; >l[5n] : any diff --git a/tests/cases/compiler/bigintPropertyName.ts b/tests/cases/compiler/bigintPropertyName.ts index b1927b885cde0..911ba086564a4 100644 --- a/tests/cases/compiler/bigintPropertyName.ts +++ b/tests/cases/compiler/bigintPropertyName.ts @@ -32,23 +32,23 @@ class L { "5n" = 0; } -const g : G = { 2n: "hello" }; -const g2 : G = { "2n": "hello2" }; +const g : G = { 2n: "propertyNameError2" }; +const g2 : G = { "2n": "ok2" }; g[2n]; g2[2n]; -const h : H = { 3n: "hello2" }; -const h2 : H = { "3n": "hello2" }; +const h : H = { 3n: "propertyNameErrorAndMissingProperty3" }; +const h2 : H = { "3n": "ok3" }; h[3n]; h2[3n]; -const k : K = { 4n: "hello" }; -const k2 : K = { "4n": "hello2" }; +const k : K = { 4n: "propertyNameError4" }; +const k2 : K = { "4n": "ok4" }; k[4n]; k2[4n]; -const l : L = { 5n: "hello2" }; -const l2 : L = { "5n": "hello2" }; +const l : L = { 5n: "propertyNameErrorAndMissingProperty5" }; +const l2 : L = { "5n": "ok4" }; l[5n]; l2[5n]; From 2cb035760eb4c33e303e93cf0d580dceb19b53e5 Mon Sep 17 00:00:00 2001 From: Isabel Duan Date: Wed, 17 Jul 2024 00:14:12 -0700 Subject: [PATCH 12/15] changed error to use literal string --- src/compiler/checker.ts | 2 +- .../reference/bigintIndex.errors.txt | 8 ++--- .../reference/bigintPropertyName.errors.txt | 36 +++++++++---------- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index a9eb91ff4445e..0a6d1e2339987 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -18714,7 +18714,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { error(indexNode, Diagnostics.Type_0_has_no_matching_index_signature_for_type_1, typeToString(objectType), typeToString(indexType)); } else { - const typeString = typeToString(indexNode.kind === SyntaxKind.BigIntLiteral ? getBaseTypeOfLiteralType(getContextFreeTypeOfExpression(indexNode)) : indexType); + const typeString = indexNode.kind === SyntaxKind.BigIntLiteral ? `bigInt` : typeToString(indexType); error(indexNode, Diagnostics.Type_0_cannot_be_used_as_an_index_type, typeString); } } diff --git a/tests/baselines/reference/bigintIndex.errors.txt b/tests/baselines/reference/bigintIndex.errors.txt index 9d74c569211d7..03b5ba794cd19 100644 --- a/tests/baselines/reference/bigintIndex.errors.txt +++ b/tests/baselines/reference/bigintIndex.errors.txt @@ -1,6 +1,6 @@ a.ts(2,6): error TS1268: An index signature parameter type must be 'string', 'number', 'symbol', or a template literal type. -a.ts(8,11): error TS2538: Type 'bigint' cannot be used as an index type. -a.ts(9,17): error TS2538: Type 'bigint' cannot be used as an index type. +a.ts(8,11): error TS2538: Type 'bigInt' cannot be used as an index type. +a.ts(9,17): error TS2538: Type 'bigInt' cannot be used as an index type. a.ts(15,1): error TS2322: Type 'bigint' is not assignable to type 'string | number | symbol'. a.ts(20,12): error TS2538: Type 'bigint' cannot be used as an index type. @@ -17,10 +17,10 @@ a.ts(20,12): error TS2538: Type 'bigint' cannot be used as an index type. num = arr["1"]; num = arr[1n]; // should error ~~ -!!! error TS2538: Type 'bigint' cannot be used as an index type. +!!! error TS2538: Type 'bigInt' cannot be used as an index type. num = [1, 2, 3][1n]; // should error ~~ -!!! error TS2538: Type 'bigint' cannot be used as an index type. +!!! error TS2538: Type 'bigInt' cannot be used as an index type. let key: keyof any; // should be type "string | number | symbol" key = 123; diff --git a/tests/baselines/reference/bigintPropertyName.errors.txt b/tests/baselines/reference/bigintPropertyName.errors.txt index 7a52f0325dc00..b861157afecb2 100644 --- a/tests/baselines/reference/bigintPropertyName.errors.txt +++ b/tests/baselines/reference/bigintPropertyName.errors.txt @@ -2,25 +2,25 @@ a.ts(2,5): error TS1538: A `bigint` literal may not be used as a property name. a.ts(5,13): error TS1538: A `bigint` literal may not be used as a property name. a.ts(6,13): error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'. a.ts(7,13): error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'. -a.ts(12,9): error TS2538: Type 'bigint' cannot be used as an index type. +a.ts(12,9): error TS2538: Type 'bigInt' cannot be used as an index type. a.ts(15,13): error TS1538: A `bigint` literal may not be used as a property name. g.ts(2,5): error TS1538: A `bigint` literal may not be used as a property name. g.ts(8,5): error TS1538: A `bigint` literal may not be used as a property name. g.ts(15,17): error TS1538: A `bigint` literal may not be used as a property name. -g.ts(17,3): error TS2538: Type 'bigint' cannot be used as an index type. -g.ts(18,4): error TS2538: Type 'bigint' cannot be used as an index type. +g.ts(17,3): error TS2538: Type 'bigInt' cannot be used as an index type. +g.ts(18,4): error TS2538: Type 'bigInt' cannot be used as an index type. g.ts(20,7): error TS2741: Property '"3n"' is missing in type '{}' but required in type 'H'. g.ts(20,17): error TS1538: A `bigint` literal may not be used as a property name. -g.ts(22,3): error TS2538: Type 'bigint' cannot be used as an index type. -g.ts(23,4): error TS2538: Type 'bigint' cannot be used as an index type. +g.ts(22,3): error TS2538: Type 'bigInt' cannot be used as an index type. +g.ts(23,4): error TS2538: Type 'bigInt' cannot be used as an index type. g.ts(25,17): error TS1538: A `bigint` literal may not be used as a property name. -g.ts(27,3): error TS2538: Type 'bigint' cannot be used as an index type. -g.ts(28,4): error TS2538: Type 'bigint' cannot be used as an index type. +g.ts(27,3): error TS2538: Type 'bigInt' cannot be used as an index type. +g.ts(28,4): error TS2538: Type 'bigInt' cannot be used as an index type. g.ts(30,7): error TS2741: Property '"5n"' is missing in type '{}' but required in type 'L'. g.ts(30,17): error TS1538: A `bigint` literal may not be used as a property name. g.ts(31,18): error TS2322: Type 'string' is not assignable to type 'number'. -g.ts(32,3): error TS2538: Type 'bigint' cannot be used as an index type. -g.ts(33,4): error TS2538: Type 'bigint' cannot be used as an index type. +g.ts(32,3): error TS2538: Type 'bigInt' cannot be used as an index type. +g.ts(33,4): error TS2538: Type 'bigInt' cannot be used as an index type. g.ts(35,1): error TS1434: Unexpected keyword or identifier. g.ts(35,2): error TS1353: A bigint literal must be an integer. q.ts(2,19): error TS2322: Type 'bigint' is not assignable to type 'string | number | symbol'. @@ -49,7 +49,7 @@ q.ts(2,19): error TS2322: Type 'bigint' is not assignable to type 'string | numb const { "0": e } = arr; const { 0n: f } = arr; // bigint should give an index error ~~ -!!! error TS2538: Type 'bigint' cannot be used as an index type. +!!! error TS2538: Type 'bigInt' cannot be used as an index type. // BigInt cannot be used as an property name const x = { 0n: 123 }; @@ -81,10 +81,10 @@ q.ts(2,19): error TS2322: Type 'bigint' is not assignable to type 'string | numb const g2 : G = { "2n": "ok2" }; g[2n]; ~~ -!!! error TS2538: Type 'bigint' cannot be used as an index type. +!!! error TS2538: Type 'bigInt' cannot be used as an index type. g2[2n]; ~~ -!!! error TS2538: Type 'bigint' cannot be used as an index type. +!!! error TS2538: Type 'bigInt' cannot be used as an index type. const h : H = { 3n: "propertyNameErrorAndMissingProperty3" }; ~ @@ -95,10 +95,10 @@ q.ts(2,19): error TS2322: Type 'bigint' is not assignable to type 'string | numb const h2 : H = { "3n": "ok3" }; h[3n]; ~~ -!!! error TS2538: Type 'bigint' cannot be used as an index type. +!!! error TS2538: Type 'bigInt' cannot be used as an index type. h2[3n]; ~~ -!!! error TS2538: Type 'bigint' cannot be used as an index type. +!!! error TS2538: Type 'bigInt' cannot be used as an index type. const k : K = { 4n: "propertyNameError4" }; ~~ @@ -106,10 +106,10 @@ q.ts(2,19): error TS2322: Type 'bigint' is not assignable to type 'string | numb const k2 : K = { "4n": "ok4" }; k[4n]; ~~ -!!! error TS2538: Type 'bigint' cannot be used as an index type. +!!! error TS2538: Type 'bigInt' cannot be used as an index type. k2[4n]; ~~ -!!! error TS2538: Type 'bigint' cannot be used as an index type. +!!! error TS2538: Type 'bigInt' cannot be used as an index type. const l : L = { 5n: "propertyNameErrorAndMissingProperty5" }; ~ @@ -123,10 +123,10 @@ q.ts(2,19): error TS2322: Type 'bigint' is not assignable to type 'string | numb !!! related TS6500 g.ts:12:5: The expected type comes from property '5n' which is declared here on type 'L' l[5n]; ~~ -!!! error TS2538: Type 'bigint' cannot be used as an index type. +!!! error TS2538: Type 'bigInt' cannot be used as an index type. l2[5n]; ~~ -!!! error TS2538: Type 'bigint' cannot be used as an index type. +!!! error TS2538: Type 'bigInt' cannot be used as an index type. g.2n; // not valid JS ~ From 4a4ee7e0b64acf5138b571a601af0b2a748517eb Mon Sep 17 00:00:00 2001 From: Isabel Duan Date: Fri, 19 Jul 2024 14:53:35 -0700 Subject: [PATCH 13/15] fix error --- src/compiler/checker.ts | 2 +- .../reference/bigintIndex.errors.txt | 8 ++--- .../reference/bigintPropertyName.errors.txt | 36 +++++++++---------- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 0a6d1e2339987..c0026632bed30 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -18714,7 +18714,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { error(indexNode, Diagnostics.Type_0_has_no_matching_index_signature_for_type_1, typeToString(objectType), typeToString(indexType)); } else { - const typeString = indexNode.kind === SyntaxKind.BigIntLiteral ? `bigInt` : typeToString(indexType); + const typeString = indexNode.kind === SyntaxKind.BigIntLiteral ? `bigint` : typeToString(indexType); error(indexNode, Diagnostics.Type_0_cannot_be_used_as_an_index_type, typeString); } } diff --git a/tests/baselines/reference/bigintIndex.errors.txt b/tests/baselines/reference/bigintIndex.errors.txt index 03b5ba794cd19..9d74c569211d7 100644 --- a/tests/baselines/reference/bigintIndex.errors.txt +++ b/tests/baselines/reference/bigintIndex.errors.txt @@ -1,6 +1,6 @@ a.ts(2,6): error TS1268: An index signature parameter type must be 'string', 'number', 'symbol', or a template literal type. -a.ts(8,11): error TS2538: Type 'bigInt' cannot be used as an index type. -a.ts(9,17): error TS2538: Type 'bigInt' cannot be used as an index type. +a.ts(8,11): error TS2538: Type 'bigint' cannot be used as an index type. +a.ts(9,17): error TS2538: Type 'bigint' cannot be used as an index type. a.ts(15,1): error TS2322: Type 'bigint' is not assignable to type 'string | number | symbol'. a.ts(20,12): error TS2538: Type 'bigint' cannot be used as an index type. @@ -17,10 +17,10 @@ a.ts(20,12): error TS2538: Type 'bigint' cannot be used as an index type. num = arr["1"]; num = arr[1n]; // should error ~~ -!!! error TS2538: Type 'bigInt' cannot be used as an index type. +!!! error TS2538: Type 'bigint' cannot be used as an index type. num = [1, 2, 3][1n]; // should error ~~ -!!! error TS2538: Type 'bigInt' cannot be used as an index type. +!!! error TS2538: Type 'bigint' cannot be used as an index type. let key: keyof any; // should be type "string | number | symbol" key = 123; diff --git a/tests/baselines/reference/bigintPropertyName.errors.txt b/tests/baselines/reference/bigintPropertyName.errors.txt index b861157afecb2..7a52f0325dc00 100644 --- a/tests/baselines/reference/bigintPropertyName.errors.txt +++ b/tests/baselines/reference/bigintPropertyName.errors.txt @@ -2,25 +2,25 @@ a.ts(2,5): error TS1538: A `bigint` literal may not be used as a property name. a.ts(5,13): error TS1538: A `bigint` literal may not be used as a property name. a.ts(6,13): error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'. a.ts(7,13): error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'. -a.ts(12,9): error TS2538: Type 'bigInt' cannot be used as an index type. +a.ts(12,9): error TS2538: Type 'bigint' cannot be used as an index type. a.ts(15,13): error TS1538: A `bigint` literal may not be used as a property name. g.ts(2,5): error TS1538: A `bigint` literal may not be used as a property name. g.ts(8,5): error TS1538: A `bigint` literal may not be used as a property name. g.ts(15,17): error TS1538: A `bigint` literal may not be used as a property name. -g.ts(17,3): error TS2538: Type 'bigInt' cannot be used as an index type. -g.ts(18,4): error TS2538: Type 'bigInt' cannot be used as an index type. +g.ts(17,3): error TS2538: Type 'bigint' cannot be used as an index type. +g.ts(18,4): error TS2538: Type 'bigint' cannot be used as an index type. g.ts(20,7): error TS2741: Property '"3n"' is missing in type '{}' but required in type 'H'. g.ts(20,17): error TS1538: A `bigint` literal may not be used as a property name. -g.ts(22,3): error TS2538: Type 'bigInt' cannot be used as an index type. -g.ts(23,4): error TS2538: Type 'bigInt' cannot be used as an index type. +g.ts(22,3): error TS2538: Type 'bigint' cannot be used as an index type. +g.ts(23,4): error TS2538: Type 'bigint' cannot be used as an index type. g.ts(25,17): error TS1538: A `bigint` literal may not be used as a property name. -g.ts(27,3): error TS2538: Type 'bigInt' cannot be used as an index type. -g.ts(28,4): error TS2538: Type 'bigInt' cannot be used as an index type. +g.ts(27,3): error TS2538: Type 'bigint' cannot be used as an index type. +g.ts(28,4): error TS2538: Type 'bigint' cannot be used as an index type. g.ts(30,7): error TS2741: Property '"5n"' is missing in type '{}' but required in type 'L'. g.ts(30,17): error TS1538: A `bigint` literal may not be used as a property name. g.ts(31,18): error TS2322: Type 'string' is not assignable to type 'number'. -g.ts(32,3): error TS2538: Type 'bigInt' cannot be used as an index type. -g.ts(33,4): error TS2538: Type 'bigInt' cannot be used as an index type. +g.ts(32,3): error TS2538: Type 'bigint' cannot be used as an index type. +g.ts(33,4): error TS2538: Type 'bigint' cannot be used as an index type. g.ts(35,1): error TS1434: Unexpected keyword or identifier. g.ts(35,2): error TS1353: A bigint literal must be an integer. q.ts(2,19): error TS2322: Type 'bigint' is not assignable to type 'string | number | symbol'. @@ -49,7 +49,7 @@ q.ts(2,19): error TS2322: Type 'bigint' is not assignable to type 'string | numb const { "0": e } = arr; const { 0n: f } = arr; // bigint should give an index error ~~ -!!! error TS2538: Type 'bigInt' cannot be used as an index type. +!!! error TS2538: Type 'bigint' cannot be used as an index type. // BigInt cannot be used as an property name const x = { 0n: 123 }; @@ -81,10 +81,10 @@ q.ts(2,19): error TS2322: Type 'bigint' is not assignable to type 'string | numb const g2 : G = { "2n": "ok2" }; g[2n]; ~~ -!!! error TS2538: Type 'bigInt' cannot be used as an index type. +!!! error TS2538: Type 'bigint' cannot be used as an index type. g2[2n]; ~~ -!!! error TS2538: Type 'bigInt' cannot be used as an index type. +!!! error TS2538: Type 'bigint' cannot be used as an index type. const h : H = { 3n: "propertyNameErrorAndMissingProperty3" }; ~ @@ -95,10 +95,10 @@ q.ts(2,19): error TS2322: Type 'bigint' is not assignable to type 'string | numb const h2 : H = { "3n": "ok3" }; h[3n]; ~~ -!!! error TS2538: Type 'bigInt' cannot be used as an index type. +!!! error TS2538: Type 'bigint' cannot be used as an index type. h2[3n]; ~~ -!!! error TS2538: Type 'bigInt' cannot be used as an index type. +!!! error TS2538: Type 'bigint' cannot be used as an index type. const k : K = { 4n: "propertyNameError4" }; ~~ @@ -106,10 +106,10 @@ q.ts(2,19): error TS2322: Type 'bigint' is not assignable to type 'string | numb const k2 : K = { "4n": "ok4" }; k[4n]; ~~ -!!! error TS2538: Type 'bigInt' cannot be used as an index type. +!!! error TS2538: Type 'bigint' cannot be used as an index type. k2[4n]; ~~ -!!! error TS2538: Type 'bigInt' cannot be used as an index type. +!!! error TS2538: Type 'bigint' cannot be used as an index type. const l : L = { 5n: "propertyNameErrorAndMissingProperty5" }; ~ @@ -123,10 +123,10 @@ q.ts(2,19): error TS2322: Type 'bigint' is not assignable to type 'string | numb !!! related TS6500 g.ts:12:5: The expected type comes from property '5n' which is declared here on type 'L' l[5n]; ~~ -!!! error TS2538: Type 'bigInt' cannot be used as an index type. +!!! error TS2538: Type 'bigint' cannot be used as an index type. l2[5n]; ~~ -!!! error TS2538: Type 'bigInt' cannot be used as an index type. +!!! error TS2538: Type 'bigint' cannot be used as an index type. g.2n; // not valid JS ~ From 2c222c6b3b5b114d14cddc8e88d0b0970cc3a23f Mon Sep 17 00:00:00 2001 From: Isabel Duan Date: Fri, 19 Jul 2024 15:59:46 -0700 Subject: [PATCH 14/15] update baselines --- .../reference/bigintPropertyName.errors.txt | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/tests/baselines/reference/bigintPropertyName.errors.txt b/tests/baselines/reference/bigintPropertyName.errors.txt index 7a52f0325dc00..430c06e92bdd4 100644 --- a/tests/baselines/reference/bigintPropertyName.errors.txt +++ b/tests/baselines/reference/bigintPropertyName.errors.txt @@ -1,23 +1,23 @@ -a.ts(2,5): error TS1538: A `bigint` literal may not be used as a property name. -a.ts(5,13): error TS1538: A `bigint` literal may not be used as a property name. +a.ts(2,5): error TS1539: A `bigint` literal may not be used as a property name. +a.ts(5,13): error TS1539: A `bigint` literal may not be used as a property name. a.ts(6,13): error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'. a.ts(7,13): error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'. a.ts(12,9): error TS2538: Type 'bigint' cannot be used as an index type. -a.ts(15,13): error TS1538: A `bigint` literal may not be used as a property name. -g.ts(2,5): error TS1538: A `bigint` literal may not be used as a property name. -g.ts(8,5): error TS1538: A `bigint` literal may not be used as a property name. -g.ts(15,17): error TS1538: A `bigint` literal may not be used as a property name. +a.ts(15,13): error TS1539: A `bigint` literal may not be used as a property name. +g.ts(2,5): error TS1539: A `bigint` literal may not be used as a property name. +g.ts(8,5): error TS1539: A `bigint` literal may not be used as a property name. +g.ts(15,17): error TS1539: A `bigint` literal may not be used as a property name. g.ts(17,3): error TS2538: Type 'bigint' cannot be used as an index type. g.ts(18,4): error TS2538: Type 'bigint' cannot be used as an index type. g.ts(20,7): error TS2741: Property '"3n"' is missing in type '{}' but required in type 'H'. -g.ts(20,17): error TS1538: A `bigint` literal may not be used as a property name. +g.ts(20,17): error TS1539: A `bigint` literal may not be used as a property name. g.ts(22,3): error TS2538: Type 'bigint' cannot be used as an index type. g.ts(23,4): error TS2538: Type 'bigint' cannot be used as an index type. -g.ts(25,17): error TS1538: A `bigint` literal may not be used as a property name. +g.ts(25,17): error TS1539: A `bigint` literal may not be used as a property name. g.ts(27,3): error TS2538: Type 'bigint' cannot be used as an index type. g.ts(28,4): error TS2538: Type 'bigint' cannot be used as an index type. g.ts(30,7): error TS2741: Property '"5n"' is missing in type '{}' but required in type 'L'. -g.ts(30,17): error TS1538: A `bigint` literal may not be used as a property name. +g.ts(30,17): error TS1539: A `bigint` literal may not be used as a property name. g.ts(31,18): error TS2322: Type 'string' is not assignable to type 'number'. g.ts(32,3): error TS2538: Type 'bigint' cannot be used as an index type. g.ts(33,4): error TS2538: Type 'bigint' cannot be used as an index type. @@ -31,12 +31,12 @@ q.ts(2,19): error TS2322: Type 'bigint' is not assignable to type 'string | numb // BigInt cannot be used as an object literal property { ({1n: 123}); }; ~~ -!!! error TS1538: A `bigint` literal may not be used as a property name. +!!! error TS1539: A `bigint` literal may not be used as a property name. const bigNum: bigint = 0n; const a = { 1n: 123 }; ~~ -!!! error TS1538: A `bigint` literal may not be used as a property name. +!!! error TS1539: A `bigint` literal may not be used as a property name. const b = { [1n]: 456 }; ~~~~ !!! error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'. @@ -54,13 +54,13 @@ q.ts(2,19): error TS2322: Type 'bigint' is not assignable to type 'string | numb // BigInt cannot be used as an property name const x = { 0n: 123 }; ~~ -!!! error TS1538: A `bigint` literal may not be used as a property name. +!!! error TS1539: A `bigint` literal may not be used as a property name. ==== g.ts (19 errors) ==== interface G { 2n: string; ~~ -!!! error TS1538: A `bigint` literal may not be used as a property name. +!!! error TS1539: A `bigint` literal may not be used as a property name. } interface H { "3n": string; @@ -68,7 +68,7 @@ q.ts(2,19): error TS2322: Type 'bigint' is not assignable to type 'string | numb class K { 4n = 0; ~~ -!!! error TS1538: A `bigint` literal may not be used as a property name. +!!! error TS1539: A `bigint` literal may not be used as a property name. } class L { @@ -77,7 +77,7 @@ q.ts(2,19): error TS2322: Type 'bigint' is not assignable to type 'string | numb const g : G = { 2n: "propertyNameError2" }; ~~ -!!! error TS1538: A `bigint` literal may not be used as a property name. +!!! error TS1539: A `bigint` literal may not be used as a property name. const g2 : G = { "2n": "ok2" }; g[2n]; ~~ @@ -91,7 +91,7 @@ q.ts(2,19): error TS2322: Type 'bigint' is not assignable to type 'string | numb !!! error TS2741: Property '"3n"' is missing in type '{}' but required in type 'H'. !!! related TS2728 g.ts:5:5: '"3n"' is declared here. ~~ -!!! error TS1538: A `bigint` literal may not be used as a property name. +!!! error TS1539: A `bigint` literal may not be used as a property name. const h2 : H = { "3n": "ok3" }; h[3n]; ~~ @@ -102,7 +102,7 @@ q.ts(2,19): error TS2322: Type 'bigint' is not assignable to type 'string | numb const k : K = { 4n: "propertyNameError4" }; ~~ -!!! error TS1538: A `bigint` literal may not be used as a property name. +!!! error TS1539: A `bigint` literal may not be used as a property name. const k2 : K = { "4n": "ok4" }; k[4n]; ~~ @@ -116,7 +116,7 @@ q.ts(2,19): error TS2322: Type 'bigint' is not assignable to type 'string | numb !!! error TS2741: Property '"5n"' is missing in type '{}' but required in type 'L'. !!! related TS2728 g.ts:12:5: '"5n"' is declared here. ~~ -!!! error TS1538: A `bigint` literal may not be used as a property name. +!!! error TS1539: A `bigint` literal may not be used as a property name. const l2 : L = { "5n": "ok4" }; ~~~~ !!! error TS2322: Type 'string' is not assignable to type 'number'. From 46f1b4484710f872fc3a5a1170adf2ab2223557f Mon Sep 17 00:00:00 2001 From: Isabel Duan Date: Fri, 19 Jul 2024 17:29:09 -0700 Subject: [PATCH 15/15] fix error messages --- src/compiler/checker.ts | 6 ++-- src/compiler/diagnosticMessages.json | 2 +- .../reference/bigintPropertyName.errors.txt | 36 +++++++++---------- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 8e6eb90bedc28..ddf28e27fd5a0 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -18760,7 +18760,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { error(indexNode, Diagnostics.Type_0_has_no_matching_index_signature_for_type_1, typeToString(objectType), typeToString(indexType)); } else { - const typeString = indexNode.kind === SyntaxKind.BigIntLiteral ? `bigint` : typeToString(indexType); + const typeString = indexNode.kind === SyntaxKind.BigIntLiteral ? "bigint" : typeToString(indexType); error(indexNode, Diagnostics.Type_0_cannot_be_used_as_an_index_type, typeString); } } @@ -43891,7 +43891,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { } if (node.name.kind === SyntaxKind.BigIntLiteral) { - error(node.name, Diagnostics.A_bigint_literal_may_not_be_used_as_a_property_name); + error(node.name, Diagnostics.A_bigint_literal_cannot_be_used_as_a_property_name); } const type = convertAutoToAny(getTypeOfSymbol(symbol)); @@ -51094,7 +51094,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { checkGrammarNumericLiteral(name); } if (name.kind === SyntaxKind.BigIntLiteral) { - addErrorOrSuggestion(/*isError*/ true, createDiagnosticForNode(name, Diagnostics.A_bigint_literal_may_not_be_used_as_a_property_name)); + addErrorOrSuggestion(/*isError*/ true, createDiagnosticForNode(name, Diagnostics.A_bigint_literal_cannot_be_used_as_a_property_name)); } currentKind = DeclarationMeaning.PropertyAssignment; break; diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 621aeead41025..9478c523432c5 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1809,7 +1809,7 @@ "category": "Error", "code": 1538 }, - "A `bigint` literal may not be used as a property name.": { + "A 'bigint' literal cannot be used as a property name.": { "category": "Error", "code": 1539 }, diff --git a/tests/baselines/reference/bigintPropertyName.errors.txt b/tests/baselines/reference/bigintPropertyName.errors.txt index 430c06e92bdd4..2b2db4f45c631 100644 --- a/tests/baselines/reference/bigintPropertyName.errors.txt +++ b/tests/baselines/reference/bigintPropertyName.errors.txt @@ -1,23 +1,23 @@ -a.ts(2,5): error TS1539: A `bigint` literal may not be used as a property name. -a.ts(5,13): error TS1539: A `bigint` literal may not be used as a property name. +a.ts(2,5): error TS1539: A 'bigint' literal cannot be used as a property name. +a.ts(5,13): error TS1539: A 'bigint' literal cannot be used as a property name. a.ts(6,13): error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'. a.ts(7,13): error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'. a.ts(12,9): error TS2538: Type 'bigint' cannot be used as an index type. -a.ts(15,13): error TS1539: A `bigint` literal may not be used as a property name. -g.ts(2,5): error TS1539: A `bigint` literal may not be used as a property name. -g.ts(8,5): error TS1539: A `bigint` literal may not be used as a property name. -g.ts(15,17): error TS1539: A `bigint` literal may not be used as a property name. +a.ts(15,13): error TS1539: A 'bigint' literal cannot be used as a property name. +g.ts(2,5): error TS1539: A 'bigint' literal cannot be used as a property name. +g.ts(8,5): error TS1539: A 'bigint' literal cannot be used as a property name. +g.ts(15,17): error TS1539: A 'bigint' literal cannot be used as a property name. g.ts(17,3): error TS2538: Type 'bigint' cannot be used as an index type. g.ts(18,4): error TS2538: Type 'bigint' cannot be used as an index type. g.ts(20,7): error TS2741: Property '"3n"' is missing in type '{}' but required in type 'H'. -g.ts(20,17): error TS1539: A `bigint` literal may not be used as a property name. +g.ts(20,17): error TS1539: A 'bigint' literal cannot be used as a property name. g.ts(22,3): error TS2538: Type 'bigint' cannot be used as an index type. g.ts(23,4): error TS2538: Type 'bigint' cannot be used as an index type. -g.ts(25,17): error TS1539: A `bigint` literal may not be used as a property name. +g.ts(25,17): error TS1539: A 'bigint' literal cannot be used as a property name. g.ts(27,3): error TS2538: Type 'bigint' cannot be used as an index type. g.ts(28,4): error TS2538: Type 'bigint' cannot be used as an index type. g.ts(30,7): error TS2741: Property '"5n"' is missing in type '{}' but required in type 'L'. -g.ts(30,17): error TS1539: A `bigint` literal may not be used as a property name. +g.ts(30,17): error TS1539: A 'bigint' literal cannot be used as a property name. g.ts(31,18): error TS2322: Type 'string' is not assignable to type 'number'. g.ts(32,3): error TS2538: Type 'bigint' cannot be used as an index type. g.ts(33,4): error TS2538: Type 'bigint' cannot be used as an index type. @@ -31,12 +31,12 @@ q.ts(2,19): error TS2322: Type 'bigint' is not assignable to type 'string | numb // BigInt cannot be used as an object literal property { ({1n: 123}); }; ~~ -!!! error TS1539: A `bigint` literal may not be used as a property name. +!!! error TS1539: A 'bigint' literal cannot be used as a property name. const bigNum: bigint = 0n; const a = { 1n: 123 }; ~~ -!!! error TS1539: A `bigint` literal may not be used as a property name. +!!! error TS1539: A 'bigint' literal cannot be used as a property name. const b = { [1n]: 456 }; ~~~~ !!! error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'. @@ -54,13 +54,13 @@ q.ts(2,19): error TS2322: Type 'bigint' is not assignable to type 'string | numb // BigInt cannot be used as an property name const x = { 0n: 123 }; ~~ -!!! error TS1539: A `bigint` literal may not be used as a property name. +!!! error TS1539: A 'bigint' literal cannot be used as a property name. ==== g.ts (19 errors) ==== interface G { 2n: string; ~~ -!!! error TS1539: A `bigint` literal may not be used as a property name. +!!! error TS1539: A 'bigint' literal cannot be used as a property name. } interface H { "3n": string; @@ -68,7 +68,7 @@ q.ts(2,19): error TS2322: Type 'bigint' is not assignable to type 'string | numb class K { 4n = 0; ~~ -!!! error TS1539: A `bigint` literal may not be used as a property name. +!!! error TS1539: A 'bigint' literal cannot be used as a property name. } class L { @@ -77,7 +77,7 @@ q.ts(2,19): error TS2322: Type 'bigint' is not assignable to type 'string | numb const g : G = { 2n: "propertyNameError2" }; ~~ -!!! error TS1539: A `bigint` literal may not be used as a property name. +!!! error TS1539: A 'bigint' literal cannot be used as a property name. const g2 : G = { "2n": "ok2" }; g[2n]; ~~ @@ -91,7 +91,7 @@ q.ts(2,19): error TS2322: Type 'bigint' is not assignable to type 'string | numb !!! error TS2741: Property '"3n"' is missing in type '{}' but required in type 'H'. !!! related TS2728 g.ts:5:5: '"3n"' is declared here. ~~ -!!! error TS1539: A `bigint` literal may not be used as a property name. +!!! error TS1539: A 'bigint' literal cannot be used as a property name. const h2 : H = { "3n": "ok3" }; h[3n]; ~~ @@ -102,7 +102,7 @@ q.ts(2,19): error TS2322: Type 'bigint' is not assignable to type 'string | numb const k : K = { 4n: "propertyNameError4" }; ~~ -!!! error TS1539: A `bigint` literal may not be used as a property name. +!!! error TS1539: A 'bigint' literal cannot be used as a property name. const k2 : K = { "4n": "ok4" }; k[4n]; ~~ @@ -116,7 +116,7 @@ q.ts(2,19): error TS2322: Type 'bigint' is not assignable to type 'string | numb !!! error TS2741: Property '"5n"' is missing in type '{}' but required in type 'L'. !!! related TS2728 g.ts:12:5: '"5n"' is declared here. ~~ -!!! error TS1539: A `bigint` literal may not be used as a property name. +!!! error TS1539: A 'bigint' literal cannot be used as a property name. const l2 : L = { "5n": "ok4" }; ~~~~ !!! error TS2322: Type 'string' is not assignable to type 'number'.