Skip to content

Commit 59403d5

Browse files
committed
Implemented simple type inference
- If RHS is an unknown, its type will be inferred as the LHS's type
1 parent 62f5292 commit 59403d5

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/typecheck.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,19 @@ fn check_stmt_types(
6161
Stmt::Skip | Stmt::Step | Stmt::Fork => Ok(()),
6262
Stmt::Assign(lhs, rhs) => {
6363
let lhs_type = st[lhs].tpe();
64-
let rhs_type = check_expr_types(tr, st, handler, rhs)?;
64+
let mut rhs_type = check_expr_types(tr, st, handler, rhs)?;
65+
if rhs_type == Type::Unknown {
66+
rhs_type = lhs_type.clone();
67+
handler.emit_diagnostic_stmt(
68+
tr,
69+
stmt_id,
70+
&format!(
71+
"Inferred RHS type as {:?} from LHS type {:?}.",
72+
rhs_type, lhs_type
73+
),
74+
Level::Warning,
75+
);
76+
}
6577
if lhs_type.is_equivalent(&rhs_type) {
6678
Ok(())
6779
} else {

0 commit comments

Comments
 (0)