ziglings
ziglings copied to clipboard
Ex 65 doesn't build
It fails with this error after the other problems have been solved.
Compiling 065_builtins2.zig...
.\exercises\065_builtins2.zig:56:5: error: unable to evaluate constant expression
var narcissus: Narcissus = Narcissus{};
@ricardomatias I just ran my checker script against the latest copy of Ziglings using a fresh snapshot of Zig:
$ zig version
0.10.0-dev.3394+1a1b7a3af
Compiling 065_builtins2.zig...
Checking 065_builtins2.zig...
PASSED:
A Narcissus loves all Narcissuses. He has room in his heart for: me myself.
That line 56 looks current. And it should check your minimum Zig version. Hmmmm... Oh, I think there was an instance where somebody was running a new version of Zig, but an old version of the standard library. Maybe it's something like that?
Could you paste the result of zig env
?
Here's mine:
$ zig env
{
"zig_exe": "/home/dave/zig/zig",
"lib_dir": "/home/dave/zig/lib",
"std_dir": "/home/dave/zig/lib/std",
"global_cache_dir": "/home/dave/.cache/zig",
"version": "0.10.0-dev.3394+1a1b7a3af"
}
I have encountered same problem. Windows, Zig is 0.10.0-dev.3475+b3d463c9e.
On a side note, I think it uses local zig-cache in repo folder, not global one.
Even fiddling with official @This()
example sometimes gives that error, so probably it's language issue
Btw, my understanding that you need to add (self: Narcissus)
parameter, but it will complain about self
not used, and supressing with _ = self
explained only in Ex70. (I just happen to know this from somewhere)
@ratfactor sorry for the late reply.. here it is:
{
"zig_exe": "C:\\Users\\Ricardo\\scoop\\apps\\zig-dev\\current\\zig.exe",
"lib_dir": "C:\\Users\\Ricardo\\scoop\\apps\\zig-dev\\current\\lib",
"std_dir": "C:\\Users\\Ricardo\\scoop\\apps\\zig-dev\\current\\lib\\std",
"global_cache_dir": "C:\\Users\\Ricardo\\AppData\\Local\\zig",
"version": "0.10.0-dev.3394+1a1b7a3af"
}
Wild. I do have a Windows desktop here I can test on.
@realgdman Well, a self
parameter should not be required to complete this one. I'm looking for a solution that uses builtins. You can peek at patches/patches/065_builtins2.patch
to see what's expected.
Actually, @ricardomatias, this did not occur to me before for some reason, but could you check your answer versus the "official" answer :point_up:? Thanks!
It's possible that what's expected in this exercise is not clear, in which case it may need some fixing to make it more clear!
I just ran into this too 👀 and was stuck for a while. going back to exercises on methods seem to explain what is going on here 😆
@ratfactor oh I got it, I misunderstand wording about "self parameter" and was fixing declaration instead of call.
@realgdman Thanks for that. Clearly the wording on this one needs a little help!
Okay everybody, I think I've improved it. I didn't fully realize how misleading and confusing the hints were on that one until I went in to fix it. Here it is now:
// Oh dear, we seem to have done something wrong when calling
// this function. We called it as a method, which would work
// if it had a self parameter. But it doesn't. (See above.)
//
// The fix for this is very subtle, but it makes a big
// difference!
const Type2 = narcissus.fetchTheMostBeautifulType();
I hope it's much clearer now that we want to change the calling site, not the declaration! Thanks for all the helpful comments on this issue!