Hashlink incoherent error message "string" should be a number

I am trying to develop an application in Haxe, I would like to use hashlink for performance.

The results didn’t made sense for me, so I hooked the debugger, but I could not get whats going on

THis is my function

 function is_match(callid:String,did:String,ip:String,cfg:Config){
	 var t1=(callid==null || cfg.callid==callid);
	 var t2=(did==null || cfg.hotline==did);
	 var t3=(ip==null || cfg.ip==ip);
	 trace(t1,t2,t3);
	 var is_match= t1 && t2 && t3;
	trace(callid,did,ip,cfg,is_match);
	return is_match;
 }

in regular sense did==cfg.hotline, the other parameters are null (meaning any)
I would expect all conditons to be true.
Unfortanly t2 was false.

I added some watch expressions in the vscode haslink debugger
cfg.hotline==did: “9457208489” should be a number
Std.parseInt(did)==Std.parseInt(cfg.hotline): true

I couldn’t wrap my head around why comparing two equal strings should fail, and what the error is about, why does it expect a number.
the cfg class have been instantiated with Json.parse, it might not be a proper class, however the field in the json file is a string, same when checking with the debugger its value.

What furthor action/test do anyone recommand?

Thanks

Two thoughts:

  • Please post the code where Config is declared.
  • Try did==cfg.hotline instead of cfg.hotline==did.
class Config {
	public function new() {
		
	}
	public var callid="";
	public var hotline="";
	public var change_callid="";
	public var change_did="";
	public var dest="";
	
	public function dest_is_final(){
		var ip_regex=~/^((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)\.?\b){4}$/g;
		return ip_regex.match(dest);
	}
	//source ip htat is allowed to use this route
	public var ip="";
	public var priority=0;
}

swapping the right and left values didn’t changed.

I was loading the Config struct from a json file, using haxe.Json.parse, I changed to use the haxelib json2object instead, now the problem is solved, the error is still misleading (or maybe, not leading at all), I would like to understand it, but at least it is working.

I changed from hashlink to python, to be able to continue development (big pro for haxe), I bumped into a situation where i had to call a method on the config, something that wasn’t possible using the Dynamic generated by Json.parse, after changing to json2object I reverted back to hashlink and it is working now.

Thanks anyway

I wish I could understand the error.

That explains it. Json.parse() doesn’t return class instances. and you’re going to run into errors on static targets if you try to use it that way.

json2object looks like a good solution for this case, but for future reference, anonymous structures are fully compatible with Json.parse().

typedef Config = {
	var callid:String;
	var hotline:String;
	var change_callid:String;
	var change_did:String;
	var dest:String;
	//source ip htat is allowed to use this route
	var ip:String;
	var priority:String;
};

Thanks, I see.

And use static extensions for the methods?

Static extensions would work, as would an abstract wrapper. Or stick with json2object, for data validation. Or mix and match; json2object is compatible with anonymous structures and should probably be compatible with abstracts.