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

feat: Consistent "create_<ctorname>" method for record types #3034

Merged

Conversation

robin-aws
Copy link
Member

@robin-aws robin-aws commented Nov 10, 2022

Currently in C# and Java, compiled datatypes expose a create_A(...) factory method for each A data constructor. However, datatypes with a single data constructor, also called "record types", will instead expose a single create method. This is slightly nicer for hand-written external code, but creates an annoying special case for generated code.

This change ensures that record types expose BOTH a create_<ctorname> method for the single data constructor AND a create method that thunks to it, to maintain backwards compatibility but also provide consistent naming.

Added cases to test this to the existing Extern.dfy test case, which now shows that at least all supported languages in that test case provide such consistently-named (within a language at least) factory methods, and don't require direct calls to constructors (note that Python has built-in support such that for a class Foo, Foo(...) can be redefined as needed, and so provides the same flexibility as a factory method).

By submitting this pull request, I confirm that my contribution is made under the terms of the MIT license.

@robin-aws robin-aws marked this pull request as ready for review November 10, 2022 00:12
texastony added a commit to smithy-lang/smithy-dafny that referenced this pull request Feb 15, 2023
Where "srv's Op strucs" is
a Service's Operation Structures,
or all of a Service's Operations' Input, Output, Errors
and all shapes related to the above.

We need dafny-lang/dafny#3034
to resolve singular datatype creation
(now known as a "Record Type").

DONE:
- [x] Test Java KMS
- [x] Test Java DDB
- [x] Merge #83 into this

TODO:
- [ ] Test Java DDB again
- [ ] Address Issues raised in PR #82, #92, #83
robin-aws and others added 2 commits February 15, 2023 11:16
…ate-method-for-record-types

# Conflicts:
#	Test/comp/Extern.dfy
#	Test/comp/Extern.dfy.expect
#	Test/comp/Extern4.go
#	Test/comp/Extern5.py
texastony added a commit to smithy-lang/smithy-dafny that referenced this pull request Feb 20, 2023
TODO:
- [ ] Implement ToNative Double solution
- [ ] Test Java DDB again
- [ ] Address Issues raised in PR #82, #92, #83
- [ ] Consolidate duplicated code
- [ ] Test Java KMS & DDB Again
- [ ] PR & Merge
@fabiomadge fabiomadge enabled auto-merge (squash) February 21, 2023 00:35
@fabiomadge fabiomadge merged commit 050dfc0 into dafny-lang:master Feb 21, 2023
texastony added a commit to smithy-lang/smithy-dafny that referenced this pull request Mar 2, 2023
Where "srv's Op strucs" is
a Service's Operation Structures,
or all of a Service's Operations' Input, Output, Errors
and all shapes related to the above.

We need dafny-lang/dafny#3034
to resolve singular datatype creation
(now known as a "Record Type").

DONE:
- [x] Test Java KMS
- [x] Test Java DDB
- [x] Merge #83 into this

TODO:
- [ ] Test Java DDB again
- [ ] Address Issues raised in PR #82, #92, #83
texastony added a commit to smithy-lang/smithy-dafny that referenced this pull request Mar 2, 2023
TODO:
- [ ] Implement ToNative Double solution
- [ ] Test Java DDB again
- [ ] Address Issues raised in PR #82, #92, #83
- [ ] Consolidate duplicated code
- [ ] Test Java KMS & DDB Again
- [ ] PR & Merge
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants