BBx-Kitchen / bbj-language-server

BBj Language Server
MIT License
7 stars 6 forks source link

initializing a variable with null() breaks later discovery of types #92

Closed StephanWald closed 2 months ago

StephanWald commented 1 year ago

In the following example

tc!=null()
tc! = BBjAPI().getThinClient()
clientfs! = tc!.getClientFileSystem()

the getClientFileSystem() gets flagged. If you remove the first line assigning tc!=null() then all works as expected. Probably an initialization with null() should simply be ignored for the type discovery?

dhuebner commented 2 months ago

The problem here is that we only consider first initialization of a variable when computing the variable type. As the first initialization was null no members are available later on.

Following an example without null() but works the same as original example.

tc!=new java.util.List()
tc! = BBjAPI()
tc!.add("item"); REM can not access .getThinClient() but List members

It is not easy to derive a proper variable type as shown in the example below:

x = 2
tc!=new java.util.List()
if(x = 3) 
    tc! = BBjAPI()
endif
tc!.getThinClient()

What we can try to do, is looking up the siblings for the first initialization and try compute the type. This will work in some cases, but not in general, so the best way is still using declare :

declare BBjAPI tc!
tc!=null()
tc! = BBjAPI()
tc!.getThinClient()
dhuebner commented 2 months ago

Note: this will also make scoping->linking->build slower.

StephanWald commented 2 months ago

declare needs to be used in that case