I've been fixing issues related to our Web builds and I came across something 
strange (in terms of the code generated).

We have this call to `hash`: 
<https://github.com/arturo-lang/arturo/blob/c873dec7accc58ae0ffbab1345fe94f35db94786/src/vm/eval.nim#L563>

`root` is a Value (which is a `ref object`)

And the `hash` to be used is here: 
<https://github.com/arturo-lang/arturo/blob/c873dec7accc58ae0ffbab1345fe94f35db94786/src/vm/values/value.nim#L1151>

I kept getting an `undefined` reference for the value inside `hash` so I 
decided to investigate the issue a bit more. Basically, the _passed_ object to 
`hash` was not nil, while `hash` kept seeing it as nil.

My discovery is that the code generate for hash is a bit peculiar:
    
    
    function hash_1644167535(v_1644167536) {
            // unrelated code
      
      var result_1644177936 = 0;
        
        rawEcho([226,154,160,239,184,143,32,105,110,32,72,65,83,72]);
        if ((v_1644167536[0] == null)) {
        rawEcho([86,32,105,115,32,78,73,76,33,33,33]);
        }
        
        rawEcho(([118,46,107,105,110,100,32,61,32] || 
[]).concat(reprEnum(v_1644167536[0].kind, NTI2113929226) || []));
        result_1644177936 = hash_1644177943(v_1644167536[0].kind);
        switch (v_1644167536[0].kind) {
        case 0:
          break;
        case 1:
          result_1644177936 = HEX21HEX26_1207959555(result_1644177936, 
SetMinus(v_1644167536[0].flags, NonLogicalF_1845493823));
          break;
       
       // more code...
    
    
    Run

Basically, the passed parameter (`v_1644167536`) is accessed continuously via 
`v_1644167536[0]` (as if it was an array!). When I - manually - changed all 
references from `v_1644167536[0]` to `v_1644167536`, it's working fine.

Can you please tell me if it's actually a bug and/or what I could do to 
circumvent this?

P.S. I can obviously open an issue, but I have to make sure it is what I think 
it is. Also, given that the codebase is practically vast, it seems as if it's 
the only case where this is happening. Could it be `hash`? Does it receive any 
special treatment that confuses the compiler? 

Reply via email to