haxe
haxe copied to clipboard
Missing argument: 3 expected but 2 passed
I am using Map<String, Dynamic>.
When the value is a String this line works only in JS target:
if(mymap["key"].indexOf("text")<0) // do something
It throws a runtime error in HL target: Missing argument: 3 expected but 2 passed
To make it work in HL I have to go to the length of making sure the compiler knows it is a string:
var str:String = mymap["key"]; if(str.indexOf("text")<0) // do something
Is it the expected behaviour? Would be nice if the code behaved the same war on both targets or threw error/warning during compilation and not crash at runtime like it does now.
Newest version of haxe.
You're using Dynamic, so the compiler can't do anything with it and you're at the mercy of the run-time, which may or may not do anything useful with it.
Having said that, I thought dynamic calls were supposed to support missing optional arguments. Does this also fail with Reflect.callMethod?
I encountered the same problem; I am using an Array<Array<Dynamic>> and the following call fails on HashLink with a 'missing argument' error:
var randomChats:Array<Array<Dynamic>>
// ...
randomChats[i].indexOf(str)
I can work around the issue with an explicit cast:
var randomChats:Array<Array<Dynamic>>
// ...
cast(randomChats[i], Array<Dynamic>).indexOf(str)
Another workaround if I remember correctly is just:
var s:String = randomChats[i]; s.indexOf(str)
Haxe has to know it is a string.