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

Dafny can't model C# classes without public constructors #313

Open
samuelgruetter opened this issue Jul 11, 2019 · 1 comment
Open

Dafny can't model C# classes without public constructors #313

samuelgruetter opened this issue Jul 11, 2019 · 1 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 priority: not yet Will reconsider working on this when we're looking for work

Comments

@samuelgruetter
Copy link
Collaborator

Suppose I have the following C# classes, which are given by some library and I can't change:

class Bar{}

class Foo {
    Bar x;
    private Foo() {}
}

Note that the constructor of Foo is private, and some part of the library I know nothing about will construct new Foo objects.

I try to model this in Dafny as follows:

class {:extern} Bar{}

class {:extern} Foo {
    var {:extern} x: Bar
}

But I get the error

class 'Foo' with fields without known initializers, like 'x' of type 'Bar', must declare a constructor

The obvious workaround is to just add a constructor in Dafny, but then if I write a Dafny file which uses this constructor, it will verify and successfully compile to a C# program, but compiling the C# program will fail. This is undesirable. It would be better if Dafny did not require a constructor for fully extern classes.

@robin-aws
Copy link
Member

Relevant to #469: it may be better to have a different annotation to refer to an existing type.

@robin-aws robin-aws added the area: ffi The {:extern} attribute and otherwise interfacing with code in other languages label Jun 22, 2020
@robin-aws robin-aws added this to the Dafny 3.0 milestone Jun 22, 2020
@robin-aws robin-aws modified the milestones: Dafny 3.0, Post 3.0 Dec 2, 2020
@robin-aws robin-aws added the kind: enhancement Enhancements, feature requests, etc. These are NOT bugs, but ways we can improve Dafny label Sep 22, 2021
@robin-aws robin-aws removed this from the Post 3.1 milestone Sep 22, 2021
@MikaelMayer MikaelMayer added the priority: not yet Will reconsider working on this when we're looking for work label Aug 15, 2024
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 priority: not yet Will reconsider working on this when we're looking for work
Projects
None yet
Development

No branches or pull requests

3 participants