@@ -11,6 +11,7 @@ use typetable::*;
11
11
12
12
type ResultTreeType = Result < ( Rc < Box < TypeTree > > , Ty ) , usize > ;
13
13
14
+ #[ derive( Debug ) ]
14
15
pub struct LintSource < ' buf , ' ttb , ' sco > {
15
16
buffer : & ' buf str ,
16
17
idx : u32 ,
@@ -124,7 +125,7 @@ impl<'buf, 'ttb, 'sco> LintSource<'buf, 'ttb, 'sco> {
124
125
self . inc_scope_tracker ( ) ;
125
126
if let Some ( args) = td. args . as_ref ( ) {
126
127
args. iter ( ) . for_each ( |x| {
127
- let res = self . lint_recurse ( x ) ;
128
+ let res = self . check_arg_def ( & x . into_arg_def ( ) ) ;
128
129
if let Ok ( a) = res {
129
130
largs. push ( a. 0 ) ;
130
131
largs_curried. push ( a. 1 ) ;
@@ -311,15 +312,14 @@ impl<'buf, 'ttb, 'sco> LintSource<'buf, 'ttb, 'sco> {
311
312
}
312
313
313
314
pub fn check_value_type ( & mut self , _vt : & ValueType ) -> ResultTreeType {
314
- let mut curried = Ty :: Unknown ;
315
- match _vt. val . token {
316
- Token :: U64 => curried = Ty :: U64 ,
317
- Token :: U32 => curried = Ty :: U32 ,
318
- Token :: USize => curried = Ty :: USize ,
319
- Token :: ISize => curried = Ty :: ISize ,
320
- Token :: F64 => curried = Ty :: F64 ,
321
- Token :: U8 => curried = Ty :: U8 ,
322
- Token :: Char => curried = Ty :: Char ,
315
+ let curried = match _vt. val . token {
316
+ Token :: U64 => Ty :: U64 ,
317
+ Token :: U32 => Ty :: U32 ,
318
+ Token :: USize => Ty :: USize ,
319
+ Token :: ISize => Ty :: ISize ,
320
+ Token :: F64 => Ty :: F64 ,
321
+ Token :: U8 => Ty :: U8 ,
322
+ Token :: Char => Ty :: Char ,
323
323
_ => panic ! ( "type lang issue, unmatched value type: {:?}" , _vt. val) ,
324
324
} ;
325
325
let copied = curried. clone ( ) ;
@@ -339,37 +339,54 @@ impl<'buf, 'ttb, 'sco> LintSource<'buf, 'ttb, 'sco> {
339
339
let mut c_err: Option < Ty > = None ;
340
340
let mut c_undefined: Option < Ty > = None ;
341
341
let mut curried = Ty :: Unknown ;
342
+ let mut tag = vec ! [ ] ;
342
343
343
344
if let Some ( right) = & _sig. right_most_type {
344
345
c_right = match self . lint_recurse ( & right) {
345
- Err ( _) => Some ( Ty :: Unknown ) ,
346
- Ok ( v) => Some ( v. 1 ) ,
346
+ Err ( _) => {
347
+ tag. push ( Ty :: Unknown ) ;
348
+ Some ( Ty :: Unknown )
349
+ }
350
+ Ok ( v) => {
351
+ tag. push ( v. 1 . clone ( ) ) ;
352
+ Some ( v. 1 )
353
+ }
347
354
}
348
355
}
349
356
if let Some ( left) = & _sig. left_most_type {
350
357
c_left = match self . lint_recurse ( & left) {
351
- Err ( _) => Ty :: Unknown ,
352
- Ok ( v) => v. 1 ,
358
+ Err ( _) => {
359
+ tag. push ( Ty :: Unknown ) ;
360
+ Ty :: Unknown
361
+ }
362
+ Ok ( v) => {
363
+ tag. push ( v. 1 . clone ( ) ) ;
364
+ v. 1
365
+ }
353
366
}
354
367
}
355
368
if let Some ( _) = & _sig. err {
356
369
c_err = Some ( Ty :: Error ) ;
370
+ tag. push ( Ty :: Error ) ;
357
371
}
358
372
if let Some ( _) = & _sig. undef {
359
373
c_undefined = Some ( Ty :: Undefined ) ;
374
+ tag. push ( Ty :: Undefined ) ;
360
375
}
361
376
if c_right. is_some ( ) || c_err. is_some ( ) || c_undefined. is_some ( ) {
362
377
sig_info. left = c_left;
363
378
sig_info. err = c_err;
364
379
sig_info. undefined = c_undefined;
365
380
sig_info. right = c_right;
366
381
let full = tree ! ( SigTypes , sig_info) ;
382
+ curried = Ty :: Tag ( tag) ;
367
383
368
384
return Ok ( ( full, curried) ) ;
369
385
}
370
386
371
- let full = tree ! ( SingleType , c_left) ;
372
- return Ok ( ( full, curried) ) ;
387
+ curried = c_left. clone ( ) ;
388
+ let full = tree ! ( SingleType , curried) ;
389
+ return Ok ( ( full, c_left) ) ;
373
390
}
374
391
375
392
pub fn check_self_value ( & mut self ) -> ResultTreeType {
@@ -835,7 +852,7 @@ impl<'buf, 'ttb, 'sco> LintSource<'buf, 'ttb, 'sco> {
835
852
836
853
let tbl = self . ttbls . get_mut ( self . curr_scope as usize ) . unwrap ( ) ;
837
854
838
- let full: Rc < Box < TypeTree > > = tree ! ( SelfAccess , a) ;
855
+ let full: Rc < Box < TypeTree > > = tree ! ( SelfInit , a) ;
839
856
tbl. table . insert ( "self" . to_string ( ) , Rc :: clone ( & full) ) ;
840
857
841
858
return Ok ( ( full, curried) ) ;
@@ -1237,6 +1254,24 @@ mod tests {
1237
1254
assert ! ( linter. issues. len( ) == 0 ) ;
1238
1255
}
1239
1256
#[ test]
1257
+ fn it_should_handle_sigs ( ) {
1258
+ const TEST_STR : & ' static str = "
1259
+ const val: zerror!?usize = 2
1260
+ const val2: !?usize = 3
1261
+ const val3: ?usize = 4
1262
+ const val4: usize = 5
1263
+ " ;
1264
+ let lexer = TLexer :: new ( TEST_STR ) ;
1265
+ let mut parser = Parser :: new ( lexer) ;
1266
+ let result = parser. all ( ) ;
1267
+ let mut tts = vec ! [ ] ;
1268
+ let mut scps = vec ! [ ] ;
1269
+ let mut linter = LintSource :: new ( TEST_STR , & mut scps, & mut tts) ;
1270
+ let _ = linter. lint_check ( & result. unwrap ( ) ) ;
1271
+
1272
+ assert ! ( linter. issues. len( ) == 0 ) ;
1273
+ }
1274
+ #[ test]
1240
1275
fn it_should_handle_global_data ( ) {
1241
1276
const TEST_STR : & ' static str = "const val: usize = 2
1242
1277
const main = fn() void { return 7 + val }
0 commit comments