[Verse] How do you reference modules in different folder ?

Hey,

I’ve been trying to organize my code in different folders. However, this has been difficult as I can’t find a working way to reference other modules I defined.

The using command refuses to take localhost as a path.

I need to use different folders, because else defnitions are causing problem. For example, if I want to define type aliases to be used in multiple files, I can’t because of some weird declaration errors. : Can’t access a type alias from a preceding expression.(3502)

Code example :
Both files in the same folder
file1

 player_map := [player]int
   var PlayerList<public> : player_map = map{}

file2

    var OtherPlayerList<public> : player_map = map{}

I will get the error in file2, and in file1 if I move the alias declaration.

Is there any way to solve this problem ? Is there any documention on how to structure the files in uefn ?

1 Like

Hi @The_Fump:

I actually can’t reproduce the issue as described. You should be able to have the following two files in the same folder:

file1.verse

using { /Verse.org/Simulation }

player_map := [player]int
A:= class:
    var PlayerList<public> : player_map = map{}

file2.verse

B:= class:
    var OtherPlayerList<public> : player_map = map{}

This should compile fine. You shouldn’t need to include any other using statements because the two files are still within the same module. A folder is treated implicitly as a Verse module by the compiler.

Could you post the full Verse source code and the folder structure you have so that I can see why the semantic analyzer is giving you that diagnostic?

Also, you can refer to Modules and Paths for more information on how Verse paths work.

Docs are incorrect or there are bugs in Verse. To reference module from a different folder DOT has to be used. For ex:

  • Verse/main_device.verse
  • Verse/MyModule/another_device.verse
# another_device.verse:
ModuleInsideMyModule<public> := module:
        another_device := class(creative_device):

To use another_device in main_device:

using { MyModule.ModuleInsideMyModule }

Another weird thing I found is that after moving another_device deeper to Verse/MyModule/MyModule2 there’s no way to reference it as it’s internal to “MyModule”.

6 Likes

Thanks @Kamyker, this is very useful.

Thanks @sonictke, unfortunately I can’t provide a repro, I moved to a different structure and now when I try to get the issue again it’s doesn’t happen.

An couple additional things on the issue from what I could see :

  • The order of folders seemed important : if I added _ before file2, then the issue would disappear.
  • I didn’t use the verse creator to create all my files, I also used the explorer to quickly make them instead.

If I find a repro, i’ll make sure to update this thread.

1 Like

I think to reproduce the bug, you need to create the files in a specific order.

I also get a “Can’t access preceding type” error when trying to access parametrics across files.

#FileA.verse
parametric_class(t: type)=class:

#FileB.verse
child_class:=class(parametric_class(int)):

This sometimes errors and sometimes works.
If you rename FileA, then it will error. If you rename FileB, then the error disappears. If you rename FileA again, then it errors again.