New object with bad parameters silently failing

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
danielo515
Posts: 58
Joined: 18 Feb 2015, 15:06

New object with bad parameters silently failing

01 May 2015, 09:32

Hello Everyone,

I'm not sure if this is a Bug or an intended behavior, so feel free to move the thread if it does not fits here.
Today I went absolutely crazy with an objects behavior that took me some hours to figure out. Imagine an object like this

Code: Select all

class test{
   __New(something){
        this.something := something
   }
}
If you call it without parameters, it will not fail, and it will create the object. If you do the same with a function you will get an error, but with objects the only thing that happens is that the function __New never gets executed.

Of course is easy to address just adding somethin:=0 to add a default value, but until you figure this happens you can drive yourself crazy.

Regards.
lexikos
Posts: 9690
Joined: 30 Sep 2013, 04:07
Contact:

Re: New object with bad parameters silently failing

01 May 2015, 20:29

That the method/function isn't called is intended. This is consistent with other dynamic function calls:
If the function cannot be called due to one of the reasons below, the evaluation of the expression containing the call stops silently and prematurely, which may lead to inconsistent results:
  • Calling a nonexistent function, which can be avoided by using If IsFunc(VarContainingFuncName). Except for built-in functions, the called function's definition must exist explicitly in the script by means such as #Include or a non-dynamic call to a library function.
  • Passing too few parameters, which can be avoided by checking IsFunc()'s return value (which is the number of mandatory parameters plus one). Note: In v1.0.48+, passing too many parameters is tolerated; each extra parameter is fully evaluated (including any calls to functions) and then discarded.
That the object is still constructed despite failing to call __New was originally unintended, but is kept for backward-compatibility. It has already been changed in v2.
I'm not sure if this is a Bug or an intended behavior,
In that case, don't post in Bug Reports.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: macromint, peter_ahk, Spawnova, wineguy and 279 guests