Invalid DSL when passing a class with a `type_parameter` to `attribute`'s `cast_type`
Nobody has claimed this yet.
- Dominant language
- Ruby
- Stars
- 873
- Forks
- 164
- Avg merge
- 4d 27m
- Merged PRs (30d)
- 9
Description
Sorry if this belongs on Discourse – I was initially going to post this there but I believe this is a bug considering invalid DSL is being generated rather than an error popping up with the code I've written. I can move to Discourse if it makes more sense there.
Tapioca generates invalid DSL when I pass an instance of a class that has a type_member to attribute's cast_type (2nd argument). For example, given a class GenericValue which inherits from ActiveRecord::Type::Value and that has a ValueType = type_member:
- If I just do
attribute :column, GenericValue.new, the methods in the generated DSL use justValueTypeas a parameter/return value which doesn't exist outsideGenericValue, so Sorbet raisesUnable to resolve constant ValueTypeall over the place. - If I explicitly pass a type
attribute :column, GenericValue[SomeObject].new, the methods in the generated DSL fall back toT.untyped, even if the parameter/return value in theserialize/deserializedo not useValueType.
Here's an example commit: https://github.com/ShopifyFRS/bourgeois/compare/do-not-merge-generic-attribute-cast-type
non_generic_valueuses::Acceptance::SomeObjectas expected.generic_valueusesValueTypeinstead of::Acceptance::SomeObjectand which is undefined outsideAcceptance::GenericValue.explicit_generic_valueusesT.untypedinstead ofAcceptance::SomeObjectImpl(my expectation).
I've also tried reproducing the issue in a separate blank repo using the latest versions of Sorbet and Tapioca but the same thing happens. Unfortunately I cannot push this to GitHub since I cannot create repos in the Shopify organization.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the issue with the GenericValue, non_generic_value, generic_value, and explicit_generic_value examples, then trace Tapioca's handling of attribute's cast_type and generated DSL types. Done means the generated DSL resolves the type_member correctly for implicit and explicit generic casts instead of emitting an undefined ValueType or T.untyped.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rails, ruby
- Domain
- developer-experience, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100