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

Cannot compile default generic values in C# #2885

Closed
MikaelMayer opened this issue Oct 12, 2022 · 0 comments · Fixed by #2967
Closed

Cannot compile default generic values in C# #2885

MikaelMayer opened this issue Oct 12, 2022 · 0 comments · Fixed by #2967
Labels
kind: bug Crashes, unsoundness, incorrect output, etc. If possible, add a `part:` label lang: c# Dafny's C# transpiler and its runtime part: code-generation Support for transpiling Dafny to another language. If relevant, add a `lang:` tag

Comments

@MikaelMayer
Copy link
Member

If you compile the following program:

datatype KeyValues<T> = Store(underlying: map<string, T> := map[])

function method CreateStore<T>(): (r: KeyValues<T>) {
  Store()
}

You'll get a compilation error:

Errors compiling program into csharpcompilerbug
(4886,69): error CS0246: The type or namespace name 'T' could not be found (are you missing a using directive or an assembly reference?)

(4886,36): error CS1503: Argument 1: cannot convert from 'Dafny.Map<Dafny.ISequence<char>, T>' to 'Dafny.IMap<Dafny.ISequence<char>, __T>'

This comes from the fact that Dafny did not infer the type parameter of the default variable to be the same T, and there is no way to provide this in the constructor as far as I know.

The workaround is to explicit the default value for now:

datatype KeyValues<T> = Store(underlying: map<string, T> := map[])

function method CreateStore<T>(): (r: KeyValues<T>) {
  var x: map<string, T> := map[];
  Store(x)
}
@MikaelMayer MikaelMayer added kind: bug Crashes, unsoundness, incorrect output, etc. If possible, add a `part:` label part: code-generation Support for transpiling Dafny to another language. If relevant, add a `lang:` tag lang: c# Dafny's C# transpiler and its runtime labels Oct 12, 2022
MikaelMayer added a commit that referenced this issue Nov 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: bug Crashes, unsoundness, incorrect output, etc. If possible, add a `part:` label lang: c# Dafny's C# transpiler and its runtime part: code-generation Support for transpiling Dafny to another language. If relevant, add a `lang:` tag
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant