@@ -36,7 +36,7 @@ impl BuildManager {
36
36
let file = Box :: new ( Self :: parse_file ( & build_source. source , build_source. module ) ) ;
37
37
let symbol_table = SymbolTable :: new ( crate :: symbol_table:: SymbolTableType :: Module , 0 ) ;
38
38
39
- modules. insert ( mod_name, State { file, symbol_table } ) ;
39
+ modules. insert ( mod_name, State :: new ( file) ) ;
40
40
}
41
41
42
42
BuildManager {
@@ -75,24 +75,21 @@ impl BuildManager {
75
75
}
76
76
}
77
77
78
- // TODO: separate this can build to be able to test pre analysis and type checking separately
79
78
// Performs type checking passes over the code
80
79
pub fn type_check ( & mut self ) {
81
80
self . pre_analysis ( ) ;
82
81
for state in self . modules . iter_mut ( ) {
83
82
let mut checker = TypeChecker :: new ( state. 1 , & self . options ) ;
84
- checker. type_check ( ) ;
83
+ for stmt in & state. 1 . file . body {
84
+ checker. type_check ( stmt) ;
85
+ }
85
86
self . errors . append ( & mut checker. errors ) ;
86
87
}
87
88
}
88
89
}
89
90
90
91
#[ cfg( test) ]
91
92
mod tests {
92
- use parser:: ast:: GetNode ;
93
-
94
- use crate :: type_check:: type_evaluator:: TypeEvaluator ;
95
-
96
93
use super :: * ;
97
94
fn snapshot_symbol_table ( source : & str ) -> String {
98
95
let mut manager = BuildManager :: new (
@@ -108,7 +105,7 @@ mod tests {
108
105
109
106
let module = manager. modules . values ( ) . last ( ) . unwrap ( ) ;
110
107
111
- format ! ( "{}" , module. symbol_table )
108
+ format ! ( "{}" , module. get_symbol_table ( ) )
112
109
}
113
110
114
111
fn snapshot_type_check ( source : & str ) -> String {
@@ -126,50 +123,6 @@ mod tests {
126
123
manager. errors . join ( "\n " ) . to_string ( )
127
124
}
128
125
129
- // TODO: refactor and move the test to type check mod
130
- fn snapshot_type_eval ( source : & str ) -> String {
131
- let mut manager = BuildManager :: new (
132
- vec ! [ BuildSource {
133
- path: PathBuf :: from( "test.py" ) ,
134
- module: String :: from( "test" ) ,
135
- source: source. to_string( ) ,
136
- followed: false ,
137
- } ] ,
138
- Settings :: test_settings ( ) ,
139
- ) ;
140
-
141
- manager. build ( ) ;
142
-
143
- let module = manager. modules . values ( ) . last ( ) . unwrap ( ) ;
144
- let symbol_table = module. symbol_table . clone ( ) ;
145
- let enderpy_file = module. file . clone ( ) ;
146
-
147
- let type_eval = TypeEvaluator :: new ( symbol_table) ;
148
-
149
- let mut result = HashMap :: new ( ) ;
150
-
151
- for stmt in enderpy_file. body {
152
- match stmt {
153
- parser:: ast:: Statement :: ExpressionStatement ( e) => {
154
- let t = type_eval. get_type ( & e) ;
155
- match e {
156
- parser:: ast:: Expression :: Name ( n) => {
157
- result. insert ( n. id , t. to_string ( ) ) ;
158
- }
159
- _ => panic ! ( "don't use this test for other expressions" ) ,
160
- }
161
- }
162
- _ => { }
163
- }
164
- }
165
-
166
- // sort result by key
167
- let mut result_sorted = result. clone ( ) . into_iter ( ) . collect :: < Vec < _ > > ( ) ;
168
- result_sorted. sort_by ( |a, b| a. 0 . cmp ( & b. 0 ) ) ;
169
-
170
- return format ! ( "{:#?}" , result_sorted) ;
171
- }
172
-
173
126
macro_rules! snap {
174
127
( $name: tt, $path: tt) => {
175
128
#[ test]
@@ -202,22 +155,6 @@ mod tests {
202
155
} ;
203
156
}
204
157
205
- macro_rules! snap_type_eval {
206
- ( $name: tt, $path: tt) => {
207
- #[ test]
208
- fn $name( ) {
209
- let contents = include_str!( $path) ;
210
- let result = snapshot_type_eval( contents) ;
211
- let mut settings = insta:: Settings :: clone_current( ) ;
212
- settings. set_snapshot_path( "../testdata/output/" ) ;
213
- settings. set_description( contents) ;
214
- settings. bind( || {
215
- insta:: assert_snapshot!( result) ;
216
- } ) ;
217
- }
218
- } ;
219
- }
220
-
221
158
snap ! (
222
159
test_simple_var_assignments,
223
160
"../testdata/inputs/simple_var_assignment.py"
@@ -239,6 +176,4 @@ mod tests {
239
176
test_type_check_list,
240
177
"../testdata/inputs/type_check_list.py"
241
178
) ;
242
-
243
- snap_type_eval ! ( test_type_eval_vars, "../testdata/inputs/type_eval_vars.py" ) ;
244
179
}
0 commit comments