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

Need a way to pattern match datatypes without referencing all nameonly parameters #5907

Open
robin-aws opened this issue Nov 8, 2024 · 0 comments
Labels
kind: enhancement Enhancements, feature requests, etc. These are NOT bugs, but ways we can improve Dafny part: language definition Relating to the Dafny language definition itself

Comments

@robin-aws
Copy link
Member

robin-aws commented Nov 8, 2024

Part of the motivation for supporting nameonly parameters and default arguments was enabling backwards compatibility:

datatype Foo = Foo(
  nameonly a: Option<int> := None,
  nameonly b: Option<int> := None
)

..

var f := Foo(a := Some(42));   // b defaults to None
// Adding a similar `c` parameter later doesn't break the statement above

However, there's currently no way to deconstruct such datatypes in match statements/expressions that isn't broken when more optional nameonly parameters are added:

var Foo(a, b) := f;    // breaks when `c` is added

(This has been hit in the past in smithy-dafny, when picking up AWS service model changes that should be backwards compatible but aren't because of this)

We need to support syntax similar to var Foo(a, b, ...) := ..., or more pessimistically not allow deconstructing datatypes with any nameonly parameters.

@robin-aws robin-aws added kind: enhancement Enhancements, feature requests, etc. These are NOT bugs, but ways we can improve Dafny part: language definition Relating to the Dafny language definition itself labels Nov 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: enhancement Enhancements, feature requests, etc. These are NOT bugs, but ways we can improve Dafny part: language definition Relating to the Dafny language definition itself
Projects
None yet
Development

No branches or pull requests

1 participant