[Zig] resistor-color-duo - u4 overflowed

I couldn’t pass the tests even though I had the same solution as vazub's solution for Resistor Color Duo in Zig on Exercism. It shows:

resistor_color_duo.zig:15:34: error: overflow of integer type 'u4' with value '60'
   return @enumToInt(colors[0]) * 10 + @enumToInt(colors[1]);

Adding @as worked:

pub fn colorCode(colors: []const ColorBand) anyerror!isize {
   return @as(isize, @enumToInt(colors[0])) * 10 + @enumToInt(colors[1]);
  1. Yesterday description of exercise talked about colors function. Today there is nothing like that.

There are two exercises that involve resistor colors: Resistor Color and Resistor Color Duo. Only the first has a colors function. Are you mixing them up?

  1. Today I cannot pass the tests even though I have the same solution as vazub’s solution for Resistor Color Duo in Zig on Exercism.

I confirm that the exact linked solution is a valid solution for Resistor Color Duo. There should be no error when running the tests for that exercise with that exact solution. But I get exactly the error you mention if I make exactly this change:

- pub const ColorBand = enum(isize) {
+ pub const ColorBand = enum(u4) {

Are you sure that your solution is not different in this way?

Sorry for confusion. I mistaken resistor-color for restistor-color-duo.

So the only problem I had with overflow which I had solved with @as(isize, ...)

I have this overflow error without adding enum(u4). I am on zig 0.11.0-dev.1817+f6c934677