Skip to content

Commit 2079d67

Browse files
committed
work on u32
1 parent 2054e27 commit 2079d67

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

src/checker.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,15 @@ impl Checker {
239239
fn check_expr(&mut self, id: ExprID, arena: &ExprArena, decls: &DeclTable) -> TypeID {
240240
let ty = match &arena[id] {
241241
Expr::True | Expr::False => mk_type(Type::Bool),
242-
Expr::Int(_) => mk_type(Type::Int32),
242+
Expr::Int(_) => {
243+
let ty = self.fresh();
244+
let alts = vec![
245+
Alt {ty: mk_type(Type::Int32), interfaces: vec![]},
246+
// Alt {ty: mk_type(Type::UInt32), interfaces: vec![]},
247+
];
248+
self.add_constraint(Constraint::Or(ty, alts, arena.locs[id]));
249+
ty
250+
}
243251
Expr::Real(_) => mk_type(Type::Float32),
244252
Expr::Char(_) => mk_type(Type::Int8),
245253
Expr::String(s) => {
@@ -777,6 +785,7 @@ mod tests {
777785
for decl in &table.decls {
778786
let mut type_checker = Checker::new();
779787
type_checker.check_decl(decl, &table);
788+
type_checker.print_errors();
780789
result.append(&mut type_checker.errors);
781790
}
782791

@@ -798,4 +807,17 @@ mod tests {
798807
let errors = check(s);
799808
assert!(errors.is_empty());
800809
}
810+
811+
#[test]
812+
pub fn test_inc_i32() {
813+
let s = "
814+
f {
815+
var i: i32
816+
i = i + 1
817+
}
818+
";
819+
820+
let errors = check(s);
821+
assert!(errors.is_empty());
822+
}
801823
}

0 commit comments

Comments
 (0)