mirror of
https://github.com/roc-lang/roc.git
synced 2025-12-23 08:48:03 +00:00
Remove unnecessary getBool helper
This commit is contained in:
parent
9b6ac7f899
commit
1629b012dd
1 changed files with 12 additions and 18 deletions
|
|
@ -496,12 +496,6 @@ fn freshFromContent(self: *Self, content: Content, rank: types_mod.Rank, new_reg
|
|||
return var_;
|
||||
}
|
||||
|
||||
/// Get the Bool type variable (no instantiation needed since Bool has no type parameters)
|
||||
fn getBool(self: *Self) Var {
|
||||
_ = self;
|
||||
return ModuleEnv.varFrom(can.Can.BUILTIN_BOOL);
|
||||
}
|
||||
|
||||
// fresh vars //
|
||||
|
||||
fn updateVar(self: *Self, target_var: Var, content: types_mod.Content, rank: types_mod.Rank) std.mem.Allocator.Error!void {
|
||||
|
|
@ -2186,7 +2180,7 @@ fn checkExpr(self: *Self, expr_idx: CIR.Expr.Idx, rank: types_mod.Rank, expected
|
|||
does_fx = try self.checkExpr(expr_stmt.body, rank, .no_expectation) or does_fx;
|
||||
const stmt_expr: Var = ModuleEnv.varFrom(expr_stmt.body);
|
||||
|
||||
const bool_var = self.getBool();
|
||||
const bool_var = ModuleEnv.varFrom(can.Can.BUILTIN_BOOL);
|
||||
_ = try self.unify(bool_var, stmt_expr, rank);
|
||||
},
|
||||
else => {
|
||||
|
|
@ -2764,7 +2758,7 @@ fn checkIfElseExpr(
|
|||
// Check the condition of the 1st branch
|
||||
var does_fx = try self.checkExpr(first_branch.cond, rank, .no_expectation);
|
||||
const first_cond_var: Var = ModuleEnv.varFrom(first_branch.cond);
|
||||
const bool_var = self.getBool();
|
||||
const bool_var = ModuleEnv.varFrom(can.Can.BUILTIN_BOOL);
|
||||
const first_cond_result = try self.unify(bool_var, first_cond_var, rank);
|
||||
self.setDetailIfTypeMismatch(first_cond_result, .incompatible_if_cond);
|
||||
|
||||
|
|
@ -2786,7 +2780,7 @@ fn checkIfElseExpr(
|
|||
// Check the branches condition
|
||||
does_fx = try self.checkExpr(branch.cond, rank, .no_expectation) or does_fx;
|
||||
const cond_var: Var = ModuleEnv.varFrom(branch.cond);
|
||||
const branch_bool_var = self.getBool();
|
||||
const branch_bool_var = ModuleEnv.varFrom(can.Can.BUILTIN_BOOL);
|
||||
const cond_result = try self.unify(branch_bool_var, cond_var, rank);
|
||||
self.setDetailIfTypeMismatch(cond_result, .incompatible_if_cond);
|
||||
|
||||
|
|
@ -2809,7 +2803,7 @@ fn checkIfElseExpr(
|
|||
does_fx = try self.checkExpr(remaining_branch.cond, rank, .no_expectation) or does_fx;
|
||||
const remaining_cond_var: Var = ModuleEnv.varFrom(remaining_branch.cond);
|
||||
|
||||
const fresh_bool = self.getBool();
|
||||
const fresh_bool = ModuleEnv.varFrom(can.Can.BUILTIN_BOOL);
|
||||
const remaining_cond_result = try self.unify(fresh_bool, remaining_cond_var, rank);
|
||||
self.setDetailIfTypeMismatch(remaining_cond_result, .incompatible_if_cond);
|
||||
|
||||
|
|
@ -2996,7 +2990,7 @@ fn checkUnaryNotExpr(self: *Self, expr_idx: CIR.Expr.Idx, expr_region: Region, r
|
|||
const result_var = @as(Var, ModuleEnv.varFrom(expr_idx));
|
||||
|
||||
// Create a fresh boolean variable for the operation
|
||||
const bool_var = self.getBool();
|
||||
const bool_var = ModuleEnv.varFrom(can.Can.BUILTIN_BOOL);
|
||||
|
||||
// Unify operand and result with the boolean type
|
||||
_ = try self.unify(bool_var, operand_var, rank);
|
||||
|
|
@ -3078,14 +3072,14 @@ fn checkBinopExpr(
|
|||
const result = try self.unify(lhs_var, rhs_var, rank);
|
||||
|
||||
if (result.isOk()) {
|
||||
const fresh_bool = self.getBool();
|
||||
const fresh_bool = ModuleEnv.varFrom(can.Can.BUILTIN_BOOL);
|
||||
try self.types.setVarRedirect(expr_var, fresh_bool);
|
||||
} else {
|
||||
try self.updateVar(expr_var, .err, rank);
|
||||
}
|
||||
},
|
||||
.@"and" => {
|
||||
const lhs_fresh_bool = self.getBool();
|
||||
const lhs_fresh_bool = ModuleEnv.varFrom(can.Can.BUILTIN_BOOL);
|
||||
const lhs_result = try self.unify(lhs_fresh_bool, lhs_var, rank);
|
||||
self.setDetailIfTypeMismatch(lhs_result, .{ .invalid_bool_binop = .{
|
||||
.binop_expr = expr_idx,
|
||||
|
|
@ -3093,8 +3087,8 @@ fn checkBinopExpr(
|
|||
.binop = .@"and",
|
||||
} });
|
||||
|
||||
const rhs_fresh_bool = self.getBool();
|
||||
const rhs_result = try self.unify(rhs_fresh_bool, rhs_var, rank);
|
||||
const rhs_bool = ModuleEnv.varFrom(can.Can.BUILTIN_BOOL);
|
||||
const rhs_result = try self.unify(rhs_bool, rhs_var, rank);
|
||||
self.setDetailIfTypeMismatch(rhs_result, .{ .invalid_bool_binop = .{
|
||||
.binop_expr = expr_idx,
|
||||
.problem_side = .rhs,
|
||||
|
|
@ -3109,7 +3103,7 @@ fn checkBinopExpr(
|
|||
try self.types.setVarRedirect(expr_var, lhs_var);
|
||||
},
|
||||
.@"or" => {
|
||||
const lhs_fresh_bool = self.getBool();
|
||||
const lhs_fresh_bool = ModuleEnv.varFrom(can.Can.BUILTIN_BOOL);
|
||||
const lhs_result = try self.unify(lhs_fresh_bool, lhs_var, rank);
|
||||
self.setDetailIfTypeMismatch(lhs_result, .{ .invalid_bool_binop = .{
|
||||
.binop_expr = expr_idx,
|
||||
|
|
@ -3117,8 +3111,8 @@ fn checkBinopExpr(
|
|||
.binop = .@"and",
|
||||
} });
|
||||
|
||||
const rhs_fresh_bool = self.getBool();
|
||||
const rhs_result = try self.unify(rhs_fresh_bool, rhs_var, rank);
|
||||
const rhs_bool = ModuleEnv.varFrom(can.Can.BUILTIN_BOOL);
|
||||
const rhs_result = try self.unify(rhs_bool, rhs_var, rank);
|
||||
self.setDetailIfTypeMismatch(rhs_result, .{ .invalid_bool_binop = .{
|
||||
.binop_expr = expr_idx,
|
||||
.problem_side = .rhs,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue