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

Auto import of some types #946

Open
johnynek opened this issue Feb 26, 2023 · 1 comment
Open

Auto import of some types #946

johnynek opened this issue Feb 26, 2023 · 1 comment

Comments

@johnynek
Copy link
Owner

If we don't mention a type, but it is needed to typecheck a mentioned method and we declare a dependency on the module, we shouldn't error but automatically import.

If we don't depend on the module we need, we should error but explain the solution is add a dependency on a certain module.

It's a bit weird to have two different rules, but the real rule is that by reading the code a human or simple tool can see the dependency structure of the code, and we shouldn't otherwise need to import names not used in the code.

@johnynek
Copy link
Owner Author

this came up in #1174

I think the main rules are:

  1. we should be able to read the code and see where all names came from
  2. we should be able to see package dependency graph via parsing, without type checking

So, if you use a function, but don't mention one of the types it needs, but we do depend on that package already, we shouldn't error. So, one way we could do that is look at all values imported, and then traverse the set of all root type constants. Any type constants from imported packages, we can import. This should happen after SourceConverter, so that it doesn't allow you to name in the source types or constructors without importing, but we shouldn't have to import a type from a package we already depend on just to satisfy inference.

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

1 participant