AutoHotkey Community

It is currently May 27th, 2012, 6:48 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 11 posts ] 
Author Message
PostPosted: May 23rd, 2011, 2:17 pm 
Offline
User avatar

Joined: May 10th, 2007, 10:54 am
Posts: 649
Location: .switzerland
Edit: It turned out that the error is just a (wrong) #Warn Message, see some Posts below :arrow: http://www.autohotkey.com/forum/viewtop ... 575#446575

_________________
http://securityvision.ch
AHK 2D GAME ENGINE


Last edited by IsNull on May 23rd, 2011, 4:01 pm, edited 2 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 23rd, 2011, 2:35 pm 
Offline
User avatar

Joined: May 5th, 2007, 7:24 pm
Posts: 1240
Location: Seville, Spain
You have to use the base pseudo-keyword alone (kind of like super in Java). Please read the manual before confirming it's a bug next time:
Code:
c := new BetterCar(10, "hu")

class Car
{
   var Name := []
   
   __New(name){
      MsgBox I'm the base Constructor and was called
      this.Name := name
   }
}

class BetterCar extends Car
{
   var Name
   var X
   __New(x, name){
      this.X := x
      base.__New(name)
   }
}

_________________
fincs
Highly recommended: AutoHotkey_L (see why) (all my code snippets require it)
Formal request to polyethene - I support the unity of the AutoHotkey community
Get SciTE4AutoHotkey v3.0.00 (Release Candidate)
[My project list]


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 23rd, 2011, 3:11 pm 
Offline
User avatar

Joined: May 10th, 2007, 10:54 am
Posts: 649
Location: .switzerland
When #Warn is turned on (I've it always turned on), base.__New() throws an "Using value of uninitialized variable"-Warn Exception, so base.__New() is not valid code I thought.

(Coming with a C# background, I tried base.__new() first, but it won't work as explained above)

So it seems to be an bug in the #Warn System then...

If you can confirm this I update the initial posting.

_________________
http://securityvision.ch
AHK 2D GAME ENGINE


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 23rd, 2011, 3:30 pm 
Offline
User avatar

Joined: May 10th, 2007, 10:54 am
Posts: 649
Location: .switzerland
I got the problematic part now. I used also the provided debug example to detect improperly invocations of non objects:

Code:

;Base
{
   "".base.__Call := "Default__Warn"
   "".base.__Set  := "Default__Warn"
   "".base.__Get  := "Default__Warn"

   Default__Warn(nonobj, p1="", p2="", p3="", p4="")
   {
      ListLines
      MsgBox A non-object value was improperly invoked.`n`nSpecifically: %nonobj%
   }
}

#Warn
#Warn, LocalSameAsGlobal, Off


game := new TicTacToeGame()

class PlayTable2D
{
   __New(){
   }
   
}

class TicTacToeGame extends PlayTable2D
{
   __New(){
      base.__New()
   }
}


The above code will produce the "Using value of uninitialized variable" Warning Message on the --> base.__New() Line.

_________________
http://securityvision.ch
AHK 2D GAME ENGINE


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 27th, 2011, 3:10 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7503
Location: Australia
Technically, base hasn't been initialized - base itself has no value. Invocations like base.Method() work via the default base mechanism. Since the warnings are undesirable, it will be changed at some point.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 31st, 2011, 4:32 pm 
Offline
User avatar

Joined: May 10th, 2007, 10:54 am
Posts: 649
Location: .switzerland
Quote:
Since the warnings are undesirable, it will be changed at some point.

That would be nice, thank you. (Or any other mechanism (additional #Warn directive maybe) to detect calls to (object) Methods which doesn't exist would be fine too)

_________________
http://securityvision.ch
AHK 2D GAME ENGINE


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 17th, 2011, 2:30 pm 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7503
Location: Australia
The following change has been implemented in v1.1.00.01:
Quote:
Changed: base.Method() no longer triggers a default meta-function or a warning.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 25th, 2011, 2:39 am 
Offline

Joined: May 29th, 2011, 3:06 am
Posts: 85
Looks like this one might have popped up again.
Code:
#Warn All

BB := new B

class A
{
}
class B extends A
{
    Var1 := "1"
}
Warning: Using value of uninitialized variable. Specifically: base
---> 000: base.__Init()

Seems to only occur for instance variables in sub classes though.
AHK_L v1.1.2.2


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 2nd, 2011, 4:54 am 
Offline

Joined: May 29th, 2011, 3:06 am
Posts: 85
Ah, Lexikos (or other bug fixing folk - I dunno if there are any), I'm not sure if you saw the previous post about the warnings for base coming up again? It's still occurs 1.1.3.0 anyhow, when there are instance variables in the subclass only it seems.

Can you let me know if you see this please? Thanks :)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 2nd, 2011, 5:17 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7503
Location: Australia
This occurs because base.__Init() isn't handled; i.e. because the base class has no __Init method. It won't occur if you declare at least one instance variable in the base class. Note that an instance variable declared in one class can be reassigned by a declaration in a derived class.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 2nd, 2011, 9:14 am 
Offline

Joined: May 29th, 2011, 3:06 am
Posts: 85
Hmm, ok. Well, to avoid this problem could it do something like base.HasKey("__Init") internally to verify that method exists before trying to invoke it?

Or perhaps it would be faster to have an internal flag to indicate if a class object or any of it's bases needed to run __Init when constructed? Just wondering what would be the fastest way to do it without invoking __Call for using HasKey (assuming it does or would do that).


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 11 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 4 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
cron
Powered by phpBB® Forum Software © phpBB Group