Skip to content

Commit

Permalink
Fix type analysis?
Browse files Browse the repository at this point in the history
  • Loading branch information
Yey007 committed May 17, 2024
1 parent 9dd3bd5 commit d20857f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
![CI Status](https://github.com/ethanuppal/cs3110_compiler/actions/workflows/ci.yaml/badge.svg)

> "x86 is simple trust me bro"
> Last updated: 2024-05-16 15:36:15.102847
> Last updated: 2024-05-16 21:11:04.891980
```
$ ./main -h
Expand Down
8 changes: 4 additions & 4 deletions lib/frontend/analysis.ml
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ let rec infer_stmt (ctx : Type.t Context.t) return_ctx (stmt : stmt) :
(match hint with
| None -> ()
| Some hint_ty ->
if hint_ty <> expr_ty then
if not (Type.equal hint_ty expr_ty) then
raise
(type_mismatch_error hint_ty expr_ty ~msg:"in let statement"
(Right stmt)));
Expand All @@ -216,15 +216,15 @@ let rec infer_stmt (ctx : Type.t Context.t) return_ctx (stmt : stmt) :
(Right stmt))
| If { cond; body } ->
let cond_ty = infer_expr ctx cond in
if cond_ty <> Type.bool_prim_type then
if not (Type.equal cond_ty Type.bool_prim_type) then
raise
(type_mismatch_error Type.bool_prim_type cond_ty
~msg:"in if statement condition" (Right stmt));
infer_body ctx return_ctx body
| Assignment (name, expr) ->
let exp_ty = get_type_of_name ctx name (Right stmt) in
let expr_ty = infer_expr ctx expr in
if exp_ty <> expr_ty then
if not (Type.equal exp_ty expr_ty) then
raise
(type_mismatch_error exp_ty expr_ty
~msg:"variable types cannot be modified" (Right stmt));
Expand All @@ -238,7 +238,7 @@ let rec infer_stmt (ctx : Type.t Context.t) return_ctx (stmt : stmt) :
| None -> Type.unit_prim_type
| Some expr -> infer_expr ctx expr
in
if return_ctx <> expr_ty then
if not (Type.equal return_ctx expr_ty) then
raise
(type_mismatch_error return_ctx expr_ty ~msg:"invalid return type"
(Right stmt));
Expand Down

0 comments on commit d20857f

Please sign in to comment.