@@ -14,23 +14,21 @@ use sml_frontend::ast::*;
14
14
use sml_util:: diagnostics:: Diagnostic ;
15
15
use sml_util:: interner:: * ;
16
16
use sml_util:: span:: Span ;
17
-
18
17
use std:: collections:: { HashSet , VecDeque } ;
19
18
20
19
const BUILTIN_CONSTRUCTORS : [ Symbol ; 5 ] = [ S_NIL , S_CONS , S_TRUE , S_FALSE , S_REF ] ;
21
20
22
- # [ derive ( Default , Debug ) ]
23
- pub struct Check {
21
+ pub struct Check < ' a > {
22
+ interner : & ' a Interner ,
24
23
pub diags : Vec < Diagnostic > ,
25
24
}
26
25
27
- impl Check {
28
- pub fn check_program ( program : & [ Decl ] ) -> Vec < Diagnostic > {
29
- let mut check = Check { diags : Vec :: new ( ) } ;
30
- for d in program {
31
- check . check_decl ( d ) ;
26
+ impl < ' a > Check < ' a > {
27
+ pub fn new ( interner : & ' a Interner ) -> Self {
28
+ Self {
29
+ interner ,
30
+ diags : Vec :: new ( ) ,
32
31
}
33
- check. diags
34
32
}
35
33
36
34
fn check_pat ( & mut self , pattern : & Pat ) {
@@ -59,7 +57,10 @@ impl Check {
59
57
self . diags . push (
60
58
Diagnostic :: error (
61
59
pattern. span ,
62
- format ! ( "duplicate variable in pattern: '{:?}'" , sym) ,
60
+ format ! (
61
+ "duplicate variable in pattern: '{}'" ,
62
+ self . interner. get( * sym) . unwrap_or( "?" )
63
+ ) ,
63
64
)
64
65
. message ( pat. span , "redefined here" ) ,
65
66
) ;
@@ -77,7 +78,10 @@ impl Check {
77
78
if !set. insert ( row. label ) {
78
79
self . diags . push ( Diagnostic :: error (
79
80
row. span ,
80
- format ! ( "duplicate record label: '{:?}'" , row. label) ,
81
+ format ! (
82
+ "duplicate record label: '{}'" ,
83
+ self . interner. get( row. label) . unwrap_or( "?" )
84
+ ) ,
81
85
) ) ;
82
86
}
83
87
f ( self , & row. data ) ;
@@ -171,7 +175,10 @@ impl Check {
171
175
if !set. insert ( tv) {
172
176
self . diags . push ( Diagnostic :: error (
173
177
sp,
174
- format ! ( "type variable '{:?}' cannot be rebound" , tv) ,
178
+ format ! (
179
+ "type variable '{}' cannot be rebound" ,
180
+ self . interner. get( * tv) . unwrap_or( "?" )
181
+ ) ,
175
182
) ) ;
176
183
}
177
184
}
@@ -188,8 +195,8 @@ impl Check {
188
195
self . diags . push ( Diagnostic :: error (
189
196
con. span ,
190
197
format ! (
191
- "builtin data constructor '{:? }' cannot be rebound" ,
192
- con. label
198
+ "builtin data constructor '{}' cannot be rebound" ,
199
+ self . interner . get ( con. label) . unwrap_or ( "?" )
193
200
) ,
194
201
) ) ;
195
202
}
@@ -207,7 +214,10 @@ impl Check {
207
214
if BUILTIN_CONSTRUCTORS . contains ( & s) {
208
215
self . diags . push ( Diagnostic :: error (
209
216
pat. span ,
210
- format ! ( "builtin data constructor '{:?}' cannot be rebound" , s) ,
217
+ format ! (
218
+ "builtin data constructor '{}' cannot be rebound" ,
219
+ self . interner. get( s) . unwrap_or( "?" )
220
+ ) ,
211
221
) ) ;
212
222
}
213
223
}
@@ -226,16 +236,17 @@ impl Check {
226
236
self . diags . push ( Diagnostic :: error (
227
237
fb. span ,
228
238
format ! (
229
- "function clause with a different name; expected: {:?}, found {:?}" ,
230
- n, fb. name
239
+ "function clause with a different name; expected: {}, found {}" ,
240
+ self . interner. get( n) . unwrap_or( "?" ) ,
241
+ self . interner. get( fb. name) . unwrap_or( "?" )
231
242
) ,
232
243
) ) ;
233
244
}
234
245
if a != fb. pats . len ( ) {
235
246
self . diags . push ( Diagnostic :: error (
236
247
fb. span ,
237
248
format ! (
238
- "function clause with a different number of args; expected: {:? }, found {:? }" ,
249
+ "function clause with a different number of args; expected: {}, found {}" ,
239
250
a, fb. pats. len( )
240
251
)
241
252
) ) ;
@@ -245,8 +256,8 @@ impl Check {
245
256
self . diags . push ( Diagnostic :: error (
246
257
f. span ,
247
258
format ! (
248
- "function '{:? }' was previously defined in function bindings" ,
249
- n
259
+ "function '{}' was previously defined in function bindings" ,
260
+ self . interner . get ( n ) . unwrap_or ( "?" )
250
261
) ,
251
262
) ) ;
252
263
}
0 commit comments