1. Phix type check bug
- Posted by xecronix 1 week ago
- 244 views
ChatGPT thinks the bug I'm reporting has to do with the nesting of type check calls. FWIW.
This function is called first. Prior to this function call I type check the sequnece 'token'. It's good.
public function add_var(t_scope scope, sequence file_name,sequence name, t_ast_token token, name_space = "" ) return add_sysmap(_var_map, scope, file_name, name, token, name_space) end function
This is the function the above is calling.
function add_sysmap(integer mapid, t_scope scope, sequence file_name,sequence name, t_ast_token token, name_space = "" ) t_sysmap m = new_sysmap() if idx_of(mapid, scope, file_name, name, name_space) = 0 then m[sysmap_scope] = scope m[sysmap_file_name] = file_name m[sysmap_name] = name m[sysmap_token] = token m[sysmap_namespace] = name_space else return 1 end if if mapid = _fun_map then _funs = append(_funs, m) logger(LOG_DEBUG, sprintf("Added to fun map\n[%s]", {map_entry_str(m)})) return 1 elsif mapid = _var_map then _vars = append(_vars, m) logger(LOG_DEBUG, sprintf("Added to var map\n[%s]", {map_entry_str(m)})) return 1 end if logger(LOG_ERROR, sprintf("add_sysmap: invalid mapid [%d]",{mapid})) return 0 -- could not add fun/var. end function
Both functions call the type checker below. Which I had to relax due to a bug. See the comments in the code for a detailed description of the bug. I'm using Phix Version 1.0.5 32 bit.
public type t_ast_token (object s) if not sequence(s) or length(s) = 0 then sequence msg if s = 0 then -- This message should log but doesn't. Notice the word 'value' in this log message ... msg = sprintf("t_ast_token type check expects a sequence but value [%d] was provided",{s}) else -- This is the message that actually logs... -- Notice the word 'atom' in the log message. -- I'm guessing NULL and 0 are handled differently? IDK -- But you can see I compare s = 0 at the beginning of the block. -- So now I'm in the else block which means s is not 0. But it does -- log this message. This means somehow 0 is not equal to 0 msg = sprintf("t_ast_token type check expects a sequence but atom [%d] was provided",{s}) end if logger(LOG_WARN, msg) -- the following is the message from the log -- [WARNING] [2025-06-21 22:02:29] t_ast_token type check expects a sequence but atom [0] was provided -- there is a bug in type checking somewhere. -- sometimes the type check is called with a NULL or 0 -- I didn't want to do this, but, I couldn't move forward in my project without it. -- Once I relaxed the typecheck the rest of the program did what is was supposed to -- do. I did manually type check via is_token(sequence s) functions prior to this -- chain of events... Not because I normaly manually typecheck, but rather because -- of the issues I was having. return 1 end if atom retval = is_token(s) if retval = 0 then logger(LOG_ERROR, sprintf("type check failure for t_ast_token %s", {s})) abort(1) end if return retval end type public function is_token(sequence s) if equal(s[_ast_token_type], AST_TOKEN_ID) then if s[_ast_token_my_size] = _ast_token_my_size then return 1 end if end if return 0 end function
Just in case someone looking at this asks.
function new_sysmap() sequence m = repeat(0, _sysmap_my_size) m[_sysmap_type] = SYSMAP_ID m[_sysmap_my_size] = _sysmap_my_size return m end function
2. Re: Phix type check bug
- Posted by petelomax 1 week ago
- 188 views
I suspect your main problems right now are all about the "%d".
%d - print an atom as a decimal integer (nb. truncated rather than rounded)
So if s is (say) 0.9999, it would come out as "0".
In fact, somewhat unintentionally but I'm not about to start making it crash now,
should s be {}, or indeed any sequence or string, it'll also come out as 0.
What you probably want is %v, the result of sprint(), which will handle any phix object, instead of %d.
To clarify, [s]printf() mostly mimics the C counterparts, which really only cope with numbers/strings,
whereas [s]print() [without an f] copes with any (single) phix object, of any type and nesting depth,
and the %v format specifier causes the former to invoke the latter.
PS: What I really meant to say is I will make sprintf("%d",{<not atom>}) crash if and only if
there is a pretty strong consensus on this forum to make that change, but not unilaterally.
3. Re: Phix type check bug
- Posted by xecronix 1 week ago
- 177 views
Maybe it's not a bug - in which case, I'll just say thank you for an awesome language. I'm really enjoying using Phix/Euphoria and learning more about it. If everything is working as intended, I definitely don't want any changes.
All the sprintf stuff was just me trying to leave myself a clue in the logs that the type check was being skipped. That way, if I run into a real issue downstream, I'll know where to start looking.
The potential bug I'm seeing is that the type check seems to be called twice - once as expected, and then a second time that I can't account for. Unfortunately, in that second call, the bonafide t_ast_token is zero.
Maybe I'll put together a quick video tomorrow. If you're interested in seeing what I see while stepping through the debugger, great. My goal is just to be helpful.
4. Re: Phix type check bug
- Posted by petelomax 1 week ago
- 160 views
Oh, I've no doubt this thread isn't over, there's an issue you haven't yet managed to express because you ran headlong into %d.
I'm expecting you to get very different and much less confusing logs as soon as you switch to using %v.
I'll be looking for an mcve - a minimum complete verifiable example, that demonstrates and undeniably proves the existence of the problem.
5. Re: Phix type check bug
- Posted by petelomax 1 week ago
- 155 views
Ah, I think I might have spotted it (spaces added to align things):
public function add_var( t_scope scope, sequence file_name, sequence name, t_ast_token token, name_space = "" ) function add_sysmap(integer mapid, t_scope scope, sequence file_name, sequence name, t_ast_token token, name_space = "" )
Phix allows omission of repeated consecutive parameter types (docs), so you could have said "..., sequence filename, name, ..." to the same effect.
It also means that name_space is implicitly of type t_ast_token, which I strongly suspect is not at all what you wanted.
HTH
6. Re: Phix type check bug
- Posted by xecronix 1 week ago
- 150 views
Thank you Pete! The bug was mine. I needed
sequence name_space=""
Unexpected but cool feature, though.
I just got set up for recording my screen, too. I'm glad this business is behind us.