mirror of
https://github.com/roc-lang/roc.git
synced 2025-12-23 08:48:03 +00:00
Fix frac unify
This commit is contained in:
parent
c58afd7d39
commit
96779768c1
3 changed files with 26 additions and 25 deletions
|
|
@ -6040,17 +6040,6 @@ fn currentScopeIdx(self: *Self) usize {
|
|||
|
||||
/// This will be used later for builtins like Num.nan, Num.infinity, etc.
|
||||
pub fn addNonFiniteFloat(self: *Self, value: f64, region: base.Region) !Expr.Idx {
|
||||
// Dec doesn't have infinity, -infinity, or NaN
|
||||
const requirements = types.Num.Frac.Requirements{
|
||||
.fits_in_f32 = true,
|
||||
.fits_in_dec = false,
|
||||
};
|
||||
|
||||
const frac_requirements = types.Num.FracRequirements{
|
||||
.fits_in_f32 = requirements.fits_in_f32,
|
||||
.fits_in_dec = requirements.fits_in_dec,
|
||||
};
|
||||
|
||||
// then in the final slot the actual expr is inserted
|
||||
const expr_idx = try self.env.addExprAndTypeVar(
|
||||
CIR.Expr{
|
||||
|
|
@ -6059,7 +6048,7 @@ pub fn addNonFiniteFloat(self: *Self, value: f64, region: base.Region) !Expr.Idx
|
|||
.has_suffix = false,
|
||||
},
|
||||
},
|
||||
Content{ .structure = .{ .num = .{ .frac_unbound = frac_requirements } } },
|
||||
.err,
|
||||
region,
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -743,7 +743,7 @@ test "check type - binops math sub" {
|
|||
\\
|
||||
\\x = 1 - 0.2
|
||||
;
|
||||
try assertFileTypeCheckPass(source, "Num(Int(Unsigned32))");
|
||||
try assertFileTypeCheckPass(source, "Num(Frac(_size))");
|
||||
}
|
||||
|
||||
test "check type - binops ord" {
|
||||
|
|
|
|||
|
|
@ -1185,12 +1185,18 @@ fn Unifier(comptime StoreTypeB: type) type {
|
|||
.int_requirements = b_reqs.int_requirements.unify(a_reqs.int_requirements),
|
||||
.frac_requirements = b_reqs.frac_requirements.unify(a_reqs.frac_requirements),
|
||||
} } } }),
|
||||
.int_unbound => |a_reqs| self.merge(vars, .{ .structure = .{ .num = .{
|
||||
.int_unbound = b_reqs.int_requirements.unify(a_reqs),
|
||||
} } }),
|
||||
.frac_unbound => |a_reqs| self.merge(vars, .{ .structure = .{ .num = .{
|
||||
.frac_unbound = b_reqs.frac_requirements.unify(a_reqs),
|
||||
} } }),
|
||||
.int_unbound => |a_reqs| {
|
||||
const poly_unbound = self.fresh(vars, .{ .structure = .{
|
||||
.num = .{ .int_unbound = b_reqs.int_requirements.unify(a_reqs) },
|
||||
} }) catch return Error.AllocatorError;
|
||||
self.merge(vars, .{ .structure = .{ .num = .{ .num_poly = poly_unbound } } });
|
||||
},
|
||||
.frac_unbound => |a_reqs| {
|
||||
const poly_unbound = self.fresh(vars, .{ .structure = .{
|
||||
.num = .{ .frac_unbound = b_reqs.frac_requirements.unify(a_reqs) },
|
||||
} }) catch return Error.AllocatorError;
|
||||
self.merge(vars, .{ .structure = .{ .num = .{ .num_poly = poly_unbound } } });
|
||||
},
|
||||
|
||||
// If the variable inside an int with a precision
|
||||
.int_resolved => |a_int| {
|
||||
|
|
@ -1256,12 +1262,18 @@ fn Unifier(comptime StoreTypeB: type) type {
|
|||
.int_requirements = a_reqs.int_requirements.unify(b_reqs.int_requirements),
|
||||
.frac_requirements = a_reqs.frac_requirements.unify(b_reqs.frac_requirements),
|
||||
} } } }),
|
||||
.int_unbound => |b_reqs| self.merge(vars, .{ .structure = .{ .num = .{
|
||||
.int_unbound = a_reqs.int_requirements.unify(b_reqs),
|
||||
} } }),
|
||||
.frac_unbound => |b_reqs| self.merge(vars, .{ .structure = .{ .num = .{
|
||||
.frac_unbound = a_reqs.frac_requirements.unify(b_reqs),
|
||||
} } }),
|
||||
.int_unbound => |b_reqs| {
|
||||
const poly_unbound = self.fresh(vars, .{ .structure = .{
|
||||
.num = .{ .int_unbound = a_reqs.int_requirements.unify(b_reqs) },
|
||||
} }) catch return Error.AllocatorError;
|
||||
self.merge(vars, .{ .structure = .{ .num = .{ .num_poly = poly_unbound } } });
|
||||
},
|
||||
.frac_unbound => |b_reqs| {
|
||||
const poly_unbound = self.fresh(vars, .{ .structure = .{
|
||||
.num = .{ .frac_unbound = a_reqs.frac_requirements.unify(b_reqs) },
|
||||
} }) catch return Error.AllocatorError;
|
||||
self.merge(vars, .{ .structure = .{ .num = .{ .num_poly = poly_unbound } } });
|
||||
},
|
||||
|
||||
// If the variable inside an int with a precision
|
||||
.int_resolved => |b_int| {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue