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

Nested package statements not inferred for Scala #13655

Closed
stuhood opened this issue Nov 17, 2021 · 5 comments · Fixed by #13758
Closed

Nested package statements not inferred for Scala #13655

stuhood opened this issue Nov 17, 2021 · 5 comments · Fixed by #13758
Assignees

Comments

@stuhood
Copy link
Member

stuhood commented Nov 17, 2021

package akka.shapeless
package ops

...results in symbols in both packages being available as unqualified within the file.

This is likely because we don't attempt to resolve against all of the nested scopes for a symbol here:

# TODO: We compute "the package" as the "shortest scope in the file" to handle the most
# common case of consuming a type from within your package. But this doesn't account
# for the fact that any of the intermediate scopes might be relevant as well. Solving that
# would require resolving the type recursively upward.
package = min(
(*self.imports_by_scope.keys(), *self.consumed_symbols_by_scope.keys()),
key=len,
default="",
)

@tdyas
Copy link
Contributor

tdyas commented Nov 23, 2021

@stuhood: Is there a particular example of this? I'm not sure what is meant by "results in symbols in both packages being available". The provided symbols calculated for a file should all be attributed to akka.shapeless.ops, correct?

@stuhood
Copy link
Member Author

stuhood commented Nov 29, 2021

Sorry, clarified the description to indicate that this is about which symbols are available as unqualified within the file, rather than which package declared symbols live in.

@tdyas
Copy link
Contributor

tdyas commented Nov 29, 2021

Example of how it should work:

Foo.scala:

package foo

object Foo {
  def grok(): Unit = {
    println("Foo.grok")
  }
}

Main.scala:

package foo
package bar

object Main {
  def main(args: Array[String]): Unit = {
    Foo.grok()
  }
}

foo.bar.Main can refer to foo.Foo since it has a package foo directive.

Okay first step will be a PR to analyze the actual package statements.

@tdyas
Copy link
Contributor

tdyas commented Nov 29, 2021

#13738 parses out the package scopes.

@tdyas tdyas self-assigned this Nov 29, 2021
tdyas pushed a commit that referenced this issue Nov 30, 2021
As described in #13655, unqualified symbols in Scala code can come from any of the packages for which there is a `package` directive in the source file. The first step to solving this issue is to parse the packages referenced by a Scala file.

[ci skip-build-wheels]
@stuhood
Copy link
Member Author

stuhood commented Nov 30, 2021

This represented roughly 10% of the issues in akka-http.

tdyas pushed a commit that referenced this issue Dec 1, 2021
…mediate scopes (#13758)

Infer Scala source dependencies based on consumed symbols provided by ancestor scopes that are not the immediately-enclosing scope.

Fixes #13655.

[ci skip-rust]
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

Successfully merging a pull request may close this issue.

2 participants