AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

function library - obscure/incorrect error message

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Bug Reports
View previous topic :: View next topic  
Author Message
Lexikos



Joined: 17 Oct 2006
Posts: 2486
Location: Australia, Qld

PostPosted: Sun Sep 16, 2007 6:24 pm    Post subject: function library - obscure/incorrect error message Reply with quote

Let the test script tell this minor tale:
Code:
LibTest_DoesntExist()

LibTest_DoesExist()
{
}

Quote:
---------------------------
LibTest.ahk
---------------------------
Error at line 3 in #include file "...\AutoHotkey\Lib\LibTest.ahk".

Line Text: LibTest_DoesExist()
Error: Duplicate function definition.

The program will exit.
---------------------------
OK
---------------------------
Expected result:
Quote:
---------------------------
LibTest.ahk
---------------------------
Error: Call to nonexistent function.

Specifically: LibTest_DoesntExist()

Line#
---> 001: LibTest_DoesntExist()

The program will exit.
---------------------------
OK
---------------------------
It seems because the nonexistent function is prefixed with the name of the script, AutoHotkey tries to include the script within itself. (I encountered this while testing a script in my function library, after renaming a function.)
Back to top
View user's profile Send private message
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10467

PostPosted: Sun Nov 11, 2007 11:02 pm    Post subject: Reply with quote

Sorry for the late reply. The bug is easy to reproduce thanks to your easy example.

Given the rarity of this bug and the fact that its only consequence is a misleading error message, perhaps it wouldn't be worth the added code size to fix it. Comments are welcome.

Thanks.
Back to top
View user's profile Send private message Send e-mail
Lexikos



Joined: 17 Oct 2006
Posts: 2486
Location: Australia, Qld

PostPosted: Mon Nov 12, 2007 1:30 am    Post subject: Reply with quote

Normally, I would agree. However...
lexikos wrote:
Actually, only one change would be required; in Script::FindFuncInLibrary():
Code:
if (!LoadIncludedFile(sLib[i].path, true, false))
to
Code:
if (!LoadIncludedFile(sLib[i].path, false, false))
There's a comment on that line that explains why true is passed:
Quote:
For performance, pass true for allow-dupe so that it doesn't have to check for a duplicate file (seems too rare to worry about duplicates since by definition, the function doesn't yet exist so it's file shouldn't yet be included).
I tested the change with corrupt's example. The message given is:
Quote:
---------------------------
libtest.ahk
---------------------------
Error: Call to nonexistent function.

Specifically: fun_notsomuch()

Line#
001: fun()
002: fun_wow()
---> 003: fun_notsomuch()
003: Exit
001: {
002: MsgBox,hmm
003: Return
004: }
006: {
007: MsgBox,wow

The program will exit.
---------------------------
OK
---------------------------

Posted in StdLib bug (thread started by majkinetor a couple days after this one. Rolling Eyes)
Back to top
View user's profile Send private message
majkinetor



Joined: 24 May 2006
Posts: 3615
Location: Belgrade

PostPosted: Mon Nov 12, 2007 9:56 am    Post subject: Reply with quote

I think this bug should be fixed. Its not rare at all if you develop stdlib functions.
_________________
Back to top
View user's profile Send private message MSN Messenger
engunneer



Joined: 30 Aug 2005
Posts: 6511
Location: Pacific Northwest, US

PostPosted: Mon Nov 12, 2007 5:25 pm    Post subject: Reply with quote

I also agree. simple fix, no downside, reasonably common problem for developers.
_________________
Unless otherwise noted, all code is untested.
Common Answers: 1.(Loops, Viruses, etc.) 2. Search 3.RTFM
Back to top
View user's profile Send private message Visit poster's website
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10467

PostPosted: Tue Nov 13, 2007 12:23 pm    Post subject: Reply with quote

I hadn't realized the fix was so simple. Due to the risk of introducing new bugs, I'm usually wary of making changes that don't add significant value for 99% of users. But this change seems low-risk.

Although script-loading performance will be slightly reduced (especially for scripts with dozens of included files), you all say it's important enough, so the change will be made.

Thanks for the testing and analysis.
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Bug Reports All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group