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

Module name "Module" cannot be used with Java #4256

Open
RustanLeino opened this issue Jul 6, 2023 · 0 comments
Open

Module name "Module" cannot be used with Java #4256

RustanLeino opened this issue Jul 6, 2023 · 0 comments
Labels
during 2: compilation of correct program Dafny rejects a valid program during compilation kind: bug Crashes, unsoundness, incorrect output, etc. If possible, add a `part:` label lang: java Dafny's Java transpiler and its runtime priority: next Will consider working on this after in progress work is done

Comments

@RustanLeino
Copy link
Collaborator

Dafny version

2023-06-03 (post 4.1.0)

Code to produce this issue

method Main() {
  Module.Hello();
}

module Module {
  method Hello() {
    print "hello Module\n";
  }
}

Command to run and resulting output

% dafny run --target:java test.dfy

Dafny program verifier finished with 1 verified, 0 errors
./test-java/_System/__default.java:13: error: cannot find symbol
    Module.__default.Hello();
          ^
  symbol:   variable __default
  location: class Module
1 error
Error while compiling Java files. Process exited with exit code 1

What happened?

For some reason, the name Module cannot be used as a module in Java. Everything works by renaming the module to, say, ModuleM or MODULE, in the Dafny source.

Another repro that shows the same problem is to rename Module to String in the example above.

It seems that Java is resolving these names to java.lang.Module or java.lang.String.

Notes:

  • The Dafny compilers all have a mechanism for mangling Dafny identifiers that would otherwise clash with target-language keywords. However, there's currently no mechanism to mangle names that may be picked up from some standard always-included library. One simple solution would be to include these names (Module, String, ...) among the reserved keywords. A more precise solution would be to build a similar mechanism that's applied only to module names.
  • A similar problem for the module name enum in Python, which seems to always resolve to the standard-library enum in Python. If this bug gets fixed, Python should be updated accordingly. See also Test/dafny4/Bug116.dfy.

What type of operating system are you experiencing the problem on?

Mac

@RustanLeino RustanLeino added the kind: bug Crashes, unsoundness, incorrect output, etc. If possible, add a `part:` label label Jul 6, 2023
@keyboardDrummer keyboardDrummer added during 2: compilation of correct program Dafny rejects a valid program during compilation priority: next Will consider working on this after in progress work is done lang: java Dafny's Java transpiler and its runtime labels Apr 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
during 2: compilation of correct program Dafny rejects a valid program during compilation kind: bug Crashes, unsoundness, incorrect output, etc. If possible, add a `part:` label lang: java Dafny's Java transpiler and its runtime priority: next Will consider working on this after in progress work is done
Projects
None yet
Development

No branches or pull requests

2 participants