Types across Code modules

Foz

Member
Licensed User
Longtime User
It appears that it matters in what order Code modules are added when using Types.

Create a new project and then try the following:
Add a code module (mod1)
Add another code module (mod2)
In mod2, in the Process_Globals add
B4X:
Type aaa (a As Int)
Go back to mod1, and add
B4X:
Type zzz (a as aaa)

Now it won't compile - missing type "aaa".

If you do it the other way around (type aaa in mod1 and zzz in mod2) it works.

Can this be fixed please?
 

agraham

Expert
Licensed User
Longtime User
There's a related "problem" that may or may not be worth coding against. While the compiler will pick and error duplicate types with different signatures

B4X:
[COLOR="Blue"]    Mod1              Mod2
Type a (a As Int)    Type a (b As String)[/COLOR]
It will not error when the type signatures are the same, even if the internal types are different. The compiled code however will always use the first definition that it encountered.

B4X:
[COLOR="Blue"]    Mod1                Mod2
Type a (a As Int)    Type a (a As String)[/COLOR]
 

Foz

Member
Licensed User
Longtime User
Is there any sort of work around for this problem with the types?

It kinda stops me dead in my tracks when I'm adding custom types further down the line...

If fact, what is causing it to not compile? The resulting java code shouldn't have a problem with it...
 

Foz

Member
Licensed User
Longtime User
Thanks - but for clean coding, I prefer to keep my types separate as it's as close to OOP style as I can manage within the restrictions of no OOP. ;)

Does this mean it will be fixed in the next version?
 

Foz

Member
Licensed User
Longtime User
Sigh, not fixed yet:
B4X:
Compiling code.                         Error
Error parsing program.
Error description: Unknown type: aaa
Are you missing a library reference?
Occurred on line: 6
Type zzz (a As aaa)
I'll hope and pray for the next version.
 

Joe_L

Member
Licensed User
Longtime User
Is this fixed yet or is there a workaround? I need to create a module containing shared code but can't get the existing modules to recognise it.

B4X:
'Module SharedStuff
Sub Process_Globals
   Type MYTYPE(a As Int, b As string)
End Sub
'end module sharedstuff

'Activity Uses_SharedStuff
    Private Sub Mysub() 
        Dim param As SharedStuff.MYTYPE
        '.....
    End Sub

Parsing code. Error
Error parsing program.
Error description: Unknown type: sharedstuff
Are you missing a library reference?
Occurred on line: 1228
Dim param As SharedStuff.MYTYPE
 
Top