ziglings icon indicating copy to clipboard operation
ziglings copied to clipboard

Ex 65 doesn't build

Open ricardomatias opened this issue 2 years ago • 3 comments

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 avatar Aug 02 '22 10:08 ricardomatias

@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"
}

ratfactor avatar Aug 02 '22 20:08 ratfactor

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)

realgdman avatar Aug 09 '22 14:08 realgdman

@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"
}

ricardomatias avatar Aug 09 '22 15:08 ricardomatias

Wild. I do have a Windows desktop here I can test on.

ratfactor avatar Aug 11 '22 19:08 ratfactor

@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!

ratfactor avatar Aug 11 '22 19:08 ratfactor

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 😆

wontaeyang avatar Aug 12 '22 01:08 wontaeyang

@ratfactor oh I got it, I misunderstand wording about "self parameter" and was fixing declaration instead of call.

realgdman avatar Aug 20 '22 18:08 realgdman

@realgdman Thanks for that. Clearly the wording on this one needs a little help!

ratfactor avatar Aug 22 '22 13:08 ratfactor

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!

ratfactor avatar Aug 29 '22 22:08 ratfactor