Skip to content

Commit d2c96d0

Browse files
committed
Merge pull request #667 from dotty-staging/fix/#646-array-addition
Fix/#646 array addition
2 parents 7c88469 + 74e9107 commit d2c96d0

File tree

9 files changed

+57
-24
lines changed

9 files changed

+57
-24
lines changed

src/dotty/DottyPredef.scala

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,34 @@ import scala.reflect.ClassTag
44
import scala.reflect.runtime.universe.TypeTag
55
import scala.Predef.??? // this is currently ineffective, because of #530
66

7-
object DottyPredef {
8-
/** implicits for ClassTag and TypeTag. Should be implemented with macros */
7+
abstract class I1 {
98
implicit def classTag[T]: ClassTag[T] = scala.Predef.???
109
implicit def typeTag[T]: TypeTag[T] = scala.Predef.???
11-
12-
13-
/** ClassTags for final classes */
10+
implicit val DoubleClassTag: ClassTag[Double] = ClassTag.Double
11+
}
12+
abstract class I2 extends I1 {
13+
implicit val FloatClassTag: ClassTag[Double] = ClassTag.Double
14+
}
15+
abstract class I3 extends I2 {
16+
implicit val LongClassTag: ClassTag[Long] = ClassTag.Long
17+
}
18+
abstract class I4 extends I3 {
1419
implicit val IntClassTag: ClassTag[Int] = ClassTag.Int
15-
implicit val ByteClassTag: ClassTag[Byte] = ClassTag.Byte
20+
}
21+
abstract class I5 extends I4 {
1622
implicit val ShortClassTag: ClassTag[Short] = ClassTag.Short
23+
}
24+
abstract class I6 extends I5 {
25+
implicit val ByteClassTag: ClassTag[Byte] = ClassTag.Byte
1726
implicit val CharClassTag: ClassTag[Char] = ClassTag.Char
18-
implicit val LongClassTag: ClassTag[Long] = ClassTag.Long
19-
implicit val FloatClassTag: ClassTag[Float] = ClassTag.Float
20-
implicit val DoubleClassTag: ClassTag[Double] = ClassTag.Double
2127
implicit val BooleanClassTag: ClassTag[Boolean] = ClassTag.Boolean
2228
implicit val UnitClassTag: ClassTag[Unit] = ClassTag.Unit
2329
implicit val NullClassTag: ClassTag[Null] = ClassTag.Null
30+
}
31+
32+
/** implicits for ClassTag and TypeTag. Should be implemented with macros */
33+
object DottyPredef extends I6 {
34+
35+
/** ClassTags for final classes */
2436
implicit val NothingClassTag: ClassTag[Nothing] = ClassTag.Nothing
2537
}

src/dotty/tools/dotc/core/Contexts.scala

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -386,13 +386,6 @@ object Contexts {
386386
final def withOwner(owner: Symbol): Context =
387387
if (owner ne this.owner) fresh.setOwner(owner) else this
388388

389-
final def withMode(mode: Mode): Context =
390-
if (mode != this.mode) fresh.setMode(mode) else this
391-
392-
final def addMode(mode: Mode): Context = withMode(this.mode | mode)
393-
final def maskMode(mode: Mode): Context = withMode(this.mode & mode)
394-
final def retractMode(mode: Mode): Context = withMode(this.mode &~ mode)
395-
396389
override def toString =
397390
"Context(\n" +
398391
(outersIterator map ( ctx => s" owner = ${ctx.owner}, scope = ${ctx.scope}") mkString "\n")
@@ -444,6 +437,21 @@ object Contexts {
444437
def setDebug = setSetting(base.settings.debug, true)
445438
}
446439

440+
implicit class ModeChanges(val c: Context) extends AnyVal {
441+
final def withMode(mode: Mode): Context =
442+
if (mode != c.mode) c.fresh.setMode(mode) else c
443+
444+
final def addMode(mode: Mode): Context = withMode(c.mode | mode)
445+
final def maskMode(mode: Mode): Context = withMode(c.mode & mode)
446+
final def retractMode(mode: Mode): Context = withMode(c.mode &~ mode)
447+
}
448+
449+
implicit class FreshModeChanges(val c: FreshContext) extends AnyVal {
450+
final def addMode(mode: Mode): c.type = c.setMode(c.mode | mode)
451+
final def maskMode(mode: Mode): c.type = c.setMode(c.mode & mode)
452+
final def retractMode(mode: Mode): c.type = c.setMode(c.mode &~ mode)
453+
}
454+
447455
/** A class defining the initial context with given context base
448456
* and set of possible settings.
449457
*/

src/dotty/tools/dotc/printing/PlainPrinter.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import typer.Mode
1212
import scala.annotation.switch
1313

1414
class PlainPrinter(_ctx: Context) extends Printer {
15-
protected[this] implicit def ctx: Context = _ctx.fresh.addMode(Mode.Printing)
15+
protected[this] implicit def ctx: Context = _ctx.addMode(Mode.Printing)
1616

1717
protected def maxToTextRecursions = 100
1818

src/dotty/tools/dotc/printing/RefinedPrinter.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,8 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
148148
case JavaArrayType(elemtp) =>
149149
return toText(elemtp) ~ "[]"
150150
case tp: SelectionProto =>
151-
return "?{ " ~ toText(tp.name) ~ ": " ~ toText(tp.memberProto) ~ " }"
151+
return "?{ " ~ toText(tp.name) ~ (" " provided !tp.name.decode.last.isLetterOrDigit) ~
152+
": " ~ toText(tp.memberProto) ~ " }"
152153
case tp: ViewProto =>
153154
return toText(tp.argType) ~ " ?=>? " ~ toText(tp.resultType)
154155
case tp @ FunProto(args, resultType, _) =>

src/dotty/tools/dotc/typer/Implicits.scala

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ object Implicits {
9090
}
9191

9292
if (refs.isEmpty) refs
93-
else refs filter (refMatches(_)(ctx.fresh.setExploreTyperState.addMode(Mode.TypevarsMissContext))) // create a defensive copy of ctx to avoid constraint pollution
93+
else refs filter (refMatches(_)(ctx.fresh.addMode(Mode.TypevarsMissContext).setExploreTyperState)) // create a defensive copy of ctx to avoid constraint pollution
9494
}
9595
}
9696

@@ -384,7 +384,9 @@ trait Implicits { self: Typer =>
384384
&& (ctx.mode is Mode.ImplicitsEnabled)
385385
&& from.isInstanceOf[ValueType]
386386
&& ( from.isValueSubType(to)
387-
|| inferView(dummyTreeOfType(from), to)(ctx.fresh.setExploreTyperState).isInstanceOf[SearchSuccess]
387+
|| inferView(dummyTreeOfType(from), to)
388+
(ctx.fresh.addMode(Mode.ImplicitExploration).setExploreTyperState)
389+
.isInstanceOf[SearchSuccess]
388390
)
389391
)
390392

@@ -480,7 +482,8 @@ trait Implicits { self: Typer =>
480482
pt)
481483
val generated1 = adapt(generated, pt)
482484
lazy val shadowing =
483-
typed(untpd.Ident(ref.name) withPos pos.toSynthetic, funProto)(nestedContext.setNewTyperState.addMode(Mode.ImplicitShadowing))
485+
typed(untpd.Ident(ref.name) withPos pos.toSynthetic, funProto)
486+
(nestedContext.addMode(Mode.ImplicitShadowing).setNewTyperState)
484487
def refMatches(shadowing: Tree): Boolean =
485488
ref.symbol == closureBody(shadowing).symbol || {
486489
shadowing match {
@@ -514,8 +517,11 @@ trait Implicits { self: Typer =>
514517
case fail: SearchFailure =>
515518
rankImplicits(pending1, acc)
516519
case best: SearchSuccess =>
517-
val newPending = pending1 filter (isAsGood(_, best.ref)(nestedContext.setExploreTyperState))
518-
rankImplicits(newPending, best :: acc)
520+
if (ctx.mode.is(Mode.ImplicitExploration)) best :: Nil
521+
else {
522+
val newPending = pending1 filter (isAsGood(_, best.ref)(nestedContext.setExploreTyperState))
523+
rankImplicits(newPending, best :: acc)
524+
}
519525
}
520526
case nil => acc
521527
}

src/dotty/tools/dotc/typer/Mode.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,5 +73,11 @@ object Mode {
7373
*/
7474
val ImplicitShadowing = newMode(11, "ImplicitShadowing")
7575

76+
/** We are currently in a `viewExists` check. In that case, ambiguous
77+
* implicits checks are disabled and we succeed with the first implicit
78+
* found.
79+
*/
80+
val ImplicitExploration = newMode(12, "ImplicitExploration")
81+
7682
val PatternOrType = Pattern | Type
7783
}

src/dotty/tools/dotc/typer/Namer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -701,7 +701,7 @@ class Namer { typer: Typer =>
701701

702702
// println(s"final inherited for $sym: ${inherited.toString}") !!!
703703
// println(s"owner = ${sym.owner}, decls = ${sym.owner.info.decls.show}")
704-
val rhsCtx = ctx.fresh addMode Mode.InferringReturnType
704+
val rhsCtx = ctx.addMode(Mode.InferringReturnType)
705705
def rhsType = ctx.deskolemize(
706706
typedAheadExpr(mdef.rhs, rhsProto)(rhsCtx).tpe.widen.approximateUnion)
707707
def lhsType = fullyDefinedType(rhsType, "right-hand side", mdef.pos)

0 commit comments

Comments
 (0)