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

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

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

Post by swagfag » 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: 4709
Joined: 17 Jul 2016, 01:02
Contact:

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

Post by Helgef » 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: 3469
Joined: 09 Oct 2013, 10:31

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

Post by guest3456 » 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: 6222
Joined: 11 Jan 2017, 17:59

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

Post by swagfag » 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: 9690
Joined: 30 Sep 2013, 04:07
Contact:

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

Post by lexikos » 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: 6222
Joined: 11 Jan 2017, 17:59

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

Post by swagfag » 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
Post Reply

Return to “Ask for Help (v2)”