diff --git a/src/zir.zig b/src/zir.zig index e7ca2ce9c490275151134f3b164f81a72025053c..13830947ea1d62f50fedb40943cd95c6ccc94822 100644 --- a/src/zir.zig +++ b/src/zir.zig @@ -275,7 +275,7 @@ pub const Inst = struct { /// A switch expression. switchbr, /// A range in a switch case, `lhs...rhs`. - /// Only checks that `lhs >= rhs` if they are ints or floats, everything else is + /// Only checks that `lhs >= rhs` if they are ints, everything else is /// validated by the .switch instruction. switch_range, diff --git a/src/zir_sema.zig b/src/zir_sema.zig index c0b5b7b7bc4950f70003d23ce21227f9cd35a080..9bad703ce79deca14916421a830bba5b63572206 100644 --- a/src/zir_sema.zig +++ b/src/zir_sema.zig @@ -1214,11 +1214,11 @@ fn analyzeInstSwitchRange(mod: *Module, scope: *Scope, inst: *zir.Inst.BinOp) In const end = try resolveInst(mod, scope, inst.positionals.rhs); switch (start.ty.zigTypeTag()) { - .Int, .ComptimeInt, .Float, .ComptimeFloat => {}, + .Int, .ComptimeInt => {}, else => return mod.constVoid(scope, inst.base.src), } switch (end.ty.zigTypeTag()) { - .Int, .ComptimeInt, .Float, .ComptimeFloat => {}, + .Int, .ComptimeInt => {}, else => return mod.constVoid(scope, inst.base.src), } if (start.value()) |start_val| { @@ -1280,7 +1280,7 @@ fn validateSwitch(mod: *Module, scope: *Scope, target: *Inst, inst: *zir.Inst.Sw // check that target type supports ranges if (inst.kw_args.range) |range_inst| { switch (target.ty.zigTypeTag()) { - .Int, .ComptimeInt, .Float, .ComptimeFloat => {}, + .Int, .ComptimeInt => {}, else => { return mod.fail(scope, target.src, "ranges not allowed when switching on type {}", .{target.ty}); // TODO notes "range used here" range_inst.src @@ -1291,7 +1291,6 @@ fn validateSwitch(mod: *Module, scope: *Scope, target: *Inst, inst: *zir.Inst.Sw // validate for duplicate items/missing else prong switch (target.ty.zigTypeTag()) { .Int, .ComptimeInt => return mod.fail(scope, inst.base.src, "TODO validateSwitch .Int, .ComptimeInt", .{}), - .Float, .ComptimeFloat => return mod.fail(scope, inst.base.src, "TODO validateSwitch .Float, .ComptimeFloat", .{}), .Enum => return mod.fail(scope, inst.base.src, "TODO validateSwitch .Enum", .{}), .ErrorSet => return mod.fail(scope, inst.base.src, "TODO validateSwitch .ErrorSet", .{}), .Union => return mod.fail(scope, inst.base.src, "TODO validateSwitch .Union", .{}), @@ -1350,6 +1349,8 @@ fn validateSwitch(mod: *Module, scope: *Scope, target: *Inst, inst: *zir.Inst.Sw .Vector, .Frame, .AnyFrame, + .ComptimeFloat, + .Float, => { return mod.fail(scope, target.src, "invalid switch target type '{}'", .{target.ty}); },