Possible bug, extended class properties and __get()

Report problems with documented functionality
OpalMonkey
Posts: 18
Joined: 23 Jan 2014, 03:02

Possible bug, extended class properties and __get()

Post by OpalMonkey » 28 Mar 2014, 03:40

Okay, so not quite sure what to call this. Also not 100% sure it's a bug, but it sure feels like one. Here's the code in question.

Code: Select all

vObj1 := new progen()
vObj2 := new extend1()
vObj3 := new extend2()
MsgBox, % "progen: [" vObj1.Test "]`nextend1: [" vObj2.Test "]`nextend2: [" vObj3.Test "]"
Return

class progen
{
	__Test := 1
	Test() {
	}
	__Get(pName) {
		If ObjHasKey(this, "__" pName)
			Return this["__" pName]
	}
}
class extend1 extends progen
{
	__Test := 2
}
class extend2 extends progen
{
	__Test := 3
	Test() {
	}
}
Here's the expected output.

Code: Select all

progen: [1]
extend1: [2]
extend2: [3]
And here's the actual output.

Code: Select all

progen: [1]
extend1: [2]
extend2: []
The Test method in extend2 seems to be interfering with the property before it can get to the __Get method in progen. The reason I think it's a bug is because the exact same Test method in progen doesn't interfere with anything.

Maybe I'm just missing something? If it's an intended behaviour, I would very much appreciate a brief explanation as to why it works like that. If it is a bug, then I'll just be glad to have found a second bug... after several years of using AHK :)
User avatar
fincs
Posts: 527
Joined: 30 Sep 2013, 14:17
Location: Seville, Spain
Contact:

Re: Possible bug, extended class properties and __get()

Post by fincs » 28 Mar 2014, 04:28

Not a bug, this is the expected behaviour. Elements that are defined more recently in the base-object inheritance tree have more priority. So since Extend2.Test() exists vObj3.Test returns a reference to the function.

EDIT: Corrected the reason.
fincs
Windows 11 Pro (Version 22H2) | AMD Ryzen 7 3700X with 32 GB of RAM | AutoHotkey v2.0.0 + v1.1.36.02
Get SciTE4AutoHotkey v3.1.0 - [My project list]
OpalMonkey
Posts: 18
Joined: 23 Jan 2014, 03:02

Re: Possible bug, extended class properties and __get()

Post by OpalMonkey » 28 Mar 2014, 05:11

Hmm, alright. Thanks fincs. That makes sense. Guess I still don't fully understand how objects work in AHK.

So I'm guessing the only way to get around that would be to add the same __Get method to extend2 so it would take priority?
Post Reply

Return to “Bug Reports”