Skip to content

Commit

Permalink
Record Scala package object as provided name (pantsbuild#15582)
Browse files Browse the repository at this point in the history
The package object should also be recorded as provided name, as it also behaves as an object. 

An example that will fail without this fix:

File t.scala:
```
package object example {
   trait T[A]
}
```

File a.scala:
```
package example

package object a {
   implicit val tString: T[String] = new T[String] {}
}
```

File b.scala:
```
package example.b

import example.T
import example.a._

object B {
   val x = implicitly[T[String]]
}
```

# Rust tests and lints will be skipped. Delete if not intended.
[ci skip-rust]

# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
  • Loading branch information
somdoron authored and stuhood committed May 23, 2022
1 parent 4a62a85 commit 27d776a
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ class SourceAnalysisTraverser extends Traverser {
visitMods(mods)
val name = extractName(nameNode)
recordScope(name)
recordProvidedName(name, sawObject = true)
visitTemplate(templ, name)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ def test_package_object(rule_runner: RuleRunner) -> None:
"""
),
)
assert sorted(analysis.provided_symbols) == ["foo.bar.Hello"]
assert sorted(analysis.provided_symbols) == ["foo.bar", "foo.bar.Hello"]


def test_extract_annotations(rule_runner: RuleRunner) -> None:
Expand Down

0 comments on commit 27d776a

Please sign in to comment.