Skip to content

Commit

Permalink
take accessibility into account
Browse files Browse the repository at this point in the history
  • Loading branch information
eed3si9n committed Jun 8, 2018
1 parent 2bfb74d commit 1e8ec90
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 13 deletions.
8 changes: 5 additions & 3 deletions src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ trait ContextErrors {
issueNormalTypeError(tree, "ambiguous parent class qualifier")

//typedSelect
def NotAMemberError(sel: Tree, qual: Tree, name: Name) = {
def NotAMemberError(sel: Tree, qual: Tree, name: Name, cx: Context) = {
import util.{ EditDistance, StringUtil }
def errMsg: String = {
val owner = qual.tpe.typeSymbol
Expand All @@ -364,8 +364,10 @@ trait ContextErrors {
if (x.size < 2) Nil
else {
target.nonPrivateMembers.iterator
.filterNot(m => m.isConstructor || nme.isLocalName(m.name))
.filter(sym => sym.isTerm == name.isTermName)
.filter(sym => (sym.isTerm == name.isTermName) &&
!sym.isConstructor &&
!nme.isLocalName(sym.name) &&
cx.isAccessible(sym, target))

This comment has been minimized.

Copy link
@retronym

retronym Jun 8, 2018

Member

You'll also need to change nonPrivateMembers to members.

.map(_.name.decode)
.filter(n => (n.length > 2) &&
(math.abs(n.length - x.length) <= editThreshold) &&
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/scala/tools/nsc/typechecker/Namers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ trait Namers extends MethodSynthesis {
if (isValid(from)) {
// for Java code importing Scala objects
if (!nme.isModuleName(from) || isValid(from.dropModule)) {
typer.TyperErrorGen.NotAMemberError(tree, expr, from)
typer.TyperErrorGen.NotAMemberError(tree, expr, from, context.outer)
}
}
// Setting the position at the import means that if there is
Expand Down
10 changes: 8 additions & 2 deletions src/compiler/scala/tools/nsc/typechecker/Typers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4321,11 +4321,17 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
if (name == nme.ERROR || qual.tpe.widen.isErroneous)
NoSymbol
else lookupInOwner(qual.tpe.typeSymbol, name) orElse {
NotAMemberError(tree, qual, name)
NotAMemberError(tree, qual, name, startingIdentContext)
NoSymbol
}
)

def startingIdentContext = (
// ignore current variable scope in patterns to enforce linearity
if (mode.inNone(PATTERNmode | TYPEPATmode)) context
else context.outer
)

def typedAnnotated(atd: Annotated): Tree = {
val ann = atd.annot
val arg1 = typed(atd.arg, mode, pt)
Expand Down Expand Up @@ -4613,7 +4619,7 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
if (sym.isAbstractType || sym.hasAbstractFlag)
IsAbstractError(tree, sym)
else if (isPrimitiveValueClass(sym)) {
NotAMemberError(tpt, TypeTree(tp), nme.CONSTRUCTOR)
NotAMemberError(tpt, TypeTree(tp), nme.CONSTRUCTOR, startingIdentContext)
setError(tpt)
}
else if (!( tp == sym.typeOfThis // when there's no explicit self type -- with (#3612) or without self variable
Expand Down
8 changes: 6 additions & 2 deletions test/files/neg/suggest-similar.check
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@ suggest-similar.scala:20: error: object stdin is not a member of package io
did you mean StdIn?
import scala.io.stdin.{readLine => line}
^
suggest-similar.scala:33: error: value foo is not a member of object example.Hohokus
suggest-similar.scala:37: error: value foo is not a member of object example.Hohokus
did you mean foo1, foo2, foo3, or foo4?
Hohokus.foo
^
6 errors found
suggest-similar.scala:41: error: value bar is not a member of example.Hohokus
did you mean bar2?
new Hohokus().bar // don't suggest bar1
^
7 errors found
8 changes: 8 additions & 0 deletions test/files/neg/suggest-similar.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ object C {
import scala.io.stdin.{readLine => line}
}

class Hohokus {
protected def bar1
protected[example] def bar2
}
object Hohokus {
def foo1 = 1
def foo2 = 2
Expand All @@ -32,3 +36,7 @@ object Hohokus {
object D {
Hohokus.foo
}

object E {
new Hohokus().bar // don't suggest bar1
}
10 changes: 5 additions & 5 deletions test/files/neg/t3871b.check
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ did you mean prot or protE?
c.protT // not allowed
^
t3871b.scala:81: error: value protT is not a member of E.this.A
did you mean prot or protE?
did you mean protE?
a.protT // not allowed
^
t3871b.scala:91: error: method prot in class A cannot be accessed in E.this.A
Expand All @@ -34,7 +34,7 @@ did you mean prot or protE?
c.protT // not allowed
^
t3871b.scala:95: error: value protT is not a member of E.this.A
did you mean prot or protE?
did you mean protE?
a.protT // not allowed
^
t3871b.scala:102: error: method prot in class A cannot be accessed in E.this.B
Expand All @@ -56,15 +56,15 @@ t3871b.scala:104: error: method prot in class A cannot be accessed in E.this.A
a.prot // not allowed
^
t3871b.scala:109: error: value protT is not a member of E.this.B
did you mean prot or protE?
did you mean protE?
b.protT // not allowed
^
t3871b.scala:110: error: value protT is not a member of E.this.C
did you mean prot or protE?
did you mean protE?
c.protT // not allowed
^
t3871b.scala:111: error: value protT is not a member of E.this.A
did you mean prot or protE?
did you mean protE?
a.protT // not allowed
^
t3871b.scala:120: error: method prot in class A cannot be accessed in Other.this.e.B
Expand Down

0 comments on commit 1e8ec90

Please sign in to comment.