My compiler is 0.10.1 downloaded straight from the github page. I also thought it had to be “old”, because for loops (like for (things, 0..) |thing, i|) in other projects were broken.
Also, now I’m very VERY confused. I’ve tried to dumb down my example to something simpler, easier to tackle and the error message is even worse:
my code is:
_ = eql(u8, word, "GET");
and the error message is:
/archive/ARCHIVE/sources/zeb/src/http.zig:53:25: error: expected type '[]u8', found '[]const u8'
2 => {
^
What is going on? Why is the compiler pointing me to a completely different part of the program, but the initial error message is the same as in the example of the original post?
Another discovery:
Normally I’d use zig build test to run all of my tests and running my project that way apparently causes the issue to occur. Without clearing the global and the local caches and running just zig build works fine - everything compiles, no errors, no warnings.
Note that the code that I’m trying to get to work is not placed is a test block
I suggest you post a complete program (a test would work the best), as minimal as possible, that reproduces your symptom. Right now we are not seeing your imports or the rest of the code, it is very difficult to guess what may be going on. Also, please include the output of zig version.
/archive/ARCHIVE/sources/zeb/src/http.zig:41:43: error: expected type '[]u8', found '[]const u8'
} else if (eql(u8, word, "GET")) {
~~~^~~~~~~~~~~~~~~~~
/archive/ARCHIVE/sources/zeb/src/http.zig:41:43: note: cast discards const qualifier
referenced by:
parseHttp: /archive/ARCHIVE/sources/zeb/src/server.zig:4:38
start: /archive/ARCHIVE/sources/zeb/src/server.zig:41:39
remaining reference traces hidden; use '-freference-trace' to see all reference traces
error: test...
error: The following command exited with error code 1:
/archive/ARCHIVE/zig-bootstrap-0.10.1/zig-bootstrap-0.10.1/out/host/bin/zig test /archive/ARCHIVE/sources/zeb/src/server.zig --cache-dir /archive/ARCHIVE/sources/zeb/zig-cache --global-cache-dir /home/kamil/.cache/zig --name test --pkg-begin network /archive/ARCHIVE/sources/zeb/zig-network/network.zig --pkg-end --enable-cache
error: the following build command failed with exit code 1:
/archive/ARCHIVE/sources/zeb/zig-cache/o/91ee4fae979ffd9866c9825a2464d259/build /archive/ARCHIVE/zig-bootstrap-0.10.1/zig-bootstrap-0.10.1/out/host/bin/zig /archive/ARCHIVE/sources/zeb /archive/ARCHIVE/sources/zeb/zig-cache /home/kamil/.cache/zig test
So the first thing I would say to try here is starting with this error message. You are saying it’s a u8, but the compiler is complaining that you are discarding a const qualifier. So perhaps const u8 is appropriate here. I think going one piece at a time is probably a good way to start.
Also, be careful with storing word as the route field in HttpRequestInfo since tokenize produces slices pointing to the bytes in line; when line goes out of scope, you’ll have a slice pointing to garbage memory.
Just so you know, most Zig projects at the moment track the master branch, and are using a completely different compiler than the one from 0.10. Unless you see in a Zig project’s readme that they are using an older version of Zig, they are probably tracking master (or they were when they last updated their code). I’d recommend downloading a more recent version of Zig than 0.10. 0.11 will be officially released soon though.
IMHO using stable version of Zig (currently 0.10) is not a good strategy at all.
Unless there’s a specific reason, going with the nightly build and adapting to the changes as they arrive is easier than migrating the code to the next release when it comes in one go.