aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorodersky <odersky@gmail.com>2015-06-22 13:09:24 +0200
committerodersky <odersky@gmail.com>2015-06-22 13:09:24 +0200
commitd2c96d02fccef3a82b88ee1ff31253b6ef17f900 (patch)
treeae953d7d2a4e610fc6725102f34b4a3dab55cd80
parent7c88469bdaf212cfdccce565d6ffe638dd5c1dff (diff)
parent74e9107e25a2b2f50a8d80b3b13136e5ab9eb6e9 (diff)
downloaddotty-d2c96d02fccef3a82b88ee1ff31253b6ef17f900.tar.gz
dotty-d2c96d02fccef3a82b88ee1ff31253b6ef17f900.tar.bz2
dotty-d2c96d02fccef3a82b88ee1ff31253b6ef17f900.zip
Merge pull request #667 from dotty-staging/fix/#646-array-addition
Fix/#646 array addition
-rw-r--r--src/dotty/DottyPredef.scala30
-rw-r--r--src/dotty/tools/dotc/core/Contexts.scala22
-rw-r--r--src/dotty/tools/dotc/printing/PlainPrinter.scala2
-rw-r--r--src/dotty/tools/dotc/printing/RefinedPrinter.scala3
-rw-r--r--src/dotty/tools/dotc/typer/Implicits.scala16
-rw-r--r--src/dotty/tools/dotc/typer/Mode.scala6
-rw-r--r--src/dotty/tools/dotc/typer/Namer.scala2
-rw-r--r--tests/run/array-addition.check (renamed from tests/pending/run/array-addition.check)0
-rw-r--r--tests/run/array-addition.scala (renamed from tests/pending/run/array-addition.scala)0
9 files changed, 57 insertions, 24 deletions
diff --git a/src/dotty/DottyPredef.scala b/src/dotty/DottyPredef.scala
index 7c8098bd1..0a5d4d7f3 100644
--- a/src/dotty/DottyPredef.scala
+++ b/src/dotty/DottyPredef.scala
@@ -4,22 +4,34 @@ import scala.reflect.ClassTag
import scala.reflect.runtime.universe.TypeTag
import scala.Predef.??? // this is currently ineffective, because of #530
-object DottyPredef {
- /** implicits for ClassTag and TypeTag. Should be implemented with macros */
+abstract class I1 {
implicit def classTag[T]: ClassTag[T] = scala.Predef.???
implicit def typeTag[T]: TypeTag[T] = scala.Predef.???
-
-
- /** ClassTags for final classes */
+ implicit val DoubleClassTag: ClassTag[Double] = ClassTag.Double
+}
+abstract class I2 extends I1 {
+ implicit val FloatClassTag: ClassTag[Double] = ClassTag.Double
+}
+abstract class I3 extends I2 {
+ implicit val LongClassTag: ClassTag[Long] = ClassTag.Long
+}
+abstract class I4 extends I3 {
implicit val IntClassTag: ClassTag[Int] = ClassTag.Int
- implicit val ByteClassTag: ClassTag[Byte] = ClassTag.Byte
+}
+abstract class I5 extends I4 {
implicit val ShortClassTag: ClassTag[Short] = ClassTag.Short
+}
+abstract class I6 extends I5 {
+ implicit val ByteClassTag: ClassTag[Byte] = ClassTag.Byte
implicit val CharClassTag: ClassTag[Char] = ClassTag.Char
- implicit val LongClassTag: ClassTag[Long] = ClassTag.Long
- implicit val FloatClassTag: ClassTag[Float] = ClassTag.Float
- implicit val DoubleClassTag: ClassTag[Double] = ClassTag.Double
implicit val BooleanClassTag: ClassTag[Boolean] = ClassTag.Boolean
implicit val UnitClassTag: ClassTag[Unit] = ClassTag.Unit
implicit val NullClassTag: ClassTag[Null] = ClassTag.Null
+}
+
+/** implicits for ClassTag and TypeTag. Should be implemented with macros */
+object DottyPredef extends I6 {
+
+ /** ClassTags for final classes */
implicit val NothingClassTag: ClassTag[Nothing] = ClassTag.Nothing
}
diff --git a/src/dotty/tools/dotc/core/Contexts.scala b/src/dotty/tools/dotc/core/Contexts.scala
index b00896117..c9deaab10 100644
--- a/src/dotty/tools/dotc/core/Contexts.scala
+++ b/src/dotty/tools/dotc/core/Contexts.scala
@@ -386,13 +386,6 @@ object Contexts {
final def withOwner(owner: Symbol): Context =
if (owner ne this.owner) fresh.setOwner(owner) else this
- final def withMode(mode: Mode): Context =
- if (mode != this.mode) fresh.setMode(mode) else this
-
- final def addMode(mode: Mode): Context = withMode(this.mode | mode)
- final def maskMode(mode: Mode): Context = withMode(this.mode & mode)
- final def retractMode(mode: Mode): Context = withMode(this.mode &~ mode)
-
override def toString =
"Context(\n" +
(outersIterator map ( ctx => s" owner = ${ctx.owner}, scope = ${ctx.scope}") mkString "\n")
@@ -444,6 +437,21 @@ object Contexts {
def setDebug = setSetting(base.settings.debug, true)
}
+ implicit class ModeChanges(val c: Context) extends AnyVal {
+ final def withMode(mode: Mode): Context =
+ if (mode != c.mode) c.fresh.setMode(mode) else c
+
+ final def addMode(mode: Mode): Context = withMode(c.mode | mode)
+ final def maskMode(mode: Mode): Context = withMode(c.mode & mode)
+ final def retractMode(mode: Mode): Context = withMode(c.mode &~ mode)
+ }
+
+ implicit class FreshModeChanges(val c: FreshContext) extends AnyVal {
+ final def addMode(mode: Mode): c.type = c.setMode(c.mode | mode)
+ final def maskMode(mode: Mode): c.type = c.setMode(c.mode & mode)
+ final def retractMode(mode: Mode): c.type = c.setMode(c.mode &~ mode)
+ }
+
/** A class defining the initial context with given context base
* and set of possible settings.
*/
diff --git a/src/dotty/tools/dotc/printing/PlainPrinter.scala b/src/dotty/tools/dotc/printing/PlainPrinter.scala
index 86dd3878c..5d2309e95 100644
--- a/src/dotty/tools/dotc/printing/PlainPrinter.scala
+++ b/src/dotty/tools/dotc/printing/PlainPrinter.scala
@@ -12,7 +12,7 @@ import typer.Mode
import scala.annotation.switch
class PlainPrinter(_ctx: Context) extends Printer {
- protected[this] implicit def ctx: Context = _ctx.fresh.addMode(Mode.Printing)
+ protected[this] implicit def ctx: Context = _ctx.addMode(Mode.Printing)
protected def maxToTextRecursions = 100
diff --git a/src/dotty/tools/dotc/printing/RefinedPrinter.scala b/src/dotty/tools/dotc/printing/RefinedPrinter.scala
index 2288fe9c0..70fab7e0f 100644
--- a/src/dotty/tools/dotc/printing/RefinedPrinter.scala
+++ b/src/dotty/tools/dotc/printing/RefinedPrinter.scala
@@ -148,7 +148,8 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
case JavaArrayType(elemtp) =>
return toText(elemtp) ~ "[]"
case tp: SelectionProto =>
- return "?{ " ~ toText(tp.name) ~ ": " ~ toText(tp.memberProto) ~ " }"
+ return "?{ " ~ toText(tp.name) ~ (" " provided !tp.name.decode.last.isLetterOrDigit) ~
+ ": " ~ toText(tp.memberProto) ~ " }"
case tp: ViewProto =>
return toText(tp.argType) ~ " ?=>? " ~ toText(tp.resultType)
case tp @ FunProto(args, resultType, _) =>
diff --git a/src/dotty/tools/dotc/typer/Implicits.scala b/src/dotty/tools/dotc/typer/Implicits.scala
index 43d93b2b8..a3ddca5d9 100644
--- a/src/dotty/tools/dotc/typer/Implicits.scala
+++ b/src/dotty/tools/dotc/typer/Implicits.scala
@@ -90,7 +90,7 @@ object Implicits {
}
if (refs.isEmpty) refs
- else refs filter (refMatches(_)(ctx.fresh.setExploreTyperState.addMode(Mode.TypevarsMissContext))) // create a defensive copy of ctx to avoid constraint pollution
+ else refs filter (refMatches(_)(ctx.fresh.addMode(Mode.TypevarsMissContext).setExploreTyperState)) // create a defensive copy of ctx to avoid constraint pollution
}
}
@@ -384,7 +384,9 @@ trait Implicits { self: Typer =>
&& (ctx.mode is Mode.ImplicitsEnabled)
&& from.isInstanceOf[ValueType]
&& ( from.isValueSubType(to)
- || inferView(dummyTreeOfType(from), to)(ctx.fresh.setExploreTyperState).isInstanceOf[SearchSuccess]
+ || inferView(dummyTreeOfType(from), to)
+ (ctx.fresh.addMode(Mode.ImplicitExploration).setExploreTyperState)
+ .isInstanceOf[SearchSuccess]
)
)
@@ -480,7 +482,8 @@ trait Implicits { self: Typer =>
pt)
val generated1 = adapt(generated, pt)
lazy val shadowing =
- typed(untpd.Ident(ref.name) withPos pos.toSynthetic, funProto)(nestedContext.setNewTyperState.addMode(Mode.ImplicitShadowing))
+ typed(untpd.Ident(ref.name) withPos pos.toSynthetic, funProto)
+ (nestedContext.addMode(Mode.ImplicitShadowing).setNewTyperState)
def refMatches(shadowing: Tree): Boolean =
ref.symbol == closureBody(shadowing).symbol || {
shadowing match {
@@ -514,8 +517,11 @@ trait Implicits { self: Typer =>
case fail: SearchFailure =>
rankImplicits(pending1, acc)
case best: SearchSuccess =>
- val newPending = pending1 filter (isAsGood(_, best.ref)(nestedContext.setExploreTyperState))
- rankImplicits(newPending, best :: acc)
+ if (ctx.mode.is(Mode.ImplicitExploration)) best :: Nil
+ else {
+ val newPending = pending1 filter (isAsGood(_, best.ref)(nestedContext.setExploreTyperState))
+ rankImplicits(newPending, best :: acc)
+ }
}
case nil => acc
}
diff --git a/src/dotty/tools/dotc/typer/Mode.scala b/src/dotty/tools/dotc/typer/Mode.scala
index e84ef2784..b903049d2 100644
--- a/src/dotty/tools/dotc/typer/Mode.scala
+++ b/src/dotty/tools/dotc/typer/Mode.scala
@@ -73,5 +73,11 @@ object Mode {
*/
val ImplicitShadowing = newMode(11, "ImplicitShadowing")
+ /** We are currently in a `viewExists` check. In that case, ambiguous
+ * implicits checks are disabled and we succeed with the first implicit
+ * found.
+ */
+ val ImplicitExploration = newMode(12, "ImplicitExploration")
+
val PatternOrType = Pattern | Type
}
diff --git a/src/dotty/tools/dotc/typer/Namer.scala b/src/dotty/tools/dotc/typer/Namer.scala
index 11a0bd76e..d5a6ec8f4 100644
--- a/src/dotty/tools/dotc/typer/Namer.scala
+++ b/src/dotty/tools/dotc/typer/Namer.scala
@@ -701,7 +701,7 @@ class Namer { typer: Typer =>
// println(s"final inherited for $sym: ${inherited.toString}") !!!
// println(s"owner = ${sym.owner}, decls = ${sym.owner.info.decls.show}")
- val rhsCtx = ctx.fresh addMode Mode.InferringReturnType
+ val rhsCtx = ctx.addMode(Mode.InferringReturnType)
def rhsType = ctx.deskolemize(
typedAheadExpr(mdef.rhs, rhsProto)(rhsCtx).tpe.widen.approximateUnion)
def lhsType = fullyDefinedType(rhsType, "right-hand side", mdef.pos)
diff --git a/tests/pending/run/array-addition.check b/tests/run/array-addition.check
index 7bfbd9c71..7bfbd9c71 100644
--- a/tests/pending/run/array-addition.check
+++ b/tests/run/array-addition.check
diff --git a/tests/pending/run/array-addition.scala b/tests/run/array-addition.scala
index 8def48e85..8def48e85 100644
--- a/tests/pending/run/array-addition.scala
+++ b/tests/run/array-addition.scala