You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Imagine this scenario.
I have a class _BaseClass and _SubClass. I want to autogenerate subclasses for both so that I the end I'd have this hierarchy:
_BaseClassBaseClass// auto generated_SubClassSubClass// autogenerated
I'd declare my typed classes as:
class_BaseClass
and
class_SubClass:BaseClass
That almost works except for the fact that I can't get supertype of _SubClass at build time. I assume that happens because build_runner (or source_gen) at the start of generation first deletes autogenerated files (BaseClass and SubClass in my case) and then the declaration
class_SubClass:BaseClass
isn't valid anymore since there is no BaseClass.
In fact analyzer returns me an Object as _SubClass' supertype, not BaseClass.
On possible workaround would be to use a custom attribute, i.e.
Is it the same builder creating both BaseClass and SubClass? If they are different builders then as long as the one for SubClass runs after the one for BaseClass it should be able to resolve it.
If they are the same builder then I think it should work to separate your package into two targets, the source file for _SubClass should be in a target that depends on the one with _BaseClass. That would enforce that generating SubClass happens after BaseClass exists and should be resolvable.
@natebosch It's the same builder. Separating sources in packages is not an option. Imagine a scenario where I have a type hierarchy and I'd like to add augmentation to all of them. Subclass methods should include arguments based on fields on superclass.
If I went with different packages, it'd be soon a package mess. Thanks for ideas though, appreciated.
Imagine this scenario.
I have a class _BaseClass and _SubClass. I want to autogenerate subclasses for both so that I the end I'd have this hierarchy:
I'd declare my typed classes as:
and
That almost works except for the fact that I can't get supertype of _SubClass at build time. I assume that happens because build_runner (or source_gen) at the start of generation first deletes autogenerated files (BaseClass and SubClass in my case) and then the declaration
isn't valid anymore since there is no BaseClass.
In fact analyzer returns me an Object as _SubClass' supertype, not BaseClass.
On possible workaround would be to use a custom attribute, i.e.
But this solution is a bit more error prone. Are there any better solutions?
The text was updated successfully, but these errors were encountered: