Skip to content

Commit 149f6cf

Browse files
committed
Fix the type checking issue
1 parent 3c275ed commit 149f6cf

7 files changed

+30
-31
lines changed

tests/expr7.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
def test_pow():
2-
a: f64
2+
a: i32
33
a = pow(2, 2)
44

5-
6-
def test_pow_1(a: i32, b: i32) -> f64:
7-
res: f64
5+
def test_pow_1(a: i32, b: i32) -> i32:
6+
res: i32
87
res = pow(a, b)
98
return res
109

1110
def main0():
1211
test_pow()
13-
c: f64
12+
c: i32
1413
c = test_pow_1(1, 2)
1514

1615
main0()

tests/reference/asr-expr7-480ba2f.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
"basename": "asr-expr7-480ba2f",
33
"cmd": "lpython --show-asr --no-color {infile} -o {outfile}",
44
"infile": "tests/expr7.py",
5-
"infile_hash": "fae3ed29e0e4f0db9ba4c72e0bf99afa832859b9a4e832a8e8b2f495",
5+
"infile_hash": "4a455e2279eb7dd269d81c1a257dea625b17b100d92e304e5ac34421",
66
"outfile": null,
77
"outfile_hash": null,
8-
"stdout": null,
9-
"stdout_hash": null,
10-
"stderr": "asr-expr7-480ba2f.stderr",
11-
"stderr_hash": "50ced47ea5891f2a40ad48b4bedbf04d2884693ba85db38405d6b0a3",
12-
"returncode": 2
8+
"stdout": "asr-expr7-480ba2f.stdout",
9+
"stdout_hash": "18355b490c6f9e0360d341cfa2eab28d5b9e3efea8fbbbb05b508638",
10+
"stderr": null,
11+
"stderr_hash": null,
12+
"returncode": 0
1313
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
(TranslationUnit (SymbolTable 1 {_lpython_main_program: (Subroutine (SymbolTable 37 {}) _lpython_main_program [] [(SubroutineCall 1 main0 () [] ())] Source Public Implementation () .false. .false.), lpython_builtin: (IntrinsicModule lpython_builtin), main0: (Subroutine (SymbolTable 4 {c: (Variable 4 c Local () () Default (Real 8 []) Source Public Required .false.)}) main0 [] [(SubroutineCall 1 test_pow () [] ()) (= (Var 4 c) (FunctionCall 1 test_pow_1 () [(ConstantInteger 1 (Integer 4 [])) (ConstantInteger 2 (Integer 4 []))] [] (Real 8 []) () ()) ())] Source Public Implementation () .false. .false.), main_program: (Program (SymbolTable 36 {}) main_program [] [(SubroutineCall 1 _lpython_main_program () [] ())]), test_pow: (Subroutine (SymbolTable 2 {a: (Variable 2 a Local () () Default (Real 8 []) Source Public Required .false.), pow: (ExternalSymbol 2 pow 6 pow lpython_builtin [] pow Private)}) test_pow [] [(= (Var 2 a) (FunctionCall 2 pow () [(ConstantInteger 2 (Integer 4 [])) (ConstantInteger 2 (Integer 4 []))] [] (Real 8 []) (ConstantInteger 4 (Integer 4 [])) ()) ())] Source Public Implementation () .false. .false.), test_pow_1: (Function (SymbolTable 3 {_lpython_return_variable: (Variable 3 _lpython_return_variable ReturnVar () () Default (Real 8 []) Source Public Required .false.), a: (Variable 3 a In () () Default (Integer 4 []) Source Public Required .false.), b: (Variable 3 b In () () Default (Integer 4 []) Source Public Required .false.), pow: (ExternalSymbol 3 pow 6 pow lpython_builtin [] pow Private), res: (Variable 3 res Local () () Default (Real 8 []) Source Public Required .false.)}) test_pow_1 [(Var 3 a) (Var 3 b)] [(= (Var 3 res) (FunctionCall 3 pow () [(Var 3 a) (Var 3 b)] [] (Real 8 []) () ()) ()) (= (Var 3 _lpython_return_variable) (Var 3 res) ()) (Return)] (Var 3 _lpython_return_variable) Source Public Implementation ())}) [])
1+
(TranslationUnit (SymbolTable 1 {_lpython_main_program: (Subroutine (SymbolTable 40 {}) _lpython_main_program [] [(SubroutineCall 1 main0 () [] ())] Source Public Implementation () .false. .false.), lpython_builtin: (IntrinsicModule lpython_builtin), main0: (Subroutine (SymbolTable 4 {c: (Variable 4 c Local () () Default (Integer 4 []) Source Public Required .false.)}) main0 [] [(SubroutineCall 1 test_pow () [] ()) (= (Var 4 c) (FunctionCall 1 test_pow_1 () [(ConstantInteger 1 (Integer 4 [])) (ConstantInteger 2 (Integer 4 []))] [] (Integer 4 []) () ()) ())] Source Public Implementation () .false. .false.), main_program: (Program (SymbolTable 39 {}) main_program [] [(SubroutineCall 1 _lpython_main_program () [] ())]), pow@__lpython_overloaded_0__pow: (ExternalSymbol 1 pow@__lpython_overloaded_0__pow 6 __lpython_overloaded_0__pow lpython_builtin [] __lpython_overloaded_0__pow Public), test_pow: (Subroutine (SymbolTable 2 {a: (Variable 2 a Local () () Default (Integer 4 []) Source Public Required .false.), pow: (ExternalSymbol 2 pow 6 pow lpython_builtin [] pow Private)}) test_pow [] [(= (Var 2 a) (FunctionCall 1 pow@__lpython_overloaded_0__pow 2 pow [(ConstantInteger 2 (Integer 4 [])) (ConstantInteger 2 (Integer 4 []))] [] (Integer 4 []) (ConstantInteger 4 (Integer 4 [])) ()) ())] Source Public Implementation () .false. .false.), test_pow_1: (Function (SymbolTable 3 {_lpython_return_variable: (Variable 3 _lpython_return_variable ReturnVar () () Default (Integer 4 []) Source Public Required .false.), a: (Variable 3 a In () () Default (Integer 4 []) Source Public Required .false.), b: (Variable 3 b In () () Default (Integer 4 []) Source Public Required .false.), pow: (ExternalSymbol 3 pow 6 pow lpython_builtin [] pow Private), res: (Variable 3 res Local () () Default (Integer 4 []) Source Public Required .false.)}) test_pow_1 [(Var 3 a) (Var 3 b)] [(= (Var 3 res) (FunctionCall 1 pow@__lpython_overloaded_0__pow 3 pow [(Var 3 a) (Var 3 b)] [] (Integer 4 []) () ()) ()) (= (Var 3 _lpython_return_variable) (Var 3 res) ()) (Return)] (Var 3 _lpython_return_variable) Source Public Implementation ())}) [])

