forked from python/mypy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenops-basic.test
3355 lines (3202 loc) · 62.5 KB
/
genops-basic.test
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
[case testTrivialFunction]
def f() -> int:
return 1
[out]
def f():
r0 :: short_int
L0:
r0 = 1
return r0
[case testFunctionArgument]
def f(x: int) -> int:
return x
[out]
def f(x):
x :: int
L0:
return x
[case testExplicitNoneReturn]
def f() -> None:
return
[out]
def f():
r0 :: None
L0:
r0 = None
return r0
[case testExplicitNoneReturn2]
def f() -> None:
return None
[out]
def f():
r0 :: None
L0:
r0 = None
return r0
[case testAssignment]
def f() -> int:
x = 1
y = x
return y
[out]
def f():
r0 :: short_int
x, y :: int
L0:
r0 = 1
x = r0
y = x
return y
[case testAssignmentTwice]
def f(x: int) -> None:
y = 1
y = x
return
[out]
def f(x):
x :: int
r0 :: short_int
y :: int
r1 :: None
L0:
r0 = 1
y = r0
y = x
r1 = None
return r1
[case testIntArithmetic]
def f(x: int, y: int) -> int:
return x * (y + 1)
[out]
def f(x, y):
x, y :: int
r0 :: short_int
r1, r2 :: int
L0:
r0 = 1
r1 = y + r0 :: int
r2 = x * r1 :: int
return r2
[case testIf]
def f(x: int, y: int) -> int:
if x < y:
x = 1
return x
[out]
def f(x, y):
x, y :: int
r0 :: bool
r1 :: short_int
L0:
r0 = x < y :: int
if r0 goto L1 else goto L2 :: bool
L1:
r1 = 1
x = r1
L2:
return x
[case testIfElse]
def f(x: int, y: int) -> int:
if x < y:
x = 1
else:
x = 2
return x
[out]
def f(x, y):
x, y :: int
r0 :: bool
r1, r2 :: short_int
L0:
r0 = x < y :: int
if r0 goto L1 else goto L2 :: bool
L1:
r1 = 1
x = r1
goto L3
L2:
r2 = 2
x = r2
L3:
return x
[case testAnd1]
def f(x: int, y: int) -> int:
if x < y and x > y:
x = 1
else:
x = 2
return x
[out]
def f(x, y):
x, y :: int
r0, r1 :: bool
r2, r3 :: short_int
L0:
r0 = x < y :: int
if r0 goto L1 else goto L3 :: bool
L1:
r1 = x > y :: int
if r1 goto L2 else goto L3 :: bool
L2:
r2 = 1
x = r2
goto L4
L3:
r3 = 2
x = r3
L4:
return x
[case testAnd2]
def f(x: object, y: object) -> str:
return str(x) or str(y)
[out]
def f(x, y):
x, y :: object
r0, r1 :: str
r2 :: bool
r3 :: str
L0:
r1 = str x :: object
r2 = bool r1 :: object
if r2 goto L1 else goto L2 :: bool
L1:
r0 = r1
goto L3
L2:
r3 = str y :: object
r0 = r3
L3:
return r0
[case testOr]
def f(x: int, y: int) -> int:
if x < y or x > y:
x = 1
else:
x = 2
return x
[out]
def f(x, y):
x, y :: int
r0, r1 :: bool
r2, r3 :: short_int
L0:
r0 = x < y :: int
if r0 goto L2 else goto L1 :: bool
L1:
r1 = x > y :: int
if r1 goto L2 else goto L3 :: bool
L2:
r2 = 1
x = r2
goto L4
L3:
r3 = 2
x = r3
L4:
return x
[case testOr2]
def f(x: object, y: object) -> str:
return str(x) and str(y)
[out]
def f(x, y):
x, y :: object
r0, r1 :: str
r2 :: bool
r3 :: str
L0:
r1 = str x :: object
r2 = bool r1 :: object
if r2 goto L2 else goto L1 :: bool
L1:
r0 = r1
goto L3
L2:
r3 = str y :: object
r0 = r3
L3:
return r0
[case testSimpleNot]
def f(x: int, y: int) -> int:
if not (x < y):
x = 1
return x
[out]
def f(x, y):
x, y :: int
r0 :: bool
r1 :: short_int
L0:
r0 = x < y :: int
if r0 goto L2 else goto L1 :: bool
L1:
r1 = 1
x = r1
L2:
return x
[case testNotAnd]
def f(x: int, y: int) -> int:
if not (x < y and x > y):
x = 1
return x
[out]
def f(x, y):
x, y :: int
r0, r1 :: bool
r2 :: short_int
L0:
r0 = x < y :: int
if r0 goto L1 else goto L2 :: bool
L1:
r1 = x > y :: int
if r1 goto L3 else goto L2 :: bool
L2:
r2 = 1
x = r2
L3:
return x
[case testWhile]
def f(x: int, y: int) -> int:
while x > y:
x = x - y
return x
[out]
def f(x, y):
x, y :: int
r0 :: bool
r1 :: int
L0:
L1:
r0 = x > y :: int
if r0 goto L2 else goto L3 :: bool
L2:
r1 = x - y :: int
x = r1
goto L1
L3:
return x
[case testWhile2]
def f(x: int, y: int) -> int:
x = 1
while x > y:
x = x - y
return x
[out]
def f(x, y):
x, y :: int
r0 :: short_int
r1 :: bool
r2 :: int
L0:
r0 = 1
x = r0
L1:
r1 = x > y :: int
if r1 goto L2 else goto L3 :: bool
L2:
r2 = x - y :: int
x = r2
goto L1
L3:
return x
[case testImplicitNoneReturn]
def f() -> None:
pass
[out]
def f():
r0 :: None
L0:
r0 = None
return r0
[case testImplicitNoneReturn2]
def f() -> None:
x = 1
[out]
def f():
r0 :: short_int
x :: int
r1 :: None
L0:
r0 = 1
x = r0
r1 = None
return r1
[case testImplicitNoneReturnAndIf]
def f(x: int, y: int) -> None:
if x < y:
x = 1
else:
y = 2
[out]
def f(x, y):
x, y :: int
r0 :: bool
r1, r2 :: short_int
r3 :: None
L0:
r0 = x < y :: int
if r0 goto L1 else goto L2 :: bool
L1:
r1 = 1
x = r1
goto L3
L2:
r2 = 2
y = r2
L3:
r3 = None
return r3
[case testRecursion]
def f(n: int) -> int:
if n <= 1:
return 1
else:
return f(n - 1) + f(n - 2)
[out]
def f(n):
n :: int
r0 :: short_int
r1 :: bool
r2, r3 :: short_int
r4, r5 :: int
r6 :: short_int
r7, r8, r9 :: int
L0:
r0 = 1
r1 = n <= r0 :: int
if r1 goto L1 else goto L2 :: bool
L1:
r2 = 1
return r2
L2:
r3 = 1
r4 = n - r3 :: int
r5 = f(r4)
r6 = 2
r7 = n - r6 :: int
r8 = f(r7)
r9 = r5 + r8 :: int
return r9
L3:
unreachable
[case testReportTypeCheckError]
def f() -> None:
return 1 # E: No return value expected
[case testReportSemanticaAnalysisError1]
def f(x: List[int]) -> None: pass # E: Name 'List' is not defined \
# N: Did you forget to import it from "typing"? (Suggestion: "from typing import List")
[case testReportSemanticaAnalysisError2]
def f() -> None:
x # E: Name 'x' is not defined
[case testElif]
def f(n: int) -> int:
if n < 0:
x = 1
elif n == 0:
x = 1
else:
x = 2
return x
[out]
def f(n):
n :: int
r0 :: short_int
r1 :: bool
r2 :: short_int
x :: int
r3 :: short_int
r4 :: bool
r5, r6 :: short_int
L0:
r0 = 0
r1 = n < r0 :: int
if r1 goto L1 else goto L2 :: bool
L1:
r2 = 1
x = r2
goto L6
L2:
r3 = 0
r4 = n == r3 :: int
if r4 goto L3 else goto L4 :: bool
L3:
r5 = 1
x = r5
goto L5
L4:
r6 = 2
x = r6
L5:
L6:
return x
[case testUnaryMinus]
def f(n: int) -> int:
return -1
[out]
def f(n):
n :: int
r0 :: short_int
r1 :: int
L0:
r0 = 1
r1 = -r0 :: int
return r1
[case testConditionalExpr]
def f(n: int) -> int:
return 0 if n == 0 else 1
[out]
def f(n):
n :: int
r0 :: short_int
r1 :: bool
r2 :: int
r3, r4 :: short_int
L0:
r0 = 0
r1 = n == r0 :: int
if r1 goto L1 else goto L2 :: bool
L1:
r3 = 0
r2 = r3
goto L3
L2:
r4 = 1
r2 = r4
L3:
return r2
[case testOperatorAssignment]
def f() -> int:
x = 0
x += 1
return x
[out]
def f():
r0 :: short_int
x :: int
r1 :: short_int
r2 :: int
L0:
r0 = 0
x = r0
r1 = 1
r2 = x += r1 :: int
x = r2
return x
[case testTrue]
def f() -> bool:
return True
[out]
def f():
r0 :: bool
L0:
r0 = True
return r0
[case testFalse]
def f() -> bool:
return False
[out]
def f():
r0 :: bool
L0:
r0 = False
return r0
[case testBoolCond]
def f(x: bool) -> bool:
if x:
return False
else:
return True
[out]
def f(x):
x, r0, r1 :: bool
L0:
if x goto L1 else goto L2 :: bool
L1:
r0 = False
return r0
L2:
r1 = True
return r1
L3:
unreachable
[case testPycall]
import testmodule
def f(x: int) -> int:
return testmodule.factorial(x)
[file testmodule.py]
def factorial(x: int) -> int:
if x == 0:
return 1
else:
return x * factorial(x-1)
[out]
def f(x):
x :: int
r0 :: object
r1 :: str
r2, r3, r4 :: object
r5 :: int
L0:
r0 = testmodule.module :: static
r1 = unicode_2 :: static ('factorial')
r2 = getattr r0, r1
r3 = box(int, x)
r4 = py_call(r2, r3)
r5 = unbox(int, r4)
return r5
[case testFromImport]
from testmodule import g
def f(x: int) -> int:
return g(x)
[file testmodule.py]
def g(x: int) -> int:
return x + 1
[out]
def f(x):
x :: int
r0 :: dict
r1 :: str
r2, r3, r4 :: object
r5 :: int
L0:
r0 = __main__.globals :: static
r1 = unicode_2 :: static ('g')
r2 = r0[r1] :: dict
r3 = box(int, x)
r4 = py_call(r2, r3)
r5 = unbox(int, r4)
return r5
[case testPrintFullname]
import builtins
def f(x: int) -> None:
builtins.print(5)
[out]
def f(x):
x :: int
r0 :: object
r1 :: str
r2 :: object
r3 :: short_int
r4, r5 :: object
r6, r7 :: None
L0:
r0 = builtins.module :: static
r1 = unicode_1 :: static ('print')
r2 = getattr r0, r1
r3 = 5
r4 = box(short_int, r3)
r5 = py_call(r2, r4)
r6 = unbox(None, r5)
r7 = None
return r7
[case testPrint]
import builtins
def f(x: int) -> None:
print(5)
[out]
def f(x):
x :: int
r0 :: short_int
r1 :: object
r2 :: str
r3, r4, r5 :: object
r6, r7 :: None
L0:
r0 = 5
r1 = builtins.module :: static
r2 = unicode_1 :: static ('print')
r3 = getattr r1, r2
r4 = box(short_int, r0)
r5 = py_call(r3, r4)
r6 = unbox(None, r5)
r7 = None
return r7
[case testUnicodeLiteral]
def f() -> str:
x = "some string"
return "some other string"
[out]
def f():
r0, x, r1 :: str
L0:
r0 = unicode_1 :: static ('some string')
x = r0
r1 = unicode_2 :: static ('some other string')
return r1
[case testBytesLiteral]
def f() -> bytes:
x = b'\xf0'
return b'1234'
[out]
def f():
r0, x, r1 :: object
L0:
r0 = bytes_1 :: static (b'\xf0')
x = r0
r1 = bytes_2 :: static (b'1234')
return r1
[case testPyMethodCall1]
from typing import Any
def f(x: Any) -> int:
y: int = x.pop()
return x.pop()
[out]
def f(x):
x :: object
r0 :: str
r1 :: object
y, r2 :: int
r3 :: str
r4 :: object
r5 :: int
L0:
r0 = unicode_3 :: static ('pop')
r1 = py_method_call(x, r0)
r2 = unbox(int, r1)
y = r2
r3 = unicode_3 :: static ('pop')
r4 = py_method_call(x, r3)
r5 = unbox(int, r4)
return r5
[case testObjectType]
def g(y: object) -> None:
g(y)
g([1])
g(None)
[out]
def g(y):
y :: object
r0 :: None
r1 :: short_int
r2 :: object
r3 :: list
r4, r5 :: None
r6 :: object
r7, r8 :: None
L0:
r0 = g(y)
r1 = 1
r2 = box(short_int, r1)
r3 = [r2]
r4 = g(r3)
r5 = None
r6 = box(None, r5)
r7 = g(r6)
r8 = None
return r8
[case testCoerceToObject1]
def g(y: object) -> object:
g(1)
a = [y]
a[0] = (1, 2)
y = True
return 3
[out]
def g(y):
y :: object
r0 :: short_int
r1, r2 :: object
r3, a :: list
r4, r5 :: short_int
r6 :: tuple[int, int]
r7 :: short_int
r8 :: object
r9, r10 :: bool
r11 :: object
r12 :: short_int
r13 :: object
L0:
r0 = 1
r1 = box(short_int, r0)
r2 = g(r1)
r3 = [y]
a = r3
r4 = 1
r5 = 2
r6 = (r4, r5)
r7 = 0
r8 = box(tuple[int, int], r6)
r9 = a.__setitem__(r7, r8) :: list
r10 = True
r11 = box(bool, r10)
y = r11
r12 = 3
r13 = box(short_int, r12)
return r13
[case testCoerceToObject2]
class A:
x: object
n: int
def f(a: A, o: object) -> None:
a.x = 1
o = a.n
[out]
def f(a, o):
a :: A
o :: object
r0 :: short_int
r1 :: object
r2 :: bool
r3 :: int
r4 :: object
r5 :: None
L0:
r0 = 1
r1 = box(short_int, r0)
a.x = r1; r2 = is_error
r3 = a.n
r4 = box(int, r3)
o = r4
r5 = None
return r5
[case testDownCast]
from typing import cast, List, Tuple
class A: pass
def f(x: object) -> None:
n = cast(int, x)
b = cast(bool, x)
a = cast(A, x)
l = cast(List[int], x)
t = cast(Tuple[int, A], x)
[out]
def f(x):
x :: object
r0, n :: int
r1, b :: bool
r2, a :: A
r3, l :: list
r4, t :: tuple[int, A]
r5 :: None
L0:
r0 = unbox(int, x)
n = r0
r1 = unbox(bool, x)
b = r1
r2 = cast(A, x)
a = r2
r3 = cast(list, x)
l = r3
r4 = unbox(tuple[int, A], x)
t = r4
r5 = None
return r5
[case testDownCastSpecialCases]
from typing import cast, Optional, Tuple
class A: pass
def f(o: Optional[A], n: int, t: Tuple[int, ...]) -> None:
a = cast(A, o)
m = cast(bool, n)
tt: Tuple[int, int]
t = tt
[out]
def f(o, n, t):
o :: union[A, None]
n :: int
t :: tuple
r0, a :: A
r1 :: object
r2, m :: bool
tt :: tuple[int, int]
r3 :: object
r4 :: None
L0:
r0 = cast(A, o)
a = r0
r1 = box(int, n)
r2 = unbox(bool, r1)
m = r2
r3 = box(tuple[int, int], tt)
t = r3
r4 = None
return r4
[case testSuccessfulCast]
from typing import cast, Optional, Tuple, List, Dict
class A: pass
def f(o: object,
p: Optional[A],
n: int,
b: bool,
t: Tuple[int, ...],
s: Tuple[int, int],
a: A,
l: List[A],
d: Dict[int, str]) -> None:
o = cast(object, o)
p = cast(Optional[A], p)
n = cast(int, n)
b = cast(bool, b)
t = cast(Tuple[int, ...], t)
s = cast(Tuple[int, int], s)
o = cast(object, n)
a = cast(A, a)
l2 = cast(List[object], l)
d2 = cast(Dict[object, str], d)
[out]
def f(o, p, n, b, t, s, a, l, d):
o :: object
p :: union[A, None]
n :: int
b :: bool
t :: tuple
s :: tuple[int, int]
a :: A
l :: list
d :: dict
r0 :: object
l2 :: list
d2 :: dict
r1 :: None
L0:
o = o
p = p
n = n
b = b
t = t
s = s
r0 = box(int, n)
o = r0
a = a
l2 = l
d2 = d
r1 = None
return r1
[case testGenericSetItem]
from typing import Any
def f(x: Any, y: Any, z: Any) -> None:
x[y] = z
[out]
def f(x, y, z):
x, y, z :: object
r0 :: bool
r1 :: None
L0:
r0 = x.__setitem__(y, z) :: object
r1 = None
return r1
[case testLoadFloatSum]
def assign_and_return_float_sum() -> float:
f1 = 1.0
f2 = 2.0
f3 = 3.0
return f1 * f2 + f3
[out]
def assign_and_return_float_sum():
r0, f1, r1, f2, r2, f3 :: float
r3 :: object
r4 :: float
r5 :: object
r6 :: float
L0:
r0 = float_1 :: static (1.0)
f1 = r0
r1 = float_2 :: static (2.0)
f2 = r1
r2 = float_3 :: static (3.0)
f3 = r2
r3 = f1 * f2
r4 = cast(float, r3)
r5 = r4 + f3
r6 = cast(float, r5)
return r6
[case testLoadComplex]
def load() -> complex:
return 5j+1.0
[out]
def load():
r0 :: object
r1 :: float
r2 :: object
L0:
r0 = complex_1 :: static (5j)
r1 = float_2 :: static (1.0)
r2 = r0 + r1
return r2
[case testBigIntLiteral]
def big_int() -> None:
a_62_bit = 4611686018427387902
max_62_bit = 4611686018427387903
b_63_bit = 4611686018427387904
c_63_bit = 9223372036854775806
max_63_bit = 9223372036854775807
d_64_bit = 9223372036854775808
max_32_bit = 2147483647
max_31_bit = 1073741823
[out]
def big_int():
r0, a_62_bit, r1, max_62_bit, r2, b_63_bit, r3, c_63_bit, r4, max_63_bit, r5, d_64_bit, r6, max_32_bit :: int
r7 :: short_int
max_31_bit :: int
r8 :: None
L0:
r0 = int_1 :: static (4611686018427387902)
a_62_bit = r0
r1 = int_2 :: static (4611686018427387903)
max_62_bit = r1
r2 = int_3 :: static (4611686018427387904)
b_63_bit = r2
r3 = int_4 :: static (9223372036854775806)
c_63_bit = r3
r4 = int_5 :: static (9223372036854775807)
max_63_bit = r4
r5 = int_6 :: static (9223372036854775808)
d_64_bit = r5
r6 = int_7 :: static (2147483647)
max_32_bit = r6
r7 = 1073741823
max_31_bit = r7
r8 = None
return r8
[case testCallableTypes]
from typing import Callable
def absolute_value(x: int) -> int: