-
Jul 22nd, 2021, 11:53 PM
#1
Thread Starter
Hyperactive Member
Compiler bug
Greetings,
Yes I made a mistake but I got bitten hard by this in production yesterday.
Create an empty project
In the form load:
dim someObject as object
set someObject = createobject("any.valid.object")
Create an empty function someFunction in form that accepts no arguments
In the form load
someFunction someObject
compile & run
Boom
Access violation.
Why does it even compile?
EDIT
If you make someFunction have a return value like "as boolean" then it no longer compiles
EDIT EDIT
if define someFuncion as a sub instead of a function it also does not compile.
Last edited by vbwins; Jul 23rd, 2021 at 12:08 AM.
-
Jul 23rd, 2021, 09:22 AM
#2
Re: Compiler bug
Just copy/paste all the code that goes into Form1 of an empty Std-EXE (don't describe it in prose) which will show Access Violation once compiled.
And remember: Select Isn't Broken a.k.a. The First Rule of Programming: It's Always Your Fault
cheers,
</wqw>
-
Jul 23rd, 2021, 09:54 AM
#3
Re: Compiler bug
same crash in native code calling __vbaVarIndexLoad
pcode dump more concise, trying to do an array value load after the function call for some reason.
Code:
401890 Form1.Form_Load:
401890 F5 00000000 LitI4 0x0
401895 1B 0000 LitStr str_40152C='Scripting.FilesystemObject'
401898 04 68FF FLdRfVar var_98
40189B 0A 01000C00 ImpAdCallFPR4 rtcCreateObject2
4018A0 04 68FF FLdRfVar var_98
4018A3 FC34 CAdVar
4018A5 FCF8 78FF FStAd var_88
4018A9 35 68FF FFree1Var var_98
4018AC 04 78FF FLdRfVar var_88
4018AF FD93 0940 CDargRef 0x4009 (IDisp | ByRef)
4018B3 04 68FF FLdRfVar var_98
4018B6 10 F8060200 ThisVCallHresult Form1.someFunction
4018BB 04 68FF FLdRfVar var_98
4018BE FEAE 00000100 VarIndexLdVar arg_0 dim:0x1 <-- crash
4018C4 FC8B PopAd
4018C6 35 68FF FFree1Var var_98
4018C9 13 ExitProcHresult
-
Jul 24th, 2021, 10:50 PM
#4
Re: Compiler bug
just because i was bored, i decided to test as described, but i did not get the same error, i got the expected type mismatch trying to pass the object to a function with no parameters
with a return for the function i got "wrong number of arguments or invalid property assignment"
maybe the description wasn't clear enough for me
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Jul 25th, 2021, 05:10 AM
#5
Re: Compiler bug
Originally Posted by westconn1
just because i was bored, i decided to test as described, but i did not get the same error, i got the expected type mismatch trying to pass the object to a function with no parameters
with a return for the function i got "wrong number of arguments or invalid property assignment"
maybe the description wasn't clear enough for me
Same here, Type mismatch error, no compile.
-
Jul 25th, 2021, 05:34 AM
#6
Re: Compiler bug
The empty function returns a Variant value. A variant value can contain an object or an array so the code compiles successfully. You get an access violation error because compiler bug. So to reproduce the error you could do it more simplier:
Code:
Private Sub Form_Load()
foo 2
End Sub
Private Function foo()
foo = Array(1, 2, 3, 4)
End Function
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|