Invalid DSL when passing a class with a `type_parameter` to `attribute`'s `cast_type`
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.
You already made most of the investigation here. Could you write a test like this one in the test suite and maybe submit a PR fixing the issue?
I'd be happy to give it a shot!