Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Static analysis exception "Procedure cannot be resolved" when procedure exists #1239

Open
Anatoliy057 opened this issue Aug 11, 2020 · 3 comments

Comments

@Anatoliy057
Copy link
Contributor

Static analysis will throw exception with message "Procedure cannot be resolved" for all user procedures in this case:

# main.ms
proc _path() {
    return('test-2.ms')
}

proc _test() {
    console('test')
}

include('test-1.ms')
# test-1.ms
include(_path())
# test-2.ms
_test()
ms.lang.IncludeException: There was a compile error when trying to include the script at C:\Users\A-y57\Dev\minecraft\plugins\CommandHelper\test-2.ms
Procedure cannot be resolved: _test :: test-2.ms:1
        at <<include test-1.ms>>:C:\Users\A-y57\Dev\minecraft\plugins\CommandHelper\test-1.ms:1.9
        at <<main code>>:C:\Users\A-y57\Dev\minecraft\plugins\CommandHelper\main.ms:9.2

If replace _path with 'test-2.ms' - everything works
If disable static analysis, everything works

@Pieter12345
Copy link
Contributor

You cannot use procedures defined in dynamic includes (e.g. include(arg) where arg isn't a hard-coded string) outside of those includes. Static analysis happens at compile time, and dynamic includes are simply not known at that stage. The solution is to hard-code all paths in your includes, where you can also use include_dir() to include all files in a certain directory in a static way.

@Pieter12345
Copy link
Contributor

As a side note, keep in mind that when using dynamic includes, static analysis can no longer analyze these included files because they are not known at compile time. This means that you might get some exceptions in runtime that static analysis would have otherwise caught earlier (in compile time) otherwise.

@LadyCailin
Copy link
Member

I would like to attach a (suppressable) compiler warning if dynamic includes are used, with basic information about what kinds of error they may cause, so that things like this can be understood without having to file a bug report. So let's leave this open as a placeholder for adding that compiler warning.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants