|
1 | 1 | from unittest.mock import Mock, patch |
2 | 2 |
|
3 | 3 | from parser.common import StrRegion |
4 | | -from parser.typecheck.typecheck import NameResolver |
| 4 | +from parser.typecheck.typecheck import ( |
| 5 | + NameResolver, Scope, NameInfo, BoolType, ValType, VoidType, |
| 6 | + FuncInfo, ParamInfo) |
5 | 7 | from test.common import CommonTestCase |
6 | 8 |
|
7 | 9 |
|
@@ -48,6 +50,29 @@ def test_top_scope_attr(self): |
48 | 50 | self.assertIs(v2, nr.top_scope) |
49 | 51 | m.assert_called_once() # Still only once |
50 | 52 |
|
| 53 | + def test_params(self): |
| 54 | + src = ('def f1(bool b0, val v0, string s0, number n0) {let L0=s0..v0;};' |
| 55 | + 'def f2() {}') |
| 56 | + sc = Scope() |
| 57 | + f1_scope = Scope() |
| 58 | + f1_scope.declared = { |
| 59 | + 'b0': NameInfo(f1_scope, 'b0', BoolType(), is_param=True), |
| 60 | + 'v0': (v0 := NameInfo(f1_scope, 'v0', ValType(), is_param=True)), |
| 61 | + 's0': (s0 := NameInfo(f1_scope, 's0', ValType(), is_param=True)), |
| 62 | + 'n0': NameInfo(f1_scope, 'n0', ValType(), is_param=True), |
| 63 | + } |
| 64 | + f1_scope.used = {'v0': v0, 's0': s0} |
| 65 | + sc.declared = { |
| 66 | + 'f1': FuncInfo.from_param_info(sc, 'f1', [ |
| 67 | + ParamInfo('b0', BoolType()), |
| 68 | + ParamInfo('v0', ValType()), |
| 69 | + ParamInfo('s0', ValType()), # val == string == number for now |
| 70 | + ParamInfo('n0', ValType()), |
| 71 | + ], VoidType(), f1_scope), |
| 72 | + 'f2': FuncInfo.from_param_info(sc, 'f2', [], VoidType(), Scope()) |
| 73 | + } |
| 74 | + self.assertEqual(self.getNameResolver(src).run(), sc) |
| 75 | + |
51 | 76 |
|
52 | 77 | class TestNameResolveErrors(CommonTestCase): |
53 | 78 | def test_undefined_var(self): |
|
0 commit comments