authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2020-10-16 17:05:13+03:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2020-10-30 15:58:13+02:00
log3c96d799531dbfaf4127ed2fcaa0e69658f90e23
tree643fc5fee4e70e84f7624af258199b66bb9af397
parent7db17a2d89c866efadf9a487acf2f9b0535ba859
signaturelock-open Commit is signed but in an unrecognized format.

stage2: disallow switching on floats


2 files changed, 6 insertions(+), 5 deletions(-)

src/zir.zig+1-1
......@@ -275,7 +275,7 @@ pub const Inst = struct {
275275 /// A switch expression.
276276 switchbr,
277277 /// A range in a switch case, `lhs...rhs`.
278 /// Only checks that `lhs >= rhs` if they are ints or floats, everything else is
278 /// Only checks that `lhs >= rhs` if they are ints, everything else is
279279 /// validated by the .switch instruction.
280280 switch_range,
281281
src/zir_sema.zig+5-4
......@@ -1214,11 +1214,11 @@ fn analyzeInstSwitchRange(mod: *Module, scope: *Scope, inst: *zir.Inst.BinOp) In
12141214 const end = try resolveInst(mod, scope, inst.positionals.rhs);
12151215
12161216 switch (start.ty.zigTypeTag()) {
1217 .Int, .ComptimeInt, .Float, .ComptimeFloat => {},
1217 .Int, .ComptimeInt => {},
12181218 else => return mod.constVoid(scope, inst.base.src),
12191219 }
12201220 switch (end.ty.zigTypeTag()) {
1221 .Int, .ComptimeInt, .Float, .ComptimeFloat => {},
1221 .Int, .ComptimeInt => {},
12221222 else => return mod.constVoid(scope, inst.base.src),
12231223 }
12241224 if (start.value()) |start_val| {
......@@ -1280,7 +1280,7 @@ fn validateSwitch(mod: *Module, scope: *Scope, target: *Inst, inst: *zir.Inst.Sw
12801280 // check that target type supports ranges
12811281 if (inst.kw_args.range) |range_inst| {
12821282 switch (target.ty.zigTypeTag()) {
1283 .Int, .ComptimeInt, .Float, .ComptimeFloat => {},
1283 .Int, .ComptimeInt => {},
12841284 else => {
12851285 return mod.fail(scope, target.src, "ranges not allowed when switching on type {}", .{target.ty});
12861286 // TODO notes "range used here" range_inst.src
......@@ -1291,7 +1291,6 @@ fn validateSwitch(mod: *Module, scope: *Scope, target: *Inst, inst: *zir.Inst.Sw
12911291 // validate for duplicate items/missing else prong
12921292 switch (target.ty.zigTypeTag()) {
12931293 .Int, .ComptimeInt => return mod.fail(scope, inst.base.src, "TODO validateSwitch .Int, .ComptimeInt", .{}),
1294 .Float, .ComptimeFloat => return mod.fail(scope, inst.base.src, "TODO validateSwitch .Float, .ComptimeFloat", .{}),
12951294 .Enum => return mod.fail(scope, inst.base.src, "TODO validateSwitch .Enum", .{}),
12961295 .ErrorSet => return mod.fail(scope, inst.base.src, "TODO validateSwitch .ErrorSet", .{}),
12971296 .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
13501349 .Vector,
13511350 .Frame,
13521351 .AnyFrame,
1352 .ComptimeFloat,
1353 .Float,
13531354 => {
13541355 return mod.fail(scope, target.src, "invalid switch target type '{}'", .{target.ty});
13551356 },