B4J Question No Error message in the IDE

Midimaster

Active Member
Licensed User
Today I did a copy/paste typo and the IDE did not find this bug, but handled the sub call as normal. But the variable was empty afterwards.

Lets say I would have this function:
B4X:
Sub Button1_Click
    Dim Original As String ="abcdefg"
    Dim After As String  =NonSenseFunction(Original)
    Log("<" & After & "><" & Original &">")
End Sub

Sub NonSenseFunction(text As String) As String
    Return "12345"
End Sub

this would return:
<12345><abcdefg>

But if I do this typo:
B4X:
Sub Button1_Click
    Dim Original As String ="abcdefg"
    Dim After As String  =NonSenseFunction(Original),Original
    Log("<" & After & "><" & Original &">")
End Sub

Sub NonSenseFunction(text As String) As String
    Return "12345"
End Sub
it returns this:
<12345><>

Is this a valid code line? Shouldn't the IDE find that error?
 

stevel05

Expert
Licensed User
Longtime User
Although you should see a warning in the log, something like:

B4X:
Variable declaration type is missing. String type will be used. (warning #5)
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Dim After As String =NonSenseFunction(Original),Original
Snap1.png
 
Upvote 0

Midimaster

Active Member
Licensed User
Yes afterwards I recognized the warning. (It was there from the beginning, but I did not see. )

But did you expect that already inside the SUB the value was redimmed?
B4X:
Sub NonSenseFunction(text As String) As String
    log("TEXT=" & text") ' shows an empty string'
    Return "12345"
End Sub
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
But did you expect that already inside the SUB the value was redimmed?
No, it will be compiled in this order

B4X:
Dim Original As String = ""
Original = "abcdefg"
Dim After As String = ""
After = NonSenseFunction(Original)
Dim Original As String = ""
Log("<" & After & "><" & Original &">")
 
Upvote 0
Top