Functions that require strings also accepting objects

Discuss the future of the AutoHotkey language
iseahound
Posts: 1472
Joined: 13 Aug 2016, 21:04
Contact:

Functions that require strings also accepting objects

Post by iseahound » 11 Dec 2021, 11:54

Is there any guidance of what to expect from the AutoHotkey v2 type system? I noticed recently that it was possible to input objects into string functions such as Trim({prop: "value"}).

I am wondering if functions such as Trim() will eventually call toString(), like in Java. This seems to be the current behavior of String() in v2.

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

Re: Functions that require strings also accepting objects

Post by lexikos » 18 Jun 2022, 19:30

Expectations are documented for each function. Trim specifically says it requires a string and does not even support numbers.
I noticed recently that it was possible to input objects into string functions
It has always been possible, but not exactly valid. For v1, "If an object is used in any context where an object is not expected, it is treated as an empty string." This is still true for functions in v2 that don't explicitly implement type checking, due to cost vs. benefit and implementation reasons. Before the final v2.0 release, my intention is to change the way that built-in functions are linked into the script so that type checking and coercion can be performed for all functions in one place (among other reasons).
functions such as Trim() will eventually call toString()
Yes. See "coercion" above.

Post Reply

Return to “AutoHotkey Development”