diff --git a/linter/src/lib.rs b/linter/src/lib.rs index eb454ff..64868b0 100644 --- a/linter/src/lib.rs +++ b/linter/src/lib.rs @@ -11,6 +11,7 @@ use typetable::*; type ResultTreeType = Result<(Rc>, Ty), usize>; +#[derive(Debug)] pub struct LintSource<'buf, 'ttb, 'sco> { buffer: &'buf str, idx: u32, @@ -124,7 +125,7 @@ impl<'buf, 'ttb, 'sco> LintSource<'buf, 'ttb, 'sco> { self.inc_scope_tracker(); if let Some(args) = td.args.as_ref() { args.iter().for_each(|x| { - let res = self.lint_recurse(x); + let res = self.check_arg_def(&x.into_arg_def()); if let Ok(a) = res { largs.push(a.0); largs_curried.push(a.1); @@ -311,15 +312,14 @@ impl<'buf, 'ttb, 'sco> LintSource<'buf, 'ttb, 'sco> { } pub fn check_value_type(&mut self, _vt: &ValueType) -> ResultTreeType { - let mut curried = Ty::Unknown; - match _vt.val.token { - Token::U64 => curried = Ty::U64, - Token::U32 => curried = Ty::U32, - Token::USize => curried = Ty::USize, - Token::ISize => curried = Ty::ISize, - Token::F64 => curried = Ty::F64, - Token::U8 => curried = Ty::U8, - Token::Char => curried = Ty::Char, + let curried = match _vt.val.token { + Token::U64 => Ty::U64, + Token::U32 => Ty::U32, + Token::USize => Ty::USize, + Token::ISize => Ty::ISize, + Token::F64 => Ty::F64, + Token::U8 => Ty::U8, + Token::Char => Ty::Char, _ => panic!("type lang issue, unmatched value type: {:?}", _vt.val), }; let copied = curried.clone(); @@ -339,24 +339,39 @@ impl<'buf, 'ttb, 'sco> LintSource<'buf, 'ttb, 'sco> { let mut c_err: Option = None; let mut c_undefined: Option = None; let mut curried = Ty::Unknown; + let mut tag = vec![]; if let Some(right) = &_sig.right_most_type { c_right = match self.lint_recurse(&right) { - Err(_) => Some(Ty::Unknown), - Ok(v) => Some(v.1), + Err(_) => { + tag.push(Ty::Unknown); + Some(Ty::Unknown) + } + Ok(v) => { + tag.push(v.1.clone()); + Some(v.1) + } } } if let Some(left) = &_sig.left_most_type { c_left = match self.lint_recurse(&left) { - Err(_) => Ty::Unknown, - Ok(v) => v.1, + Err(_) => { + tag.push(Ty::Unknown); + Ty::Unknown + } + Ok(v) => { + tag.push(v.1.clone()); + v.1 + } } } if let Some(_) = &_sig.err { c_err = Some(Ty::Error); + tag.push(Ty::Error); } if let Some(_) = &_sig.undef { c_undefined = Some(Ty::Undefined); + tag.push(Ty::Undefined); } if c_right.is_some() || c_err.is_some() || c_undefined.is_some() { sig_info.left = c_left; @@ -364,12 +379,14 @@ impl<'buf, 'ttb, 'sco> LintSource<'buf, 'ttb, 'sco> { sig_info.undefined = c_undefined; sig_info.right = c_right; let full = tree!(SigTypes, sig_info); + curried = Ty::Tag(tag); return Ok((full, curried)); } - let full = tree!(SingleType, c_left); - return Ok((full, curried)); + curried = c_left.clone(); + let full = tree!(SingleType, curried); + return Ok((full, c_left)); } pub fn check_self_value(&mut self) -> ResultTreeType { @@ -835,7 +852,7 @@ impl<'buf, 'ttb, 'sco> LintSource<'buf, 'ttb, 'sco> { let tbl = self.ttbls.get_mut(self.curr_scope as usize).unwrap(); - let full: Rc> = tree!(SelfAccess, a); + let full: Rc> = tree!(SelfInit, a); tbl.table.insert("self".to_string(), Rc::clone(&full)); return Ok((full, curried)); @@ -1237,6 +1254,24 @@ mod tests { assert!(linter.issues.len() == 0); } #[test] + fn it_should_handle_sigs() { + const TEST_STR: &'static str = " + const val: zerror!?usize = 2 + const val2: !?usize = 3 + const val3: ?usize = 4 + const val4: usize = 5 + "; + let lexer = TLexer::new(TEST_STR); + let mut parser = Parser::new(lexer); + let result = parser.all(); + let mut tts = vec![]; + let mut scps = vec![]; + let mut linter = LintSource::new(TEST_STR, &mut scps, &mut tts); + let _ = linter.lint_check(&result.unwrap()); + + assert!(linter.issues.len() == 0); + } + #[test] fn it_should_handle_global_data() { const TEST_STR: &'static str = "const val: usize = 2 const main = fn() void { return 7 + val } diff --git a/playground.ty b/playground.ty index d334793..a50f73d 100644 --- a/playground.ty +++ b/playground.ty @@ -4,8 +4,8 @@ pub type Motorcycle = struct { } // Data has a type. can be manually declared with : -const x = 7; -const y: usize = 7; +const x = 7 +const y: usize = 7 // Types have types // this is usually redundant @@ -29,7 +29,7 @@ impl Car = trait(Movable) { // default implementations can be achieved pub const set_wheels_default = fn(self: Movable, wheels: u8) void { - self.wheels = wheels; + self.wheels = wheels } // default implementation