[a101] querying instance var tries to call method instead, bug? Topic is solved

Discuss the future of the AutoHotkey language
swagfag
Posts: 2601
Joined: 11 Jan 2017, 17:59

[a101] querying instance var tries to call method instead, bug?

09 May 2019, 11:46

Code: Select all

class Thing
{
	var := 123
}

t := new Thing()
t.var
Image
why is this happening? if i have a property that implements get with sideeffects, i cant use it purely for its side effects alone??
v1 valid, v2 not valid
Helgef
Posts: 3776
Joined: 17 Jul 2016, 01:02
Contact:

Re: [a101] querying instance var tries to call method instead, bug?  Topic is solved

09 May 2019, 11:53

That is a method call without (). No you cannot, alone at the start of a line.

Edit, see Expression Statements.
guest3456
Posts: 2537
Joined: 09 Oct 2013, 10:31

Re: [a101] querying instance var tries to call method instead, bug?

09 May 2019, 12:25

swagfag wrote:
09 May 2019, 11:46
why is this happening?
its a function call with no params, using the new "command-like" syntax.

same as if you typed MsgBox on a line by itself

swagfag
Posts: 2601
Joined: 11 Jan 2017, 17:59

Re: [a101] querying instance var tries to call method instead, bug?

09 May 2019, 12:44

the very last line
Method calls which lack parentheses take the remainder of the line as their parameter list. For example, ExcelApp.Quit or x.y.z "my parameter". This is technically not an expression, but rather a method call statement.
lexikos
Posts: 6397
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: [a101] querying instance var tries to call method instead, bug?

09 May 2019, 18:12

If you find yourself getting a property just for its side-effects and not its value, you should re-think your design.
swagfag
Posts: 2601
Joined: 11 Jan 2017, 17:59

Re: [a101] querying instance var tries to call method instead, bug?

10 May 2019, 07:08

yes ive scrapped it already
i was porting some v1 and was surprised to find out it didnt compile, is all

Return to “AutoHotkey v2 Development”

Who is online

Users browsing this forum: No registered users and 5 guests