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

Allow (or always) prefix for dart:core elements #362

Open
srawlins opened this issue Jun 6, 2022 · 5 comments
Open

Allow (or always) prefix for dart:core elements #362

srawlins opened this issue Jun 6, 2022 · 5 comments
Labels
type-enhancement A request for a change that isn't a bug

Comments

@srawlins
Copy link
Member

srawlins commented Jun 6, 2022

I am encountering code in mockito, generating code which includes a class which implements a method called List. I think this is a method defined in proto-generated services. In any case, when mockito generates this code, we get an error for other code which refers to the type, List:

78: List<String> get idFields => List isn't a type.

Boo. The only way to get around this is to import core with a prefix, import 'dart:core' as core; or whatever.

I think this would make most code, er... very hard to read. But I'd also love this option for mockito 😄 .

@natebosch
Copy link
Member

I'm not sure if it is feasible for us to handle this automatically. We can't tell if a refer('List') is intended to refer to dart:core, or something local to the library being generated.

I think we might need to use refer('List', 'dart:core') in mockito.

@srawlins
Copy link
Member Author

srawlins commented Jun 7, 2022

I think we might need to use refer('List', 'dart:core') in mockito.

I think we do, here (approximately, we build a TypeReference manually).

I think the comment here and the code here indicate that dart:core will never be prefixed.

@natebosch
Copy link
Member

Thanks! I think an option to keep prefixes for dart:core makes sense.

@srawlins
Copy link
Member Author

srawlins commented Jun 7, 2022

I wish I could even hack around _doNotPrefix, like maybe say refer('List', 'dArT : core ') or something. 😏

But it would be a big ole breaking change to always prefix. E.g. in mockito we have code like refer('Invocation') assuming it is imported without a prefix. I imagine there is a ton of code out there like that.

We could deal with that by adding an option on DartEmitter, like prefixCore or something.

@natebosch
Copy link
Member

We could deal with that by adding an option on DartEmitter, like prefixCore or something.

SGTM.

assuming it is imported without a prefix.

We could either try to clean all of those up, or we could add an unprefixed import of dart:core to catch the straggling references.

@devoncarew devoncarew added type-enhancement A request for a change that isn't a bug and removed feature labels Aug 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

3 participants