aboutsummaryrefslogtreecommitdiff
path: root/compiler/src
diff options
context:
space:
mode:
authorGuillaume Martres <smarter@ubuntu.com>2016-12-21 21:05:12 +0100
committerGitHub <noreply@github.com>2016-12-21 21:05:12 +0100
commitf3bf225c241fcf0db8f71585e15161f2cda9bd59 (patch)
tree86447535e894c20ae01143e786439f595e4e7887 /compiler/src
parent098c50ac83eb4d18b23a1ed888cf601053c46ae6 (diff)
parentd1b7f2c39561ae64c95b94242fe3bc91beb8af25 (diff)
downloaddotty-f3bf225c241fcf0db8f71585e15161f2cda9bd59.tar.gz
dotty-f3bf225c241fcf0db8f71585e15161f2cda9bd59.tar.bz2
dotty-f3bf225c241fcf0db8f71585e15161f2cda9bd59.zip
Merge pull request #1848 from dotty-staging/fix-#1795
Fix #1795: Avoid infinite recursion between member and asSeenFrom
Diffstat (limited to 'compiler/src')
-rw-r--r--compiler/src/dotty/tools/dotc/config/Config.scala4
-rw-r--r--compiler/src/dotty/tools/dotc/core/TypeOps.scala20
-rw-r--r--compiler/src/dotty/tools/dotc/core/Types.scala6
3 files changed, 24 insertions, 6 deletions
diff --git a/compiler/src/dotty/tools/dotc/config/Config.scala b/compiler/src/dotty/tools/dotc/config/Config.scala
index 7744a5479..119af9483 100644
--- a/compiler/src/dotty/tools/dotc/config/Config.scala
+++ b/compiler/src/dotty/tools/dotc/config/Config.scala
@@ -133,6 +133,8 @@ object Config {
*/
final val LogPendingFindMemberThreshold = 10
- /** Maximal number of outstanding recursive calls to findMember */
+ /** Maximal number of outstanding recursive calls to findMember before backing out
+ * when findMemberLimit is set.
+ */
final val PendingFindMemberLimit = LogPendingFindMemberThreshold * 4
}
diff --git a/compiler/src/dotty/tools/dotc/core/TypeOps.scala b/compiler/src/dotty/tools/dotc/core/TypeOps.scala
index f134412a7..db73daaa2 100644
--- a/compiler/src/dotty/tools/dotc/core/TypeOps.scala
+++ b/compiler/src/dotty/tools/dotc/core/TypeOps.scala
@@ -10,7 +10,8 @@ import NameOps._
import Decorators._
import StdNames._
import Annotations._
-import util.SimpleMap
+import config.Config
+import util.{SimpleMap, Property}
import collection.mutable
import ast.tpd._
@@ -67,7 +68,10 @@ trait TypeOps { this: Context => // TODO: Make standalone object.
if (thiscls.derivesFrom(cls) && pre.baseTypeRef(thiscls).exists) {
if (theMap != null && theMap.currentVariance <= 0 && !isLegalPrefix(pre)) {
ctx.base.unsafeNonvariant = ctx.runId
- AnnotatedType(pre, Annotation(defn.UnsafeNonvariantAnnot, Nil))
+ pre match {
+ case AnnotatedType(_, ann) if ann.symbol == defn.UnsafeNonvariantAnnot => pre
+ case _ => AnnotatedType(pre, Annotation(defn.UnsafeNonvariantAnnot, Nil))
+ }
}
else pre
}
@@ -85,13 +89,15 @@ trait TypeOps { this: Context => // TODO: Make standalone object.
if (sym.isStatic) tp
else {
val pre1 = asSeenFrom(tp.prefix, pre, cls, theMap)
- if (pre1.isUnsafeNonvariant)
- pre1.member(tp.name).info match {
+ if (pre1.isUnsafeNonvariant) {
+ val safeCtx = ctx.withProperty(TypeOps.findMemberLimit, Some(()))
+ pre1.member(tp.name)(safeCtx).info match {
case TypeAlias(alias) =>
// try to follow aliases of this will avoid skolemization.
return alias
case _ =>
}
+ }
tp.derivedSelect(pre1)
}
case tp: ThisType =>
@@ -554,4 +560,10 @@ trait TypeOps { this: Context => // TODO: Make standalone object.
object TypeOps {
@sharable var track = false // !!!DEBUG
+
+ /** When a property with this key is set in a context, it limit the number
+ * of recursive member searches. If the limit is reached, findMember returns
+ * NoDenotation.
+ */
+ val findMemberLimit = new Property.Key[Unit]
}
diff --git a/compiler/src/dotty/tools/dotc/core/Types.scala b/compiler/src/dotty/tools/dotc/core/Types.scala
index 069b4f60d..64fa48071 100644
--- a/compiler/src/dotty/tools/dotc/core/Types.scala
+++ b/compiler/src/dotty/tools/dotc/core/Types.scala
@@ -573,8 +573,12 @@ object Types {
{ val recCount = ctx.findMemberCount + 1
ctx.findMemberCount = recCount
- if (recCount >= Config.LogPendingFindMemberThreshold)
+ if (recCount >= Config.LogPendingFindMemberThreshold) {
ctx.pendingMemberSearches = name :: ctx.pendingMemberSearches
+ if (ctx.property(TypeOps.findMemberLimit).isDefined &&
+ ctx.findMemberCount > Config.PendingFindMemberLimit)
+ return NoDenotation
+ }
}
//assert(ctx.findMemberCount < 20)