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

Scala: Detect consumed symbols in self-type annotations #20960

Merged
merged 3 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/notes/2.22.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ deploy jars, in addition to those specified on a per-jar basis in the `deploy_ja
This option's default value excludes signature files from constituent jars, which are known to cause the deploy jar
to fail to execute (since naturally it doesn't match those signatures).

Scala dependency inference used to ignore self-type annotations, which led to not being able to detect dependencies between files in the same package where self-type annotations were used. Moving forward if self-type annotations are being used and no import present for the given type, it will be assumed the referenced type is defined in the same package.

Also reduced verbosity of log messages for the internal Nailgun server instances used for running or compiling code
replacing it by a single message informing about the size of the Nailgun pool. Previous log messages are still
emitted at debug log level.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ class SourceAnalysisTraverser extends Traverser {
withNamePart(
name,
() => {
apply(templ.self)
apply(templ.early)
apply(templ.stats)
}
Expand Down Expand Up @@ -383,6 +384,9 @@ class SourceAnalysisTraverser extends Traverser {
init.argss.foreach(arg => apply(arg))
}

case Self(_name, Some(decltpe)) =>
extractNamesFromTypeTree(decltpe).foreach(recordConsumedSymbol(_))

case node @ Term.Select(_, _) => {
val name = extractName(node)
recordConsumedSymbol(name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -735,3 +735,21 @@ def doSomething[F[_] : Applicative]() = ()
"foo.Applicative",
"foo.Functor",
]


def test_self_types_on_same_package(rule_runner: RuleRunner) -> None:
analysis = _analyze(
rule_runner,
textwrap.dedent(
"""\
package foo

trait Bar { self: Foo =>
}
"""
),
)

assert sorted(analysis.fully_qualified_consumed_symbols()) == [
"foo.Foo",
]
Loading