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

Unqualified reference to module constant from extern-ed class doesn't compile in Java #634

Open
robin-aws opened this issue May 27, 2020 · 0 comments
Labels
area: ffi The {:extern} attribute and otherwise interfacing with code in other languages kind: enhancement Enhancements, feature requests, etc. These are NOT bugs, but ways we can improve Dafny lang: java Dafny's Java transpiler and its runtime part: code-generation Support for transpiling Dafny to another language. If relevant, add a `lang:` tag

Comments

@robin-aws
Copy link
Member

Repro:

module {:extern} M {
  const FOO := 5

  class R {
    var v: int
    constructor() {
      v := FOO;
    }
  }
}

The Dafny-to-Java compiler produces __default.FOO for the constant reference in the constructor, which doesn't resolve because the FOO constant is defined in M_Compile._ExternBase___default.java. The fix is to manually define an empty __default class:

package M_Compile;

public class __default extends _ExternBase___default {
}

This is a side-effect of the mechanism for mixed Dafny/Java classes as described in #469, but calling this out separately because it's especially difficult to recognize that modules need the same empty subclass.

@robin-aws robin-aws added part: code-generation Support for transpiling Dafny to another language. If relevant, add a `lang:` tag lang: java Dafny's Java transpiler and its runtime kind: enhancement Enhancements, feature requests, etc. These are NOT bugs, but ways we can improve Dafny labels Jun 23, 2020
@acioc acioc added this to the Post 3.0 milestone Jul 22, 2020
@davidcok davidcok added the area: ffi The {:extern} attribute and otherwise interfacing with code in other languages label Jul 22, 2020
@robin-aws robin-aws removed this from the Post 3.1 milestone Sep 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: ffi The {:extern} attribute and otherwise interfacing with code in other languages kind: enhancement Enhancements, feature requests, etc. These are NOT bugs, but ways we can improve Dafny lang: java Dafny's Java transpiler and its runtime part: code-generation Support for transpiling Dafny to another language. If relevant, add a `lang:` tag
Projects
None yet
Development

No branches or pull requests

3 participants