Skip to content

Commit b1cb657

Browse files
committed
Merge pull request scala#1697 from retronym/ticket/6745-2
Don't return unimportables from importedSymbol.
2 parents d64f99f + ff9cfd9 commit b1cb657

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

src/compiler/scala/tools/nsc/typechecker/Contexts.scala

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -996,7 +996,14 @@ trait Contexts { self: Analyzer =>
996996
if (settings.lint.value && selectors.nonEmpty && result != NoSymbol && pos != NoPosition)
997997
recordUsage(current, result)
998998

999-
result
999+
// Harden against the fallout from bugs like SI-6745
1000+
//
1001+
// [JZ] I considered issuing a devWarning and moving the
1002+
// check inside the above loop, as I believe that
1003+
// this always represents a mistake on the part of
1004+
// the caller.
1005+
if (definitions isImportable result) result
1006+
else NoSymbol
10001007
}
10011008
private def selectorString(s: ImportSelector): String = {
10021009
if (s.name == nme.WILDCARD && s.rename == null) "_"

test/files/run/t6745-2.scala

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import scala.tools.nsc._
2+
import scala.tools.partest.CompilerTest
3+
import scala.collection.{ mutable, immutable, generic }
4+
5+
object Test extends CompilerTest {
6+
import global._
7+
import rootMirror._
8+
import definitions._
9+
import global.analyzer.{Context, ImportInfo}
10+
11+
override def code = """
12+
package context {
13+
}
14+
"""
15+
16+
def check(source: String, unit: global.CompilationUnit) = {
17+
val context: Context = global.analyzer.rootContext(unit)
18+
val importInfo: ImportInfo = context.imports.head // Predef._
19+
val importedSym = importInfo.importedSymbol(nme.CONSTRUCTOR)
20+
assert(importedSym == NoSymbol, importedSym) // was "constructor Predef"
21+
}
22+
}

0 commit comments

Comments
 (0)