Phix type check bug
- Posted by xecronix in June
- 528 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

