Skip to content

Commit

Permalink
Include type bound constraints in consumed symbols during Scala infer…
Browse files Browse the repository at this point in the history
  • Loading branch information
alonsodomin authored Aug 30, 2022
1 parent baa20cb commit d396098
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -235,18 +235,20 @@ class SourceAnalysisTraverser extends Traverser {
)
}

case Defn.Class(mods, nameNode, _tparams, ctor, templ) => {
case Defn.Class(mods, nameNode, tparams, ctor, templ) => {
visitMods(mods)
val name = extractName(nameNode)
recordProvidedName(name, sawClass = true)
apply(tparams)
apply(ctor)
visitTemplate(templ, name)
}

case Defn.Trait(mods, nameNode, _tparams, ctor, templ) => {
case Defn.Trait(mods, nameNode, tparams, ctor, templ) => {
visitMods(mods)
val name = extractName(nameNode)
recordProvidedName(name, sawTrait = true)
apply(tparams)
apply(ctor)
visitTemplate(templ, name)
}
Expand Down Expand Up @@ -299,7 +301,7 @@ class SourceAnalysisTraverser extends Traverser {
super.apply(rhs)
}

case Defn.Def(mods, nameNode, _tparams, params, decltpe, body) => {
case Defn.Def(mods, nameNode, tparams, params, decltpe, body) => {
visitMods(mods)
val name = extractName(nameNode)
recordProvidedName(name)
Expand All @@ -308,14 +310,16 @@ class SourceAnalysisTraverser extends Traverser {
extractNamesFromTypeTree(tpe).foreach(recordConsumedSymbol(_))
})

apply(tparams)
params.foreach(param => apply(param))

withSuppressProvidedNames(() => apply(body))
}

case Decl.Def(mods, _nameNode, _tparams, params, decltpe) => {
case Decl.Def(mods, _nameNode, tparams, params, decltpe) => {
visitMods(mods)
extractNamesFromTypeTree(decltpe).foreach(recordConsumedSymbol(_))
apply(tparams)
params.foreach(param => apply(param))
}

Expand Down Expand Up @@ -366,6 +370,11 @@ class SourceAnalysisTraverser extends Traverser {
})
}

case Type.Param(mods, _name, _tparams, bounds, _vbounds, _cbounds) => {
visitMods(mods)
extractNamesFromTypeTree(bounds).foreach(recordConsumedSymbol(_))
}

case Ctor.Primary(mods, _name, params_list) => {
visitMods(mods)
params_list.foreach(params => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -593,3 +593,31 @@ def test_package_object_extends_trait(rule_runner: RuleRunner) -> None:
)

assert sorted(analysis.fully_qualified_consumed_symbols()) == ["foo.Trait", "foo.bar.Trait"]


def test_type_constaint(rule_runner: RuleRunner) -> None:
analysis = _analyze(
rule_runner,
textwrap.dedent(
"""\
package foo
trait Foo[T >: A <: B]
class Bar[T >: C <: D]
class Quxx {
def doSomething[T >: E <: F]() = ()
}
"""
),
)

assert sorted(analysis.fully_qualified_consumed_symbols()) == [
"foo.A",
"foo.B",
"foo.C",
"foo.D",
"foo.E",
"foo.F",
]

0 comments on commit d396098

Please sign in to comment.