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

Allow swift decorator constraints to apply to generics #173

Merged

Conversation

darrell-roberts
Copy link
Member

Allow #[typeshare(swift = "Constraint")] to be applied to generic members.

Example in included test case.

@kevinbhayes
Copy link
Collaborator

Will we ever want to apply different decorators to the generics? i.e.
#[typeshare(swift = "Constraint", swiftGeneric = "DifferentConstraint")]

Copy link
Collaborator

@charlespierce charlespierce left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change LGTM! I'm not familiar with Swift, but would we need to do similar logic in write_enum? This block seems to be doing essentially the same as what you replaced in write_struct.

@darrell-roberts
Copy link
Member Author

This change LGTM! I'm not familiar with Swift, but would we need to do similar logic in write_enum? This block seems to be doing essentially the same as what you replaced in write_struct.

Yup I'll update that as well.

@charlespierce charlespierce merged commit e8b7f76 into 1Password:main Jun 4, 2024
5 checks passed
dandro pushed a commit to dandro/typeshare that referenced this pull request Jun 5, 2024
…s-generics

Allow swift decorator constraints to apply to generics

Support CSharp

Create basic language implementation.
Start adding tests.

Add snapshot tests

Update slice type to map to IEnumerable instead of Array.
Drop support for Unit type and return an error.

Support anonymous structs

Update slice of user type test snapshot

Support namespace option

Support serialization with json attributes

Remove EnumLabel and use EnumMember attribute instead.
Update all test snapshots according to the new changes.

C# without naming convention option

Add required attribute

For newtonsoft json to require a non optional property, the property has
to have the required attribute. Otherwise, it allows it to be null and a
default value is provided.
@kevinbhayes
Copy link
Collaborator

Update: yes, there is a case where we don't want to apply the same decorators to both the struct and its generic type. We often want structs to be Identifiable, but do not want to place that restriction on the generic type. We should look at a mechanism to define separate decorators for the struct itself, and the generic type.

@kevinbhayes
Copy link
Collaborator

@charlespierce unfortunately, this can break any code with generics that don't need the same constraints as the struct itself. e.g. the generic type doesn't need Identifiable, but the struct does.

@darrell-roberts is working on a fix to allow separate designation of generic constraint decorators, so please coordinate with him on getting the fix in soon, or consider rolling back this one.

Thanks.

@darrell-roberts darrell-roberts deleted the swift-decorators-generics branch June 7, 2024 12:21
dandro pushed a commit to dandro/typeshare that referenced this pull request Jun 13, 2024
…s-generics

Allow swift decorator constraints to apply to generics

Support CSharp

Create basic language implementation.
Start adding tests.

Add snapshot tests

Update slice type to map to IEnumerable instead of Array.
Drop support for Unit type and return an error.

Support anonymous structs

Update slice of user type test snapshot

Support namespace option

Support serialization with json attributes

Remove EnumLabel and use EnumMember attribute instead.
Update all test snapshots according to the new changes.

C# without naming convention option

Add required attribute

For newtonsoft json to require a non optional property, the property has
to have the required attribute. Otherwise, it allows it to be null and a
default value is provided.
dandro pushed a commit to dandro/typeshare that referenced this pull request Jun 30, 2024
…s-generics

Allow swift decorator constraints to apply to generics

Support CSharp

Create basic language implementation.
Start adding tests.

Add snapshot tests

Update slice type to map to IEnumerable instead of Array.
Drop support for Unit type and return an error.

Support anonymous structs

Update slice of user type test snapshot

Support namespace option

Support serialization with json attributes

Remove EnumLabel and use EnumMember attribute instead.
Update all test snapshots according to the new changes.

C# without naming convention option

Add required attribute

For newtonsoft json to require a non optional property, the property has
to have the required attribute. Otherwise, it allows it to be null and a
default value is provided.
dandro pushed a commit to dandro/typeshare that referenced this pull request Jul 23, 2024
…s-generics

Allow swift decorator constraints to apply to generics

Support CSharp

Create basic language implementation.
Start adding tests.

Add snapshot tests

Update slice type to map to IEnumerable instead of Array.
Drop support for Unit type and return an error.

Support anonymous structs

Update slice of user type test snapshot

Support namespace option

Support serialization with json attributes

Remove EnumLabel and use EnumMember attribute instead.
Update all test snapshots according to the new changes.

C# without naming convention option

Add required attribute

For newtonsoft json to require a non optional property, the property has
to have the required attribute. Otherwise, it allows it to be null and a
default value is provided.
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.

3 participants