Some compiler warnings...

frla

Member
Licensed User
Longtime User
I wish that if it detects ; at the end of the line it will warn me about it... I work a lot also with C# and Delphi (Pascal) and sometimes I add the ; as pure routine.

I would also like to get some kind of warning if I happened to use + instead of &.. now I just stare at the code when I release that the correct character is &...

Otherwise.. great product! Love it! :)
 

Vader

Well-Known Member
Licensed User
Longtime User
It would also be nice to have the comiler warn about things like single-character variable names (i, j, k etc) as they don't follow any documented coding conventions.

And, if people want to ignore warnings, they should be able to turn them off.
 

gawie007

Member
Licensed User
Longtime User
2.70 Beta Warning 2

Hi Erel,
I am not sure if this means anything but I have created a method in a class that returns a string.

The variables vStr and vLen are used in the method.
The following code returns a warning 2, "Not all code paths return a value" on the line Sub Adj...
B4X:
Sub AdjustStringLength(vStr As String, vLen as Int) As String
    Dim retStr As String
    ...
    retStr = "abc"
    Return retStr

if I change this to(which I think was my original code):
B4X:
Sub AdjustStringLength(vStr As String, vLen as Int)
    Dim retStr As String
    ...
    retStr = "abc"
    Return retStr
The last line, "Return retStr" has a warning 3, "Return Type(in Sub signature) should be set explicitly." which is what I tried to do in the first section of code.
Kind regards
Gavin
 
Last edited:

gawie007

Member
Licensed User
Longtime User
Problem solved

Thank's AGraham,
Schoolboy error - had it nested in my outside IF statement. Return MUST BE THE LAST STATEMENT!
Too many early mornings driving past you to customers in Liverpool & a 3 year old girl that doesn't sleep too well!

Thank's Erel,
There is a bug that was actually a Unit test that passed!
I really thought I was onto something and wanted to contribute.
Sorry for wasting your time over this busy period!

Kind regards
Gavin
 

agraham

Expert
Licensed User
Longtime User
Return MUST BE THE LAST STATEMENT!
That is not strictly true. As long as all the paths the code could take include a Return you can have multiple Returns embedded in loops and If statements as long as every possibility Returns a value. Mind you it is very common to need a "catch-all" Return at the end of a Sub to complete the requirement for all paths to return a value.
 

gawie007

Member
Licensed User
Longtime User
You are both right, I have used these in the past - I think that is what threw me off.
My error is the If statement I was using (trying to trap errors inside the class):

B4X:
Sub ..
    If vStr <> Null Then
        ...
        Return retStr
    End If
End Sub
This leaves this with the possibility of no value being returned i.e. vStr = Null
Solution (Not open ended):
B4X:
Sub ..
    If vStr <> Null Then
        ...
        retStr = "notNull"
        Return retStr
    Else
        retStr = "isNull"
        Return retStr
    End If
End Sub
They say you are never too old to learn!
What a basic mistake!
Anyways, on a lighter note, thank you guys for the "Return statement tutorial".
Keep up the GREAT work!!!
....and I will still try to contribute in some little ways.
Cheers
Gavin
 
Top