tests/reference/ast-expr7-fe52776.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
"basename": "ast-expr7-fe52776",
33
"cmd": "lpython --show-ast --no-color {infile} -o {outfile}",
44
"infile": "tests/expr7.py",
5-
"infile_hash": "fae3ed29e0e4f0db9ba4c72e0bf99afa832859b9a4e832a8e8b2f495",
5+
"infile_hash": "4a455e2279eb7dd269d81c1a257dea625b17b100d92e304e5ac34421",
66
"outfile": null,
77
"outfile_hash": null,
88
"stdout": "ast-expr7-fe52776.stdout",
9-
"stdout_hash": "c136c389b566b6a8316247fe5dd191e47fd2c593e49c6b50737471a4",
9+
"stdout_hash": "eb95e2f66e29e53b80188f6fd239ae88c21ae560a388437514e44517",
1010
"stderr": null,
1111
"stderr_hash": null,
1212
"returncode": 0
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
(Module [(FunctionDef test_pow ([] [] [] [] [] [] []) [(AnnAssign (Name a Store) (Name f64 Load) () 1) (Assign [(Name a Store)] (Call (Name pow Load) [(ConstantInt 2 ()) (ConstantInt 2 ())] []) ())] [] () ()) (FunctionDef test_pow_1 ([] [(a (Name i32 Load) ()) (b (Name i32 Load) ())] [] [] [] [] []) [(AnnAssign (Name res Store) (Name f64 Load) () 1) (Assign [(Name res Store)] (Call (Name pow Load) [(Name a Load) (Name b Load)] []) ()) (Return (Name res Load))] [] (Name f64 Load) ()) (FunctionDef main0 ([] [] [] [] [] [] []) [(Expr (Call (Name test_pow Load) [] [])) (AnnAssign (Name c Store) (Name f64 Load) () 1) (Assign [(Name c Store)] (Call (Name test_pow_1 Load) [(ConstantInt 1 ()) (ConstantInt 2 ())] []) ())] [] () ()) (Expr (Call (Name main0 Load) [] []))] [])
1+
(Module [(FunctionDef test_pow ([] [] [] [] [] [] []) [(AnnAssign (Name a Store) (Name i32 Load) () 1) (Assign [(Name a Store)] (Call (Name pow Load) [(ConstantInt 2 ()) (ConstantInt 2 ())] []) ())] [] () ()) (FunctionDef test_pow_1 ([] [(a (Name i32 Load) ()) (b (Name i32 Load) ())] [] [] [] [] []) [(AnnAssign (Name res Store) (Name i32 Load) () 1) (Assign [(Name res Store)] (Call (Name pow Load) [(Name a Load) (Name b Load)] []) ()) (Return (Name res Load))] [] (Name i32 Load) ()) (FunctionDef main0 ([] [] [] [] [] [] []) [(Expr (Call (Name test_pow Load) [] [])) (AnnAssign (Name c Store) (Name i32 Load) () 1) (Assign [(Name c Store)] (Call (Name test_pow_1 Load) [(ConstantInt 1 ()) (ConstantInt 2 ())] []) ())] [] () ()) (Expr (Call (Name main0 Load) [] []))] [])

