@@ -30,6 +30,8 @@ final class StaticBigIntTests {
30
30
let testSuite = TestSuite ( " StaticBigIntTests " )
31
31
testSuite. test ( " BinaryRepresentation " , testCase. testBinaryRepresentation)
32
32
testSuite. test ( " TextualRepresentation " , testCase. testTextualRepresentation)
33
+ testSuite. test ( " PrefixPlusTypeInference " , testCase. testPrefixPlusTypeInference)
34
+ testSuite. test ( " PrefixMinusTypeInference " , testCase. testPrefixMinusTypeInference)
33
35
testSuite. test ( " WrapperAssociatedType " , testCase. testWrapperAssociatedType)
34
36
runAllTests ( )
35
37
}
@@ -55,14 +57,14 @@ extension StaticBigIntTests {
55
57
- 0x3 : ( - 1 , 3 , [ ~ 2 , ~ 0 , ~ 0 , ~ 0 , ~ 0 ] , [ ~ 2 , ~ 0 , ~ 0 ] ) ,
56
58
- 0x2 : ( - 1 , 2 , [ ~ 1 , ~ 0 , ~ 0 , ~ 0 , ~ 0 ] , [ ~ 1 , ~ 0 , ~ 0 ] ) ,
57
59
- 0x1 : ( - 1 , 1 , [ ~ 0 , ~ 0 , ~ 0 , ~ 0 , ~ 0 ] , [ ~ 0 , ~ 0 , ~ 0 ] ) ,
58
- + 0x0 : ( 0 , 1 , [ 0 , 0 , 0 , 0 , 0 ] , [ 0 , 0 , 0 ] ) ,
59
- + 0x1 : ( + 1 , 2 , [ 1 , 0 , 0 , 0 , 0 ] , [ 1 , 0 , 0 ] ) ,
60
- + 0x2 : ( + 1 , 3 , [ 2 , 0 , 0 , 0 , 0 ] , [ 2 , 0 , 0 ] ) ,
61
- + 0x3 : ( + 1 , 3 , [ 3 , 0 , 0 , 0 , 0 ] , [ 3 , 0 , 0 ] ) ,
62
- + 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE : ( + 1 , 128 , [ ~ 1 , ~ 0 , ~ 0 , ~ m, 0 ] , [ ~ 1 , ~ m, 0 ] ) ,
63
- + 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF : ( + 1 , 128 , [ ~ 0 , ~ 0 , ~ 0 , ~ m, 0 ] , [ ~ 0 , ~ m, 0 ] ) ,
64
- + 0x80000000000000000000000000000000 : ( + 1 , 129 , [ 0 , 0 , 0 , m, 0 ] , [ 0 , m, 0 ] ) ,
65
- + 0x80000000000000000000000000000001 : ( + 1 , 129 , [ 1 , 0 , 0 , m, 0 ] , [ 1 , m, 0 ] ) ,
60
+ 0x0 : ( 0 , 1 , [ 0 , 0 , 0 , 0 , 0 ] , [ 0 , 0 , 0 ] ) ,
61
+ 0x1 : ( + 1 , 2 , [ 1 , 0 , 0 , 0 , 0 ] , [ 1 , 0 , 0 ] ) ,
62
+ 0x2 : ( + 1 , 3 , [ 2 , 0 , 0 , 0 , 0 ] , [ 2 , 0 , 0 ] ) ,
63
+ 0x3 : ( + 1 , 3 , [ 3 , 0 , 0 , 0 , 0 ] , [ 3 , 0 , 0 ] ) ,
64
+ 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE : ( + 1 , 128 , [ ~ 1 , ~ 0 , ~ 0 , ~ m, 0 ] , [ ~ 1 , ~ m, 0 ] ) ,
65
+ 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF : ( + 1 , 128 , [ ~ 0 , ~ 0 , ~ 0 , ~ m, 0 ] , [ ~ 0 , ~ m, 0 ] ) ,
66
+ 0x80000000000000000000000000000000 : ( + 1 , 129 , [ 0 , 0 , 0 , m, 0 ] , [ 0 , m, 0 ] ) ,
67
+ 0x80000000000000000000000000000001 : ( + 1 , 129 , [ 1 , 0 , 0 , m, 0 ] , [ 1 , m, 0 ] ) ,
66
68
]
67
69
for (actual, expected) in keyValuePairs {
68
70
expectEqual ( expected. signum, actual. signum ( ) )
@@ -108,20 +110,20 @@ extension StaticBigIntTests {
108
110
- 0x3 : " -0x3 " ,
109
111
- 0x2 : " -0x2 " ,
110
112
- 0x1 : " -0x1 " ,
111
- + 0x0 : " +0x0 " ,
112
- + 0x1 : " +0x1 " ,
113
- + 0x2 : " +0x2 " ,
114
- + 0x3 : " +0x3 " ,
115
- + 0x10 : " +0x10 " ,
116
- + 0x100 : " +0x100 " ,
117
- + 0x1000 : " +0x1000 " ,
118
- + 0x123456789ABC : " +0x123456789ABC " ,
119
- + 0x123456789ABCD : " +0x123456789ABCD " ,
120
- + 0x123456789ABCDE : " +0x123456789ABCDE " ,
121
- + 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE : " +0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE " ,
122
- + 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF : " +0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF " ,
123
- + 0x80000000000000000000000000000000 : " +0x80000000000000000000000000000000 " ,
124
- + 0x80000000000000000000000000000001 : " +0x80000000000000000000000000000001 " ,
113
+ 0x0 : " +0x0 " ,
114
+ 0x1 : " +0x1 " ,
115
+ 0x2 : " +0x2 " ,
116
+ 0x3 : " +0x3 " ,
117
+ 0x10 : " +0x10 " ,
118
+ 0x100 : " +0x100 " ,
119
+ 0x1000 : " +0x1000 " ,
120
+ 0x123456789ABC : " +0x123456789ABC " ,
121
+ 0x123456789ABCD : " +0x123456789ABCD " ,
122
+ 0x123456789ABCDE : " +0x123456789ABCDE " ,
123
+ 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE : " +0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE " ,
124
+ 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF : " +0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF " ,
125
+ 0x80000000000000000000000000000000 : " +0x80000000000000000000000000000000 " ,
126
+ 0x80000000000000000000000000000001 : " +0x80000000000000000000000000000001 " ,
125
127
]
126
128
for (actual, expected) in keyValuePairs {
127
129
expectEqual ( expected, String ( reflecting: actual) )
@@ -147,6 +149,26 @@ extension StaticBigIntTests {
147
149
self . actual = actual
148
150
}
149
151
}
152
+
153
+ func testPrefixPlusTypeInference( ) {
154
+ let a : Int = 7
155
+ // An earlier version of StaticBigInt contained a prefix + operation,
156
+ // which caused b to be inferred to have type StaticBigInt rather than
157
+ // Int:
158
+ let b = + 1
159
+ // and then this would fail to typecheck, because there's no
160
+ // Int + StaticBigInt operation.
161
+ let c = a + b
162
+ }
163
+
164
+ func testPrefixMinusTypeInference( ) {
165
+ // This example shouldn't suffer from the same problem as above, because
166
+ // -1 is a literal, not a prefix operator followed by a literal.
167
+ // Nonetheless, let's test it.
168
+ let a : Int = 7
169
+ let b = - 1
170
+ let c = a + b
171
+ }
150
172
151
173
@available ( SwiftStdlib 5 . 8 , * )
152
174
func testWrapperAssociatedType( ) {
0 commit comments