diff --git a/docs/notes/2.22.x.md b/docs/notes/2.22.x.md index 1811469957f..150a2cb6cbb 100644 --- a/docs/notes/2.22.x.md +++ b/docs/notes/2.22.x.md @@ -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. diff --git a/src/python/pants/backend/scala/dependency_inference/ScalaParser.scala b/src/python/pants/backend/scala/dependency_inference/ScalaParser.scala index 08e96f5517b..af4d957362a 100644 --- a/src/python/pants/backend/scala/dependency_inference/ScalaParser.scala +++ b/src/python/pants/backend/scala/dependency_inference/ScalaParser.scala @@ -185,6 +185,7 @@ class SourceAnalysisTraverser extends Traverser { withNamePart( name, () => { + apply(templ.self) apply(templ.early) apply(templ.stats) } @@ -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) diff --git a/src/python/pants/backend/scala/dependency_inference/scala_parser_test.py b/src/python/pants/backend/scala/dependency_inference/scala_parser_test.py index 144cb6c162d..71c14d6422d 100644 --- a/src/python/pants/backend/scala/dependency_inference/scala_parser_test.py +++ b/src/python/pants/backend/scala/dependency_inference/scala_parser_test.py @@ -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", + ]