aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/typer/Typer.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2016-08-26 18:29:17 +0200
committerMartin Odersky <odersky@gmail.com>2016-08-26 18:29:25 +0200
commit99afc892839ca6209786ccd0dbca2544633be2e8 (patch)
treed1a48aee4e95bbee6a6399fd7157648572645778 /src/dotty/tools/dotc/typer/Typer.scala
parent1a538af06323f7d6cd471ae0af39842f26e9e7be (diff)
downloaddotty-99afc892839ca6209786ccd0dbca2544633be2e8.tar.gz
dotty-99afc892839ca6209786ccd0dbca2544633be2e8.tar.bz2
dotty-99afc892839ca6209786ccd0dbca2544633be2e8.zip
Accommodate Scala2 name resolution scheme
Scala2 does not conform to spec Section 2, where it says: Bindings of different kinds have a precedence defined on them: 1. Definitions and declarations that are local, inherited, or made available by a package clause and also defined in the same compilation unit as the reference, have highest precedence. 2. Explicit imports have next highest precedence. 3. Wildcard imports have next highest precedence. 4. Definitions made available by a package clause, but not also defined in the same compilation unit as the reference, have lowest precedence. In fact Scala 2, merges (1) and (4) into highest precedence. This commit simulates the Scala2 behavior under -language:Scala2, but gives a migration warning. For the naming-resolution test case we get: dotc *.scala -language:Scala2 -migration callsite.scala:9: migration warning: Name resolution will change. currently selected : naming.resolution.Files in the future, without -language:Scala2: java.nio.file.Files' where Files is a type in package object package which is an alias of java.util.stream.Stream[java.nio.file.Path] Files' is a class in package file def gimmeFiles: Files = Files.list(Paths.get(".")) ^ one warning found
Diffstat (limited to 'src/dotty/tools/dotc/typer/Typer.scala')
-rw-r--r--src/dotty/tools/dotc/typer/Typer.scala31
1 files changed, 26 insertions, 5 deletions
diff --git a/src/dotty/tools/dotc/typer/Typer.scala b/src/dotty/tools/dotc/typer/Typer.scala
index 52470ba87..5fbb395ba 100644
--- a/src/dotty/tools/dotc/typer/Typer.scala
+++ b/src/dotty/tools/dotc/typer/Typer.scala
@@ -72,6 +72,13 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
*/
private var importedFromRoot: Set[Symbol] = Set()
+ /** Temporary data item for single call to typed ident:
+ * This symbol would be found under Scala2 mode, but is not
+ * in dotty (because dotty conforms to spec section 2
+ * wrt to package member resolution but scalac doe not).
+ */
+ private var foundUnderScala2: Type = _
+
def newLikeThis: Typer = new Typer
/** Attribute an identifier consisting of a simple name or wildcard
@@ -228,10 +235,14 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
else curOwner.thisType.select(name, defDenot)
if (!(curOwner is Package) || isDefinedInCurrentUnit(defDenot))
return checkNewOrShadowed(found, definition) // no need to go further out, we found highest prec entry
- else if (defDenot.symbol is Package)
- return checkNewOrShadowed(previous orElse found, packageClause)
- else if (prevPrec < packageClause)
- return findRef(found, packageClause, ctx)(outer)
+ else {
+ if (ctx.scala2Mode)
+ foundUnderScala2 = checkNewOrShadowed(found, definition)
+ if (defDenot.symbol is Package)
+ return checkNewOrShadowed(previous orElse found, packageClause)
+ else if (prevPrec < packageClause)
+ return findRef(found, packageClause, ctx)(outer)
+ }
}
}
val curImport = ctx.importInfo
@@ -267,10 +278,20 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
val saved = importedFromRoot
importedFromRoot = Set.empty
- val rawType =
+ foundUnderScala2 = NoType
+
+ var rawType =
try findRef(NoType, BindingPrec.nothingBound, NoContext)
finally importedFromRoot = saved
+ if (foundUnderScala2.exists && (foundUnderScala2 ne rawType)) {
+ ctx.migrationWarning(
+ ex"""Name resolution will change.
+ | currently selected : $foundUnderScala2
+ | in the future, without -language:Scala2: $rawType""", tree.pos)
+ rawType = foundUnderScala2
+ }
+
val ownType =
if (rawType.exists)
ensureAccessible(rawType, superAccess = false, tree.pos)