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

Support Subscript builders #69

Closed
lickel opened this issue Jan 25, 2023 · 4 comments · Fixed by #76
Closed

Support Subscript builders #69

lickel opened this issue Jan 25, 2023 · 4 comments · Fixed by #76

Comments

@lickel
Copy link
Collaborator

lickel commented Jan 25, 2023

I wanted to add conformance to @dynamicMemberLookup in some generated code.
This is not possible as there's no way (that I can tell) to create subscripts.

Specifically, I wanted to create something like subscript<Property>(dynamicMember keyPath: KeyPath<BackingData, Property>) -> Property.

There doesn't seem to be any "escape hatch" for TypeSpec.Builder to just type "raw" Swift code.
As such, I think the only way to solve this would be a dedicated function/builder.

@kdubb
Copy link
Contributor

kdubb commented Jan 25, 2023

What's wrong with creating a function named subscript?

@lickel
Copy link
Collaborator Author

lickel commented Jan 26, 2023

There's two problems:

  • I need to support both the getter and setter flavors
  • the FunctionSpec builder notices it's a keyword and escapes it

@kdubb
Copy link
Contributor

kdubb commented Jan 26, 2023

Got it. I tend to forget that subscript is kind of a special property.

That being the case... adding support to PropertySpec should be easy.

@lickel
Copy link
Collaborator Author

lickel commented Jan 26, 2023

Yeah I figured it should be relatively straightforward since it's basically a special property except that it shares the flexibile generics and method signatures of a function.

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 a pull request may close this issue.

2 participants