Skip to content

Scope completion includes shadowed vars and vals #7997

@scabug

Description

@scabug

Member vars and vals appears in scope completion results, even if they are shadowed by local vars or vals.

The following presentation compiler partest

package test

class Completion2 {

  val v1 = 0
  var r1 = 1
  def f1 = 2
  type t1 = Int

  def foo {

    // local declarations shadow imported members
    val v1 = "a"
    var r1 = "b"
    def f1 = "c"
    type t1 = String

    /*_*/

  }

}

generates this output

reload: Completion.scala, Test.scala

askScopeCompletion at Completion.scala(18,4)
================================================================================
[response] askScopeCompletion at (18,4)
retrieved 9 members
class Completion2 extends AnyRef
def <init>(): test.Completion2
def f1: String
def foo: Unit
private[this] val v1: Int
private[this] var r1: Int
type t1 = t1
val v1: String
var r1: String
================================================================================

v1 and r1 are listed twice, once for the local variables, once for the class members. f1 and t1 correctly appear only once.

The problem is in the Members.addNonShadowed() method. It checks for duplicated names, but doesn't handle the fact that members vars and vals contains an extra space in their name.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions