164 |
| _ => err (cxt, [S "arguments to \"&&\" must have bool type"]) |
| _ => err (cxt, [S "arguments to \"&&\" must have bool type"]) |
165 |
(* end case *) |
(* end case *) |
166 |
end |
end |
167 |
|
| PT.E_Cond(e1, cond, e2) => let |
168 |
|
val (e1', ty1) = checkExpr(env, cxt, e1) |
169 |
|
val (e2', ty2) = checkExpr(env, cxt, e2) |
170 |
|
in |
171 |
|
case checkExpr(env, cxt, cond) |
172 |
|
of (cond', Ty.T_Bool) => |
173 |
|
if U.matchType(ty1, ty2) |
174 |
|
then (AST.E_Cond(cond', e1', e2'), ty1) |
175 |
|
else err (cxt, [ |
176 |
|
S "type do not match in conditional expression\n", |
177 |
|
S " true branch: ", TY ty1, |
178 |
|
S " false branch: ", TY ty2 |
179 |
|
]) |
180 |
|
| (_, ty') => err (cxt, [S "expected bool type, but found ", TY ty']) |
181 |
|
(* end case *) |
182 |
|
end |
183 |
| PT.E_BinOp(e1, rator, e2) => let |
| PT.E_BinOp(e1, rator, e2) => let |
184 |
val (e1', ty1) = checkExpr(env, cxt, e1) |
val (e1', ty1) = checkExpr(env, cxt, e1) |
185 |
val (e2', ty2) = checkExpr(env, cxt, e2) |
val (e2', ty2) = checkExpr(env, cxt, e2) |