tests/reference/cpp-expr7-529bd53.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
"basename": "cpp-expr7-529bd53",
33
"cmd": "lpython --no-color --show-cpp {infile}",
44
"infile": "tests/expr7.py",
5-
"infile_hash": "fae3ed29e0e4f0db9ba4c72e0bf99afa832859b9a4e832a8e8b2f495",
5+
"infile_hash": "4a455e2279eb7dd269d81c1a257dea625b17b100d92e304e5ac34421",
66
"outfile": null,
77
"outfile_hash": null,
8-
"stdout": null,
9-
"stdout_hash": null,
10-
"stderr": "cpp-expr7-529bd53.stderr",
11-
"stderr_hash": "50ced47ea5891f2a40ad48b4bedbf04d2884693ba85db38405d6b0a3",
12-
"returncode": 2
8+
"stdout": "cpp-expr7-529bd53.stdout",
9+
"stdout_hash": "8a8ded44e2568a07f90eefa92a606bb253483c6c9aed31507b6612a4",
10+
"stderr": null,
11+
"stderr_hash": null,
12+
"returncode": 0
1313
}

tests/reference/cpp-expr7-529bd53.stdout

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,30 +23,30 @@ void _lpython_main_program()
2323

2424
void main0()
2525
{
26-
double c;
26+
int c;
2727
test_pow();
2828
c = test_pow_1(1, 2);
2929
}
3030

3131
void test_pow()
3232
{
33-
double a;
34-
a = pow(2, 2);
33+
int a;
34+
a = __lpython_overloaded_0__pow(2, 2);
3535
}
3636

37-
float test_pow_1(int a, int b)
37+
int test_pow_1(int a, int b)
3838
{
39-
double _lpython_return_variable;
40-
double res;
41-
res = pow(a, b);
39+
int _lpython_return_variable;
40+
int res;
41+
res = __lpython_overloaded_0__pow(a, b);
4242
_lpython_return_variable = res;
4343
return _lpython_return_variable;
4444
}
4545

46-
float pow(int x, int y)
46+
int __lpython_overloaded_0__pow(int x, int y)
4747
{
48-
double _lpython_return_variable;
49-
_lpython_return_variable = 1.000000*(float)(std::pow(x, y));
48+
int _lpython_return_variable;
49+
_lpython_return_variable = std::pow(x, y);
5050
return _lpython_return_variable;
5151
}
5252

0 commit comments

Comments
 (0)