Skip to content

Commit 76f1673

Browse files
committed
Merge remote-tracking branch 'scala/2.10.x' into patmat-refactor-master
Conflicts: src/compiler/scala/tools/nsc/typechecker/Implicits.scala
2 parents 1404802 + f51ed74 commit 76f1673

File tree

13 files changed

+102
-16
lines changed

13 files changed

+102
-16
lines changed

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,14 @@ trait Contexts { self: Analyzer =>
630630
new ImplicitInfo(sym.name, pre, sym)
631631

632632
private def collectImplicitImports(imp: ImportInfo): List[ImplicitInfo] = {
633-
val pre = imp.qual.tpe
633+
val qual = imp.qual
634+
635+
val pre =
636+
if (qual.tpe.typeSymbol.isPackageClass)
637+
// SI-6225 important if the imported symbol is inherited by the the package object.
638+
singleType(qual.tpe, qual.tpe member nme.PACKAGE)
639+
else
640+
qual.tpe
634641
def collect(sels: List[ImportSelector]): List[ImplicitInfo] = sels match {
635642
case List() =>
636643
List()

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ trait Implicits {
149149
class SearchResult(val tree: Tree, val subst: TreeTypeSubstituter) {
150150
override def toString = "SearchResult(%s, %s)".format(tree,
151151
if (subst.isEmpty) "" else subst)
152-
152+
153153
def isFailure = false
154154
def isAmbiguousFailure = false
155155
final def isSuccess = !isFailure
@@ -158,7 +158,7 @@ trait Implicits {
158158
lazy val SearchFailure = new SearchResult(EmptyTree, EmptyTreeTypeSubstituter) {
159159
override def isFailure = true
160160
}
161-
161+
162162
lazy val AmbiguousSearchFailure = new SearchResult(EmptyTree, EmptyTreeTypeSubstituter) {
163163
override def isFailure = true
164164
override def isAmbiguousFailure = true
@@ -244,7 +244,7 @@ trait Implicits {
244244
object HasMember {
245245
private val hasMemberCache = perRunCaches.newMap[Name, Type]()
246246
def apply(name: Name): Type = hasMemberCache.getOrElseUpdate(name, memberWildcardType(name, WildcardType))
247-
}
247+
}
248248

249249
/** An extractor for types of the form ? { name: (? >: argtpe <: Any*)restp }
250250
*/
@@ -1128,7 +1128,7 @@ trait Implicits {
11281128
)
11291129
// todo. migrate hardcoded materialization in Implicits to corresponding implicit macros
11301130
val materializer = atPos(pos.focus)(gen.mkMethodCall(TagMaterializers(tagClass), List(tp), if (prefix != EmptyTree) List(prefix) else List()))
1131-
if (settings.XlogImplicits.value) println("materializing requested %s.%s[%s] using %s".format(pre, tagClass.name, tp, materializer))
1131+
if (settings.XlogImplicits.value) reporter.echo(pos, "materializing requested %s.%s[%s] using %s".format(pre, tagClass.name, tp, materializer))
11321132
if (context.macrosEnabled) success(materializer)
11331133
// don't call `failure` here. if macros are disabled, we just fail silently
11341134
// otherwise -Xlog-implicits will spam the long with zillions of "macros are disabled"

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,9 @@ abstract class TreeCheckers extends Analyzer {
298298
}
299299
for {
300300
sym <- referencedSymbols
301+
// Accessors are known to steal the type of the underlying field without cloning existential symbols at the new owner.
302+
// This happens in Namer#accessorTypeCompleter. We just look the other way here.
303+
if !tree.symbol.isAccessor
301304
if (sym.isTypeParameter || sym.isLocal) && !(tree.symbol hasTransOwner sym.owner)
302305
} errorFn(s"The symbol, tpe or info of tree `(${tree}) : ${info}` refers to a out-of-scope symbol, ${sym.fullLocationString}. tree.symbol.ownerChain: ${tree.symbol.ownerChain.mkString(", ")}")
303306
}

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

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -525,17 +525,24 @@ trait TypeDiagnostics {
525525
}
526526

527527
object checkDead {
528-
private var expr: Symbol = NoSymbol
528+
private val exprStack: mutable.Stack[Symbol] = mutable.Stack(NoSymbol)
529+
// The method being applied to `tree` when `apply` is called.
530+
private def expr = exprStack.top
529531

530532
private def exprOK =
531533
(expr != Object_synchronized) &&
532534
!(expr.isLabel && treeInfo.isSynthCaseSymbol(expr)) // it's okay to jump to matchEnd (or another case) with an argument of type nothing
533535

534-
private def treeOK(tree: Tree) = tree.tpe != null && tree.tpe.typeSymbol == NothingClass
536+
private def treeOK(tree: Tree) = {
537+
val isLabelDef = tree match { case _: LabelDef => true; case _ => false}
538+
tree.tpe != null && tree.tpe.typeSymbol == NothingClass && !isLabelDef
539+
}
535540

536-
def updateExpr(fn: Tree) = {
537-
if (fn.symbol != null && fn.symbol.isMethod && !fn.symbol.isConstructor)
538-
checkDead.expr = fn.symbol
541+
@inline def updateExpr[A](fn: Tree)(f: => A) = {
542+
if (fn.symbol != null && fn.symbol.isMethod && !fn.symbol.isConstructor) {
543+
exprStack push fn.symbol
544+
try f finally exprStack.pop()
545+
} else f
539546
}
540547
def apply(tree: Tree): Tree = {
541548
// Error suppression will squash some of these warnings unless we circumvent it.

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3238,8 +3238,6 @@ trait Typers extends Adaptations with Tags {
32383238
// but behaves as if it were (=> T) => T) we need to know what is the actual
32393239
// target of a call. Since this information is no longer available from
32403240
// typedArg, it is recorded here.
3241-
checkDead.updateExpr(fun)
3242-
32433241
val args1 =
32443242
// no expected type when jumping to a match label -- anything goes (this is ok since we're typing the translation of well-typed code)
32453243
// ... except during erasure: we must take the expected type into account as it drives the insertion of casts!
@@ -3274,7 +3272,9 @@ trait Typers extends Adaptations with Tags {
32743272
else
32753273
constfold(treeCopy.Apply(tree, fun, args1) setType ifPatternSkipFormals(restpe))
32763274
}
3277-
handleMonomorphicCall
3275+
checkDead.updateExpr(fun) {
3276+
handleMonomorphicCall
3277+
}
32783278
} else if (needsInstantiation(tparams, formals, args)) {
32793279
//println("needs inst "+fun+" "+tparams+"/"+(tparams map (_.info)))
32803280
inferExprInstance(fun, tparams)

src/library/scala/collection/immutable/ListMap.scala

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,12 @@ extends AbstractMap[A, B]
156156
* @return the value associated with the given key.
157157
*/
158158
override def apply(k: A): B1 = apply0(this, k)
159-
160-
@tailrec private def apply0(cur: ListMap[A, B1], k: A): B1 = if (k == cur.key) cur.value else apply0(cur.tail, k)
159+
160+
161+
@tailrec private def apply0(cur: ListMap[A, B1], k: A): B1 =
162+
if (cur.isEmpty) throw new NoSuchElementException("key not found: "+k)
163+
else if (k == cur.key) cur.value
164+
else apply0(cur.tail, k)
161165

162166
/** Checks if this map maps `key` to a value and return the
163167
* value if it exists.

src/library/scala/runtime/BoxedUnit.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ public final class BoxedUnit implements java.io.Serializable {
1717
public final static BoxedUnit UNIT = new BoxedUnit();
1818

1919
public final static Class<Void> TYPE = java.lang.Void.TYPE;
20+
21+
private Object readResolve() { return UNIT; }
2022

2123
private BoxedUnit() { }
2224

src/partest/scala/tools/partest/nest/RunnerManager.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,7 @@ class RunnerManager(kind: String, val fileManager: FileManager, params: TestRunP
720720
if (passed exists (x => !x)) {
721721
if (fileManager.showDiff || isPartestDebug)
722722
NestUI.normal(testDiff)
723-
else if (fileManager.showLog)
723+
if (fileManager.showLog)
724724
showLog(logFile)
725725
}
726726
}

test/files/neg/t6323a.check

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
t6323a.scala:10: materializing requested scala.reflect.type.ClassTag[Test] using `package`.this.materializeClassTag[Test]()
2+
val lookAtMe = m.reflect(Test("a",List(5)))
3+
^
4+
t6323a.scala:11: materializing requested reflect.runtime.universe.type.TypeTag[Test] using `package`.this.materializeTypeTag[Test](scala.reflect.runtime.`package`.universe)
5+
val value = u.typeOf[Test]
6+
^
17
t6323a.scala:11: `package`.this.materializeTypeTag[Test](scala.reflect.runtime.`package`.universe) is not a valid implicit value for reflect.runtime.universe.TypeTag[Test] because:
28
failed to typecheck the materialized tag:
39
cannot create a TypeTag referring to local class Test.Test: use WeakTypeTag instead

test/files/pos/t6225.scala

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
package library.x {
3+
class X {
4+
class Foo
5+
implicit val foo: Foo = new Foo
6+
}
7+
}
8+
package library {
9+
package object y extends library.x.X
10+
}
11+
12+
object ko {
13+
import library.y.{Foo, foo}
14+
implicitly[Foo]
15+
}
16+
17+
object ko2 {
18+
import library.y._
19+
implicitly[Foo]
20+
}

0 commit comments

Comments
 (0)