Skip to content

Commit d1f7968

Browse files
authored
Merge pull request #2716 from dotty-staging/fix-#2570-2
Fix #2570: Part 3 - The great () insert
2 parents 94e45f4 + b7afd43 commit d1f7968

File tree

128 files changed

+737
-488
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

128 files changed

+737
-488
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,4 @@ compiler/test/debug/Gen.jar
7070

7171
compiler/before-pickling.txt
7272
compiler/after-pickling.txt
73+
*.dotty-ide-version

collection-strawman

Submodule collection-strawman updated 60 files

compiler/src/dotty/tools/dotc/ast/Desugar.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ object desugar {
6969
val originalOwner = sym.owner
7070
def apply(tp: Type) = tp match {
7171
case tp: NamedType if tp.symbol.exists && (tp.symbol.owner eq originalOwner) =>
72-
val defctx = ctx.outersIterator.dropWhile(_.scope eq ctx.scope).next
72+
val defctx = ctx.outersIterator.dropWhile(_.scope eq ctx.scope).next()
7373
var local = defctx.denotNamed(tp.name).suchThat(_ is ParamOrAccessor).symbol
7474
if (local.exists) (defctx.owner.thisType select local).dealias
7575
else {
@@ -538,12 +538,12 @@ object desugar {
538538
val cdef1 = addEnumFlags {
539539
val originalTparamsIt = originalTparams.toIterator
540540
val originalVparamsIt = originalVparamss.toIterator.flatten
541-
val tparamAccessors = derivedTparams.map(_.withMods(originalTparamsIt.next.mods))
541+
val tparamAccessors = derivedTparams.map(_.withMods(originalTparamsIt.next().mods))
542542
val caseAccessor = if (isCaseClass) CaseAccessor else EmptyFlags
543543
val vparamAccessors = derivedVparamss match {
544544
case first :: rest =>
545-
first.map(_.withMods(originalVparamsIt.next.mods | caseAccessor)) ++
546-
rest.flatten.map(_.withMods(originalVparamsIt.next.mods))
545+
first.map(_.withMods(originalVparamsIt.next().mods | caseAccessor)) ++
546+
rest.flatten.map(_.withMods(originalVparamsIt.next().mods))
547547
case _ =>
548548
Nil
549549
}

compiler/src/dotty/tools/dotc/ast/NavigateAST.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ object NavigateAST {
7070
def pathTo(pos: Position, from: Positioned, skipZeroExtent: Boolean = false)(implicit ctx: Context): List[Positioned] = {
7171
def childPath(it: Iterator[Any], path: List[Positioned]): List[Positioned] = {
7272
while (it.hasNext) {
73-
val path1 = it.next match {
73+
val path1 = it.next() match {
7474
case p: Positioned => singlePath(p, path)
7575
case xs: List[_] => childPath(xs.iterator, path)
7676
case _ => path

compiler/src/dotty/tools/dotc/ast/TreeInfo.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ trait TreeInfo[T >: Untyped <: Type] { self: Trees.Instance[T] =>
5353
def map[R](f: (Symbol, Tree) => R): List[R] = {
5454
val b = List.newBuilder[R]
5555
foreach(b += f(_, _))
56-
b.result
56+
b.result()
5757
}
5858
}
5959

compiler/src/dotty/tools/dotc/ast/Trees.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ object Trees {
129129
private def checkChildrenTyped(it: Iterator[Any])(implicit ctx: Context): Unit =
130130
if (!this.isInstanceOf[Import[_]])
131131
while (it.hasNext)
132-
it.next match {
132+
it.next() match {
133133
case x: Ident[_] => // untyped idents are used in a number of places in typed trees
134134
case x: Tree[_] =>
135135
assert(x.hasType || ctx.reporter.errorsReported,

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,15 +348,15 @@ object Contexts {
348348
*/
349349
def thisCallArgContext: Context = {
350350
assert(owner.isClassConstructor)
351-
val constrCtx = outersIterator.dropWhile(_.outer.owner == owner).next
351+
val constrCtx = outersIterator.dropWhile(_.outer.owner == owner).next()
352352
superOrThisCallContext(owner, constrCtx.scope)
353353
.setTyperState(typerState)
354354
.setGadt(gadt)
355355
}
356356

357357
/** The super- or this-call context with given owner and locals. */
358358
private def superOrThisCallContext(owner: Symbol, locals: Scope): FreshContext = {
359-
var classCtx = outersIterator.dropWhile(!_.isClassDefContext).next
359+
var classCtx = outersIterator.dropWhile(!_.isClassDefContext).next()
360360
classCtx.outer.fresh.setOwner(owner)
361361
.setScope(locals)
362362
.setMode(classCtx.mode | Mode.InSuperCall)

compiler/src/dotty/tools/dotc/core/Decorators.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ object Decorators {
3737
implicit class SymbolIteratorDecorator(val it: Iterator[Symbol]) extends AnyVal {
3838
final def findSymbol(p: Symbol => Boolean): Symbol = {
3939
while (it.hasNext) {
40-
val sym = it.next
40+
val sym = it.next()
4141
if (p(sym)) return sym
4242
}
4343
NoSymbol

compiler/src/dotty/tools/dotc/core/Denotations.scala

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,8 @@ object Denotations {
408408

409409
/** Sym preference provided types also override */
410410
def prefer(sym1: Symbol, sym2: Symbol, info1: Type, info2: Type) =
411-
preferSym(sym1, sym2) && info1.overrides(info2)
411+
preferSym(sym1, sym2) &&
412+
info1.overrides(info2, sym1.matchNullaryLoosely || sym2.matchNullaryLoosely)
412413

413414
def handleDoubleDef =
414415
if (preferSym(sym1, sym2)) denot1
@@ -512,7 +513,7 @@ object Denotations {
512513
def lubSym(overrides: Iterator[Symbol], previous: Symbol): Symbol =
513514
if (!overrides.hasNext) previous
514515
else {
515-
val candidate = overrides.next
516+
val candidate = overrides.next()
516517
if (owner2 derivesFrom candidate.owner)
517518
if (candidate isAccessibleFrom pre) candidate
518519
else lubSym(overrides, previous orElse candidate)
@@ -779,7 +780,7 @@ object Denotations {
779780
}
780781

781782
if (valid.runId != currentPeriod.runId)
782-
if (exists) initial.bringForward.current
783+
if (exists) initial.bringForward().current
783784
else this
784785
else {
785786
var cur = this

compiler/src/dotty/tools/dotc/core/Phases.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ trait Phases {
2828
if ((this eq NoContext) || !phase.exists) Nil
2929
else {
3030
val rest = outersIterator.dropWhile(_.phase == phase)
31-
phase :: (if (rest.hasNext) rest.next.phasesStack else Nil)
31+
phase :: (if (rest.hasNext) rest.next().phasesStack else Nil)
3232
}
3333

3434
/** Execute `op` at given phase */

compiler/src/dotty/tools/dotc/core/SymDenotations.scala

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -763,6 +763,20 @@ object SymDenotations {
763763

764764
def isInlineMethod(implicit ctx: Context): Boolean = is(InlineMethod, butNot = Accessor)
765765

766+
/** ()T and => T types should be treated as equivalent for this symbol.
767+
* Note: For the moment, we treat Scala-2 compiled symbols as loose matching,
768+
* because the Scala library does not always follow the right conventions.
769+
* Examples are: isWhole(), toInt(), toDouble() in BigDecimal, Numeric, RichInt, ScalaNumberProxy.
770+
*/
771+
def matchNullaryLoosely(implicit ctx: Context): Boolean = {
772+
def test(sym: Symbol) =
773+
sym.is(JavaDefined) ||
774+
sym.owner == defn.AnyClass ||
775+
sym == defn.Object_clone ||
776+
sym.owner.is(Scala2x)
777+
test(symbol) || allOverriddenSymbols.exists(test)
778+
}
779+
766780
// ------ access to related symbols ---------------------------------
767781

768782
/* Modules and module classes are represented as follows:
@@ -938,7 +952,6 @@ object SymDenotations {
938952
else if (this.isClass) companionNamed(effectiveName.moduleClassName).sourceModule.moduleClass
939953
else NoSymbol
940954

941-
942955
/** Find companion class symbol with given name, or NoSymbol if none exists.
943956
* Three alternative strategies:
944957
* 1. If owner is a class, look in its members, otherwise
@@ -962,7 +975,7 @@ object SymDenotations {
962975
else if (ctx.scope.lookup(this.name) == symbol)
963976
ctx.scope.lookup(name)
964977
else
965-
companionNamed(name)(ctx.outersIterator.dropWhile(_.scope eq ctx.scope).next)
978+
companionNamed(name)(ctx.outersIterator.dropWhile(_.scope eq ctx.scope).next())
966979

967980
/** Is this symbol the same or a linked class of `sym`? */
968981
final def isLinkedWith(sym: Symbol)(implicit ctx: Context): Boolean =

compiler/src/dotty/tools/dotc/core/TypeOps.scala

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -518,8 +518,11 @@ trait TypeOps { this: Context => // TODO: Make standalone object.
518518
def dynamicsEnabled =
519519
featureEnabled(defn.LanguageModuleClass, nme.dynamics)
520520

521-
def testScala2Mode(msg: => String, pos: Position) = {
522-
if (scala2Mode) migrationWarning(msg, pos)
521+
def testScala2Mode(msg: => String, pos: Position, rewrite: => Unit = ()) = {
522+
if (scala2Mode) {
523+
migrationWarning(msg, pos)
524+
rewrite
525+
}
523526
scala2Mode
524527
}
525528
}

compiler/src/dotty/tools/dotc/core/Types.scala

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -769,21 +769,23 @@ object Types {
769769
def relaxed_<:<(that: Type)(implicit ctx: Context) =
770770
(this <:< that) || (this isValueSubType that)
771771

772-
/** Is this type a legal type for a member that overrides another
773-
* member of type `that`? This is the same as `<:<`, except that
774-
* the types `()T`, `=> T` and `T` are seen as overriding
775-
* each other.
772+
/** Is this type a legal type for member `sym1` that overrides another
773+
* member `sym2` of type `that`? This is the same as `<:<`, except that
774+
* if `matchLoosely` evaluates to true the types `=> T` and `()T` are seen
775+
* as overriding each other.
776776
*/
777-
final def overrides(that: Type)(implicit ctx: Context) = {
778-
def result(tp: Type): Type = tp match {
779-
case ExprType(_) | MethodType(Nil) => tp.resultType
777+
final def overrides(that: Type, matchLoosely: => Boolean)(implicit ctx: Context): Boolean = {
778+
def widenNullary(tp: Type) = tp match {
779+
case tp @ MethodType(Nil) => tp.resultType
780780
case _ => tp
781781
}
782-
(this frozen_<:< that) || {
783-
val rthat = result(that)
784-
val rthis = result(this)
785-
(rthat.ne(that) || rthis.ne(this)) && (rthis frozen_<:< rthat)
786-
}
782+
((this.widenExpr frozen_<:< that.widenExpr) ||
783+
matchLoosely && {
784+
val this1 = widenNullary(this)
785+
val that1 = widenNullary(that)
786+
((this1 `ne` this) || (that1 `ne` that)) && this1.overrides(this1, matchLoosely = false)
787+
}
788+
)
787789
}
788790

789791
/** Is this type close enough to that type so that members

compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class ClassfileParser(
5454

5555
def run()(implicit ctx: Context): Option[Embedded] = try {
5656
ctx.debuglog("[class] >> " + classRoot.fullName)
57-
parseHeader
57+
parseHeader()
5858
this.pool = new ConstantPool
5959
parseClass()
6060
} catch {
@@ -127,7 +127,7 @@ class ClassfileParser(
127127
// might be reassigned by later parseAttributes
128128
val staticInfo = TempClassInfoType(List(), staticScope, moduleRoot.symbol)
129129

130-
enterOwnInnerClasses
130+
enterOwnInnerClasses()
131131

132132
classRoot.setFlag(sflags)
133133
moduleRoot.setFlag(Flags.JavaDefined | Flags.ModuleClassCreationFlags)
@@ -185,7 +185,7 @@ class ClassfileParser(
185185
}
186186
// skip rest of member for now
187187
in.nextChar // info
188-
skipAttributes
188+
skipAttributes()
189189
}
190190

191191
val memberCompleter = new LazyType {

compiler/src/dotty/tools/dotc/core/tasty/TastyReader.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,12 @@ class TastyReader(val bytes: Array[Byte], start: Int, end: Int, val base: Int =
6262
/** Read a natural number fitting in an Int in big endian format, base 128.
6363
* All but the last digits have bit 0x80 set.
6464
*/
65-
def readNat(): Int = readLongNat.toInt
65+
def readNat(): Int = readLongNat().toInt
6666

6767
/** Read an integer number in 2's complement big endian format, base 128.
6868
* All but the last digits have bit 0x80 set.
6969
*/
70-
def readInt(): Int = readLongInt.toInt
70+
def readInt(): Int = readLongInt().toInt
7171

7272
/** Read a natural number fitting in a Long in big endian format, base 128.
7373
* All but the last digits have bit 0x80 set.

compiler/src/dotty/tools/dotc/parsing/JavaScanners.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ object JavaScanners {
435435
nextChar()
436436
}
437437
if (ch == 'e' || ch == 'E') {
438-
val lookahead = lookaheadReader
438+
val lookahead = lookaheadReader()
439439
lookahead.nextChar()
440440
if (lookahead.ch == '+' || lookahead.ch == '-') {
441441
lookahead.nextChar()
@@ -475,7 +475,7 @@ object JavaScanners {
475475
}
476476
token = INTLIT
477477
if (base <= 10 && ch == '.') {
478-
val lookahead = lookaheadReader
478+
val lookahead = lookaheadReader()
479479
lookahead.nextChar()
480480
lookahead.ch match {
481481
case '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' |

compiler/src/dotty/tools/dotc/parsing/MarkupParserCommon.scala

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ private[dotty] trait MarkupParserCommon {
3636
*/
3737
protected def xTag(pscope: NamespaceType): (String, AttributesType) = {
3838
val name = xName
39-
xSpaceOpt
39+
xSpaceOpt()
4040

4141
(name, mkAttributes(name, pscope))
4242
}
@@ -47,7 +47,7 @@ private[dotty] trait MarkupParserCommon {
4747
*/
4848
def xProcInstr: ElementType = {
4949
val n = xName
50-
xSpaceOpt
50+
xSpaceOpt()
5151
xTakeUntil(mkProcInstr(_, n, _), () => tmppos, "?>")
5252
}
5353

@@ -75,7 +75,7 @@ private[dotty] trait MarkupParserCommon {
7575

7676
private def takeUntilChar(it: Iterator[Char], end: Char): String = {
7777
val buf = new StringBuilder
78-
while (it.hasNext) it.next match {
78+
while (it.hasNext) it.next() match {
7979
case `end` => return buf.toString
8080
case ch => buf append ch
8181
}
@@ -89,7 +89,7 @@ private[dotty] trait MarkupParserCommon {
8989
if (xName != startName)
9090
errorNoEnd(startName)
9191

92-
xSpaceOpt
92+
xSpaceOpt()
9393
xToken('>')
9494
}
9595

@@ -136,9 +136,9 @@ private[dotty] trait MarkupParserCommon {
136136
val buf = new StringBuilder
137137
val it = attval.iterator.buffered
138138

139-
while (it.hasNext) buf append (it.next match {
139+
while (it.hasNext) buf append (it.next() match {
140140
case ' ' | '\t' | '\n' | '\r' => " "
141-
case '&' if it.head == '#' => it.next ; xCharRef(it)
141+
case '&' if it.head == '#' => it.next() ; xCharRef(it)
142142
case '&' => attr_unescape(takeUntilChar(it, ';'))
143143
case c => c
144144
})
@@ -155,11 +155,11 @@ private[dotty] trait MarkupParserCommon {
155155
Utility.parseCharRef(ch, nextch, reportSyntaxError _, truncatedError _)
156156

157157
def xCharRef(it: Iterator[Char]): String = {
158-
var c = it.next
159-
Utility.parseCharRef(() => c, () => { c = it.next }, reportSyntaxError _, truncatedError _)
158+
var c = it.next()
159+
Utility.parseCharRef(() => c, () => { c = it.next() }, reportSyntaxError _, truncatedError _)
160160
}
161161

162-
def xCharRef: String = xCharRef(() => ch, () => nextch)
162+
def xCharRef: String = xCharRef(() => ch, nextch)
163163

164164
/** Create a lookahead reader which does not influence the input */
165165
def lookahead(): BufferedIterator[Char]
@@ -192,20 +192,20 @@ private[dotty] trait MarkupParserCommon {
192192
}
193193

194194
def xToken(that: Char): Unit = {
195-
if (ch == that) nextch
195+
if (ch == that) nextch()
196196
else xHandleError(that, "'%s' expected instead of '%s'".format(that, ch))
197197
}
198198
def xToken(that: Seq[Char]): Unit = { that foreach xToken }
199199

200200
/** scan [S] '=' [S]*/
201-
def xEQ() = { xSpaceOpt; xToken('='); xSpaceOpt }
201+
def xEQ() = { xSpaceOpt(); xToken('='); xSpaceOpt() }
202202

203203
/** skip optional space S? */
204-
def xSpaceOpt() = while (isSpace(ch) && !eof) nextch
204+
def xSpaceOpt() = while (isSpace(ch) && !eof) nextch()
205205

206206
/** scan [3] S ::= (#x20 | #x9 | #xD | #xA)+ */
207207
def xSpace() =
208-
if (isSpace(ch)) { nextch; xSpaceOpt }
208+
if (isSpace(ch)) { nextch(); xSpaceOpt() }
209209
else xHandleError(ch, "whitespace expected")
210210

211211
/** Apply a function and return the passed value */
@@ -238,7 +238,7 @@ private[dotty] trait MarkupParserCommon {
238238
truncatedError("") // throws TruncatedXMLControl in compiler
239239

240240
sb append ch
241-
nextch
241+
nextch()
242242
}
243243
unreachable
244244
}
@@ -251,7 +251,7 @@ private[dotty] trait MarkupParserCommon {
251251
private def peek(lookingFor: String): Boolean =
252252
(lookahead() take lookingFor.length sameElements lookingFor.iterator) && {
253253
// drop the chars from the real reader (all lookahead + orig)
254-
(0 to lookingFor.length) foreach (_ => nextch)
254+
(0 to lookingFor.length) foreach (_ => nextch())
255255
true
256256
}
257257
}

0 commit comments

Comments
 (0)