@@ -190,13 +190,14 @@ protected function nativeCasts()
190
190
191
191
protected function nativeType (
192
192
$ typeOfType ,
193
+ IType $ parentType ,
193
194
IIndexer $ indexer = null ,
194
195
array $ unaryOperatorMap = [],
195
196
array $ castMap = []
196
197
) {
197
198
return new NativeType (
198
199
$ typeOfType ,
199
- $ this -> nativeTypes [INativeType:: TYPE_MIXED ] ,
200
+ $ parentType ,
200
201
$ typeOfType ,
201
202
$ indexer ,
202
203
$ this ->buildTypeOperations ($ typeOfType , array_filter ($ castMap + $ this ->nativeCasts ())),
@@ -217,12 +218,25 @@ protected function commonNativeUnaryOperations()
217
218
218
219
protected function nativeTypes ()
219
220
{
220
- $ this ->nativeTypes [INativeType::TYPE_MIXED ] = new MixedType (INativeType::TYPE_MIXED );
221
-
222
221
return [
223
- $ this ->nativeTypes [INativeType::TYPE_MIXED ],
222
+ $ mixedType = new MixedType (INativeType::TYPE_MIXED ),
223
+ $ numericType = $ this ->nativeType (
224
+ INativeType::TYPE_NUMERIC ,
225
+ $ mixedType ,
226
+ null ,
227
+ [
228
+ Operators \Unary::BITWISE_NOT => INativeType::TYPE_INT ,
229
+ Operators \Unary::PLUS => INativeType::TYPE_NUMERIC ,
230
+ Operators \Unary::NEGATION => INativeType::TYPE_NUMERIC ,
231
+ Operators \Unary::INCREMENT => INativeType::TYPE_NUMERIC ,
232
+ Operators \Unary::DECREMENT => INativeType::TYPE_NUMERIC ,
233
+ Operators \Unary::PRE_INCREMENT => INativeType::TYPE_NUMERIC ,
234
+ Operators \Unary::PRE_DECREMENT => INativeType::TYPE_NUMERIC ,
235
+ ]
236
+ ),
224
237
$ this ->nativeType (
225
238
INativeType::TYPE_STRING ,
239
+ $ mixedType ,
226
240
new Indexer ($ this , INativeType::TYPE_STRING , INativeType::TYPE_STRING ),
227
241
[
228
242
Operators \Unary::BITWISE_NOT => INativeType::TYPE_STRING ,
@@ -234,6 +248,7 @@ protected function nativeTypes()
234
248
),
235
249
$ this ->nativeType (
236
250
INativeType::TYPE_ARRAY ,
251
+ $ mixedType ,
237
252
new Indexer ($ this , INativeType::TYPE_ARRAY , INativeType::TYPE_MIXED ),
238
253
[
239
254
Operators \Unary::PLUS => null ,
@@ -245,6 +260,7 @@ protected function nativeTypes()
245
260
),
246
261
$ this ->nativeType (
247
262
INativeType::TYPE_INT ,
263
+ $ numericType ,
248
264
null ,
249
265
[
250
266
Operators \Unary::BITWISE_NOT => INativeType::TYPE_INT ,
@@ -254,18 +270,9 @@ protected function nativeTypes()
254
270
Operators \Unary::PRE_DECREMENT => INativeType::TYPE_INT ,
255
271
]
256
272
),
257
- $ this ->nativeType (
258
- INativeType::TYPE_BOOL ,
259
- null ,
260
- [
261
- Operators \Unary::INCREMENT => INativeType::TYPE_BOOL ,
262
- Operators \Unary::DECREMENT => INativeType::TYPE_BOOL ,
263
- Operators \Unary::PRE_INCREMENT => INativeType::TYPE_BOOL ,
264
- Operators \Unary::PRE_DECREMENT => INativeType::TYPE_BOOL ,
265
- ]
266
- ),
267
273
$ this ->nativeType (
268
274
INativeType::TYPE_DOUBLE ,
275
+ $ numericType ,
269
276
null ,
270
277
[
271
278
Operators \Unary::BITWISE_NOT => INativeType::TYPE_INT ,
@@ -277,8 +284,19 @@ protected function nativeTypes()
277
284
Operators \Unary::PRE_DECREMENT => INativeType::TYPE_DOUBLE ,
278
285
]
279
286
),
280
- $ this ->nativeType (INativeType::TYPE_NULL ),
281
- $ this ->nativeType (INativeType::TYPE_RESOURCE ),
287
+ $ this ->nativeType (
288
+ INativeType::TYPE_BOOL ,
289
+ $ mixedType ,
290
+ null ,
291
+ [
292
+ Operators \Unary::INCREMENT => INativeType::TYPE_BOOL ,
293
+ Operators \Unary::DECREMENT => INativeType::TYPE_BOOL ,
294
+ Operators \Unary::PRE_INCREMENT => INativeType::TYPE_BOOL ,
295
+ Operators \Unary::PRE_DECREMENT => INativeType::TYPE_BOOL ,
296
+ ]
297
+ ),
298
+ $ this ->nativeType (INativeType::TYPE_NULL , $ mixedType ),
299
+ $ this ->nativeType (INativeType::TYPE_RESOURCE , $ mixedType ),
282
300
];
283
301
}
284
302
@@ -431,6 +449,7 @@ protected function mathOperators($operator, $otherIntReturnType = INativeType::T
431
449
foreach ([
432
450
INativeType::TYPE_INT ,
433
451
INativeType::TYPE_DOUBLE ,
452
+ INativeType::TYPE_NUMERIC ,
434
453
INativeType::TYPE_STRING ,
435
454
INativeType::TYPE_RESOURCE ,
436
455
INativeType::TYPE_BOOL ,
@@ -441,7 +460,7 @@ protected function mathOperators($operator, $otherIntReturnType = INativeType::T
441
460
[
442
461
[$ type , $ operator , INativeType::TYPE_NULL , 'return ' => $ otherIntReturnType ],
443
462
[$ type , $ operator , INativeType::TYPE_BOOL , 'return ' => $ otherIntReturnType ],
444
- [$ type , $ operator , INativeType::TYPE_STRING , 'return ' => INativeType::TYPE_MIXED ],
463
+ [$ type , $ operator , INativeType::TYPE_STRING , 'return ' => INativeType::TYPE_NUMERIC ],
445
464
[$ type , $ operator , INativeType::TYPE_RESOURCE , 'return ' => $ otherIntReturnType ],
446
465
]
447
466
);
@@ -471,6 +490,7 @@ protected function bitwiseOperators($operator)
471
490
foreach ([
472
491
INativeType::TYPE_INT ,
473
492
INativeType::TYPE_DOUBLE ,
493
+ INativeType::TYPE_NUMERIC ,
474
494
INativeType::TYPE_STRING ,
475
495
INativeType::TYPE_RESOURCE ,
476
496
INativeType::TYPE_BOOL ,
@@ -524,7 +544,7 @@ protected function binaryOperations()
524
544
$ this ->mathOperators (Operators \Binary::ADDITION ),
525
545
$ this ->mathOperators (Operators \Binary::SUBTRACTION ),
526
546
$ this ->mathOperators (Operators \Binary::MULTIPLICATION ),
527
- $ this ->mathOperators (Operators \Binary::DIVISION , INativeType::TYPE_MIXED ),
547
+ $ this ->mathOperators (Operators \Binary::DIVISION , INativeType::TYPE_NUMERIC ),
528
548
$ this ->mathOperators (Operators \Binary::MODULUS ),
529
549
$ this ->mathOperators (Operators \Binary::POWER ),
530
550
$ this ->bitwiseOperators (Operators \Binary::BITWISE_AND ),
0 commit comments