Wish Raising errors or at least warnings if types are not compatible

b4auser1

Well-Known Member
Licensed User
Longtime User
The compiler doesn't raise any errors or at least warnings if types are not compatible (see. sample below) :(
Problems are discovered during run-time testing. It affects development process performance. If it is possible, please add validation of types incompatibility during compilation process.

B4X:
'Code module
#Region  Project Attributes
    #ApplicationLabel: B4i Example
    #Version: 1.0.0
    'Orientation possible values: Portrait, LandscapeLeft, LandscapeRight and PortraitUpsideDown
    #iPhoneOrientations: Portrait, LandscapeLeft, LandscapeRight
    #iPadOrientations: Portrait, LandscapeLeft, LandscapeRight, PortraitUpsideDown
    #Target: iPhone, iPad
    #MinVersion: 7
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'Public variables can be accessed from all modules.
    Public App As Application
    Public NavControl As NavigationController
    Private Page1 As Page

    Type A_type (iValue As Int)
    Type B_Type (sValue As String)

End Sub

Private Sub Application_Start (Nav As NavigationController)
    NavControl = Nav
    Page1.Initialize("Page1")
    Page1.Title = "Page 1"
    Page1.RootPanel.Color = Colors.White
    NavControl.ShowPage(Page1)
   
    Dim A_Value As A_type
        A_Value.Initialize
    Dim B_Value As B_Type
        B_Value.Initialize
   
    A_Value = B_Value

    Dim A_clsValue As clsA
        A_clsValue.Initialize
    Dim B_clsValue As clsB
        B_clsValue.Initialize
   
    A_clsValue = B_clsValue
   
End Sub

Private Sub Page1_Resize(Width As Int, Height As Int)
   
End Sub

Private Sub Application_Background
   
End Sub

B4X:
Sub Class_Globals
    Private m_iValue As Int
End Sub

'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize
    m_iValue = 0
End Sub

Public Sub iValue () As Int
    Return m_iValue
End Sub

B4X:
Sub Class_Globals
    Private m_sValue As String
End Sub

'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize
    m_sValue = ""
End Sub

Public Sub sValue () As String
    Return m_sValue
End Sub
 

stanmiller

Active Member
Licensed User
Longtime User
Where is the error? Can you add a comment in the code section which shows where the error occurs?

Also, if you attach a project to the post anyone can try it in the IDE and learn from this example.

Lastly, how do you workaround the incompatibility at runtime? Is it possible to check the type?, default to some value, log the error, and carry on...
 
Top