File tree 5 files changed +78
-2
lines changed
5 files changed +78
-2
lines changed Original file line number Diff line number Diff line change @@ -841,6 +841,9 @@ RUN(NAME class_01 LABELS cpython llvm llvm_jit)
841
841
RUN(NAME class_02 LABELS cpython llvm llvm_jit)
842
842
RUN(NAME class_03 LABELS cpython llvm llvm_jit)
843
843
RUN(NAME class_04 LABELS cpython llvm llvm_jit)
844
+ RUN(NAME class_05 LABELS cpython llvm llvm_jit)
845
+ RUN(NAME class_06 LABELS cpython llvm llvm_jit)
846
+
844
847
845
848
# callback_04 is to test emulation. So just run with cpython
846
849
RUN(NAME callback_04 IMPORT_PATH .. LABELS cpython)
Original file line number Diff line number Diff line change
1
+ from lpython import i32
2
+
3
+ class Animal :
4
+ def __init__ (self :"Animal" ):
5
+ self .species : str = "Generic Animal"
6
+ self .age : i32 = 0
7
+ self .is_domestic : bool = True
8
+
9
+ class Dog (Animal ):
10
+ def __init__ (self :"Dog" , name :str , age :i32 ):
11
+ super ().__init__ ()
12
+ self .species : str = "Dog"
13
+ self .name : str = name
14
+ self .age : i32 = age
15
+
16
+ class Cat (Animal ):
17
+ def __init__ (self :"Cat" , name : str , age : i32 ):
18
+ super ().__init__ ()
19
+ self .species : str = "Cat"
20
+ self .name :str = name
21
+ self .age : i32 = age
22
+
23
+ def main ():
24
+ dog : Dog = Dog ("Buddy" , 5 )
25
+ cat : Cat = Cat ("Whiskers" , 3 )
26
+ op1 : str = str (dog .name + " is a " + str (dog .age )+ "-year-old " + dog .species + "." )
27
+ print (op1 )
28
+ assert op1 == "Buddy is a 5-year-old Dog."
29
+ print (dog .is_domestic )
30
+ assert dog .is_domestic == True
31
+ op2 : str = str (cat .name + " is a " + str (cat .age )+ "-year-old " + cat .species + "." )
32
+ print (op2 )
33
+ assert op2 == "Whiskers is a 3-year-old Cat."
34
+ print (cat .is_domestic )
35
+ assert cat .is_domestic == True
36
+
37
+ main ()
Original file line number Diff line number Diff line change
1
+ from lpython import i32
2
+
3
+ class Base ():
4
+ def __init__ (self :"Base" ):
5
+ self .x : i32 = 10
6
+
7
+ def get_x (self :"Base" )-> i32 :
8
+ print (self .x )
9
+ return self .x
10
+
11
+ #Testing polymorphic fn calls
12
+ def get_x_static (d : Base )-> i32 :
13
+ print (d .x )
14
+ return d .x
15
+
16
+ class Derived (Base ):
17
+ def __init__ (self : "Derived" ):
18
+ super ().__init__ ()
19
+ self .y : i32 = 20
20
+
21
+ def get_y (self :"Derived" )-> i32 :
22
+ print (self .y )
23
+ return self .y
24
+
25
+
26
+ def main ():
27
+ d : Derived = Derived ()
28
+ x : i32 = get_x_static (d )
29
+ assert x == 10
30
+ # Testing parent method call using der obj
31
+ x = d .get_x ()
32
+ assert x == 10
33
+ y : i32 = d .get_y ()
34
+ assert y == 20
35
+
36
+ main ()
Original file line number Diff line number Diff line change 8
8
"stdout" : null ,
9
9
"stdout_hash" : null ,
10
10
"stderr" : " asr-structs_09-f3ffe08.stderr" ,
11
- "stderr_hash" : " f59ab2d213f6423e0a891e43d5a19e83d4405391b1c7bf481b4b939e " ,
11
+ "stderr_hash" : " 14119a0bc6420ad242b99395d457f2092014d96d2a1ac81d376c649d " ,
12
12
"returncode" : 2
13
13
}
Original file line number Diff line number Diff line change 1
- semantic error: read not present in StringIO dataclass
1
+ semantic error: Method not found in the class StringIO or it's parents
2
2
--> tests/errors/structs_09.py:13:23
3
3
|
4
4
13 | bytes_read: i32 = fd.read()
You can’t perform that action at this time.
0 commit comments