@@ -526,7 +526,7 @@ describe("Method calls", () => {
526
526
expr : {
527
527
tag : "method" ,
528
528
obj : { tag : "id" , name : "x" } ,
529
- field : "test" ,
529
+ method : "test" ,
530
530
args : [ ] ,
531
531
} ,
532
532
} ,
@@ -541,7 +541,7 @@ describe("Method calls", () => {
541
541
expr : {
542
542
tag : "method" ,
543
543
obj : { tag : "getfield" , obj : { tag : "id" , name : "x" } , field : "y" } ,
544
- field : "test" ,
544
+ method : "test" ,
545
545
args : [ ] ,
546
546
} ,
547
547
} ,
@@ -558,15 +558,85 @@ describe("Method calls", () => {
558
558
obj : {
559
559
tag : "method" ,
560
560
obj : { tag : "id" , name : "x" } ,
561
- field : "y" ,
561
+ method : "y" ,
562
562
args : [ ] ,
563
563
} ,
564
- field : "test" ,
564
+ method : "test" ,
565
565
args : [ ] ,
566
566
} ,
567
567
} ,
568
568
] ,
569
569
} ) ;
570
+
571
+ assertTCFail (
572
+ "Ensure we can't call nonexistant methods" ,
573
+ `
574
+ class C(object):
575
+ def test(self : C) -> int:
576
+ return 3
577
+
578
+ x : C = None
579
+ x = C()
580
+ x.funcThatDoesntExist()`
581
+ ) ;
582
+
583
+ assertTCFail (
584
+ "Ensure we can't call on nonclasses" ,
585
+ `
586
+ x : int = 3
587
+ x.asString()`
588
+ ) ;
589
+
590
+ assertTCFail (
591
+ "Ensure method calls are checked like functions" ,
592
+ `
593
+ class C(object):
594
+ def test(self : C, x : int) -> int:
595
+ return x
596
+
597
+ x : C = None
598
+ x = C()
599
+ x.test()`
600
+ ) ;
601
+
602
+ assertTC (
603
+ "Ensure we can call a method" ,
604
+ `
605
+ class C(object):
606
+ def test(self : C, x : int) -> int:
607
+ return x
608
+
609
+ x : C = None
610
+ x = C()
611
+ x.test(3)` ,
612
+ NUM
613
+ ) ;
614
+
615
+ assertTC (
616
+ "Ensure we can call a method with no args" ,
617
+ `
618
+ class C(object):
619
+ def id(self : C) -> C:
620
+ return self
621
+
622
+ x : C = None
623
+ x = C()
624
+ x.id()` ,
625
+ { tag : "object" , class : "C" }
626
+ ) ;
627
+
628
+ assertTC (
629
+ "Ensure we can call a function with None" ,
630
+ `
631
+ class C(object):
632
+ def otherId(self : C, other : C) -> C:
633
+ return other
634
+
635
+ x : C = None
636
+ x = C()
637
+ x.otherId(None)` ,
638
+ { tag : "object" , class : "C" }
639
+ ) ;
570
640
} ) ;
571
641
572
642
// Questions: print_none?
@@ -575,5 +645,4 @@ describe("Method calls", () => {
575
645
// TOOD: method calls on None, runtime error
576
646
// TODO: calls like r1.mul(None), None is an acceptable parameter for a class but should cause a runtime error!
577
647
578
- // TODO: class with no fields, but has methods! Can be called and stuff!
579
- // TODO: method that returns None in place of an object (typechecked)
648
+ // TODO: class with no fields, but has methods! Can be called and stuff with other classes existing!
0 commit comments