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

Consider importing parent mappers when using inheritance from different files #144

Open
AhmedLSayed9 opened this issue Oct 29, 2023 · 2 comments

Comments

@AhmedLSayed9
Copy link

/// File-A:
@MappableEnum()
enum SomeEnum {
  A,
  B,
}

/// File-B:
@MappableClass()
class Foo with FooMappable {
  const Foo({
    required this.someEnum,
  });

  final SomeEnum someEnum;
}

/// File-C:
@MappableClass()
class Bar extends Foo with BarMappable {
  const Bar({
    required super.someEnum,
    required this.someString,
  });

  final String someString;
}

The issue is that File-C doesn't import File-A and it won't complain as we're using super.someEnum.
but the generated file will include SomeEnumMapper as InvalidType and it needs manual import.

This is hard to spot if we're ignoring analyzing generate files and will throw at runtime.

It'd be helpful if we can auto-add imports for the needed mappers of the parent class if it's not included.

@schultek
Copy link
Owner

Unfortunately automatically adding imports to a source file is not possible with using build_runner. I understand the problem, but I don't know if or how I could fix it.

@markusmattfolkstenberg-teya

We are running in to this issue as well and it adds quite a lot of extra work, especially since it won't be caught before compiling. I'm not sure what a good generic solution could be yet, though.

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

No branches or pull requests

3 participants