File: parseBigInt.errors.txt

package info (click to toggle)
node-typescript 5.0.4%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 459,140 kB
  • sloc: javascript: 1,972,754; makefile: 6; sh: 1
file content (124 lines) | stat: -rw-r--r-- 6,660 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
tests/cases/compiler/parseBigInt.ts(51,20): error TS2736: Operator '+' cannot be applied to type 'bigint'.
tests/cases/compiler/parseBigInt.ts(52,23): error TS2736: Operator '+' cannot be applied to type 'bigint'.
tests/cases/compiler/parseBigInt.ts(56,25): error TS1005: ',' expected.
tests/cases/compiler/parseBigInt.ts(57,22): error TS1352: A bigint literal cannot use exponential notation.
tests/cases/compiler/parseBigInt.ts(58,19): error TS1353: A bigint literal must be an integer.
tests/cases/compiler/parseBigInt.ts(59,26): error TS1353: A bigint literal must be an integer.
tests/cases/compiler/parseBigInt.ts(60,23): error TS1177: Binary digit expected.
tests/cases/compiler/parseBigInt.ts(61,20): error TS1178: Octal digit expected.
tests/cases/compiler/parseBigInt.ts(62,20): error TS1125: Hexadecimal digit expected.
tests/cases/compiler/parseBigInt.ts(63,26): error TS2304: Cannot find name '_123n'.
tests/cases/compiler/parseBigInt.ts(64,30): error TS6188: Numeric separators are not allowed here.
tests/cases/compiler/parseBigInt.ts(65,33): error TS6189: Multiple consecutive numeric separators are not permitted.
tests/cases/compiler/parseBigInt.ts(69,15): error TS2345: Argument of type '0n' is not assignable to parameter of type '1n | 3n | 2n'.
tests/cases/compiler/parseBigInt.ts(70,15): error TS2345: Argument of type '0' is not assignable to parameter of type '1n | 3n | 2n'.
tests/cases/compiler/parseBigInt.ts(70,34): error TS2345: Argument of type '1' is not assignable to parameter of type '1n | 3n | 2n'.
tests/cases/compiler/parseBigInt.ts(70,53): error TS2345: Argument of type '2' is not assignable to parameter of type '1n | 3n | 2n'.
tests/cases/compiler/parseBigInt.ts(70,72): error TS2345: Argument of type '3' is not assignable to parameter of type '1n | 3n | 2n'.


==== tests/cases/compiler/parseBigInt.ts (17 errors) ====
    // All bases should allow "n" suffix
    const bin = 0b101, binBig = 0b101n; // 5, 5n
    const oct = 0o567, octBig = 0o567n; // 375, 375n
    const hex = 0xC0B, hexBig = 0xC0Bn; // 3083, 3083n
    const dec = 123,   decBig = 123n;
    
    // Test literals whose values overflow a 53-bit integer
    // These should be represented exactly in the emitted JS
    const largeBin = 0b10101010101010101010101010101010101010101010101010101010101n; // 384307168202282325n
    const largeOct = 0o123456712345671234567n; // 1505852261029722487n
    const largeDec = 12345678091234567890n;
    const largeHex = 0x1234567890abcdefn; // 1311768467294899695n
    
    // Test literals with separators
    const separatedBin = 0b010_10_1n; // 21n
    const separatedOct = 0o1234_567n; // 342391n
    const separatedDec = 123_456_789n;
    const separatedHex = 0x0_abcdefn; // 11259375n
    
    // Test parsing literals of different bit sizes
    // to ensure that parsePseudoBigInt() allocates enough space
    const zero         = 0b0n;
    const oneBit       = 0b1n;
    const twoBit       = 0b11n; // 3n
    const threeBit     = 0b111n; // 7n
    const fourBit      = 0b1111n; // 15n
    const fiveBit      = 0b11111n; // 31n
    const sixBit       = 0b111111n; // 63n
    const sevenBit     = 0b1111111n; // 127n
    const eightBit     = 0b11111111n; // 255n
    const nineBit      = 0b111111111n; // 511n
    const tenBit       = 0b1111111111n; // 1023n
    const elevenBit    = 0b11111111111n; // 2047n
    const twelveBit    = 0b111111111111n; // 4095n
    const thirteenBit  = 0b1111111111111n; // 8191n
    const fourteenBit  = 0b11111111111111n; // 16383n
    const fifteenBit   = 0b111111111111111n; // 32767n
    const sixteenBit   = 0b1111111111111111n; // 65535n
    const seventeenBit = 0b11111111111111111n; // 131071n
    
    // Test negative literals
    const neg = -123n;
    const negHex: -16n = -0x10n;
    
    // Test normalization of bigints -- all of these should succeed
    const negZero: 0n = -0n;
    const baseChange: 255n = 0xFFn;
    const leadingZeros: 0xFFn = 0x000000FFn;
    
    // Plus not allowed on literals
    const unaryPlus = +123n;
                       ~~~~
!!! error TS2736: Operator '+' cannot be applied to type 'bigint'.
    const unaryPlusHex = +0x123n;
                          ~~~~~~
!!! error TS2736: Operator '+' cannot be applied to type 'bigint'.
    
    // Parsing errors
    // In separate blocks because they each declare an "n" variable
    { const legacyOct = 0123n; }
                            ~
!!! error TS1005: ',' expected.
    { const scientific = 1e2n; }
                         ~~~~
!!! error TS1352: A bigint literal cannot use exponential notation.
    { const decimal = 4.1n; }
                      ~~~~
!!! error TS1353: A bigint literal must be an integer.
    { const leadingDecimal = .1n; }
                             ~~~
!!! error TS1353: A bigint literal must be an integer.
    const emptyBinary = 0bn; // should error but infer 0n
                          
!!! error TS1177: Binary digit expected.
    const emptyOct = 0on; // should error but infer 0n
                       
!!! error TS1178: Octal digit expected.
    const emptyHex = 0xn; // should error but infer 0n
                       
!!! error TS1125: Hexadecimal digit expected.
    const leadingSeparator = _123n;
                             ~~~~~
!!! error TS2304: Cannot find name '_123n'.
    const trailingSeparator = 123_n;
                                 ~
!!! error TS6188: Numeric separators are not allowed here.
    const doubleSeparator = 123_456__789n;
                                    ~
!!! error TS6189: Multiple consecutive numeric separators are not permitted.
    
    // Using literals as types
    const oneTwoOrThree = (x: 1n | 2n | 3n): bigint => x ** 2n;
    oneTwoOrThree(0n); oneTwoOrThree(1n); oneTwoOrThree(2n); oneTwoOrThree(3n);
                  ~~
!!! error TS2345: Argument of type '0n' is not assignable to parameter of type '1n | 3n | 2n'.
    oneTwoOrThree(0);  oneTwoOrThree(1);  oneTwoOrThree(2);  oneTwoOrThree(3);
                  ~
!!! error TS2345: Argument of type '0' is not assignable to parameter of type '1n | 3n | 2n'.
                                     ~
!!! error TS2345: Argument of type '1' is not assignable to parameter of type '1n | 3n | 2n'.
                                                        ~
!!! error TS2345: Argument of type '2' is not assignable to parameter of type '1n | 3n | 2n'.
                                                                           ~
!!! error TS2345: Argument of type '3' is not assignable to parameter of type '1n | 3n | 2n'.