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

Wrong generated code when using import alias for Dart tables #2845

Closed
davidmartos96 opened this issue Jan 18, 2024 · 2 comments
Closed

Wrong generated code when using import alias for Dart tables #2845

davidmartos96 opened this issue Jan 18, 2024 · 2 comments

Comments

@davidmartos96
Copy link
Contributor

davidmartos96 commented Jan 18, 2024

Hello!
I noticed that when using an import alias for the tables property in the DriftDatabase annotation the generated code is not using the alias, so it won't compile.

I'm not sure how actionable this issue is, I'm sure it's not that common to do this. To give more context, in electricsql a drift schema is generated automatically based on a Postgres schema, so that then the user only needs to do @DriftDatabase(tables: kElectrifiedTables). The tables list is a constant that is also generated automatically ( List<Type>).
This works, but an user reported that the drift code gen wasn't working when using an import alias for the schema file.

It can be reproduced by editing the app example in the repo as follows:

image

@simolus3
Copy link
Owner

Thanks for opening the issue, I actually wanted to fix this for a long time! In the writer, we only get a name of the element and its definition uri and we have to resolve its import alias based on that. It's not a fully sound solution, but most instances of this should be fixed by 261c151. That looks up all named imports in a library and picks the first one that matches. It's not correct because, if a name is imported both with and without a name, we won't always pick the right one now. But it's likely that most of these cases are already broken today, and this will at least improve some of them.

@davidmartos96
Copy link
Contributor Author

Thanks Simon, as always! 😄

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

2 participants