Skip to content

Commit

Permalink
Record Scala package object as provided name (#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]]
}
```
  • Loading branch information
somdoron authored May 23, 2022
1 parent 664ae63 commit e94448d
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 e94448d

Please sign in to comment.