From cc3a51d240ba7a5eaf769df5670f283b54ba0d54 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Thu, 8 Jun 2017 16:31:55 +0200 Subject: [PATCH 01/19] Drop extraneous () --- scala2-library | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scala2-library b/scala2-library index c14809b706da..fc1e40777a49 160000 --- a/scala2-library +++ b/scala2-library @@ -1 +1 @@ -Subproject commit c14809b706da013349581c713a7fde04ed47d2d3 +Subproject commit fc1e40777a49a6dd56f97b637f01496513adc24d From c8bdfbec1704ea2b3472d66b46ade7fb52cc820b Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Thu, 8 Jun 2017 16:38:26 +0200 Subject: [PATCH 02/19] Fix nullary applications in collection strawman --- collection-strawman | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/collection-strawman b/collection-strawman index c7b52041058c..b57752f281a8 160000 --- a/collection-strawman +++ b/collection-strawman @@ -1 +1 @@ -Subproject commit c7b52041058c8aa4fb36376b5f6e9188acd1f4e9 +Subproject commit b57752f281a896e29811cfd0419d1b4d13b22f10 From f7091cdcce588442a3fcb2c998054bf046910b65 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Thu, 8 Jun 2017 17:05:01 +0200 Subject: [PATCH 03/19] New nullary method fix to collection strawman. --- collection-strawman | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/collection-strawman b/collection-strawman index b57752f281a8..2905cc9ace62 160000 --- a/collection-strawman +++ b/collection-strawman @@ -1 +1 @@ -Subproject commit b57752f281a896e29811cfd0419d1b4d13b22f10 +Subproject commit 2905cc9ace62c5ce826848a3a13befcd15a2d8bd From 244257bd0e9bd65ba4cafa37b522da0f2dd92b27 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Thu, 8 Jun 2017 17:27:13 +0200 Subject: [PATCH 04/19] Allow optional rewrite rule in testScala2Mode --- compiler/src/dotty/tools/dotc/core/TypeOps.scala | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/core/TypeOps.scala b/compiler/src/dotty/tools/dotc/core/TypeOps.scala index 816a3b48f356..829b5acec00c 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeOps.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeOps.scala @@ -518,8 +518,11 @@ trait TypeOps { this: Context => // TODO: Make standalone object. def dynamicsEnabled = featureEnabled(defn.LanguageModuleClass, nme.dynamics) - def testScala2Mode(msg: => String, pos: Position) = { - if (scala2Mode) migrationWarning(msg, pos) + def testScala2Mode(msg: => String, pos: Position, rewrite: => Unit = ()) = { + if (scala2Mode) { + migrationWarning(msg, pos) + rewrite + } scala2Mode } } From f3c6d91cce9f52c0186111e222167151819833dc Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Thu, 8 Jun 2017 17:30:31 +0200 Subject: [PATCH 05/19] Only add () to calls of nullary methods if they come from Java or Scala2 Follows the scheme outlined in #2570. The reason not to flag bad calls to methods compiled from Scala 2 is that some Scala 2 libraries are not yet in a form where the parentheses are as they should be. For instance def isWhole() in some of the numeric libraries should not have the (). --- .../src/dotty/tools/dotc/typer/Typer.scala | 42 +++++++++++++------ 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index 84aa7e1bffb8..01c2da478228 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -1202,7 +1202,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit // necessary to force annotation trees to be computed. sym.annotations.foreach(_.ensureCompleted) lazy val annotCtx = { - val c = ctx.outersIterator.dropWhile(_.owner == sym).next + val c = ctx.outersIterator.dropWhile(_.owner == sym).next() c.property(ExprOwner) match { case Some(exprOwner) if c.owner.isClass => // We need to evaluate annotation arguments in an expression context, since @@ -1737,7 +1737,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit def tryAlternatively[T](op1: Context => T)(op2: Context => T)(implicit ctx: Context): T = tryEither(op1) { (failedVal, failedState) => tryEither(op2) { (_, _) => - failedState.commit + failedState.commit() failedVal } } @@ -1858,9 +1858,10 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit def methodStr = err.refStr(methPart(tree).tpe) - def missingArgs = errorTree(tree, - em"""missing arguments for $methodStr - |follow this method with `_' if you want to treat it as a partially applied function""") + def missingArgs(mt: MethodType) = { + ctx.error(em"missing arguments for $methodStr", tree.pos) + tree.withType(mt.resultType) + } def adaptOverloaded(ref: TermRef) = { val altDenots = ref.denot.alternatives @@ -2040,6 +2041,22 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit def isExpandableApply = defn.isImplicitFunctionClass(tree.symbol.maybeOwner) && defn.isFunctionType(ptNorm) + /** Is reference to this symbol `f` automatically expanded to `f()`? */ + def isAutoApplied(sym: Symbol): Boolean = { + def test(sym1: Symbol) = + sym1.is(JavaDefined) || + sym1.owner == defn.AnyClass || + sym1 == defn.Object_clone + sym.isConstructor || + test(sym) || + sym.allOverriddenSymbols.exists(test) || + sym.owner.is(Scala2x) || // need to exclude Scala-2 compiled symbols for now, since the + // Scala library does not always follow the right conventions. + // Examples are: isWhole(), toInt(), toDouble() in BigDecimal, Numeric, RichInt, ScalaNumberProxy. + ctx.testScala2Mode(em"${sym.showLocated} requires () argument", tree.pos, + patch(tree.pos.endPos, "()")) + } + // Reasons NOT to eta expand: // - we reference a constructor // - we are in a patterm @@ -2049,12 +2066,12 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit !ctx.mode.is(Mode.Pattern) && !(isSyntheticApply(tree) && !isExpandableApply)) typed(etaExpand(tree, wtp, arity), pt) - else if (wtp.paramInfos.isEmpty) + else if (wtp.paramInfos.isEmpty && isAutoApplied(tree.symbol)) adaptInterpolated(tpd.Apply(tree, Nil), pt, EmptyTree) else if (wtp.isImplicit) err.typeMismatch(tree, pt) else - missingArgs + missingArgs(wtp) case _ => ctx.typeComparer.GADTused = false if (defn.isImplicitFunctionClass(wtp.underlyingClassRef(refinementOK = false).classSymbol) && @@ -2093,11 +2110,12 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit else tree } - else if (wtp.isInstanceOf[MethodType]) missingArgs - else { - typr.println(i"adapt to subtype ${tree.tpe} !<:< $pt") - //typr.println(TypeComparer.explained(implicit ctx => tree.tpe <:< pt)) - adaptToSubType(wtp) + else wtp match { + case wtp: MethodType => missingArgs(wtp) + case _ => + typr.println(i"adapt to subtype ${tree.tpe} !<:< $pt") + //typr.println(TypeComparer.explained(implicit ctx => tree.tpe <:< pt)) + adaptToSubType(wtp) } } /** Adapt an expression of constant type to a different constant type `tpe`. */ From 774c8dab972f793de9735b9b5402b1e174cf2752 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Thu, 8 Jun 2017 17:32:20 +0200 Subject: [PATCH 06/19] Add () for nullary method applications Fix errors everywhere where a nullary method is called without a () argument. --- .gitignore | 1 + collection-strawman | 2 +- .../src/dotty/tools/dotc/ast/Desugar.scala | 8 +-- .../dotty/tools/dotc/ast/NavigateAST.scala | 2 +- .../src/dotty/tools/dotc/ast/TreeInfo.scala | 2 +- compiler/src/dotty/tools/dotc/ast/Trees.scala | 2 +- .../src/dotty/tools/dotc/core/Contexts.scala | 4 +- .../dotty/tools/dotc/core/Decorators.scala | 2 +- .../dotty/tools/dotc/core/Denotations.scala | 4 +- .../src/dotty/tools/dotc/core/Phases.scala | 2 +- .../tools/dotc/core/SymDenotations.scala | 2 +- .../dotc/core/classfile/ClassfileParser.scala | 6 +-- .../tools/dotc/core/tasty/TastyReader.scala | 4 +- .../tools/dotc/parsing/JavaScanners.scala | 4 +- .../dotc/parsing/MarkupParserCommon.scala | 30 +++++------ .../tools/dotc/parsing/MarkupParsers.scala | 46 ++++++++-------- .../dotty/tools/dotc/parsing/Parsers.scala | 14 ++--- .../dotty/tools/dotc/parsing/Scanners.scala | 10 ++-- .../dotc/repl/CompilingInterpreter.scala | 6 +-- .../dotty/tools/dotc/repl/ConsoleWriter.scala | 4 +- .../dotty/tools/dotc/transform/Flatten.scala | 2 +- .../src/dotty/tools/dotc/typer/Namer.scala | 6 +-- .../dotty/tools/dotc/typer/TypeAssigner.scala | 2 +- compiler/src/dotty/tools/io/Jar.scala | 4 +- compiler/test/debug/Gen.scala | 2 +- .../test/dotty/tools/dotc/CompilerTest.scala | 6 +-- .../tools/dotc/parsing/ScannerTest.scala | 2 +- .../test/dotty/tools/dotc/repl/TestREPL.scala | 4 +- .../transform/PatmatExhaustivityTest.scala | 4 +- .../dotty/tools/vulpix/ParallelTesting.scala | 14 ++--- scala2-library | 2 +- tests/neg/autoUnit.scala | 9 ++++ tests/neg/i1503.scala | 2 +- tests/pos-scala2/autoUnit.scala | 6 +++ .../CollectionStrawMan4.scala | 6 +-- .../CollectionStrawMan5.scala | 6 +-- .../CollectionStrawMan6.scala | 2 +- tests/pos/GenericTraversableTemplate.scala | 2 +- tests/pos/i2064.scala | 2 +- tests/pos/overloaded.scala | 2 +- tests/pos/pos_valueclasses/paramlists.scala | 8 +-- tests/pos/pos_valueclasses/t5953.scala | 2 +- tests/pos/t0165.scala | 2 +- tests/pos/t1035.scala | 4 +- tests/pos/t1107b/O.scala | 2 +- tests/pos/t1513a.scala | 2 +- tests/pos/t3636.scala | 4 +- tests/pos/t4579.scala | 6 +-- tests/pos/t5577.scala | 2 +- tests/pos/tcpoly_seq.scala | 8 +-- tests/pos/tcpoly_seq_typealias.scala | 8 +-- tests/run/CollectionTests.scala | 6 +-- tests/run/Course-2002-01.scala | 10 ++-- tests/run/Course-2002-02.scala | 54 +++++++++---------- tests/run/Course-2002-03.scala | 28 +++++----- tests/run/Course-2002-04.scala | 22 ++++---- tests/run/Course-2002-05.scala | 22 ++++---- tests/run/Course-2002-06.scala | 2 +- tests/run/Course-2002-07.scala | 36 ++++++------- tests/run/Course-2002-08.scala | 40 +++++++------- tests/run/Course-2002-09.scala | 16 +++--- tests/run/Course-2002-10.scala | 12 ++--- tests/run/Course-2002-13.scala | 6 +-- tests/run/MutableListTest.scala | 4 +- tests/run/QueueTest.scala | 16 +++--- tests/run/UnrolledBuffer.scala | 6 +-- tests/run/boolexprs.scala | 4 +- tests/run/bridges.scala | 6 +-- tests/run/colltest1.scala | 2 +- .../run/colltest4/CollectionStrawMan4_1.scala | 6 +-- .../run/colltest5/CollectionStrawMan5_1.scala | 6 +-- .../run/colltest6/CollectionStrawMan6_1.scala | 2 +- tests/run/constant-optimization.scala | 8 +-- tests/run/contrib674.scala | 2 +- tests/run/deeps.scala | 10 ++-- tests/run/exceptions.scala | 4 +- tests/run/fors.scala | 44 +++++++-------- tests/run/hashset.scala | 4 +- tests/run/i1732.scala | 2 +- tests/run/imports.scala | 10 ++-- tests/run/iq.scala | 6 +-- tests/run/iterator3444.scala | 4 +- tests/run/iterators.scala | 6 +-- tests/run/kmpSliceSearch.scala | 4 +- tests/run/map_java_conversions.scala | 4 +- tests/run/mixin-primitive-on-generic-1.scala | 2 +- tests/run/mixin-primitive-on-generic-2.scala | 2 +- tests/run/mixin-primitive-on-generic-4.scala | 2 +- tests/run/mixin-primitive-on-generic-5.scala | 2 +- tests/run/overloads.scala | 4 +- tests/run/slices.scala | 12 ++--- tests/run/t0325.scala | 6 +-- tests/run/t1909b.scala | 2 +- tests/run/t2552.scala | 6 +-- tests/run/t2813.2.scala | 8 +-- tests/run/t3242b.scala | 2 +- tests/run/t3269.scala | 2 +- tests/run/t3516.scala | 2 +- tests/run/t4054.scala | 22 ++++---- tests/run/t4809.scala | 4 +- tests/run/t8153.scala | 2 +- tests/run/unittest_iterator.scala | 8 +-- tests/run/unreachable.scala | 14 ++--- 103 files changed, 410 insertions(+), 394 deletions(-) create mode 100644 tests/neg/autoUnit.scala create mode 100644 tests/pos-scala2/autoUnit.scala diff --git a/.gitignore b/.gitignore index c84d75358520..11f3d71e8025 100644 --- a/.gitignore +++ b/.gitignore @@ -70,3 +70,4 @@ compiler/test/debug/Gen.jar compiler/before-pickling.txt compiler/after-pickling.txt +*.dotty-ide-version diff --git a/collection-strawman b/collection-strawman index 2905cc9ace62..90d7f2e8b39d 160000 --- a/collection-strawman +++ b/collection-strawman @@ -1 +1 @@ -Subproject commit 2905cc9ace62c5ce826848a3a13befcd15a2d8bd +Subproject commit 90d7f2e8b39d1f802ebbcbb075768e679d148104 diff --git a/compiler/src/dotty/tools/dotc/ast/Desugar.scala b/compiler/src/dotty/tools/dotc/ast/Desugar.scala index 855196c600bf..62d7ebddff50 100644 --- a/compiler/src/dotty/tools/dotc/ast/Desugar.scala +++ b/compiler/src/dotty/tools/dotc/ast/Desugar.scala @@ -69,7 +69,7 @@ object desugar { val originalOwner = sym.owner def apply(tp: Type) = tp match { case tp: NamedType if tp.symbol.exists && (tp.symbol.owner eq originalOwner) => - val defctx = ctx.outersIterator.dropWhile(_.scope eq ctx.scope).next + val defctx = ctx.outersIterator.dropWhile(_.scope eq ctx.scope).next() var local = defctx.denotNamed(tp.name).suchThat(_ is ParamOrAccessor).symbol if (local.exists) (defctx.owner.thisType select local).dealias else { @@ -538,12 +538,12 @@ object desugar { val cdef1 = addEnumFlags { val originalTparamsIt = originalTparams.toIterator val originalVparamsIt = originalVparamss.toIterator.flatten - val tparamAccessors = derivedTparams.map(_.withMods(originalTparamsIt.next.mods)) + val tparamAccessors = derivedTparams.map(_.withMods(originalTparamsIt.next().mods)) val caseAccessor = if (isCaseClass) CaseAccessor else EmptyFlags val vparamAccessors = derivedVparamss match { case first :: rest => - first.map(_.withMods(originalVparamsIt.next.mods | caseAccessor)) ++ - rest.flatten.map(_.withMods(originalVparamsIt.next.mods)) + first.map(_.withMods(originalVparamsIt.next().mods | caseAccessor)) ++ + rest.flatten.map(_.withMods(originalVparamsIt.next().mods)) case _ => Nil } diff --git a/compiler/src/dotty/tools/dotc/ast/NavigateAST.scala b/compiler/src/dotty/tools/dotc/ast/NavigateAST.scala index b6ff80277d35..f180b34e3aa3 100644 --- a/compiler/src/dotty/tools/dotc/ast/NavigateAST.scala +++ b/compiler/src/dotty/tools/dotc/ast/NavigateAST.scala @@ -70,7 +70,7 @@ object NavigateAST { def pathTo(pos: Position, from: Positioned, skipZeroExtent: Boolean = false)(implicit ctx: Context): List[Positioned] = { def childPath(it: Iterator[Any], path: List[Positioned]): List[Positioned] = { while (it.hasNext) { - val path1 = it.next match { + val path1 = it.next() match { case p: Positioned => singlePath(p, path) case xs: List[_] => childPath(xs.iterator, path) case _ => path diff --git a/compiler/src/dotty/tools/dotc/ast/TreeInfo.scala b/compiler/src/dotty/tools/dotc/ast/TreeInfo.scala index dd9948c31d51..9c650f8e2d63 100644 --- a/compiler/src/dotty/tools/dotc/ast/TreeInfo.scala +++ b/compiler/src/dotty/tools/dotc/ast/TreeInfo.scala @@ -53,7 +53,7 @@ trait TreeInfo[T >: Untyped <: Type] { self: Trees.Instance[T] => def map[R](f: (Symbol, Tree) => R): List[R] = { val b = List.newBuilder[R] foreach(b += f(_, _)) - b.result + b.result() } } diff --git a/compiler/src/dotty/tools/dotc/ast/Trees.scala b/compiler/src/dotty/tools/dotc/ast/Trees.scala index 2d120eca16ce..4ffcebcae028 100644 --- a/compiler/src/dotty/tools/dotc/ast/Trees.scala +++ b/compiler/src/dotty/tools/dotc/ast/Trees.scala @@ -129,7 +129,7 @@ object Trees { private def checkChildrenTyped(it: Iterator[Any])(implicit ctx: Context): Unit = if (!this.isInstanceOf[Import[_]]) while (it.hasNext) - it.next match { + it.next() match { case x: Ident[_] => // untyped idents are used in a number of places in typed trees case x: Tree[_] => assert(x.hasType || ctx.reporter.errorsReported, diff --git a/compiler/src/dotty/tools/dotc/core/Contexts.scala b/compiler/src/dotty/tools/dotc/core/Contexts.scala index ff11ec35cf54..2e7979a98c25 100644 --- a/compiler/src/dotty/tools/dotc/core/Contexts.scala +++ b/compiler/src/dotty/tools/dotc/core/Contexts.scala @@ -348,7 +348,7 @@ object Contexts { */ def thisCallArgContext: Context = { assert(owner.isClassConstructor) - val constrCtx = outersIterator.dropWhile(_.outer.owner == owner).next + val constrCtx = outersIterator.dropWhile(_.outer.owner == owner).next() superOrThisCallContext(owner, constrCtx.scope) .setTyperState(typerState) .setGadt(gadt) @@ -356,7 +356,7 @@ object Contexts { /** The super- or this-call context with given owner and locals. */ private def superOrThisCallContext(owner: Symbol, locals: Scope): FreshContext = { - var classCtx = outersIterator.dropWhile(!_.isClassDefContext).next + var classCtx = outersIterator.dropWhile(!_.isClassDefContext).next() classCtx.outer.fresh.setOwner(owner) .setScope(locals) .setMode(classCtx.mode | Mode.InSuperCall) diff --git a/compiler/src/dotty/tools/dotc/core/Decorators.scala b/compiler/src/dotty/tools/dotc/core/Decorators.scala index c65dc5b974dd..2bdb6f171cb3 100644 --- a/compiler/src/dotty/tools/dotc/core/Decorators.scala +++ b/compiler/src/dotty/tools/dotc/core/Decorators.scala @@ -37,7 +37,7 @@ object Decorators { implicit class SymbolIteratorDecorator(val it: Iterator[Symbol]) extends AnyVal { final def findSymbol(p: Symbol => Boolean): Symbol = { while (it.hasNext) { - val sym = it.next + val sym = it.next() if (p(sym)) return sym } NoSymbol diff --git a/compiler/src/dotty/tools/dotc/core/Denotations.scala b/compiler/src/dotty/tools/dotc/core/Denotations.scala index f27ede8153db..53ea192f33a8 100644 --- a/compiler/src/dotty/tools/dotc/core/Denotations.scala +++ b/compiler/src/dotty/tools/dotc/core/Denotations.scala @@ -512,7 +512,7 @@ object Denotations { def lubSym(overrides: Iterator[Symbol], previous: Symbol): Symbol = if (!overrides.hasNext) previous else { - val candidate = overrides.next + val candidate = overrides.next() if (owner2 derivesFrom candidate.owner) if (candidate isAccessibleFrom pre) candidate else lubSym(overrides, previous orElse candidate) @@ -779,7 +779,7 @@ object Denotations { } if (valid.runId != currentPeriod.runId) - if (exists) initial.bringForward.current + if (exists) initial.bringForward().current else this else { var cur = this diff --git a/compiler/src/dotty/tools/dotc/core/Phases.scala b/compiler/src/dotty/tools/dotc/core/Phases.scala index bf33471cc98f..16f281a42ee9 100644 --- a/compiler/src/dotty/tools/dotc/core/Phases.scala +++ b/compiler/src/dotty/tools/dotc/core/Phases.scala @@ -28,7 +28,7 @@ trait Phases { if ((this eq NoContext) || !phase.exists) Nil else { val rest = outersIterator.dropWhile(_.phase == phase) - phase :: (if (rest.hasNext) rest.next.phasesStack else Nil) + phase :: (if (rest.hasNext) rest.next().phasesStack else Nil) } /** Execute `op` at given phase */ diff --git a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala index 20c1c5c8e64f..fdb60211a86e 100644 --- a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala +++ b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala @@ -962,7 +962,7 @@ object SymDenotations { else if (ctx.scope.lookup(this.name) == symbol) ctx.scope.lookup(name) else - companionNamed(name)(ctx.outersIterator.dropWhile(_.scope eq ctx.scope).next) + companionNamed(name)(ctx.outersIterator.dropWhile(_.scope eq ctx.scope).next()) /** Is this symbol the same or a linked class of `sym`? */ final def isLinkedWith(sym: Symbol)(implicit ctx: Context): Boolean = diff --git a/compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala b/compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala index 4d53a80a9476..59e0fdcb4b02 100644 --- a/compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala +++ b/compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala @@ -54,7 +54,7 @@ class ClassfileParser( def run()(implicit ctx: Context): Option[Embedded] = try { ctx.debuglog("[class] >> " + classRoot.fullName) - parseHeader + parseHeader() this.pool = new ConstantPool parseClass() } catch { @@ -127,7 +127,7 @@ class ClassfileParser( // might be reassigned by later parseAttributes val staticInfo = TempClassInfoType(List(), staticScope, moduleRoot.symbol) - enterOwnInnerClasses + enterOwnInnerClasses() classRoot.setFlag(sflags) moduleRoot.setFlag(Flags.JavaDefined | Flags.ModuleClassCreationFlags) @@ -185,7 +185,7 @@ class ClassfileParser( } // skip rest of member for now in.nextChar // info - skipAttributes + skipAttributes() } val memberCompleter = new LazyType { diff --git a/compiler/src/dotty/tools/dotc/core/tasty/TastyReader.scala b/compiler/src/dotty/tools/dotc/core/tasty/TastyReader.scala index af5e78891b89..2696077b985e 100644 --- a/compiler/src/dotty/tools/dotc/core/tasty/TastyReader.scala +++ b/compiler/src/dotty/tools/dotc/core/tasty/TastyReader.scala @@ -62,12 +62,12 @@ class TastyReader(val bytes: Array[Byte], start: Int, end: Int, val base: Int = /** Read a natural number fitting in an Int in big endian format, base 128. * All but the last digits have bit 0x80 set. */ - def readNat(): Int = readLongNat.toInt + def readNat(): Int = readLongNat().toInt /** Read an integer number in 2's complement big endian format, base 128. * All but the last digits have bit 0x80 set. */ - def readInt(): Int = readLongInt.toInt + def readInt(): Int = readLongInt().toInt /** Read a natural number fitting in a Long in big endian format, base 128. * All but the last digits have bit 0x80 set. diff --git a/compiler/src/dotty/tools/dotc/parsing/JavaScanners.scala b/compiler/src/dotty/tools/dotc/parsing/JavaScanners.scala index 9e0da2c054ae..09ce8a9a38bc 100644 --- a/compiler/src/dotty/tools/dotc/parsing/JavaScanners.scala +++ b/compiler/src/dotty/tools/dotc/parsing/JavaScanners.scala @@ -435,7 +435,7 @@ object JavaScanners { nextChar() } if (ch == 'e' || ch == 'E') { - val lookahead = lookaheadReader + val lookahead = lookaheadReader() lookahead.nextChar() if (lookahead.ch == '+' || lookahead.ch == '-') { lookahead.nextChar() @@ -475,7 +475,7 @@ object JavaScanners { } token = INTLIT if (base <= 10 && ch == '.') { - val lookahead = lookaheadReader + val lookahead = lookaheadReader() lookahead.nextChar() lookahead.ch match { case '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | diff --git a/compiler/src/dotty/tools/dotc/parsing/MarkupParserCommon.scala b/compiler/src/dotty/tools/dotc/parsing/MarkupParserCommon.scala index 492a8947c89e..eb7671605f9d 100644 --- a/compiler/src/dotty/tools/dotc/parsing/MarkupParserCommon.scala +++ b/compiler/src/dotty/tools/dotc/parsing/MarkupParserCommon.scala @@ -36,7 +36,7 @@ private[dotty] trait MarkupParserCommon { */ protected def xTag(pscope: NamespaceType): (String, AttributesType) = { val name = xName - xSpaceOpt + xSpaceOpt() (name, mkAttributes(name, pscope)) } @@ -47,7 +47,7 @@ private[dotty] trait MarkupParserCommon { */ def xProcInstr: ElementType = { val n = xName - xSpaceOpt + xSpaceOpt() xTakeUntil(mkProcInstr(_, n, _), () => tmppos, "?>") } @@ -75,7 +75,7 @@ private[dotty] trait MarkupParserCommon { private def takeUntilChar(it: Iterator[Char], end: Char): String = { val buf = new StringBuilder - while (it.hasNext) it.next match { + while (it.hasNext) it.next() match { case `end` => return buf.toString case ch => buf append ch } @@ -89,7 +89,7 @@ private[dotty] trait MarkupParserCommon { if (xName != startName) errorNoEnd(startName) - xSpaceOpt + xSpaceOpt() xToken('>') } @@ -136,9 +136,9 @@ private[dotty] trait MarkupParserCommon { val buf = new StringBuilder val it = attval.iterator.buffered - while (it.hasNext) buf append (it.next match { + while (it.hasNext) buf append (it.next() match { case ' ' | '\t' | '\n' | '\r' => " " - case '&' if it.head == '#' => it.next ; xCharRef(it) + case '&' if it.head == '#' => it.next() ; xCharRef(it) case '&' => attr_unescape(takeUntilChar(it, ';')) case c => c }) @@ -155,11 +155,11 @@ private[dotty] trait MarkupParserCommon { Utility.parseCharRef(ch, nextch, reportSyntaxError _, truncatedError _) def xCharRef(it: Iterator[Char]): String = { - var c = it.next - Utility.parseCharRef(() => c, () => { c = it.next }, reportSyntaxError _, truncatedError _) + var c = it.next() + Utility.parseCharRef(() => c, () => { c = it.next() }, reportSyntaxError _, truncatedError _) } - def xCharRef: String = xCharRef(() => ch, () => nextch) + def xCharRef: String = xCharRef(() => ch, nextch) /** Create a lookahead reader which does not influence the input */ def lookahead(): BufferedIterator[Char] @@ -192,20 +192,20 @@ private[dotty] trait MarkupParserCommon { } def xToken(that: Char): Unit = { - if (ch == that) nextch + if (ch == that) nextch() else xHandleError(that, "'%s' expected instead of '%s'".format(that, ch)) } def xToken(that: Seq[Char]): Unit = { that foreach xToken } /** scan [S] '=' [S]*/ - def xEQ() = { xSpaceOpt; xToken('='); xSpaceOpt } + def xEQ() = { xSpaceOpt(); xToken('='); xSpaceOpt() } /** skip optional space S? */ - def xSpaceOpt() = while (isSpace(ch) && !eof) nextch + def xSpaceOpt() = while (isSpace(ch) && !eof) nextch() /** scan [3] S ::= (#x20 | #x9 | #xD | #xA)+ */ def xSpace() = - if (isSpace(ch)) { nextch; xSpaceOpt } + if (isSpace(ch)) { nextch(); xSpaceOpt() } else xHandleError(ch, "whitespace expected") /** Apply a function and return the passed value */ @@ -238,7 +238,7 @@ private[dotty] trait MarkupParserCommon { truncatedError("") // throws TruncatedXMLControl in compiler sb append ch - nextch + nextch() } unreachable } @@ -251,7 +251,7 @@ private[dotty] trait MarkupParserCommon { private def peek(lookingFor: String): Boolean = (lookahead() take lookingFor.length sameElements lookingFor.iterator) && { // drop the chars from the real reader (all lookahead + orig) - (0 to lookingFor.length) foreach (_ => nextch) + (0 to lookingFor.length) foreach (_ => nextch()) true } } diff --git a/compiler/src/dotty/tools/dotc/parsing/MarkupParsers.scala b/compiler/src/dotty/tools/dotc/parsing/MarkupParsers.scala index 3b091d542fba..706d38420ea3 100644 --- a/compiler/src/dotty/tools/dotc/parsing/MarkupParsers.scala +++ b/compiler/src/dotty/tools/dotc/parsing/MarkupParsers.scala @@ -103,7 +103,7 @@ object MarkupParsers { */ def xCheckEmbeddedBlock: Boolean = { // attentions, side-effect, used in xText - xEmbeddedBlock = (ch == '{') && { nextch; (ch != '{') } + xEmbeddedBlock = (ch == '{') && { nextch(); (ch != '{') } xEmbeddedBlock } @@ -119,7 +119,7 @@ object MarkupParsers { while (isNameStart(ch)) { val start = curOffset val key = xName - xEQ + xEQ() val delim = ch val mid = curOffset val value: Tree = ch match { @@ -133,7 +133,7 @@ object MarkupParsers { } case '{' => - nextch + nextch() xEmbeddedExpr case SU => throw TruncatedXMLControl @@ -146,7 +146,7 @@ object MarkupParsers { aMap(key) = value if (ch != '/' && ch != '>') - xSpace + xSpace() } aMap } @@ -198,10 +198,10 @@ object MarkupParsers { * @precond ch == '&' */ def content_AMP(ts: ArrayBuffer[Tree]): Unit = { - nextch + nextch() val toAppend = ch match { case '#' => // CharacterRef - nextch + nextch() val theChar = handle.text(tmppos, xCharRef) xToken(';') theChar @@ -233,9 +233,9 @@ object MarkupParsers { return true // end tag val toAppend = ch match { - case '!' => nextch ; if (ch =='[') xCharData else xComment // CDATA or Comment - case '?' => nextch ; xProcInstr // PI - case _ => element // child node + case '!' => nextch() ; if (ch =='[') xCharData else xComment // CDATA or Comment + case '?' => nextch() ; xProcInstr // PI + case _ => element // child node } ts append toAppend @@ -251,7 +251,7 @@ object MarkupParsers { tmppos = Position(curOffset) ch match { // end tag, cdata, comment, pi or child node - case '<' => nextch ; if (content_LT(ts)) return ts + case '<' => nextch() ; if (content_LT(ts)) return ts // either the character '{' or an embedded scala block } case '{' => content_BRACE(tmppos, ts) // } // EntityRef or CharRef @@ -283,7 +283,7 @@ object MarkupParsers { debugLastStartElement.push((start, qname)) val ts = content xEndTag(qname) - debugLastStartElement.pop + debugLastStartElement.pop() val pos = Position(start, curOffset, start) qname match { case "xml:group" => handle.group(pos, ts) @@ -302,12 +302,12 @@ object MarkupParsers { while (ch != SU) { if (ch == '}') { - if (charComingAfter(nextch) == '}') nextch + if (charComingAfter(nextch()) == '}') nextch() else errorBraces() } buf append ch - nextch + nextch() if (xCheckEmbeddedBlock || ch == '<' || ch == '&') return done } @@ -333,7 +333,7 @@ object MarkupParsers { /** Use a lookahead parser to run speculative body, and return the first char afterward. */ private def charComingAfter(body: => Unit): Char = { try { - input = input.lookaheadReader + input = input.lookaheadReader() body ch } @@ -354,12 +354,12 @@ object MarkupParsers { content_LT(ts) // parse more XML ? - if (charComingAfter(xSpaceOpt) == '<') { - xSpaceOpt + if (charComingAfter(xSpaceOpt()) == '<') { + xSpaceOpt() while (ch == '<') { - nextch + nextch() ts append element - xSpaceOpt + xSpaceOpt() } handle.makeXMLseq(Position(start, curOffset, start), ts) } @@ -380,7 +380,7 @@ object MarkupParsers { saving[Boolean, Tree](handle.isPattern, handle.isPattern = _) { handle.isPattern = true val tree = xPattern - xSpaceOpt + xSpaceOpt() tree } }, @@ -418,7 +418,7 @@ object MarkupParsers { var start = curOffset val qname = xName debugLastStartElement.push((start, qname)) - xSpaceOpt + xSpaceOpt() val ts = new ArrayBuffer[Tree] @@ -433,13 +433,13 @@ object MarkupParsers { if (xEmbeddedBlock) ts ++= xScalaPatterns else ch match { case '<' => // tag - nextch + nextch() if (ch != '/') ts append xPattern // child else return false // terminate case '{' => // embedded Scala patterns while (ch == '{') { - nextch + nextch() ts ++= xScalaPatterns } assert(!xEmbeddedBlock, "problem with embedded block") @@ -457,7 +457,7 @@ object MarkupParsers { while (doPattern) { } // call until false xEndTag(qname) - debugLastStartElement.pop + debugLastStartElement.pop() } handle.makeXMLpat(Position(start, curOffset, start), qname, ts) diff --git a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala index 9a9678c4c0c9..04f430f780bb 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala @@ -178,7 +178,7 @@ object Parsers { private var lastStatOffset = -1 def setLastStatOffset() = - if (mustStartStat && in.isAfterLineEnd) + if (mustStartStat && in.isAfterLineEnd()) lastStatOffset = in.offset /** Is offset1 less or equally indented than offset2? @@ -949,12 +949,12 @@ object Parsers { def contextBounds(pname: TypeName): List[Tree] = in.token match { case COLON => - atPos(in.skipToken) { + atPos(in.skipToken()) { AppliedTypeTree(toplevelTyp(), Ident(pname)) } :: contextBounds(pname) case VIEWBOUND => deprecationWarning("view bounds `<%' are deprecated, use a context bound `:' instead") - atPos(in.skipToken) { + atPos(in.skipToken()) { Function(Ident(pname) :: Nil, toplevelTyp()) } :: contextBounds(pname) case _ => @@ -1637,7 +1637,7 @@ object Parsers { * | `(' [Patterns `,'] Pattern2 `:' `_' `*' ') */ def argumentPatterns(): List[Tree] = - inParens(patternsOpt) + inParens(patternsOpt()) /* -------- MODIFIERS and ANNOTATIONS ------------------------------------------- */ @@ -2092,7 +2092,7 @@ object Parsers { val rhs = if (in.token == EQUALS) { in.nextToken() - expr + expr() } else if (!tpt.isEmpty) EmptyTree @@ -2242,7 +2242,7 @@ object Parsers { } newLineOptWhenFollowedBy(LBRACE) val modDef = atPos(in.offset) { - val body = inBraces(enumCaseStats) + val body = inBraces(enumCaseStats()) ModuleDef(modName, Template(emptyConstructor, Nil, EmptyValDef, body)) .withMods(mods) } @@ -2354,7 +2354,7 @@ object Parsers { def packaging(start: Int): Tree = { val pkg = qualId() newLineOptWhenFollowedBy(LBRACE) - val stats = inDefScopeBraces(topStatSeq) + val stats = inDefScopeBraces(topStatSeq()) makePackaging(start, pkg, stats) } diff --git a/compiler/src/dotty/tools/dotc/parsing/Scanners.scala b/compiler/src/dotty/tools/dotc/parsing/Scanners.scala index d146816fc0b7..f0ad4fedf0d3 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Scanners.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Scanners.scala @@ -451,7 +451,7 @@ object Scanners { getOperatorRest() } } - fetchLT + fetchLT() case '~' | '!' | '@' | '#' | '%' | '^' | '*' | '+' | '-' | /*'<' | */ '>' | '?' | ':' | '=' | '&' | @@ -485,7 +485,7 @@ object Scanners { } getNumber() } - fetchZero + fetchZero() case '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' => base = 10 getNumber() @@ -526,7 +526,7 @@ object Scanners { } } } - fetchDoubleQuote + fetchDoubleQuote() case '\'' => def fetchSingleQuote() = { nextChar() @@ -545,7 +545,7 @@ object Scanners { } } } - fetchSingleQuote + fetchSingleQuote() case '.' => nextChar() if ('0' <= ch && ch <= '9') { @@ -595,7 +595,7 @@ object Scanners { nextChar() } } - fetchOther + fetchOther() } } diff --git a/compiler/src/dotty/tools/dotc/repl/CompilingInterpreter.scala b/compiler/src/dotty/tools/dotc/repl/CompilingInterpreter.scala index 3010f7761763..ca38ba10777a 100644 --- a/compiler/src/dotty/tools/dotc/repl/CompilingInterpreter.scala +++ b/compiler/src/dotty/tools/dotc/repl/CompilingInterpreter.scala @@ -173,7 +173,7 @@ class CompilingInterpreter( def simpleParse(code: String)(implicit ctx: Context): List[Tree] = { val source = new SourceFile("", code.toCharArray()) val parser = new Parser(source) - val (selfDef, stats) = parser.templateStatSeq + val (selfDef, stats) = parser.templateStatSeq() stats } val trees = simpleParse(line)(ctx.fresh.setReporter(reporter)) @@ -592,7 +592,7 @@ class CompilingInterpreter( preamble.append("object " + impname + "{\n") trailingBraces.append("}\n") accessPath.append("." + impname) - currentImps.clear + currentImps.clear() } addWrapper() @@ -782,7 +782,7 @@ class CompilingInterpreter( // Take the DefDef and remove the `rhs` and ascribed type `tpt` val copy = ast.untpd.cpy.DefDef(defDef)( rhs = EmptyTree, - tpt = TypeTree + tpt = TypeTree() ) val tpt = defDef.tpt match { diff --git a/compiler/src/dotty/tools/dotc/repl/ConsoleWriter.scala b/compiler/src/dotty/tools/dotc/repl/ConsoleWriter.scala index 9387f366a25f..325aab628ed7 100644 --- a/compiler/src/dotty/tools/dotc/repl/ConsoleWriter.scala +++ b/compiler/src/dotty/tools/dotc/repl/ConsoleWriter.scala @@ -9,9 +9,9 @@ import java.io.Writer * @version 1.0 */ class ConsoleWriter extends Writer { - def close = flush + def close() = flush() - def flush = Console.flush + def flush() = Console.flush() def write(cbuf: Array[Char], off: Int, len: Int): Unit = if (len > 0) diff --git a/compiler/src/dotty/tools/dotc/transform/Flatten.scala b/compiler/src/dotty/tools/dotc/transform/Flatten.scala index da287bfcac7f..a3deee2e3793 100644 --- a/compiler/src/dotty/tools/dotc/transform/Flatten.scala +++ b/compiler/src/dotty/tools/dotc/transform/Flatten.scala @@ -39,7 +39,7 @@ class Flatten extends MiniPhaseTransform with SymTransformer { thisTransform => override def transformStats(stats: List[Tree])(implicit ctx: Context, info: TransformerInfo) = if (ctx.owner is Package) { val liftedStats = stats ++ liftedDefs - liftedDefs.clear + liftedDefs.clear() liftedStats } else stats diff --git a/compiler/src/dotty/tools/dotc/typer/Namer.scala b/compiler/src/dotty/tools/dotc/typer/Namer.scala index b8cf2dc4f286..74cfffbcd6a1 100644 --- a/compiler/src/dotty/tools/dotc/typer/Namer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Namer.scala @@ -86,7 +86,7 @@ trait NamerContextOps { this: Context => outersIterator .dropWhile(_.owner != sym) .dropWhile(_.owner == sym) - .next + .next() /** The given type, unless `sym` is a constructor, in which case the * type of the constructed instance is returned @@ -138,7 +138,7 @@ object NamerContextOps { private def findModuleBuddy(name: Name, scope: Scope)(implicit ctx: Context) = { val it = scope.lookupAll(name).filter(_ is Module) assert(it.hasNext, s"no companion $name in $scope") - it.next + it.next() } } @@ -911,7 +911,7 @@ class Namer { typer: Typer => Checking.checkWellFormed(cls) if (isDerivedValueClass(cls)) cls.setFlag(Final) cls.info = avoidPrivateLeaks(cls, cls.pos) - cls.baseClasses.foreach(_.invalidateBaseTypeRefCache) // we might have looked before and found nothing + cls.baseClasses.foreach(_.invalidateBaseTypeRefCache()) // we might have looked before and found nothing } } diff --git a/compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala b/compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala index eb66185164e4..aa11a1f32138 100644 --- a/compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala +++ b/compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala @@ -146,7 +146,7 @@ trait TypeAssigner { denot match { case denot: SymDenotation => denot.exists && { - denot.ensureCompleted + denot.ensureCompleted() !denot.isAbsent } case denot: SingleDenotation => diff --git a/compiler/src/dotty/tools/io/Jar.scala b/compiler/src/dotty/tools/io/Jar.scala index 850a8f3dbca7..b77a2c7df24f 100644 --- a/compiler/src/dotty/tools/io/Jar.scala +++ b/compiler/src/dotty/tools/io/Jar.scala @@ -113,9 +113,9 @@ class JarWriter(val file: File, val manifest: Manifest) { val buf = new Array[Byte](10240) @tailrec def loop(): Unit = in.read(buf, 0, buf.length) match { case -1 => in.close() - case n => out.write(buf, 0, n) ; loop + case n => out.write(buf, 0, n) ; loop() } - loop + loop() } def close() = out.close() diff --git a/compiler/test/debug/Gen.scala b/compiler/test/debug/Gen.scala index dee6b33e3c12..b8db4a5e1a59 100755 --- a/compiler/test/debug/Gen.scala +++ b/compiler/test/debug/Gen.scala @@ -64,7 +64,7 @@ object Gen { } def parse(file: String): Program = { - val lines = Source.fromFile(file).getLines.toBuffer + val lines = Source.fromFile(file).getLines().toBuffer val breaks = new ListBuffer[Break]() val cmds = new ListBuffer[Command]() diff --git a/compiler/test/dotty/tools/dotc/CompilerTest.scala b/compiler/test/dotty/tools/dotc/CompilerTest.scala index 7075756c04c9..962afb96f16d 100644 --- a/compiler/test/dotty/tools/dotc/CompilerTest.scala +++ b/compiler/test/dotty/tools/dotc/CompilerTest.scala @@ -227,7 +227,7 @@ abstract class CompilerTest { /** Extracts the errors expected for the given neg test file. */ def getErrors(fileName: String): ErrorsInFile = { - val content = SFile(fileName).slurp + val content = SFile(fileName).slurp() val (line, rest) = content.span(_ != '\n') @tailrec @@ -379,8 +379,8 @@ abstract class CompilerTest { private def getExisting(dest: Path): ExistingFiles = { val content: Option[Option[String]] = processFileDir(dest, f => try Some(f.slurp("UTF8")) catch {case io: java.io.IOException => Some(io.toString())}, d => Some("")) if (content.isDefined && content.get.isDefined) { - val flags = (dest changeExtension "flags").toFile.safeSlurp - val nerr = (dest changeExtension "nerr").toFile.safeSlurp + val flags = (dest changeExtension "flags").toFile.safeSlurp() + val nerr = (dest changeExtension "nerr").toFile.safeSlurp() ExistingFiles(content.get, flags, nerr) } else ExistingFiles() } diff --git a/compiler/test/dotty/tools/dotc/parsing/ScannerTest.scala b/compiler/test/dotty/tools/dotc/parsing/ScannerTest.scala index d1e188d2893c..001da38ee3fb 100644 --- a/compiler/test/dotty/tools/dotc/parsing/ScannerTest.scala +++ b/compiler/test/dotty/tools/dotc/parsing/ScannerTest.scala @@ -24,7 +24,7 @@ class ScannerTest extends DottyTest { var i = 0 while (scanner.token != EOF) { // print("[" + scanner.token.show +"]") - scanner.nextToken + scanner.nextToken() // i += 1 // if (i % 10 == 0) println() } diff --git a/compiler/test/dotty/tools/dotc/repl/TestREPL.scala b/compiler/test/dotty/tools/dotc/repl/TestREPL.scala index c5557b86e985..c79c02603b54 100644 --- a/compiler/test/dotty/tools/dotc/repl/TestREPL.scala +++ b/compiler/test/dotty/tools/dotc/repl/TestREPL.scala @@ -34,13 +34,13 @@ class TestREPL(script: String) extends REPL { override def input(in: Interpreter)(implicit ctx: Context) = new InteractiveReader { val lines = script.lines.buffered def readLine(prompt: String): String = { - val line = lines.next + val line = lines.next() val buf = new StringBuilder if (line.startsWith(prompt)) { output.println(line) buf append line.drop(prompt.length) while (lines.hasNext && lines.head.startsWith(continuationPrompt)) { - val continued = lines.next + val continued = lines.next() output.println(continued) buf append System.lineSeparator() buf append continued.drop(continuationPrompt.length) diff --git a/compiler/test/dotty/tools/dotc/transform/PatmatExhaustivityTest.scala b/compiler/test/dotty/tools/dotc/transform/PatmatExhaustivityTest.scala index a370a8404bff..ee2d05cc9ff7 100644 --- a/compiler/test/dotty/tools/dotc/transform/PatmatExhaustivityTest.scala +++ b/compiler/test/dotty/tools/dotc/transform/PatmatExhaustivityTest.scala @@ -32,7 +32,7 @@ class PatmatExhaustivityTest { val checkFilePath = file.getAbsolutePath.stripSuffix(".scala") + ".check" val checkContent = if (new File(checkFilePath).exists) - fromFile(checkFilePath).getLines.map(_.replaceAll("\\s+$", "")).mkString("\n").trim + fromFile(checkFilePath).getLines().map(_.replaceAll("\\s+$", "")).mkString("\n").trim else "" (file, checkContent, actual) @@ -59,7 +59,7 @@ class PatmatExhaustivityTest { val checkFilePath = file.getPath + File.separator + "expected.check" val checkContent = if (new File(checkFilePath).exists) - fromFile(checkFilePath).getLines.map(_.replaceAll("\\s+$", "")).mkString("\n").trim + fromFile(checkFilePath).getLines().map(_.replaceAll("\\s+$", "")).mkString("\n").trim else "" (file, checkContent, actual) diff --git a/compiler/test/dotty/tools/vulpix/ParallelTesting.scala b/compiler/test/dotty/tools/vulpix/ParallelTesting.scala index dacc5646d3c4..0a28ba721d8f 100644 --- a/compiler/test/dotty/tools/vulpix/ParallelTesting.scala +++ b/compiler/test/dotty/tools/vulpix/ParallelTesting.scala @@ -485,7 +485,7 @@ trait ParallelTesting extends RunnerOrchestration { self => case Success(_) if !checkFile.isDefined || !checkFile.get.exists => // success! case Success(output) => { val outputLines = output.lines.toArray - val checkLines: Array[String] = Source.fromFile(checkFile.get).getLines.toArray + val checkLines: Array[String] = Source.fromFile(checkFile.get).getLines().toArray val sourceTitle = testSource.title def linesMatch = @@ -596,7 +596,7 @@ trait ParallelTesting extends RunnerOrchestration { self => val errorMap = new HashMap[String, Integer]() var expectedErrors = 0 files.filter(_.getName.endsWith(".scala")).foreach { file => - Source.fromFile(file).getLines.zipWithIndex.foreach { case (line, lineNbr) => + Source.fromFile(file).getLines().zipWithIndex.foreach { case (line, lineNbr) => val errors = line.sliding("// error".length).count(_.mkString == "// error") if (errors > 0) errorMap.put(s"${file.getAbsolutePath}:${lineNbr}", errors) @@ -1021,7 +1021,7 @@ trait ParallelTesting extends RunnerOrchestration { self => /** Compiles a single file from the string path `f` using the supplied flags */ def compileFile(f: String, flags: Array[String])(implicit outDirectory: String): CompilationTest = { - val callingMethod = getCallingMethod + val callingMethod = getCallingMethod() val sourceFile = new JFile(f) val parent = sourceFile.getParentFile val outDir = @@ -1051,7 +1051,7 @@ trait ParallelTesting extends RunnerOrchestration { self => * can be used for randomization. */ def compileDir(f: String, flags: Array[String], randomOrder: Option[Int] = None)(implicit outDirectory: String): CompilationTest = { - val callingMethod = getCallingMethod + val callingMethod = getCallingMethod() val outDir = outDirectory + callingMethod + "/" val sourceDir = new JFile(f) checkRequirements(f, sourceDir, outDir) @@ -1080,7 +1080,7 @@ trait ParallelTesting extends RunnerOrchestration { self => * dissociated */ def compileList(testName: String, files: List[String], flags: Array[String])(implicit outDirectory: String): CompilationTest = { - val callingMethod = getCallingMethod + val callingMethod = getCallingMethod() val outDir = outDirectory + callingMethod + "/" + testName + "/" // Directories in which to compile all containing files with `flags`: @@ -1112,7 +1112,7 @@ trait ParallelTesting extends RunnerOrchestration { self => * the same name as the directory (with the file extension `.check`) */ def compileFilesInDir(f: String, flags: Array[String])(implicit outDirectory: String): CompilationTest = { - val callingMethod = getCallingMethod + val callingMethod = getCallingMethod() val outDir = outDirectory + callingMethod + "/" val sourceDir = new JFile(f) checkRequirements(f, sourceDir, outDir) @@ -1132,7 +1132,7 @@ trait ParallelTesting extends RunnerOrchestration { self => * tests. */ def compileShallowFilesInDir(f: String, flags: Array[String])(implicit outDirectory: String): CompilationTest = { - val callingMethod = getCallingMethod + val callingMethod = getCallingMethod() val outDir = outDirectory + callingMethod + "/" val sourceDir = new JFile(f) checkRequirements(f, sourceDir, outDir) diff --git a/scala2-library b/scala2-library index fc1e40777a49..b17a58607842 160000 --- a/scala2-library +++ b/scala2-library @@ -1 +1 @@ -Subproject commit fc1e40777a49a6dd56f97b637f01496513adc24d +Subproject commit b17a58607842333aaf1bd9117d7a64ee45d9ab54 diff --git a/tests/neg/autoUnit.scala b/tests/neg/autoUnit.scala new file mode 100644 index 000000000000..3f94698fe34e --- /dev/null +++ b/tests/neg/autoUnit.scala @@ -0,0 +1,9 @@ +object Test { + + val x: Any = ??? + x.toString // OK + + def f() = () + + f // error: missing arguments +} diff --git a/tests/neg/i1503.scala b/tests/neg/i1503.scala index 8433d6d35853..bf61229c4ac6 100644 --- a/tests/neg/i1503.scala +++ b/tests/neg/i1503.scala @@ -8,7 +8,7 @@ object Test { def bar2(x: Int) = println("there") def main(args: Array[String]) = { - (if (cond) foo1 else bar1)() // error: Unit does not take parameters + (if (cond) foo1 else bar1)() // error: Unit does not take parameters // error: missing args (if (cond) foo2 else bar2)(22) // OK after changes to eta expansion } } diff --git a/tests/pos-scala2/autoUnit.scala b/tests/pos-scala2/autoUnit.scala new file mode 100644 index 000000000000..f112ea9682ff --- /dev/null +++ b/tests/pos-scala2/autoUnit.scala @@ -0,0 +1,6 @@ +object Test { + + def f() = () + + f +} diff --git a/tests/pos-special/strawman-collections/CollectionStrawMan4.scala b/tests/pos-special/strawman-collections/CollectionStrawMan4.scala index 7e8de2c82cd4..d093d81e6c14 100644 --- a/tests/pos-special/strawman-collections/CollectionStrawMan4.scala +++ b/tests/pos-special/strawman-collections/CollectionStrawMan4.scala @@ -68,7 +68,7 @@ object CollectionStrawMan4 { def foldRight[B](z: B)(op: (A, B) => B): B = iterator.foldRight(z)(op) def indexWhere(p: A => Boolean): Int = iterator.indexWhere(p) def isEmpty: Boolean = !iterator.hasNext - def head: A = iterator.next + def head: A = iterator.next() } /** Transforms returning same collection type */ @@ -164,7 +164,7 @@ object CollectionStrawMan4 { object List extends IterableFactory[List] { def fromIterator[B](it: Iterator[B]): List[B] = - if (it.hasNext) Cons(it.next, fromIterator(it)) else Nil + if (it.hasNext) Cons(it.next(), fromIterator(it)) else Nil def fromIterable[B](c: Iterable[B]): List[B] = c match { case View.Concat(xs, ys: List[B]) => fromIterable(xs) ++: ys @@ -449,7 +449,7 @@ object CollectionStrawMan4 { def next(): A def iterator = this def foldLeft[B](z: B)(op: (B, A) => B): B = - if (hasNext) foldLeft(op(z, next))(op) else z + if (hasNext) foldLeft(op(z, next()))(op) else z def foldRight[B](z: B)(op: (A, B) => B): B = if (hasNext) op(next(), foldRight(z)(op)) else z def foreach(f: A => Unit): Unit = diff --git a/tests/pos-special/strawman-collections/CollectionStrawMan5.scala b/tests/pos-special/strawman-collections/CollectionStrawMan5.scala index 5d04c2c98617..4715ca24d8cd 100644 --- a/tests/pos-special/strawman-collections/CollectionStrawMan5.scala +++ b/tests/pos-special/strawman-collections/CollectionStrawMan5.scala @@ -109,7 +109,7 @@ object CollectionStrawMan5 { def foldRight[B](z: B)(op: (A, B) => B): B = iterator.foldRight(z)(op) def indexWhere(p: A => Boolean): Int = iterator.indexWhere(p) def isEmpty: Boolean = !iterator.hasNext - def head: A = iterator.next + def head: A = iterator.next() def view: View[A] = View.fromIterator(iterator) } @@ -142,7 +142,7 @@ object CollectionStrawMan5 { def reverse: Repr = { var xs: List[A] = Nil var it = coll.iterator - while (it.hasNext) xs = new Cons(it.next, xs) + while (it.hasNext) xs = new Cons(it.next(), xs) fromLikeIterable(xs) } } @@ -431,7 +431,7 @@ object CollectionStrawMan5 { def next(): A def iterator = this def foldLeft[B](z: B)(op: (B, A) => B): B = - if (hasNext) foldLeft(op(z, next))(op) else z + if (hasNext) foldLeft(op(z, next()))(op) else z def foldRight[B](z: B)(op: (A, B) => B): B = if (hasNext) op(next(), foldRight(z)(op)) else z def foreach(f: A => Unit): Unit = diff --git a/tests/pos-special/strawman-collections/CollectionStrawMan6.scala b/tests/pos-special/strawman-collections/CollectionStrawMan6.scala index c2b87cb0bfc9..0b72d256f86a 100644 --- a/tests/pos-special/strawman-collections/CollectionStrawMan6.scala +++ b/tests/pos-special/strawman-collections/CollectionStrawMan6.scala @@ -941,7 +941,7 @@ object CollectionStrawMan6 extends LowPriority { def next(): A def iterator = this def foldLeft[B](z: B)(op: (B, A) => B): B = - if (hasNext) foldLeft(op(z, next))(op) else z + if (hasNext) foldLeft(op(z, next()))(op) else z def foldRight[B](z: B)(op: (A, B) => B): B = if (hasNext) op(next(), foldRight(z)(op)) else z def foreach(f: A => Unit): Unit = diff --git a/tests/pos/GenericTraversableTemplate.scala b/tests/pos/GenericTraversableTemplate.scala index cd48cd23f4b3..70e2376d066f 100644 --- a/tests/pos/GenericTraversableTemplate.scala +++ b/tests/pos/GenericTraversableTemplate.scala @@ -225,7 +225,7 @@ trait GenericTraversableTemplate[+A, +CC[X] <: GenTraversable[X]] extends HasNew fail } val bb = genericBuilder[CC[B]] - for (b <- bs) bb += b.result + for (b <- bs) bb += b.result() bb.result() } } diff --git a/tests/pos/i2064.scala b/tests/pos/i2064.scala index 90992337271e..e210e6a93127 100644 --- a/tests/pos/i2064.scala +++ b/tests/pos/i2064.scala @@ -2,7 +2,7 @@ object p { class Foo[T] { // Crashes: - def f(): Foo[T] = (if (true) this else this).bar + def f(): Foo[T] = (if (true) this else this).bar() // Works: // def f(): Foo[T] = new Bar(if (true) this else this).bar diff --git a/tests/pos/overloaded.scala b/tests/pos/overloaded.scala index 6a8e727148d3..b1e3598cef61 100644 --- a/tests/pos/overloaded.scala +++ b/tests/pos/overloaded.scala @@ -17,7 +17,7 @@ object overloaded { val y1: Int => Int = g val y2: Any = g _ - println(g) + println(g()) val xs = List("a", "b") xs.mkString diff --git a/tests/pos/pos_valueclasses/paramlists.scala b/tests/pos/pos_valueclasses/paramlists.scala index f390a44e072d..b9252726fc55 100644 --- a/tests/pos/pos_valueclasses/paramlists.scala +++ b/tests/pos/pos_valueclasses/paramlists.scala @@ -16,8 +16,8 @@ object Test { val m1 = new Meter(1) m1.zero m1.zero2 - m1.one - m1.one2 + m1.one() + m1.one2() m1.one3(10) m1.two(11)(12) m1.two2(11)(12) @@ -27,8 +27,8 @@ object Test { zero zero2 - one - one2 + one() + one2() one3(10) two(11)(12) two2(11)(12) diff --git a/tests/pos/pos_valueclasses/t5953.scala b/tests/pos/pos_valueclasses/t5953.scala index 669fac7dfb17..e468eff11a58 100644 --- a/tests/pos/pos_valueclasses/t5953.scala +++ b/tests/pos/pos_valueclasses/t5953.scala @@ -5,7 +5,7 @@ import scala.collection.{ mutable, immutable, generic, GenTraversableOnce } package object foo { @inline implicit class TravOps[A, CC[A] <: GenTraversableOnce[A]](val coll: CC[A]) extends AnyVal { def build[CC2[X]](implicit cbf: generic.CanBuildFrom[Nothing, A, CC2[A]]): CC2[A] = { - cbf() ++= coll.toIterator result + (cbf() ++= coll.toIterator).result() } } } diff --git a/tests/pos/t0165.scala b/tests/pos/t0165.scala index 76aef8524017..c2b1b60fe44f 100644 --- a/tests/pos/t0165.scala +++ b/tests/pos/t0165.scala @@ -4,7 +4,7 @@ import scala.collection.mutable.LinkedHashMap trait Main { def asMany : ArrayResult = { object result extends LinkedHashMap[String,String] with ArrayResult { - def current = result + def current = result() } result } diff --git a/tests/pos/t1035.scala b/tests/pos/t1035.scala index ef81cb0d9fa7..9acf290b690d 100644 --- a/tests/pos/t1035.scala +++ b/tests/pos/t1035.scala @@ -16,11 +16,11 @@ class B(name:String) extends A(name,0){ class D { object A { - def unapply(p:A) = Some(p.getName) + def unapply(p:A) = Some(p.getName()) } object B { - def unapply(p:B) = Some(p.getName) + def unapply(p:B) = Some(p.getName()) } def foo(p:Any) = p match { case B(n) => println("B") diff --git a/tests/pos/t1107b/O.scala b/tests/pos/t1107b/O.scala index 0198867704bd..60d31f2fb0b4 100644 --- a/tests/pos/t1107b/O.scala +++ b/tests/pos/t1107b/O.scala @@ -8,6 +8,6 @@ object O def main(args: Array[String]): Unit = { val c = new AnyRef with C - c.bob.toString + c.bob2.toString + c.bob().toString + c.bob2().toString } } diff --git a/tests/pos/t1513a.scala b/tests/pos/t1513a.scala index 3c4c023764bb..605e098d31e5 100644 --- a/tests/pos/t1513a.scala +++ b/tests/pos/t1513a.scala @@ -29,7 +29,7 @@ object Test { def at2[NN <: Nat, OO](p: Proxy[NN])(implicit e: Accessor.Aux[String :: HNil, NN, OO]): OO = ??? // N is fixed by a value - at2(Proxy[Zero]): String + at2(Proxy[Zero]()): String // N is fixed as a type parameter (by name) at1[NN = Zero]: String diff --git a/tests/pos/t3636.scala b/tests/pos/t3636.scala index cd224a32f7a9..f3e3abbcee76 100644 --- a/tests/pos/t3636.scala +++ b/tests/pos/t3636.scala @@ -28,12 +28,12 @@ object TxnLocal { def set( v: T )( implicit tx: ProcTxn ) : Unit = c.set( v )( tx.ccstm ) def swap( v: T )( implicit tx: ProcTxn ) : T = { // currently not implemented in CTxnLocal - val oldV = apply + val oldV = apply() set( v ) oldV } def transform( f: T => T )( implicit tx: ProcTxn ): Unit = { - set( f( apply )) + set( f( apply() )) } } } diff --git a/tests/pos/t4579.scala b/tests/pos/t4579.scala index 8ce657eff6a6..907593e5bd73 100644 --- a/tests/pos/t4579.scala +++ b/tests/pos/t4579.scala @@ -457,14 +457,14 @@ class LispUser(lisp: Lisp) { Console.println(string2lisp("(lambda (x) (+ (* x x) 1))").asInstanceOf[AnyRef]); Console.println(lisp2string(string2lisp("(lambda (x) (+ (* x x) 1))"))); - Console.println; + Console.println(); Console.println("( '(1 2 3)) = " + evaluate(" (quote(1 2 3))")); Console.println("(car '(1 2 3)) = " + evaluate("(car (quote(1 2 3)))")); Console.println("(cdr '(1 2 3)) = " + evaluate("(cdr (quote(1 2 3)))")); Console.println("(null? '(2 3)) = " + evaluate("(null? (quote(2 3)))")); Console.println("(null? '()) = " + evaluate("(null? (quote()))")); - Console.println; + Console.println(); Console.println("faculty(10) = " + evaluate( "(def (faculty n) " + @@ -500,7 +500,7 @@ class LispUser(lisp: Lisp) { "(val v3 (+ (+ (foo 3) (foo 4)) (foo 5)) " + "(val v4 (foo 6) " + "(cons v1 (cons v2 (cons v3 (cons v4 nil))))))))))")); - Console.println; + Console.println(); } } diff --git a/tests/pos/t5577.scala b/tests/pos/t5577.scala index d54a37e45d30..d2b2a7dcc32d 100644 --- a/tests/pos/t5577.scala +++ b/tests/pos/t5577.scala @@ -21,7 +21,7 @@ object Test { iteratorBuilder.sizeHint(10) iteratorBuilder ++= (0 until 10) - iteratorBuilder.result.foreach(println) + iteratorBuilder.result().foreach(println) } } diff --git a/tests/pos/tcpoly_seq.scala b/tests/pos/tcpoly_seq.scala index e8711d1c4d4c..6b4c70dba81f 100644 --- a/tests/pos/tcpoly_seq.scala +++ b/tests/pos/tcpoly_seq.scala @@ -24,14 +24,14 @@ trait HOSeq { def filter(p: t => Boolean): m[t] = { val buf = accumulator[t] val elems = iterator - while (elems.hasNext) { val x = elems.next; if (p(x)) buf += x } + while (elems.hasNext) { val x = elems.next(); if (p(x)) buf += x } buf.result } def map[s](f: t => s): m[s] = { val buf = accumulator[s] val elems = iterator - while (elems.hasNext) buf += f(elems.next) + while (elems.hasNext) buf += f(elems.next()) buf.result } @@ -44,8 +44,8 @@ trait HOSeq { // -- 2nd-order type params are not yet in scope in view bound val elems = iterator while (elems.hasNext) { - val elemss: Iterator[s] = f(elems.next).iterator - while (elemss.hasNext) buf += elemss.next + val elemss: Iterator[s] = f(elems.next()).iterator + while (elemss.hasNext) buf += elemss.next() } buf.result } diff --git a/tests/pos/tcpoly_seq_typealias.scala b/tests/pos/tcpoly_seq_typealias.scala index b758ecd99257..651810512e58 100644 --- a/tests/pos/tcpoly_seq_typealias.scala +++ b/tests/pos/tcpoly_seq_typealias.scala @@ -26,14 +26,14 @@ trait HOSeq { def filter(p: t => Boolean): m[t] = { val buf = accumulator[t] val elems = iterator - while (elems.hasNext) { val x = elems.next; if (p(x)) buf += x } + while (elems.hasNext) { val x = elems.next(); if (p(x)) buf += x } buf.result } def map[s](f: t => s): m[s] = { val buf = accumulator[s] val elems = iterator - while (elems.hasNext) buf += f(elems.next) + while (elems.hasNext) buf += f(elems.next()) buf.result } @@ -46,8 +46,8 @@ trait HOSeq { // -- 2nd-order type params are not yet in scope in view bound val elems = iterator while (elems.hasNext) { - val elemss: Iterator[s] = f(elems.next).iterator - while (elemss.hasNext) buf += elemss.next + val elemss: Iterator[s] = f(elems.next()).iterator + while (elemss.hasNext) buf += elemss.next() } buf.result } diff --git a/tests/run/CollectionTests.scala b/tests/run/CollectionTests.scala index eec6749ab132..72a555f5e0ab 100644 --- a/tests/run/CollectionTests.scala +++ b/tests/run/CollectionTests.scala @@ -108,7 +108,7 @@ object CollectionStrawMan5 { def foldRight[B](z: B)(op: (A, B) => B): B = iterator.foldRight(z)(op) def indexWhere(p: A => Boolean): Int = iterator.indexWhere(p) def isEmpty: Boolean = !iterator.hasNext - def head: A = iterator.next + def head: A = iterator.next() def view: View[A] = View.fromIterator(iterator) } @@ -141,7 +141,7 @@ object CollectionStrawMan5 { def reverse: Repr = { var xs: List[A] = Nil var it = coll.iterator - while (it.hasNext) xs = new Cons(it.next, xs) + while (it.hasNext) xs = new Cons(it.next(), xs) fromLikeIterable(xs) } } @@ -430,7 +430,7 @@ object CollectionStrawMan5 { def next(): A def iterator = this def foldLeft[B](z: B)(op: (B, A) => B): B = - if (hasNext) foldLeft(op(z, next))(op) else z + if (hasNext) foldLeft(op(z, next()))(op) else z def foldRight[B](z: B)(op: (A, B) => B): B = if (hasNext) op(next(), foldRight(z)(op)) else z def foreach(f: A => Unit): Unit = diff --git a/tests/run/Course-2002-01.scala b/tests/run/Course-2002-01.scala index 3426f26eed19..dce7ee7ce0bb 100644 --- a/tests/run/Course-2002-01.scala +++ b/tests/run/Course-2002-01.scala @@ -188,19 +188,19 @@ object M4 { else pascal(c - 1, l - 1) + pascal(c, l - 1); Console.print(pascal(0,0)); - Console.println; + Console.println(); Console.print(pascal(0,1)); Console.print(' '); Console.print(pascal(1,1)); - Console.println; + Console.println(); Console.print(pascal(0,2)); Console.print(' '); Console.print(pascal(1,2)); Console.print(' '); Console.print(pascal(2,2)); - Console.println; + Console.println(); Console.print(pascal(0,3)); Console.print(' '); @@ -209,7 +209,7 @@ object M4 { Console.print(pascal(2,3)); Console.print(' '); Console.print(pascal(3,3)); - Console.println; + Console.println(); Console.print(pascal(0,4)); Console.print(' '); @@ -220,7 +220,7 @@ object M4 { Console.print(pascal(3,4)); Console.print(' '); Console.print(pascal(4,4)); - Console.println; + Console.println(); } //############################################################################ diff --git a/tests/run/Course-2002-02.scala b/tests/run/Course-2002-02.scala index b8650108ed89..02cf6f7608fc 100644 --- a/tests/run/Course-2002-02.scala +++ b/tests/run/Course-2002-02.scala @@ -8,7 +8,7 @@ object M0 { Console.println(gcd(14,21)) Console.println(factorial(5)) - Console.println + Console.println() } //############################################################################ @@ -38,7 +38,7 @@ object M1 { Console.println(sumReciprocals(1,4)) Console.println(sumCubes(1, 10) + sumReciprocals(10, 20)) Console.println("pi = " + sumPi(20)) - Console.println + Console.println() } //############################################################################ @@ -65,7 +65,7 @@ object M2 { Console.println(sumReciprocals(1,4)) Console.println(sumCubes(1, 10) + sumReciprocals(10, 20)) Console.println("pi = " + sumPi(20)) - Console.println + Console.println() } //############################################################################ @@ -85,7 +85,7 @@ object M3 { Console.println(sumReciprocals(1,4)) Console.println(sumCubes(1, 10) + sumReciprocals(10, 20)) Console.println("pi = " + sumPi(20)) - Console.println + Console.println() } //############################################################################ @@ -108,7 +108,7 @@ object M4 { Console.println(sumReciprocals(1,4)) Console.println(sumCubes(1, 10) + sumReciprocals(10, 20)) Console.println("pi = " + sumPi(20)) - Console.println + Console.println() } //############################################################################ @@ -129,7 +129,7 @@ object M5 { Console.println(sumReciprocals(1,4)) Console.println(sumCubes(1, 10) + sumReciprocals(10, 20)) Console.println("pi = " + sumPi(20)) - Console.println + Console.println() } //############################################################################ @@ -149,7 +149,7 @@ object M6 { Console.println(sumReciprocals(1,4)) Console.println(sumCubes(1, 10) + sumReciprocals(10, 20)) Console.println("pi = " + sumPi(20)) - Console.println + Console.println() } //############################################################################ @@ -172,7 +172,7 @@ object M7 { Console.println(sumReciprocals(1,4)) Console.println(sumCubes(1, 10) + sumReciprocals(10, 20)) Console.println("pi = " + sumPi(20)) - Console.println + Console.println() } //############################################################################ @@ -188,7 +188,7 @@ object M8 { Console.println("pi = " + productPi(20)) Console.println("pi = " + pi) - Console.println + Console.println() } //############################################################################ @@ -223,7 +223,7 @@ object M9 { Console.println("pi = " + sumPi(20)) Console.println("pi = " + productPi(20)) Console.println("pi = " + pi) - Console.println + Console.println() } //############################################################################ @@ -244,7 +244,7 @@ object MA { def sqrt(x: Double) = fixedPoint(y => (y + x / y) / 2)(1.0) Console.println("sqrt(2) = " + sqrt(2)) - Console.println + Console.println() } //############################################################################ @@ -266,7 +266,7 @@ object MB { def sqrt(x: Double) = fixedPoint(averageDamp(y => x/y))(1.0); Console.println("sqrt(2) = " + sqrt(2)) - Console.println + Console.println() } //############################################################################ @@ -294,13 +294,13 @@ object MC { "1 + 2 + .. + 5 = " + sum(x => x)(1, 5)); Console.println( "1 * 2 * .. * 5 = " + product(x => x)(1, 5)); - Console.println; + Console.println(); Console.println( "1^2 + 2^2 + .. + 5^2 = " + sum(x => x*x)(1, 5)); Console.println( "1^2 * 2^2 * .. * 5^2 = " + product(x => x*x)(1, 5)); - Console.println; + Console.println(); Console.println( "factorial(0) = " + factorial(0)) @@ -314,7 +314,7 @@ object MC { "factorial(4) = " + factorial(4)) Console.println( "factorial(5) = " + factorial(5)) - Console.println + Console.println() } //############################################################################ @@ -339,13 +339,13 @@ object MD { "1 + 2 + .. + 5 = " + sum(x => x)(1, 5)) Console.println( "1 * 2 * .. * 5 = " + product(x => x)(1, 5)) - Console.println; + Console.println(); Console.println( "1^2 + 2^2 + .. + 5^2 = " + sum(x => x*x)(1, 5)) Console.println( "1^2 * 2^2 * .. * 5^2 = " + product(x => x*x)(1, 5)) - Console.println; + Console.println(); Console.println( "factorial(0) = " + factorial(0)) @@ -359,7 +359,7 @@ object MD { "factorial(4) = " + factorial(4)) Console.println( "factorial(5) = " + factorial(5)) - Console.println + Console.println() } //############################################################################ @@ -382,13 +382,13 @@ object ME { "1 + 2 + .. + 5 = " + sum(x => x)(1, 5)) Console.println( "1 * 2 * .. * 5 = " + product(x => x)(1, 5)) - Console.println; + Console.println(); Console.println( "1^2 + 2^2 + .. + 5^2 = " + sum(x => x*x)(1, 5)) Console.println( "1^2 * 2^2 * .. * 5^2 = " + product(x => x*x)(1, 5)) - Console.println; + Console.println(); Console.println( "factorial(0) = " + factorial(0)) @@ -402,7 +402,7 @@ object ME { "factorial(4) = " + factorial(4)) Console.println( "factorial(5) = " + factorial(5)) - Console.println + Console.println() } //############################################################################ @@ -464,7 +464,7 @@ object MH { Console.println("power(0,6) = " + power(0,6)) Console.println("power(0,7) = " + power(0,7)) Console.println("power(0,8) = " + power(0,8)) - Console.println + Console.println() Console.println("power(1,0) = " + power(1,0)) Console.println("power(1,1) = " + power(1,1)) @@ -475,7 +475,7 @@ object MH { Console.println("power(1,6) = " + power(1,6)) Console.println("power(1,7) = " + power(1,7)) Console.println("power(1,8) = " + power(1,8)) - Console.println + Console.println() Console.println("power(2,0) = " + power(2,0)) Console.println("power(2,1) = " + power(2,1)) @@ -486,7 +486,7 @@ object MH { Console.println("power(2,6) = " + power(2,6)) Console.println("power(2,7) = " + power(2,7)) Console.println("power(2,8) = " + power(2,8)) - Console.println + Console.println() Console.println("power(3,0) = " + power(3,0)) Console.println("power(3,1) = " + power(3,1)) @@ -497,7 +497,7 @@ object MH { Console.println("power(3,6) = " + power(3,6)) Console.println("power(3,7) = " + power(3,7)) Console.println("power(3,8) = " + power(3,8)) - Console.println + Console.println() Console.println("power(4,0) = " + power(4,0)) Console.println("power(4,1) = " + power(4,1)) @@ -508,7 +508,7 @@ object MH { Console.println("power(4,6) = " + power(4,6)) Console.println("power(4,7) = " + power(4,7)) Console.println("power(4,8) = " + power(4,8)) - Console.println + Console.println() Console.println("power(5,0) = " + power(5,0)) Console.println("power(5,1) = " + power(5,1)) @@ -519,7 +519,7 @@ object MH { Console.println("power(5,6) = " + power(5,6)) Console.println("power(5,7) = " + power(5,7)) Console.println("power(5,8) = " + power(5,8)) - Console.println + Console.println() } //############################################################################ diff --git a/tests/run/Course-2002-03.scala b/tests/run/Course-2002-03.scala index 44cc75aaa53d..eb79f0da074e 100644 --- a/tests/run/Course-2002-03.scala +++ b/tests/run/Course-2002-03.scala @@ -23,7 +23,7 @@ object M0 { Console.println(x.denom); Console.println(makeString(x)); Console.println(makeString(addRational(x,y))); - Console.println; + Console.println(); } //############################################################################ @@ -50,7 +50,7 @@ object M1 { Console.println(y); Console.println(z); Console.println(x.add(y).mul(z)); - Console.println; + Console.println(); } //############################################################################ @@ -87,7 +87,7 @@ object M2 { Console.println(y); Console.println(z); Console.println(x.add(y).mul(z)); - Console.println; + Console.println(); } //############################################################################ @@ -109,7 +109,7 @@ object M3 { Console.println(y); Console.println(x.max(y)); Console.println(y.max(x)); - Console.println; + Console.println(); } //############################################################################ @@ -142,7 +142,7 @@ object M4 { val x = new Rational(1, 2); val y = new Rational(1, 3); Console.println(x * x + y * y); - Console.println; + Console.println(); } //############################################################################ @@ -174,7 +174,7 @@ object M5 { Console.println(x contains 1); Console.println(x contains 2); Console.println(x contains 3); - Console.println; + Console.println(); } //############################################################################ @@ -301,27 +301,27 @@ object M8 { Console.println("set2 = " + set2); Console.println("set3 = " + (set3.toString())); Console.println("set4 = " + set4); - Console.println; + Console.println(); Console.println("set2 contains the following elements:"); set2.foreach(Console.println); - Console.println; + Console.println(); Console.println("set3 contains the following elements:"); set3 foreach Console.println; - Console.println; + Console.println(); Console.println("set4 contains the following elements:"); set4.print(); - Console.println; + Console.println(); Console.println("2 <- set2: " + (set2 contains 2)); Console.println("3 <- set2: " + set2.contains(3)); - Console.println; + Console.println(); Console.println("setx = " + setx); Console.println("setx * 2 = " + (setx.map(x => 2 * x))); - Console.println; + Console.println(); Console.println("setx = " + setx); Console.println("sety = " + sety); @@ -331,7 +331,7 @@ object M8 { Console.println("sety > 0 = " + (sety.filter(x => x > 0))); Console.println("setx & sety = " + (setx.intersect2(sety))); Console.println("sety & setx = " + (sety.intersect2(setx))); - Console.println; + Console.println(); } } @@ -367,7 +367,7 @@ object M9 { Console.println(new Rational(2,2).asString); Console.println(new Rational(2,2).toString()); Console.println(new Rational(2,2)); - Console.println; + Console.println(); } } diff --git a/tests/run/Course-2002-04.scala b/tests/run/Course-2002-04.scala index 368e29db453d..e56d84bec558 100644 --- a/tests/run/Course-2002-04.scala +++ b/tests/run/Course-2002-04.scala @@ -34,7 +34,7 @@ object M0 { Console.println("list4 = " + list4); Console.println("list5 = " + list5); Console.println("list6 = " + list6); - Console.println; + Console.println(); } } @@ -116,7 +116,7 @@ object M1 { Console.println("list8: " + list8 + " -> " + isort(list8)); Console.println("list9: " + list9 + " -> " + isort(list9)); Console.println("listA: " + listA + " -> " + isort(listA)); - Console.println; + Console.println(); } } @@ -139,7 +139,7 @@ object M2 { Console.println("f(1) = " + horner(1, poly)); Console.println("f(2) = " + horner(2, poly)); Console.println("f(3) = " + horner(3, poly)); - Console.println; + Console.println(); } } @@ -183,38 +183,38 @@ object M3 { Console.println("v1 = " + v1); Console.println("v2 = " + v2); - Console.println; + Console.println(); Console.println("id = " + id); Console.println("m1 = " + m1); Console.println("m2 = " + m2); - Console.println; + Console.println(); Console.println("v1 * v1 = " + dotproduct(v1,v1)); Console.println("v1 * v2 = " + dotproduct(v1,v2)); Console.println("v2 * v1 = " + dotproduct(v2,v1)); Console.println("v1 * v2 = " + dotproduct(v1,v2)); - Console.println; + Console.println(); Console.println("id * v1 = " + matrixTimesVector(id,v1)); Console.println("m1 * v1 = " + matrixTimesVector(m1,v1)); Console.println("m2 * v1 = " + matrixTimesVector(m2,v1)); - Console.println; + Console.println(); Console.println("trn(id) = " + transpose(id)); Console.println("trn(m1) = " + transpose(m1)); Console.println("trn(m2) = " + transpose(m2)); - Console.println; + Console.println(); Console.println("List(v1) * id = " + matrixTimesMatrix(List(v1),id)); Console.println("List(v1) * m1 = " + matrixTimesMatrix(List(v1),m1)); Console.println("List(v1) * m2 = " + matrixTimesMatrix(List(v1),m2)); - Console.println; + Console.println(); Console.println("id * List(v1) = " + matrixTimesMatrix(id,List(v1))); Console.println("m1 * List(v1) = " + matrixTimesMatrix(m1,List(v1))); Console.println("m2 * List(v1) = " + matrixTimesMatrix(m2,List(v1))); - Console.println; + Console.println(); Console.println("id * id = " + matrixTimesMatrix(id,id)); Console.println("id * m1 = " + matrixTimesMatrix(id,m1)); @@ -225,7 +225,7 @@ object M3 { Console.println("m1 * m2 = " + matrixTimesMatrix(m1,m2)); Console.println("m2 * m1 = " + matrixTimesMatrix(m2,m1)); Console.println("m2 * m2 = " + matrixTimesMatrix(m2,m2)); - Console.println; + Console.println(); } } diff --git a/tests/run/Course-2002-05.scala b/tests/run/Course-2002-05.scala index c1e6b07c0ef4..31b600931aea 100644 --- a/tests/run/Course-2002-05.scala +++ b/tests/run/Course-2002-05.scala @@ -29,20 +29,20 @@ object M0 { Console.println(partition[Int](List(1,2,3,4,5,6,7,8), (x => x < 0))); Console.println(partition[Int](List(1,2,3,4,5,6,7,8), (x => x < 5))); Console.println(partition[Int](List(1,2,3,4,5,6,7,8), (x => x < 9))); - Console.println; + Console.println(); Console.println(partition[Int](List(8,7,6,5,4,3,2,1), (x => x < 0))); Console.println(partition[Int](List(8,7,6,5,4,3,2,1), (x => x < 5))); Console.println(partition[Int](List(8,7,6,5,4,3,2,1), (x => x < 9))); - Console.println; + Console.println(); Console.println(partition[Int](List(7,2,1,5,4,3,8,6), (x => x < 0))); Console.println(partition[Int](List(7,2,1,5,4,3,8,6), (x => x < 5))); Console.println(partition[Int](List(7,2,1,5,4,3,8,6), (x => x < 9))); - Console.println; + Console.println(); Console.println(quicksort[Int]((x,y) => x < y)(List(7,2,1,5,4,3,8,6))); - Console.println; + Console.println(); } } @@ -69,20 +69,20 @@ object M1 { Console.println(partition[Int](List(1,2,3,4,5,6,7,8), (x => x < 0))); Console.println(partition[Int](List(1,2,3,4,5,6,7,8), (x => x < 5))); Console.println(partition[Int](List(1,2,3,4,5,6,7,8), (x => x < 9))); - Console.println; + Console.println(); Console.println(partition[Int](List(8,7,6,5,4,3,2,1), (x => x < 0))); Console.println(partition[Int](List(8,7,6,5,4,3,2,1), (x => x < 5))); Console.println(partition[Int](List(8,7,6,5,4,3,2,1), (x => x < 9))); - Console.println; + Console.println(); Console.println(partition[Int](List(7,2,1,5,4,3,8,6), (x => x < 0))); Console.println(partition[Int](List(7,2,1,5,4,3,8,6), (x => x < 5))); Console.println(partition[Int](List(7,2,1,5,4,3,8,6), (x => x < 9))); - Console.println; + Console.println(); Console.println(quicksort[Int]((x,y) => x < y)(List(7,2,1,5,4,3,8,6))); - Console.println; + Console.println(); } } @@ -106,7 +106,7 @@ object M2 { Console.println(powerset(List(1,2))); Console.println(powerset(List(1,2,3))); Console.println(powerset(List(1,2,3,4))); - Console.println; + Console.println(); } } @@ -149,7 +149,7 @@ object M3 { Console.println("queens(2) = " + queens(2)); Console.println("queens(3) = " + queens(3)); Console.println("queens(4) = " + queens(4)); - Console.println; + Console.println(); } } @@ -194,7 +194,7 @@ object M4 { Console.println("queens(2) = " + queens(2)); Console.println("queens(3) = " + queens(3)); Console.println("queens(4) = " + queens(4)); - Console.println; + Console.println(); } } diff --git a/tests/run/Course-2002-06.scala b/tests/run/Course-2002-06.scala index 908a934041b8..e0402b7447f1 100644 --- a/tests/run/Course-2002-06.scala +++ b/tests/run/Course-2002-06.scala @@ -137,7 +137,7 @@ class PostScript (filename: String, _width: Double, _height: Double) /** Terminate the PS document and close the file stream. */ def close : Unit = { Console.println("stroke\nshowpage\n%%EOF"); - Console.flush; + Console.flush(); } } diff --git a/tests/run/Course-2002-07.scala b/tests/run/Course-2002-07.scala index b26eda1e0ecd..779d27188075 100644 --- a/tests/run/Course-2002-07.scala +++ b/tests/run/Course-2002-07.scala @@ -58,7 +58,7 @@ object M0 { eval(new Sum(new Number(1),new Number(2)))); Console.println("2 + 3 + 4 = " + eval(new Sum(new Sum(new Number(2),new Number(3)),new Number(4)))); - Console.println; + Console.println(); } } @@ -86,7 +86,7 @@ object M1 { new Sum(new Number(1),new Number(2)).eval); Console.println("2 + 3 + 4 = " + new Sum(new Sum(new Number(2),new Number(3)),new Number(4)).eval); - Console.println; + Console.println(); } } @@ -110,7 +110,7 @@ object M2 { Console.println(" 1 + 2 = " + eval(Sum(Number(1),Number(2)))); Console.println("2 + 3 + 4 = " + eval(Sum(Sum(Number(2),Number(3)), Number(4)))); - Console.println; + Console.println(); } } @@ -134,7 +134,7 @@ object M3 { Console.println(" 1 + 2 = " + Sum(Number(1),Number(2)).eval); Console.println("2 + 3 + 4 = " + Sum(Sum(Number(2),Number(3)), Number(4)).eval); - Console.println; + Console.println(); } } @@ -172,7 +172,7 @@ object M4 { test_concat(List(List[Int](),List(1),List(2,3,4,5,6))); // !!! [int] test_concat(List(List[Int](),List[Int](),List(1,2,3,4,5,6))); // !!! [int] test_concat(List(List(1,2),List(3,4),List(5,6))); - Console.println; + Console.println(); } } @@ -206,7 +206,7 @@ object M5 { test_zipFun(List(1,2,3),List('a','b','c')); - Console.println; + Console.println(); } } @@ -240,7 +240,7 @@ object M6 { test_zipFun(List(1,2,3),List('a','b','c')); - Console.println; + Console.println(); } } @@ -283,7 +283,7 @@ object M7 { test_heads(List(List(1,2),List(3,4),List(5,6))); - Console.println; + Console.println(); } } @@ -329,7 +329,7 @@ object M8 { test_heads(List(List(1,2),List(3,4),List(5,6))); - Console.println; + Console.println(); } } @@ -365,7 +365,7 @@ object M9 { val f1 = f0 derive x; Console.println("f (x) = " + f0); Console.println("f'(x) = " + f1); - Console.println; + Console.println(); } } @@ -440,7 +440,7 @@ object MA { Console.println("g (3) = " + evalvars(List(("x",3)))(g0)); Console.println("g'(3) = " + evalvars(List(("x",3)))(g1)); - Console.println; + Console.println(); } } @@ -651,7 +651,7 @@ object MB { Console.println("tf(x) = " + tf); Console.println("tg(x) = " + tg); Console.println("th(x) = " + th); - Console.println; + Console.println(); val f4 = (x+ _3)*(_2+x)*x*(x+ _1) + (x+ _5)*(x*(x+ _2)+x+ _1) + (x^2) + x; val f3 = f4.derive(x); @@ -664,7 +664,7 @@ object MB { Console.println("f2(x) = " + f2); Console.println("f1(x) = " + f1); Console.println("f0(x) = " + f0); - Console.println; + Console.println(); def check(n: String, f: Expr, x: Int, e: Int): Unit = { val a: Int = f.evaluate(List(("x",x))); @@ -677,25 +677,25 @@ object MB { check("f4", f4, 2, 203); check("f4", f4, 3, 524); check("f4", f4, 4, 1121); - Console.println; + Console.println(); check("f3", f3, 0, 23); check("f3", f3, 1, 88); check("f3", f3, 2, 219); check("f3", f3, 3, 440); - Console.println; + Console.println(); check("f2", f2, 0, 40); check("f2", f2, 1, 94); check("f2", f2, 2, 172); - Console.println; + Console.println(); check("f1", f1, 0, 42); check("f1", f1, 1, 66); - Console.println; + Console.println(); check("f0", f0, 0, 24); - Console.println; + Console.println(); } } diff --git a/tests/run/Course-2002-08.scala b/tests/run/Course-2002-08.scala index 5e21edaba353..1d3b8106629b 100644 --- a/tests/run/Course-2002-08.scala +++ b/tests/run/Course-2002-08.scala @@ -16,7 +16,7 @@ object M0 { count = count + 1; Console.println("x = " + x); Console.println("count = " + count); - Console.println; + Console.println(); } } @@ -45,7 +45,7 @@ object M1 { Console.print("account withdraw 20 -> "); Console.println(account withdraw 20); Console.print("account withdraw 15 -> "); - Console.println; + Console.println(); } def test1 = { @@ -54,7 +54,7 @@ object M1 { Console.print("x deposit 30 -> "); Console.println((x deposit 30).toString()); // !!! .toString Console.print("y withdraw 20 -> "); - Console.println; + Console.println(); } def test2 = { @@ -76,10 +76,10 @@ object M1 { } def test = { - test0; Console.println; - test1; Console.println; - test2; Console.println; - test3; Console.println; + test0; Console.println(); + test1; Console.println(); + test2; Console.println(); + test3; Console.println(); } } @@ -106,7 +106,7 @@ object M2 { Console.println("2^1 = " + power(2,1)); Console.println("2^2 = " + power(2,2)); Console.println("2^3 = " + power(2,3)); - Console.println; + Console.println(); } } @@ -126,7 +126,7 @@ object M3 { Console.println("2^1 = " + power(2,1)); Console.println("2^2 = " + power(2,2)); Console.println("2^3 = " + power(2,3)); - Console.println; + Console.println(); } } @@ -136,9 +136,9 @@ object M4 { def test = { for (i <- range(1, 4)) { Console.print(i + " ") }; - Console.println; + Console.println(); Console.println(for (i <- range(1, 4)) yield i); - Console.println; + Console.println(); } } @@ -274,7 +274,7 @@ object M5 { ain setSignal (if (a == 0) false else true); run; Console.println("!" + a + " = " + result); - Console.println; + Console.println(); } probe("out ", cout); @@ -296,11 +296,11 @@ object M5 { bin setSignal (if (b == 0) false else true); run; Console.println(a + " & " + b + " = " + result); - Console.println; + Console.println(); } probe("out ", cout); - Console.println; + Console.println(); test(0,0); test(0,1); @@ -321,11 +321,11 @@ object M5 { bin setSignal (if (b == 0) false else true); run; Console.println(a + " | " + b + " = " + result); - Console.println; + Console.println(); } probe("out ", cout); - Console.println; + Console.println(); test(0,0); test(0,1); @@ -349,12 +349,12 @@ object M5 { bin setSignal (if (b == 0) false else true); run; Console.println(a + " + " + b + " = " + result); - Console.println; + Console.println(); } probe("sum ", sout); probe("carry", cout); - Console.println; + Console.println(); test(0,0); test(0,1); @@ -380,12 +380,12 @@ object M5 { cin setSignal (if (c == 0) false else true); run; Console.println(a + " + " + b + " + " + c + " = " + result); - Console.println; + Console.println(); } probe("sum ", sout); probe("carry", cout); - Console.println; + Console.println(); test(0,0,0); test(0,0,1); diff --git a/tests/run/Course-2002-09.scala b/tests/run/Course-2002-09.scala index 588703ddcf68..0aa6209a2951 100644 --- a/tests/run/Course-2002-09.scala +++ b/tests/run/Course-2002-09.scala @@ -186,19 +186,19 @@ object M0 { c.setValue(0); c.forgetValue; - Console.println; + Console.println(); c.setValue(100); c.forgetValue; - Console.println; + Console.println(); f.setValue(32); f.forgetValue; - Console.println; + Console.println(); f.setValue(212); f.forgetValue; - Console.println; + Console.println(); } } @@ -239,7 +239,7 @@ object M1 { show_c2f(c, f, 100); show_f2c(c, f, 32); show_f2c(c, f, 212); - Console.println; + Console.println(); } } @@ -273,7 +273,7 @@ object M2 { show(Some(2), None , Some(6)); show(None , Some(3), Some(6)); show(Some(2), Some(3), Some(6)); - Console.println; + Console.println(); show(Some(0), None , None ); show(None , Some(0), None ); @@ -286,7 +286,7 @@ object M2 { show(Some(0), Some(7), Some(0)); show(Some(7), Some(0), Some(0)); show(Some(0), Some(0), Some(0)); - Console.println; + Console.println(); } } @@ -313,7 +313,7 @@ object M3 { Console.println("b = 4, c = 5 => a = " + a.str); b.forgetValue; c.forgetValue; - Console.println; + Console.println(); } } diff --git a/tests/run/Course-2002-10.scala b/tests/run/Course-2002-10.scala index 4cfa1deb0462..a8bf47a4e393 100644 --- a/tests/run/Course-2002-10.scala +++ b/tests/run/Course-2002-10.scala @@ -15,7 +15,7 @@ object M0 { def test = { var i = 0; fib.take(20).foreach(n => {Console.println("fib("+i+") = "+n); i=i+1}); - Console.println; + Console.println(); } } @@ -76,7 +76,7 @@ object M1 { Console.print(str(Pi) + ", "); Console.print(str(Pi) + ", "); Console.print(str(Pi) + "\n"); - Console.println; + Console.println(); i = 0; while (i < 10) { Console.print("ln("+i+") = "); @@ -89,7 +89,7 @@ object M1 { Console.print(str(log(2)) + ", "); Console.print(str(log(2)) + ", "); Console.print(str(log(2)) + "\n"); - Console.println; + Console.println(); } } @@ -107,7 +107,7 @@ object M2 { var current: Iterator[Int] = new IntIterator(2); def hasNext = true; def next = { - val p = current.next; + val p = current.next(); current = current filter { x => !((x % p) == 0) }; p } @@ -116,8 +116,8 @@ object M2 { def test = { val i = (new PrimeIterator()).take(30); Console.print("prime numbers:"); - while (i.hasNext) { Console.print(" " + i.next); } - Console.println; + while (i.hasNext) { Console.print(" " + i.next()); } + Console.println(); } } diff --git a/tests/run/Course-2002-13.scala b/tests/run/Course-2002-13.scala index a596a33873d3..774695b6c406 100644 --- a/tests/run/Course-2002-13.scala +++ b/tests/run/Course-2002-13.scala @@ -268,7 +268,7 @@ object Test { "?phrase(S,V,A,D,N).\n" + "?more.\n" ); - Console.println; + Console.println(); Prolog.process( "sujet(jean).\n" + @@ -287,7 +287,7 @@ object Test { "?phrase(S,V,A,D,N).\n" + "?more.\n" ); - Console.println; + Console.println(); Prolog.process( "sujet(jean).\n" + @@ -313,7 +313,7 @@ object Test { "?phrase(jean,mange,le,cons(grand,nil),cheval).\n" + "?phrase(jean,mange,le,cons(grand,nil),table).\n" ); - Console.println; + Console.println(); () } diff --git a/tests/run/MutableListTest.scala b/tests/run/MutableListTest.scala index 8efb8281db74..19d7dc77a49d 100644 --- a/tests/run/MutableListTest.scala +++ b/tests/run/MutableListTest.scala @@ -84,7 +84,7 @@ object Test { assert(mlist(5) == -25) assert(mlist(0) == -1) assert(mlist.last == -81) - mlist.clear + mlist.clear() assert(mlist.isEmpty) mlist += 1001 assert(mlist.head == 1001) @@ -107,7 +107,7 @@ object Test { lst += 7 assert(lst.init.last == 129) assert(lst.length == 5) - lst.clear + lst.clear() assert(lst.length == 0) for (i <- 0 until 5) lst += i assert(lst.reduceLeft(_ + _) == 10) diff --git a/tests/run/QueueTest.scala b/tests/run/QueueTest.scala index 8c35e39cb188..773def22c60f 100644 --- a/tests/run/QueueTest.scala +++ b/tests/run/QueueTest.scala @@ -34,7 +34,7 @@ object Test { assert(queue.dequeueFirst(_ > 500) == None) assert(queue.dequeueAll(_ > 500).isEmpty) - queue.clear + queue.clear() assert(queue.isEmpty) assert(queue.size == 0) assert(queue.length == 0) @@ -54,7 +54,7 @@ object Test { assert(queue.init.isEmpty) assert(queue.tail.isEmpty) - queue.clear + queue.clear() assert(queue.isEmpty) assert(queue.length == 0) @@ -64,7 +64,7 @@ object Test { assert(queue.head == 11) assert(queue.front == 11) - val deq = queue.dequeue + val deq = queue.dequeue() assert(deq == 11) assert(queue.isEmpty) assert(queue.length == 0) @@ -110,7 +110,7 @@ object Test { assert(queue.front == 10) // queue.printState - val ten = queue.dequeue + val ten = queue.dequeue() assert(ten == 10) assert(queue.length == 1) // queue.printState @@ -172,7 +172,7 @@ object Test { for (i <- 0 until 10) queue.enqueue(i * 2) for (i <- 0 until 10) { - val top = queue.dequeue + val top = queue.dequeue() assert(top == i * 2) assert(queue.length == 10 - i - 1) } @@ -191,7 +191,7 @@ object Test { assert(queue.length == 3) assert(queue.nonEmpty) - queue.clear + queue.clear() assert(queue.length == 0) assert(queue.isEmpty) @@ -258,7 +258,7 @@ object Test { assert(queue.head == 0) assert(queue.last == 3) - queue.dequeue + queue.dequeue() assert(queue.head == 3) queue.enqueue(9) @@ -267,7 +267,7 @@ object Test { assert(queue.length == 1) assert(queue.head == 9) - queue.clear + queue.clear() for (i <- -100 until 100) queue.enqueue(i * i + i % 7 + 5) assert(queue.length == 200) diff --git a/tests/run/UnrolledBuffer.scala b/tests/run/UnrolledBuffer.scala index 76201bb7cc3b..2e325dbfab97 100644 --- a/tests/run/UnrolledBuffer.scala +++ b/tests/run/UnrolledBuffer.scala @@ -21,7 +21,7 @@ object Test { assert(u1.nonEmpty) assert(u1.size == 3) - u1.clear + u1.clear() assert(u1.isEmpty) assert(u1.size == 0) @@ -40,8 +40,8 @@ object Test { val u2 = u1 map { x => (x - 1) / 2 } assert(u2 == UnrolledBuffer(0, 1, 2, 3, 4)) - u1.clear - u2.clear + u1.clear() + u2.clear() assert(u1.size == 0) assert(u2.size == 0) diff --git a/tests/run/boolexprs.scala b/tests/run/boolexprs.scala index 94313d9c8e9a..1529abaf779f 100644 --- a/tests/run/boolexprs.scala +++ b/tests/run/boolexprs.scala @@ -46,13 +46,13 @@ object Test { case exception: Throwable => Console.print(" raised exception " + exception); } - Console.println; + Console.println(); } def main(args: Array[String]): Unit = { check_success("Test1", Test1.run, 1); check_success("Test2", Test2.run, 0); - Console.println; + Console.println(); } } diff --git a/tests/run/bridges.scala b/tests/run/bridges.scala index eb036bd781dc..d91c73514e93 100644 --- a/tests/run/bridges.scala +++ b/tests/run/bridges.scala @@ -3584,13 +3584,13 @@ object Test { if (!Help.check(count, value)) { Console.print(name + " failed: "); Help.print; - Console.println; + Console.println(); errors = errors + 1; } } catch { case exception: Throwable => { Console.print(name + " raised exception " + exception); - Console.println; + Console.println(); errors = errors + 1; } } @@ -7115,7 +7115,7 @@ object Test { // */test("S_TZIfwFooXIfwBarYIf", new S_TZIfwFooXIfwBarYIf[D], 4, "mix"); if (errors > 0) { - Console.println; + Console.println(); Console.println(errors + " error" + (if (errors > 1) "s" else "")); } } diff --git a/tests/run/colltest1.scala b/tests/run/colltest1.scala index 3f1fe5530fea..ab519067b6f7 100644 --- a/tests/run/colltest1.scala +++ b/tests/run/colltest1.scala @@ -56,7 +56,7 @@ object Test extends dotty.runtime.LegacyApp { val buf = new mutable.ArrayBuffer[Int] firstFive copyToBuffer buf secondFive copyToBuffer buf - assert(buf.result == ten, buf.result) + assert(buf.result() == ten, buf.result()) assert(ten.toArray.size == 10) assert(ten.toArray.toSeq == ten, ten.toArray.toSeq) assert(ten.toIterable == ten) diff --git a/tests/run/colltest4/CollectionStrawMan4_1.scala b/tests/run/colltest4/CollectionStrawMan4_1.scala index 8f0bdc841ee0..e36c7886cc90 100644 --- a/tests/run/colltest4/CollectionStrawMan4_1.scala +++ b/tests/run/colltest4/CollectionStrawMan4_1.scala @@ -67,7 +67,7 @@ object CollectionStrawMan4 { def foldRight[B](z: B)(op: (A, B) => B): B = iterator.foldRight(z)(op) def indexWhere(p: A => Boolean): Int = iterator.indexWhere(p) def isEmpty: Boolean = !iterator.hasNext - def head: A = iterator.next + def head: A = iterator.next() } /** Transforms returning same collection type */ @@ -163,7 +163,7 @@ object CollectionStrawMan4 { object List extends IterableFactory[List] { def fromIterator[B](it: Iterator[B]): List[B] = - if (it.hasNext) Cons(it.next, fromIterator(it)) else Nil + if (it.hasNext) Cons(it.next(), fromIterator(it)) else Nil def fromIterable[B](c: Iterable[B]): List[B] = c match { case View.Concat(xs, ys: List[B]) => fromIterable(xs) ++: ys @@ -448,7 +448,7 @@ object CollectionStrawMan4 { def next(): A def iterator = this def foldLeft[B](z: B)(op: (B, A) => B): B = - if (hasNext) foldLeft(op(z, next))(op) else z + if (hasNext) foldLeft(op(z, next()))(op) else z def foldRight[B](z: B)(op: (A, B) => B): B = if (hasNext) op(next(), foldRight(z)(op)) else z def foreach(f: A => Unit): Unit = diff --git a/tests/run/colltest5/CollectionStrawMan5_1.scala b/tests/run/colltest5/CollectionStrawMan5_1.scala index bb6ed4426066..15a1f5e3536a 100644 --- a/tests/run/colltest5/CollectionStrawMan5_1.scala +++ b/tests/run/colltest5/CollectionStrawMan5_1.scala @@ -101,7 +101,7 @@ object CollectionStrawMan5 { def foldRight[B](z: B)(op: (A, B) => B): B = iterator.foldRight(z)(op) def indexWhere(p: A => Boolean): Int = iterator.indexWhere(p) def isEmpty: Boolean = !iterator.hasNext - def head: A = iterator.next + def head: A = iterator.next() def view: View[A] = View.fromIterator(iterator) } @@ -134,7 +134,7 @@ object CollectionStrawMan5 { def reverse: Repr = { var xs: List[A] = Nil var it = coll.iterator - while (it.hasNext) xs = new Cons(it.next, xs) + while (it.hasNext) xs = new Cons(it.next(), xs) fromLikeIterable(xs) } } @@ -423,7 +423,7 @@ object CollectionStrawMan5 { def next(): A def iterator = this def foldLeft[B](z: B)(op: (B, A) => B): B = - if (hasNext) foldLeft(op(z, next))(op) else z + if (hasNext) foldLeft(op(z, next()))(op) else z def foldRight[B](z: B)(op: (A, B) => B): B = if (hasNext) op(next(), foldRight(z)(op)) else z def foreach(f: A => Unit): Unit = diff --git a/tests/run/colltest6/CollectionStrawMan6_1.scala b/tests/run/colltest6/CollectionStrawMan6_1.scala index 8400fc05f6e5..294523af6e4f 100644 --- a/tests/run/colltest6/CollectionStrawMan6_1.scala +++ b/tests/run/colltest6/CollectionStrawMan6_1.scala @@ -942,7 +942,7 @@ object CollectionStrawMan6 extends LowPriority { def next(): A def iterator = this def foldLeft[B](z: B)(op: (B, A) => B): B = - if (hasNext) foldLeft(op(z, next))(op) else z + if (hasNext) foldLeft(op(z, next()))(op) else z def foldRight[B](z: B)(op: (A, B) => B): B = if (hasNext) op(next(), foldRight(z)(op)) else z def foreach(f: A => Unit): Unit = diff --git a/tests/run/constant-optimization.scala b/tests/run/constant-optimization.scala index 83cabf85654f..a709cb5e4c96 100644 --- a/tests/run/constant-optimization.scala +++ b/tests/run/constant-optimization.scala @@ -1,6 +1,6 @@ object Test extends dotty.runtime.LegacyApp { def testBothReachable(): Unit = { - val i = util.Random.nextInt + val i = util.Random.nextInt() val x = if (i % 2 == 0) null else "good" val y = if (x == null) "good" else x + "" println(s"testBothReachable: $y") @@ -14,7 +14,7 @@ object Test extends dotty.runtime.LegacyApp { } def testAllReachable(): Unit = { - val i = util.Random.nextInt + val i = util.Random.nextInt() val y = (i % 2) match { case 0 => "good" case 1 => "good" @@ -24,7 +24,7 @@ object Test extends dotty.runtime.LegacyApp { } def testOneUnreachable(): Unit = { - val i = util.Random.nextInt + val i = util.Random.nextInt() val x = if (i % 2 == 0) { 1 } else { @@ -39,7 +39,7 @@ object Test extends dotty.runtime.LegacyApp { } def testDefaultUnreachable(): Unit = { - val i = util.Random.nextInt + val i = util.Random.nextInt() val x = if (i % 2 == 0) { 1 } else { diff --git a/tests/run/contrib674.scala b/tests/run/contrib674.scala index fe7ebcccd44c..090e0bf37c17 100644 --- a/tests/run/contrib674.scala +++ b/tests/run/contrib674.scala @@ -15,5 +15,5 @@ object Test extends dotty.runtime.LegacyApp { 1 } - bad + bad() } diff --git a/tests/run/deeps.scala b/tests/run/deeps.scala index 0cb6d623196b..d155030116f9 100644 --- a/tests/run/deeps.scala +++ b/tests/run/deeps.scala @@ -10,14 +10,14 @@ object Test { println(Array(1) == Array(1)) println(Array(1) equals Array(1)) println(Array(1).deep == Array(1).deep) - println + println() } def testEquals2: Unit = { println(Array(Array(1), Array(2)) == Array(Array(1), Array(2))) println(Array(Array(1), Array(2)) equals Array(Array(1), Array(2))) println(Array(Array(1), Array(2)).deep equals Array(Array(1), Array(2)).deep) - println + println() } def testEquals3: Unit = { @@ -33,7 +33,7 @@ object Test { println(x == y) println(x equals y) println(x.deep == y.deep) - println + println() } test(a1, b1) test(a2, b2) @@ -63,7 +63,7 @@ object Test { println(a.deep.toString) println(a.deep.mkString("[", ";", "]")) println(a.deep.mkString(";")) - println + println() } val ba1 = Array(true, false) @@ -92,7 +92,7 @@ object Test { println(Array(Array(true, false), Array(false)).deep.mkString("[", "; ", "]")) println(Array(Array('1', '2'), Array('3')).deep.mkString("[", "; ", "]")) println(Array(Array(1, 2), Array(3)).deep.mkString("[", "; ", "]")) - println + println() } def testToString3: Unit = { diff --git a/tests/run/exceptions.scala b/tests/run/exceptions.scala index f0fe76946b5c..4cd389dc3993 100644 --- a/tests/run/exceptions.scala +++ b/tests/run/exceptions.scala @@ -22,8 +22,8 @@ object exceptions { if (value == "\u0000") value = "\\u0000"; Console.print(": " + what + " = " + value); if (!success) Console.print(" != " + expected); - Console.println; - Console.flush; + Console.println(); + Console.flush(); } def test: Unit = { diff --git a/tests/run/fors.scala b/tests/run/fors.scala index 1de1640295dc..f498a3a65c7d 100644 --- a/tests/run/fors.scala +++ b/tests/run/fors.scala @@ -18,29 +18,29 @@ object Test extends dotty.runtime.LegacyApp { println("\ntestOld") // lists - for (x <- xs) print(x + " "); println + for (x <- xs) print(x + " "); println() for (x <- xs; - if x % 2 == 0) print(x + " "); println + if x % 2 == 0) print(x + " "); println() for {x <- xs - if x % 2 == 0} print(x + " "); println + if x % 2 == 0} print(x + " "); println() var n = 0 for (_ <- xs) n += 1; println(n) - for ((x, y) <- xs zip ys) print(x + " "); println - for (p @ (x, y) <- xs zip ys) print(p._1 + " "); println + for ((x, y) <- xs zip ys) print(x + " "); println() + for (p @ (x, y) <- xs zip ys) print(p._1 + " "); println() // iterators - for (x <- it) print(x + " "); println + for (x <- it) print(x + " "); println() for (x <- it; - if x % 2 == 0) print(x + " "); println + if x % 2 == 0) print(x + " "); println() for {x <- it - if x % 2 == 0} print(x + " "); println + if x % 2 == 0} print(x + " "); println() // arrays - for (x <- ar) print(x + " "); println + for (x <- ar) print(x + " "); println() for (x <- ar; - if x.toInt > 97) print(x + " "); println + if x.toInt > 97) print(x + " "); println() for {x <- ar - if x.toInt > 97} print(x + " "); println + if x.toInt > 97} print(x + " "); println() } @@ -52,28 +52,28 @@ object Test extends dotty.runtime.LegacyApp { // lists var n = 0 for (_ <- xs) n += 1; println(n) - for ((x, y) <- xs zip ys) print(x + " "); println - for (p @ (x, y) <- xs zip ys) print(p._1 + " "); println + for ((x, y) <- xs zip ys) print(x + " "); println() + for (p @ (x, y) <- xs zip ys) print(p._1 + " "); println() // iterators - for (x <- it) print(x + " "); println - for (x <- it if x % 2 == 0) print(x + " "); println - for (x <- it; if x % 2 == 0) print(x + " "); println + for (x <- it) print(x + " "); println() + for (x <- it if x % 2 == 0) print(x + " "); println() + for (x <- it; if x % 2 == 0) print(x + " "); println() for (x <- it; - if x % 2 == 0) print(x + " "); println + if x % 2 == 0) print(x + " "); println() for (x <- it - if x % 2 == 0) print(x + " "); println + if x % 2 == 0) print(x + " "); println() for {x <- it - if x % 2 == 0} print(x + " "); println + if x % 2 == 0} print(x + " "); println() for (x <- it; y = 2 - if x % y == 0) print(x + " "); println + if x % y == 0) print(x + " "); println() for {x <- it y = 2 - if x % y == 0} print(x + " "); println + if x % y == 0} print(x + " "); println() // arrays - for (x <- ar) print(x + " "); println + for (x <- ar) print(x + " "); println() } diff --git a/tests/run/hashset.scala b/tests/run/hashset.scala index 0c305142b110..a6deb704283e 100644 --- a/tests/run/hashset.scala +++ b/tests/run/hashset.scala @@ -23,7 +23,7 @@ object Test extends dotty.runtime.LegacyApp { println((for (i <- 0 until 20) yield i + " " + (h1 contains i)).toList.sorted mkString(",")) println((for (i <- 20 until 40) yield i + " " + (h1 contains i)).toList.sorted mkString(",")) println(h1.toList.sorted mkString ",") - println + println() println("*** " + creator.hashSetType + " Strings with null") val h2 = creator.create[String] @@ -38,7 +38,7 @@ object Test extends dotty.runtime.LegacyApp { h2 -= "" + 0 println("null " + (h2 contains null)) println((for (i <- 0 until 20) yield i + " " + (h2 contains ("" + i))).toList.sorted mkString(",")) - println + println() } trait Creator { diff --git a/tests/run/i1732.scala b/tests/run/i1732.scala index 6c090a2eb1c7..15d8da5bd2f6 100644 --- a/tests/run/i1732.scala +++ b/tests/run/i1732.scala @@ -9,7 +9,7 @@ object Test { def main(args: Array[String]): Unit = { brk { () => ??? } Breaks.breakable { - Breaks.break + Breaks.break() } } } diff --git a/tests/run/imports.scala b/tests/run/imports.scala index 4bdbef9f95f2..adc173c6af62 100644 --- a/tests/run/imports.scala +++ b/tests/run/imports.scala @@ -7,11 +7,11 @@ object checker { def check(location: String, what: String, value: Any): Unit = { Console.print("In " + location + ", " + what + ".toString() returns "); - Console.flush; + Console.flush(); val string: String = if (value == null) "null" else value.toString(); val test = if (string == location) "ok" else "KO"; Console.println(string + " -> " + test); - Console.flush; + Console.flush(); } } @@ -31,7 +31,7 @@ class C_ico() { check("C_ico", "v_ico ", v_ico); check("C_ico", "field ", field); check("C_ico", "method", method); - Console.println; + Console.println(); } object o_ico { @@ -58,7 +58,7 @@ class C_ioc() { check("C_ioc", "v_ioc ", v_ioc); check("C_ioc", "field ", field); check("C_ioc", "method", method); - Console.println; + Console.println(); } //############################################################################ @@ -79,7 +79,7 @@ class C_oic() { check("C_oic", "v_oic ", v_oic); check("C_oic", "field ", field); check("C_oic", "method", method); - Console.println; + Console.println(); } //############################################################################ diff --git a/tests/run/iq.scala b/tests/run/iq.scala index e70b6e4f8e39..4dbdde3b4699 100644 --- a/tests/run/iq.scala +++ b/tests/run/iq.scala @@ -20,7 +20,7 @@ object iq { val q2 = q.enqueue(42).enqueue(0) val qa = q :+ 42 :+ 0 assert(q2 == qa) - + val qb = 42 +: 0 +: q assert(q2 == qb) val qc = 42 +: q :+ 0 @@ -30,7 +30,7 @@ object iq { Console.println("qa: " + qa) Console.println("qb: " + qb) Console.println("qc: " + qc) - + /* Test is empty and dequeue. * Expected: Head: 42 */ @@ -85,7 +85,7 @@ object iq { */ Console.print("Elements: "); q6.iterator.foreach(e => Console.print(" "+ e + " ")) - Console.println; + Console.println(); /* Testing mkString * Expected: String: <1-2-3-4-5-6-7-8-9> diff --git a/tests/run/iterator3444.scala b/tests/run/iterator3444.scala index 0a8f94291c3b..43037a440cf1 100644 --- a/tests/run/iterator3444.scala +++ b/tests/run/iterator3444.scala @@ -6,11 +6,11 @@ object Test { def main(args: Array[String]): Unit = { val it = (1 to 12).toSeq.iterator - assert(it.next == 1) + assert(it.next() == 1) assert(it.take(2).toList == List(2, 3)) val jt = (4 to 12).toSeq.iterator - assert(jt.next == 4) + assert(jt.next() == 4) assert(jt.drop(5).toList == List(10, 11, 12)) val kt = (1 until 10).toSeq.iterator diff --git a/tests/run/iterators.scala b/tests/run/iterators.scala index e2a97ec7a03a..2f70abd52193 100644 --- a/tests/run/iterators.scala +++ b/tests/run/iterators.scala @@ -11,7 +11,7 @@ object Test { def check_from: Int = { val it1 = Iterator.from(-1) val it2 = Iterator.from(0, -1) - it1.next + it2.next + it1.next() + it2.next() } def check_range: Int = { @@ -57,8 +57,8 @@ object Test { def check_drop: Int = { val it1 = Iterator.from(0) val it2 = it1 map { 2 * _ } - val n1 = it1 drop 2 next - val n2 = it2 drop 2 next; + val n1 = it1 drop 2 next() + val n2 = it2 drop 2 next(); n1 + n2 } diff --git a/tests/run/kmpSliceSearch.scala b/tests/run/kmpSliceSearch.scala index 4d582bb1c753..02f14df4dada 100644 --- a/tests/run/kmpSliceSearch.scala +++ b/tests/run/kmpSliceSearch.scala @@ -17,13 +17,13 @@ object Test { for (h <- Array(2,5,1000)) { for (i <- 0 to 100) { for (j <- 0 to 10) { - val xs = (0 to j).map(_ => (rng.nextInt & 0x7FFFFFFF) % h) + val xs = (0 to j).map(_ => (rng.nextInt() & 0x7FFFFFFF) % h) val xsa = xs.toArray val xsv = Vector() ++ xs val xsl = xs.toList val xss = Vector[Seq[Int]](xs,xsa,xsv,xsl) for (k <- 0 to 5) { - val ys = (0 to k).map(_ => (rng.nextInt & 0x7FFFFFFF) % h) + val ys = (0 to k).map(_ => (rng.nextInt() & 0x7FFFFFFF) % h) val ysa = ys.toArray val ysv = Vector() ++ ys val ysl = ys.toList diff --git a/tests/run/map_java_conversions.scala b/tests/run/map_java_conversions.scala index b7b39128c8f7..5c484ee35e3f 100644 --- a/tests/run/map_java_conversions.scala +++ b/tests/run/map_java_conversions.scala @@ -28,7 +28,7 @@ object Test { } def test(m: collection.mutable.Map[String, String]): Unit = { - m.clear + m.clear() assert(m.size == 0) m.put("key", "value") @@ -46,7 +46,7 @@ object Test { assert(m.nonEmpty) assert(m.remove("key") == Some("anotherValue")) - m.clear + m.clear() for (i <- 0 until 10) m += (("key" + i, "value" + i)) for ((k, v) <- m) assert(k.startsWith("key")) } diff --git a/tests/run/mixin-primitive-on-generic-1.scala b/tests/run/mixin-primitive-on-generic-1.scala index 470f543cea29..e5a051220eeb 100644 --- a/tests/run/mixin-primitive-on-generic-1.scala +++ b/tests/run/mixin-primitive-on-generic-1.scala @@ -2,7 +2,7 @@ object Test { def main(args: Array[String]): Unit = { println((new Foo: Baz).value1) - println((new Foo: Baz).value2) + println((new Foo: Baz).value2()) } } diff --git a/tests/run/mixin-primitive-on-generic-2.scala b/tests/run/mixin-primitive-on-generic-2.scala index 37e3f6035e65..5c42f61b249b 100644 --- a/tests/run/mixin-primitive-on-generic-2.scala +++ b/tests/run/mixin-primitive-on-generic-2.scala @@ -2,7 +2,7 @@ object Test { def main(args: Array[String]): Unit = { println((new Foo: Bar[Boolean]).value1) - println((new Foo: Bar[Boolean]).value2) + println((new Foo: Bar[Boolean]).value2()) } } diff --git a/tests/run/mixin-primitive-on-generic-4.scala b/tests/run/mixin-primitive-on-generic-4.scala index ddf62b92ff79..49281b956737 100644 --- a/tests/run/mixin-primitive-on-generic-4.scala +++ b/tests/run/mixin-primitive-on-generic-4.scala @@ -2,7 +2,7 @@ object Test { def main(args: Array[String]): Unit = { println((new Foo: Baz).value1.v) - println((new Foo: Baz).value2.v) + println((new Foo: Baz).value2().v) } } diff --git a/tests/run/mixin-primitive-on-generic-5.scala b/tests/run/mixin-primitive-on-generic-5.scala index 438c130de011..d852baa62586 100644 --- a/tests/run/mixin-primitive-on-generic-5.scala +++ b/tests/run/mixin-primitive-on-generic-5.scala @@ -2,7 +2,7 @@ object Test { def main(args: Array[String]): Unit = { println((new Foo: Bar[VBoolean]).value1.v) - println((new Foo: Bar[VBoolean]).value2.v) + println((new Foo: Bar[VBoolean]).value2().v) } } diff --git a/tests/run/overloads.scala b/tests/run/overloads.scala index e84fef021365..848b6f5be0fe 100644 --- a/tests/run/overloads.scala +++ b/tests/run/overloads.scala @@ -40,8 +40,8 @@ object overloads { if (value == "\u0000") value = "\\u0000"; Console.print(": " + what + " = " + value); if (!success) Console.print(" != " + expected); - Console.println; - Console.flush; + Console.println(); + Console.flush(); } def - = 0; diff --git a/tests/run/slices.scala b/tests/run/slices.scala index 1ffedaea0795..838fb46a9b64 100644 --- a/tests/run/slices.scala +++ b/tests/run/slices.scala @@ -9,21 +9,21 @@ object Test extends dotty.runtime.LegacyApp { println(List(1, 2, 3, 4).slice(-1, 1)) println(List(1, 2, 3, 4).slice(1, -1)) println(List(1, 2, 3, 4).slice(-2, 2)) - println + println() println(List(1, 2, 3, 4) take 3) println(List(1, 2, 3) take 3) println(List(1, 2) take 3) println((List(): List[Int]) take 3) println(List[Nothing]() take 3) - println + println() println(List(1, 2, 3, 4) drop 3) println(List(1, 2, 3) drop 3) println(List(1, 2) drop 3) println((List(): List[Int]) drop 3) println(List[Nothing]() drop 3) - println + println() // arrays println(Array(1, 2, 3, 4).slice(1, 2).deep) @@ -31,19 +31,19 @@ object Test extends dotty.runtime.LegacyApp { println(Array(1, 2, 3, 4).slice(-1, 1).deep) println(Array(1, 2, 3, 4).slice(1, -1).deep) println(Array(1, 2, 3, 4).slice(-2, 2).deep) - println + println() println(Array(1, 2, 3, 4) take 3 deep) println(Array(1, 2, 3) take 3 deep) println(Array(1, 2) take 3 deep) println((Array(): Array[Int]) take 3 deep) // println(Array[Nothing]() take 3) // contrib #757 - println + println() println(Array(1, 2, 3, 4) drop 3 deep) println(Array(1, 2, 3) drop 3 deep) println(Array(1, 2) drop 3 deep) println((Array(): Array[Int]) drop 3 deep) // println(Array[Nothing]() drop 3) - println + println() } diff --git a/tests/run/t0325.scala b/tests/run/t0325.scala index ea6180306f0e..35b97a97f3b0 100644 --- a/tests/run/t0325.scala +++ b/tests/run/t0325.scala @@ -33,11 +33,11 @@ object Test { for (c <- badChars) test(("a"+c+"b").split(c),"RichString split('"+ c + "')") - println + println() for (c <- badChars) test(RS("a"+c+"b").split(c),"RS split('"+ c + "')") - println + println() val badCases = List( ']' -> "x]", '&' -> "&&",'\\' -> "\\x", '[' -> "[x", @@ -45,7 +45,7 @@ object Test { ) for ((c,str) <- badCases) test(("a"+c+"b").split(str.toArray),"RichString split(\""+ str + "\")") - println + println() for ((c,str) <- badCases) test(RS("a"+c+"b").split(str.toArray),"RS split(\""+ str + "\")") diff --git a/tests/run/t1909b.scala b/tests/run/t1909b.scala index b4bb9a1e0967..073c371d9ce1 100644 --- a/tests/run/t1909b.scala +++ b/tests/run/t1909b.scala @@ -1,7 +1,7 @@ class Ticket1909 (x: Int) { def this() = this({ def bar() = 5 - bar + bar() }) } object Test extends dotty.runtime.LegacyApp { diff --git a/tests/run/t2552.scala b/tests/run/t2552.scala index 27a6606cab80..2a68b64c0fbb 100644 --- a/tests/run/t2552.scala +++ b/tests/run/t2552.scala @@ -9,9 +9,9 @@ object Test extends dotty.runtime.LegacyApp { println(zeroTo1.hasNext) println(zeroTo1.hasNext) - println(zeroTo1.next) + println(zeroTo1.next()) println(zeroTo1.hasNext) - println(zeroTo1.next) + println(zeroTo1.next()) println(zeroTo1.hasNext) println(zeroTo1.hasNext) } @@ -23,7 +23,7 @@ object Test extends dotty.runtime.LegacyApp { println(evens.hasNext) println(evens.hasNext) - println(evens.next) + println(evens.next()) evens.foreach(println _) } diff --git a/tests/run/t2813.2.scala b/tests/run/t2813.2.scala index d228eed90c21..fa97c729110c 100644 --- a/tests/run/t2813.2.scala +++ b/tests/run/t2813.2.scala @@ -32,8 +32,8 @@ object Test extends dotty.runtime.LegacyApp { assertListEquals((List(10, 11)), l) } - addAllOfNonCollectionWrapperAtZeroOnEmptyLinkedList - addAllOfNonCollectionWrapperAtZeroOnLinkedList - addAllOfCollectionWrapperAtZeroOnEmptyLinkedList - addAllOfCollectionWrapperAtZeroOnLinkedList + addAllOfNonCollectionWrapperAtZeroOnEmptyLinkedList() + addAllOfNonCollectionWrapperAtZeroOnLinkedList() + addAllOfCollectionWrapperAtZeroOnEmptyLinkedList() + addAllOfCollectionWrapperAtZeroOnLinkedList() } diff --git a/tests/run/t3242b.scala b/tests/run/t3242b.scala index 7a296aac1556..22d22ac546bc 100644 --- a/tests/run/t3242b.scala +++ b/tests/run/t3242b.scala @@ -6,7 +6,7 @@ object Test { var vb = new VectorBuilder[Int] for (i <- 0 until n) vb += i - val v = vb.result + val v = vb.result() assert(v == (0 until n), "not same as (0 until " + n + "): " + v) } diff --git a/tests/run/t3269.scala b/tests/run/t3269.scala index 17e42cdb0e94..187098790ba2 100644 --- a/tests/run/t3269.scala +++ b/tests/run/t3269.scala @@ -1,7 +1,7 @@ object Test { def main(args: Array[String]): Unit = { val it = List(1).iterator ++ { println("Hello"); Iterator.empty } - println(it.next) + println(it.next()) it.hasNext it.hasNext it.hasNext diff --git a/tests/run/t3516.scala b/tests/run/t3516.scala index aa302ce85ac3..f3392d1f6ff9 100644 --- a/tests/run/t3516.scala +++ b/tests/run/t3516.scala @@ -7,7 +7,7 @@ object Test { val s1 = mkIterator.toStream val s2 = mkInfinite.toStream // back and forth without slipping into nontermination. - println((Stream from 1).toIterator.drop(10).toStream.drop(10).toIterator.next) + println((Stream from 1).toIterator.drop(10).toStream.drop(10).toIterator.next()) () } } diff --git a/tests/run/t4054.scala b/tests/run/t4054.scala index b57c08361573..f5b5af4c4f7a 100644 --- a/tests/run/t4054.scala +++ b/tests/run/t4054.scala @@ -10,16 +10,16 @@ object Test { def main(args: Array[String]): Unit = { val it = Iterator.from(1).map(n => n * n).scanLeft(0)(_+_) - assert(it.next == 0) - assert(it.next == 1) - assert(it.next == 5) - assert(it.next == 14) - assert(it.next == 30) - assert(it.next == 55) - assert(it.next == 91) - assert(it.next == 140) - assert(it.next == 204) - assert(it.next == 285) - assert(it.next == 385) + assert(it.next() == 0) + assert(it.next() == 1) + assert(it.next() == 5) + assert(it.next() == 14) + assert(it.next() == 30) + assert(it.next() == 55) + assert(it.next() == 91) + assert(it.next() == 140) + assert(it.next() == 204) + assert(it.next() == 285) + assert(it.next() == 385) } } diff --git a/tests/run/t4809.scala b/tests/run/t4809.scala index 9c66458050db..f26d17c5b3df 100644 --- a/tests/run/t4809.scala +++ b/tests/run/t4809.scala @@ -8,7 +8,7 @@ object Test { def main(args: Array[String]): Unit = { val x = tryBreakable { - break + break() 2 } catchBreak { 3 @@ -23,7 +23,7 @@ object Test { assert(y == 2, y) val z = tryBreakable { - break + break() 1.0 } catchBreak { 2 diff --git a/tests/run/t8153.scala b/tests/run/t8153.scala index 0cbfb5b5a6cf..f3063bdc7bfc 100644 --- a/tests/run/t8153.scala +++ b/tests/run/t8153.scala @@ -2,7 +2,7 @@ object Test { def f() = { val lb = scala.collection.mutable.ListBuffer[Int](1, 2) val it = lb.iterator - if (it.hasNext) it.next + if (it.hasNext) it.next() val xs = lb.toList lb += 3 it.mkString diff --git a/tests/run/unittest_iterator.scala b/tests/run/unittest_iterator.scala index 7c47e27e3dd9..a8b9604dce2a 100644 --- a/tests/run/unittest_iterator.scala +++ b/tests/run/unittest_iterator.scala @@ -23,7 +23,7 @@ object Test { // testing by-name padding val padIt = it - assertThat(4, List(10, 1, 2)) { it grouped 3 withPadding padIt.next } + assertThat(4, List(10, 1, 2)) { it grouped 3 withPadding padIt.next() } // sliding assertThat(8, List(8, 9, 10)) { it sliding 3 } @@ -40,9 +40,9 @@ object Test { // make sure it throws past the end val thrown = try { val it = List(1,2,3).sliding(2) - it.next - it.next - it.next + it.next() + it.next() + it.next() false } catch { diff --git a/tests/run/unreachable.scala b/tests/run/unreachable.scala index 6a428c6ef02c..651f619fa06f 100644 --- a/tests/run/unreachable.scala +++ b/tests/run/unreachable.scala @@ -9,14 +9,14 @@ object Test extends dotty.runtime.LegacyApp { def unreachableIf: Int = { return 42 - if (nextInt % 2 == 0) + if (nextInt() % 2 == 0) 0 else 1 } def unreachableIfBranches: Int = { - if (nextInt % 2 == 0) + if (nextInt() % 2 == 0) return 42 else return 42 @@ -25,14 +25,14 @@ object Test extends dotty.runtime.LegacyApp { } def unreachableOneLegIf: Int = { - if (nextInt % 2 == 0) + if (nextInt() % 2 == 0) return 42 return 42 } def unreachableLeftBranch: Int = { - val result = if (nextInt % 2 == 0) + val result = if (nextInt() % 2 == 0) return 42 else 42 @@ -41,7 +41,7 @@ object Test extends dotty.runtime.LegacyApp { } def unreachableRightBranch: Int = { - val result = if (nextInt % 2 == 0) + val result = if (nextInt() % 2 == 0) 42 else return 42 @@ -92,7 +92,7 @@ object Test extends dotty.runtime.LegacyApp { def unreachableSwitch: Int = { return 42 - val x = nextInt % 2 + val x = nextInt() % 2 x match { case 0 => return 0 case 1 => return 1 @@ -102,7 +102,7 @@ object Test extends dotty.runtime.LegacyApp { } def unreachableAfterSwitch: Int = { - val x = nextInt % 2 + val x = nextInt() % 2 x match { case 0 => return 42 case 1 => return 41 + x From ced54aac1bd02f4d84e62867bd6fc617517f4b40 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Thu, 8 Jun 2017 18:10:34 +0200 Subject: [PATCH 07/19] Fix () insertion in xsbt --- sbt-bridge/src/xsbt/DelegatingReporter.scala | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sbt-bridge/src/xsbt/DelegatingReporter.scala b/sbt-bridge/src/xsbt/DelegatingReporter.scala index 8302c1f14048..ffc4792ecef0 100644 --- a/sbt-bridge/src/xsbt/DelegatingReporter.scala +++ b/sbt-bridge/src/xsbt/DelegatingReporter.scala @@ -46,15 +46,15 @@ final class DelegatingReporter(delegate: xsbti.Reporter) extends Reporter noPosition val sb = new StringBuilder() - sb.append(messageAndPos(cont.contained, cont.pos, diagnosticLevel(cont))) - if (ctx.shouldExplain(cont) && cont.contained.explanation.nonEmpty) { - sb.append(explanation(cont.contained)) + sb.append(messageAndPos(cont.contained(), cont.pos, diagnosticLevel(cont))) + if (ctx.shouldExplain(cont) && cont.contained().explanation.nonEmpty) { + sb.append(explanation(cont.contained())) } delegate.log(position, sb.toString(), severity) } - private[this] def maybe[T](opt: Option[T]): Maybe[T] = opt match { + private[this] def maybe[T](opt: Option[T]): Maybe[T] = opt match { case None => Maybe.nothing[T] case Some(s) => Maybe.just[T](s) } From 478a95517c7bbbe2e0bc8fea13b3f4ce9c9f7a3a Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Thu, 8 Jun 2017 18:44:22 +0200 Subject: [PATCH 08/19] Fix inconsistent () handling in JavaEntity --- .../src/dotty/tools/dottydoc/model/JavaConverters.scala | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc-tool/src/dotty/tools/dottydoc/model/JavaConverters.scala b/doc-tool/src/dotty/tools/dottydoc/model/JavaConverters.scala index 39a088c97ed3..9c9713b715a8 100644 --- a/doc-tool/src/dotty/tools/dottydoc/model/JavaConverters.scala +++ b/doc-tool/src/dotty/tools/dottydoc/model/JavaConverters.scala @@ -140,7 +140,7 @@ object JavaConverters { } implicit class JavaEntity(val ent: Entity) extends AnyVal { - def asJava(): JMap[String, _] = parseEntity(ent) + def asJava: JMap[String, _] = parseEntity(ent) } private def parseEntity(ent: Entity): JMap[String, _] = { @@ -149,13 +149,13 @@ object JavaConverters { "annotations" -> ent.annotations.asJava, "name" -> ent.name, "path" -> ent.path.asJava, - "children" -> ent.children.map(_.asJava()).asJava, + "children" -> ent.children.map(_.asJava).asJava, "comment" -> ent.comment.map(_.asJava).asJava, "signature" -> ent.signature ) val members = ent match { case ent: Members => Map( - "members" -> ent.members.map(_.asJava()).asJava, + "members" -> ent.members.map(_.asJava).asJava, "hasVisibleMembers" -> ent.hasVisibleMembers ) case _ => Map.empty From 0291b8fa99a09a6cba71f86d9ddf67a6e9c03b49 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Thu, 8 Jun 2017 18:46:24 +0200 Subject: [PATCH 09/19] Fix () errors in WikiParser --- .../dotty/tools/dottydoc/model/comment/WikiParser.scala | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/doc-tool/src/dotty/tools/dottydoc/model/comment/WikiParser.scala b/doc-tool/src/dotty/tools/dottydoc/model/comment/WikiParser.scala index 176dab569875..70f85a53e29c 100644 --- a/doc-tool/src/dotty/tools/dottydoc/model/comment/WikiParser.scala +++ b/doc-tool/src/dotty/tools/dottydoc/model/comment/WikiParser.scala @@ -44,7 +44,7 @@ private[comment] final class WikiParser( else if (checkSkipInitWhitespace("----")) hrule() else if (checkList) - listBlock + listBlock() else { para() } @@ -76,7 +76,7 @@ private[comment] final class WikiParser( * not a list or a different list. */ def listLine(indent: Int, style: String): Option[Block] = if (countWhitespace > indent && checkList) - Some(listBlock) + Some(listBlock()) else if (countWhitespace != indent || !checkSkipInitWhitespace(style)) None else { @@ -217,7 +217,7 @@ private[comment] final class WikiParser( check(",,") || check("[[") || isInlineEnd || - checkParaEnded || + checkParaEnded() || char == endOfLine } Text(str) @@ -227,7 +227,7 @@ private[comment] final class WikiParser( val inlines: List[Inline] = { val iss = mutable.ListBuffer.empty[Inline] iss += inline0() - while (!isInlineEnd && !checkParaEnded) { + while (!isInlineEnd && !checkParaEnded()) { val skipEndOfLine = if (char == endOfLine) { nextChar() true From 0777fa738056e74b67e501689f536df76e91b53d Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Thu, 8 Jun 2017 18:58:41 +0200 Subject: [PATCH 10/19] Fix algorithm bug in paramIndices --- .../src/dotty/tools/dotc/typer/Typer.scala | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index 01c2da478228..2fa822858148 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -732,13 +732,15 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit /** If parameter `param` appears exactly once as an argument in `args`, * the singleton list consisting of its position in `args`, otherwise `Nil`. */ - def paramIndices(param: untpd.ValDef, args: List[untpd.Tree], start: Int): List[Int] = args match { - case arg :: args1 => - if (refersTo(arg, param)) - if (paramIndices(param, args1, start + 1).isEmpty) start :: Nil - else Nil - else paramIndices(param, args1, start + 1) - case _ => Nil + def paramIndices(param: untpd.ValDef, args: List[untpd.Tree]): List[Int] = { + def loop(args: List[untpd.Tree], start: Int): List[Int] = args match { + case arg :: args1 => + val others = loop(args1, start + 1) + if (refersTo(arg, param)) start :: others else others + case _ => Nil + } + val allIndices = loop(args, 0) + if (allIndices.length == 1) allIndices else Nil } /** If function is of the form @@ -752,7 +754,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit def calleeType: Type = fnBody match { case Apply(expr, args) => paramIndex = { - for (param <- params; idx <- paramIndices(param, args, 0)) + for (param <- params; idx <- paramIndices(param, args)) yield param.name -> idx }.toMap if (paramIndex.size == params.length) From 34bffbbc2e5fe348a1a574a23b02f8879d2a4abb Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Thu, 8 Jun 2017 19:22:59 +0200 Subject: [PATCH 11/19] Fix now superfluous () in JavaConverterTest --- doc-tool/test/JavaConverterTest.scala | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/doc-tool/test/JavaConverterTest.scala b/doc-tool/test/JavaConverterTest.scala index 502488e32c72..5daf9c3d705e 100644 --- a/doc-tool/test/JavaConverterTest.scala +++ b/doc-tool/test/JavaConverterTest.scala @@ -51,7 +51,7 @@ class JavaConverterTest { def returnValue = new TypeReference("String", new NoLink("title", "target"), List()) def paramLists = List(paramList) } - assertSerializedCorrectly(df, df.asJava()) + assertSerializedCorrectly(df, df.asJava) val trt = new Trait { def symbol = NoSymbol def name = "someTrait" @@ -67,7 +67,7 @@ class JavaConverterTest { def companionPath = "path" :: "to" :: "companion" :: Nil def companionPath_=(xs: List[String]) = Unit } - assertSerializedCorrectly(trt, trt.asJava()) + assertSerializedCorrectly(trt, trt.asJava) val cls = new Class { def symbol = NoSymbol def name = "test" @@ -83,7 +83,7 @@ class JavaConverterTest { def companionPath_=(xs: List[String]) = Unit def constructors = List(List(paramList)) } - assertSerializedCorrectly(cls, cls.asJava()) + assertSerializedCorrectly(cls, cls.asJava) val caseClass = new CaseClass { def symbol = NoSymbol def name = "test" @@ -99,7 +99,7 @@ class JavaConverterTest { def companionPath = "path" :: "to" :: "companion" :: Nil def companionPath_=(xs: List[String]) = Unit } - assertSerializedCorrectly(caseClass, caseClass.asJava()) + assertSerializedCorrectly(caseClass, caseClass.asJava) val obj = new EObject { def symbol = NoSymbol def name = "someObject" @@ -114,7 +114,7 @@ class JavaConverterTest { def companionPath = "path" :: "to" :: "companion" :: Nil def companionPath_=(xs: List[String]) = Unit } - assertSerializedCorrectly(obj, obj.asJava()) + assertSerializedCorrectly(obj, obj.asJava) val typeAlias = new TypeAlias { def symbol = NoSymbol def name = "typeAlias" @@ -126,7 +126,7 @@ class JavaConverterTest { def typeParams = "String" :: "String" :: Nil def alias = Some(new TypeReference("String", new NoLink("title", "target"), List())) } - assertSerializedCorrectly(typeAlias, typeAlias.asJava()) + assertSerializedCorrectly(typeAlias, typeAlias.asJava) val vl = new Val { val kind = "val" def symbol = NoSymbol @@ -140,7 +140,7 @@ class JavaConverterTest { def implicitlyAddedFrom = Some( new TypeReference("String", new NoLink("title", "target"), List())) } - assertSerializedCorrectly(vl, vl.asJava()) + assertSerializedCorrectly(vl, vl.asJava) val pkg = new Package { def symbol = NoSymbol def name = "test" @@ -151,7 +151,7 @@ class JavaConverterTest { def members = trt :: typeAlias :: Nil def superTypes = new NoLink("title", "query") :: Nil } - assertSerializedCorrectly(pkg, pkg.asJava()) + assertSerializedCorrectly(pkg, pkg.asJava) } def assertEach[E, C[E] <: Seq[E]](expected: C[E], serialized: Any)(pairwiseAssertion: (E, Any) => Unit): Unit = { From d8e44428b2b75f4f68f25725b9e2b1aa584e3e65 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Thu, 8 Jun 2017 19:58:15 +0200 Subject: [PATCH 12/19] One more () error fixed --- doc-tool/test/DottyDocTest.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc-tool/test/DottyDocTest.scala b/doc-tool/test/DottyDocTest.scala index 12289baf5671..4535b772b73b 100644 --- a/doc-tool/test/DottyDocTest.scala +++ b/doc-tool/test/DottyDocTest.scala @@ -46,7 +46,7 @@ trait DottyDocTest extends MessageRendering { System.err.println("reporter had errors:") ctx.reporter.removeBufferedMessages.foreach { msg => System.err.println { - messageAndPos(msg.contained, msg.pos, diagnosticLevel(msg)) + messageAndPos(msg.contained(), msg.pos, diagnosticLevel(msg)) } } } From 1f37b0c5b3b7132c00e706ae4851c6789db6c197 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Fri, 9 Jun 2017 11:45:24 +0200 Subject: [PATCH 13/19] Fix nullary overrides Fix situations where a ()T method overrides a => T one, and vice versa. --- .../dotty/tools/dotc/core/Denotations.scala | 3 ++- .../tools/dotc/core/SymDenotations.scala | 15 ++++++++++- .../src/dotty/tools/dotc/core/Types.scala | 26 ++++++++++--------- .../dotty/tools/dotc/sbt/ThunkHolder.scala | 2 +- .../dotty/tools/dotc/typer/RefChecks.scala | 5 +++- .../src/dotty/tools/dotc/typer/Typer.scala | 10 +------ compiler/src/dotty/tools/dotc/util/Set.scala | 2 +- .../src/dotty/tools/io/AbstractFile.scala | 2 +- compiler/src/dotty/tools/io/PlainFile.scala | 2 +- .../src/dotty/tools/io/VirtualDirectory.scala | 2 +- compiler/src/dotty/tools/io/ZipArchive.scala | 2 +- .../CollectionStrawMan4.scala | 6 ++--- .../CollectionStrawMan5.scala | 6 ++--- .../CollectionStrawMan6.scala | 8 +++--- tests/pos/rbtree.scala | 2 +- tests/pos/tcpoly_seq.scala | 2 +- tests/pos/tcpoly_seq_typealias.scala | 2 +- tests/run/CollectionTests.scala | 6 ++--- .../run/colltest4/CollectionStrawMan4_1.scala | 6 ++--- .../run/colltest5/CollectionStrawMan5_1.scala | 6 ++--- .../run/colltest6/CollectionStrawMan6_1.scala | 8 +++--- 21 files changed, 67 insertions(+), 56 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/core/Denotations.scala b/compiler/src/dotty/tools/dotc/core/Denotations.scala index 53ea192f33a8..3aec60c657b4 100644 --- a/compiler/src/dotty/tools/dotc/core/Denotations.scala +++ b/compiler/src/dotty/tools/dotc/core/Denotations.scala @@ -408,7 +408,8 @@ object Denotations { /** Sym preference provided types also override */ def prefer(sym1: Symbol, sym2: Symbol, info1: Type, info2: Type) = - preferSym(sym1, sym2) && info1.overrides(info2) + preferSym(sym1, sym2) && + info1.overrides(info2, sym1.matchNullaryLoosely || sym2.matchNullaryLoosely) def handleDoubleDef = if (preferSym(sym1, sym2)) denot1 diff --git a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala index fdb60211a86e..7c0529ca0089 100644 --- a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala +++ b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala @@ -763,6 +763,20 @@ object SymDenotations { def isInlineMethod(implicit ctx: Context): Boolean = is(InlineMethod, butNot = Accessor) + /** ()T and => T types should be treated as equivalent for this symbol. + * Note: For the moment, we treat Scala-2 compiled symbols as loose matching, + * because the Scala library does not always follow the right conventions. + * Examples are: isWhole(), toInt(), toDouble() in BigDecimal, Numeric, RichInt, ScalaNumberProxy. + */ + def matchNullaryLoosely(implicit ctx: Context): Boolean = { + def test(sym: Symbol) = + sym.is(JavaDefined) || + sym.owner == defn.AnyClass || + sym == defn.Object_clone || + sym.owner.is(Scala2x) + test(symbol) || allOverriddenSymbols.exists(test) + } + // ------ access to related symbols --------------------------------- /* Modules and module classes are represented as follows: @@ -938,7 +952,6 @@ object SymDenotations { else if (this.isClass) companionNamed(effectiveName.moduleClassName).sourceModule.moduleClass else NoSymbol - /** Find companion class symbol with given name, or NoSymbol if none exists. * Three alternative strategies: * 1. If owner is a class, look in its members, otherwise diff --git a/compiler/src/dotty/tools/dotc/core/Types.scala b/compiler/src/dotty/tools/dotc/core/Types.scala index cc11bc4f0bd5..b2ae1daa40c0 100644 --- a/compiler/src/dotty/tools/dotc/core/Types.scala +++ b/compiler/src/dotty/tools/dotc/core/Types.scala @@ -769,21 +769,23 @@ object Types { def relaxed_<:<(that: Type)(implicit ctx: Context) = (this <:< that) || (this isValueSubType that) - /** Is this type a legal type for a member that overrides another - * member of type `that`? This is the same as `<:<`, except that - * the types `()T`, `=> T` and `T` are seen as overriding - * each other. + /** Is this type a legal type for member `sym1` that overrides another + * member `sym2` of type `that`? This is the same as `<:<`, except that + * if `matchLoosely` evaluates to true the types `=> T` and `()T` are seen + * as overriding each other. */ - final def overrides(that: Type)(implicit ctx: Context) = { - def result(tp: Type): Type = tp match { - case ExprType(_) | MethodType(Nil) => tp.resultType + final def overrides(that: Type, matchLoosely: => Boolean)(implicit ctx: Context): Boolean = { + def widenNullary(tp: Type) = tp match { + case tp @ MethodType(Nil) => tp.resultType case _ => tp } - (this frozen_<:< that) || { - val rthat = result(that) - val rthis = result(this) - (rthat.ne(that) || rthis.ne(this)) && (rthis frozen_<:< rthat) - } + ((this.widenExpr frozen_<:< that.widenExpr) || + matchLoosely && { + val this1 = widenNullary(this) + val that1 = widenNullary(that) + ((this1 `ne` this) || (that1 `ne` that)) && this1.overrides(this1, matchLoosely = false) + } + ) } /** Is this type close enough to that type so that members diff --git a/compiler/src/dotty/tools/dotc/sbt/ThunkHolder.scala b/compiler/src/dotty/tools/dotc/sbt/ThunkHolder.scala index abdd5cfdd534..350819e3a3ce 100644 --- a/compiler/src/dotty/tools/dotc/sbt/ThunkHolder.scala +++ b/compiler/src/dotty/tools/dotc/sbt/ThunkHolder.scala @@ -114,7 +114,7 @@ private object SafeLazy { eval = null // clear the reference, ensuring the only memory we hold onto is the result t } - def get: T = _t + def get(): T = _t } private[this] final class Strict[T <: AnyRef](val get: T) extends xsbti.api.Lazy[T] with java.io.Serializable diff --git a/compiler/src/dotty/tools/dotc/typer/RefChecks.scala b/compiler/src/dotty/tools/dotc/typer/RefChecks.scala index 5305fbb16592..76718ea894be 100644 --- a/compiler/src/dotty/tools/dotc/typer/RefChecks.scala +++ b/compiler/src/dotty/tools/dotc/typer/RefChecks.scala @@ -257,7 +257,10 @@ object RefChecks { } else member.name.is(DefaultGetterName) || // default getters are not checked for compatibility - memberTp.overrides(otherTp) + memberTp.overrides(otherTp, + member.matchNullaryLoosely || other.matchNullaryLoosely || + ctx.testScala2Mode(overrideErrorMsg("no longer has compatible type"), + (if (member.owner == clazz) member else clazz).pos)) catch { case ex: MissingType => // can happen when called with upwardsSelf as qualifier of memberTp and otherTp, diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index 2fa822858148..51a82b2f0e35 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -2045,16 +2045,8 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit /** Is reference to this symbol `f` automatically expanded to `f()`? */ def isAutoApplied(sym: Symbol): Boolean = { - def test(sym1: Symbol) = - sym1.is(JavaDefined) || - sym1.owner == defn.AnyClass || - sym1 == defn.Object_clone sym.isConstructor || - test(sym) || - sym.allOverriddenSymbols.exists(test) || - sym.owner.is(Scala2x) || // need to exclude Scala-2 compiled symbols for now, since the - // Scala library does not always follow the right conventions. - // Examples are: isWhole(), toInt(), toDouble() in BigDecimal, Numeric, RichInt, ScalaNumberProxy. + sym.matchNullaryLoosely || ctx.testScala2Mode(em"${sym.showLocated} requires () argument", tree.pos, patch(tree.pos.endPos, "()")) } diff --git a/compiler/src/dotty/tools/dotc/util/Set.scala b/compiler/src/dotty/tools/dotc/util/Set.scala index 3e906c6a87fb..bcaf272167ad 100644 --- a/compiler/src/dotty/tools/dotc/util/Set.scala +++ b/compiler/src/dotty/tools/dotc/util/Set.scala @@ -23,5 +23,5 @@ abstract class Set[T >: Null] { def toList = iterator.toList - def clear: Unit + def clear(): Unit } diff --git a/compiler/src/dotty/tools/io/AbstractFile.scala b/compiler/src/dotty/tools/io/AbstractFile.scala index 676113dfdb5b..c151739cdc31 100644 --- a/compiler/src/dotty/tools/io/AbstractFile.scala +++ b/compiler/src/dotty/tools/io/AbstractFile.scala @@ -186,7 +186,7 @@ abstract class AbstractFile extends Iterable[AbstractFile] { } /** Returns all abstract subfiles of this abstract directory. */ - def iterator: Iterator[AbstractFile] + def iterator(): Iterator[AbstractFile] /** Returns the abstract file in this abstract directory with the specified * name. If there is no such file, returns `null`. The argument diff --git a/compiler/src/dotty/tools/io/PlainFile.scala b/compiler/src/dotty/tools/io/PlainFile.scala index 53474e7781d6..76de56c11f01 100644 --- a/compiler/src/dotty/tools/io/PlainFile.scala +++ b/compiler/src/dotty/tools/io/PlainFile.scala @@ -9,7 +9,7 @@ package io /** ''Note: This library is considered experimental and should not be used unless you know what you are doing.'' */ class PlainDirectory(givenPath: Directory) extends PlainFile(givenPath) { override def isDirectory = true - override def iterator = givenPath.list filter (_.exists) map (x => new PlainFile(x)) + override def iterator() = givenPath.list filter (_.exists) map (x => new PlainFile(x)) override def delete(): Unit = givenPath.deleteRecursively() } diff --git a/compiler/src/dotty/tools/io/VirtualDirectory.scala b/compiler/src/dotty/tools/io/VirtualDirectory.scala index a87bb799f8d7..d3e4ebb4dee3 100644 --- a/compiler/src/dotty/tools/io/VirtualDirectory.scala +++ b/compiler/src/dotty/tools/io/VirtualDirectory.scala @@ -47,7 +47,7 @@ extends AbstractFile { // the toList is so that the directory may continue to be // modified while its elements are iterated - def iterator = files.values.toList.iterator + def iterator() = files.values.toList.iterator override def lookupName(name: String, directory: Boolean): AbstractFile = (files get name filter (_.isDirectory == directory)).orNull diff --git a/compiler/src/dotty/tools/io/ZipArchive.scala b/compiler/src/dotty/tools/io/ZipArchive.scala index 9a339a73b0e4..fe18ecf13cfa 100644 --- a/compiler/src/dotty/tools/io/ZipArchive.scala +++ b/compiler/src/dotty/tools/io/ZipArchive.scala @@ -197,7 +197,7 @@ final class FileZipArchive(file: JFile) extends ZipArchive(file) { } final class ManifestResources(val url: URL) extends ZipArchive(null) { - def iterator = { + def iterator() = { val root = new DirEntry("/") val dirs = mutable.HashMap[String, DirEntry]("/" -> root) val manifest = new Manifest(input) diff --git a/tests/pos-special/strawman-collections/CollectionStrawMan4.scala b/tests/pos-special/strawman-collections/CollectionStrawMan4.scala index d093d81e6c14..8a1d3dc97f15 100644 --- a/tests/pos-special/strawman-collections/CollectionStrawMan4.scala +++ b/tests/pos-special/strawman-collections/CollectionStrawMan4.scala @@ -135,7 +135,7 @@ object CollectionStrawMan4 { def iterator = new Iterator[A] { private[this] var current = self def hasNext = !current.isEmpty - def next = { val r = current.head; current = current.tail; r } + def next() = { val r = current.head; current = current.tail; r } } def fromIterable[B](c: Iterable[B]): List[B] = List.fromIterable(c) def apply(i: Int): A = { @@ -349,7 +349,7 @@ object CollectionStrawMan4 { def iterator: Iterator[A] = new Iterator[A] { private var current = start def hasNext = current < end - def next: A = { + def next(): A = { val r = apply(current) current += 1 r @@ -529,7 +529,7 @@ object CollectionStrawMan4 { object Iterator { val empty: Iterator[Nothing] = new Iterator[Nothing] { def hasNext = false - def next = throw new NoSuchElementException("next on empty iterator") + def next() = throw new NoSuchElementException("next on empty iterator") } def apply[A](xs: A*): Iterator[A] = new RandomAccessView[A] { val start = 0 diff --git a/tests/pos-special/strawman-collections/CollectionStrawMan5.scala b/tests/pos-special/strawman-collections/CollectionStrawMan5.scala index 4715ca24d8cd..e97051d2bccf 100644 --- a/tests/pos-special/strawman-collections/CollectionStrawMan5.scala +++ b/tests/pos-special/strawman-collections/CollectionStrawMan5.scala @@ -157,7 +157,7 @@ object CollectionStrawMan5 { def iterator = new Iterator[A] { private[this] var current = self def hasNext = !current.isEmpty - def next = { val r = current.head; current = current.tail; r } + def next() = { val r = current.head; current = current.tail; r } } def fromIterable[B](c: Iterable[B]): List[B] = List.fromIterable(c) def apply(i: Int): A = { @@ -360,7 +360,7 @@ object CollectionStrawMan5 { def iterator: Iterator[A] = new Iterator[A] { private var current = start def hasNext = current < end - def next: A = { + def next(): A = { val r = apply(current) current += 1 r @@ -511,7 +511,7 @@ object CollectionStrawMan5 { object Iterator { val empty: Iterator[Nothing] = new Iterator[Nothing] { def hasNext = false - def next = throw new NoSuchElementException("next on empty iterator") + def next() = throw new NoSuchElementException("next on empty iterator") } def apply[A](xs: A*): Iterator[A] = new RandomAccessView[A] { val start = 0 diff --git a/tests/pos-special/strawman-collections/CollectionStrawMan6.scala b/tests/pos-special/strawman-collections/CollectionStrawMan6.scala index 0b72d256f86a..c812a85f442a 100644 --- a/tests/pos-special/strawman-collections/CollectionStrawMan6.scala +++ b/tests/pos-special/strawman-collections/CollectionStrawMan6.scala @@ -142,7 +142,7 @@ object CollectionStrawMan6 extends LowPriority { def iterator = new Iterator[A] { private[this] var current: Seq[A] = self def hasNext = !current.isEmpty - def next = { val r = current.head; current = current.tail; r } + def next() = { val r = current.head; current = current.tail; r } } /** `length is defined in terms of `iterator` */ @@ -891,7 +891,7 @@ object CollectionStrawMan6 extends LowPriority { def iterator: Iterator[A] = new Iterator[A] { private var current = 0 def hasNext = current < self.length - def next: A = { + def next(): A = { val r = apply(current) current += 1 r @@ -1010,7 +1010,7 @@ object CollectionStrawMan6 extends LowPriority { def take(n: Int): Iterator[A] = new Iterator[A] { private var i = 0 def hasNext = self.hasNext && i < n - def next = + def next() = if (hasNext) { i += 1 self.next() @@ -1035,7 +1035,7 @@ object CollectionStrawMan6 extends LowPriority { object Iterator { val empty: Iterator[Nothing] = new Iterator[Nothing] { def hasNext = false - def next = throw new NoSuchElementException("next on empty iterator") + def next() = throw new NoSuchElementException("next on empty iterator") } def apply[A](xs: A*): Iterator[A] = new IndexedView[A] { val length = xs.length diff --git a/tests/pos/rbtree.scala b/tests/pos/rbtree.scala index 04c084596222..1ca9c57ddcc1 100644 --- a/tests/pos/rbtree.scala +++ b/tests/pos/rbtree.scala @@ -470,7 +470,7 @@ object RedBlackTree { override def hasNext: Boolean = lookahead ne null - override def next: R = lookahead match { + override def next(): R = lookahead match { case null => throw new NoSuchElementException("next on empty iterator") case tree => diff --git a/tests/pos/tcpoly_seq.scala b/tests/pos/tcpoly_seq.scala index 6b4c70dba81f..312ba7405818 100644 --- a/tests/pos/tcpoly_seq.scala +++ b/tests/pos/tcpoly_seq.scala @@ -111,7 +111,7 @@ trait HOSeq { def iterator: Iterator[t] = new Iterator[t] { var these = List.this def hasNext: Boolean = !these.isEmpty - def next: t = + def next(): t = if (!hasNext) throw new NoSuchElementException("next on empty Iterator") else { diff --git a/tests/pos/tcpoly_seq_typealias.scala b/tests/pos/tcpoly_seq_typealias.scala index 651810512e58..25ec38065668 100644 --- a/tests/pos/tcpoly_seq_typealias.scala +++ b/tests/pos/tcpoly_seq_typealias.scala @@ -115,7 +115,7 @@ trait HOSeq { def iterator: Iterator[t] = new Iterator[t] { var these = List.this def hasNext: Boolean = !these.isEmpty - def next: t = + def next(): t = if (!hasNext) throw new NoSuchElementException("next on empty Iterator") else { diff --git a/tests/run/CollectionTests.scala b/tests/run/CollectionTests.scala index 72a555f5e0ab..3c08bee0e874 100644 --- a/tests/run/CollectionTests.scala +++ b/tests/run/CollectionTests.scala @@ -156,7 +156,7 @@ object CollectionStrawMan5 { def iterator = new Iterator[A] { private[this] var current = self def hasNext = !current.isEmpty - def next = { val r = current.head; current = current.tail; r } + def next() = { val r = current.head; current = current.tail; r } } def fromIterable[B](c: Iterable[B]): List[B] = List.fromIterable(c) def apply(i: Int): A = { @@ -359,7 +359,7 @@ object CollectionStrawMan5 { def iterator: Iterator[A] = new Iterator[A] { private var current = start def hasNext = current < end - def next: A = { + def next(): A = { val r = apply(current) current += 1 r @@ -510,7 +510,7 @@ object CollectionStrawMan5 { object Iterator { val empty: Iterator[Nothing] = new Iterator[Nothing] { def hasNext = false - def next = throw new NoSuchElementException("next on empty iterator") + def next() = throw new NoSuchElementException("next on empty iterator") } def apply[A](xs: A*): Iterator[A] = new RandomAccessView[A] { val start = 0 diff --git a/tests/run/colltest4/CollectionStrawMan4_1.scala b/tests/run/colltest4/CollectionStrawMan4_1.scala index e36c7886cc90..bdf5641cb4de 100644 --- a/tests/run/colltest4/CollectionStrawMan4_1.scala +++ b/tests/run/colltest4/CollectionStrawMan4_1.scala @@ -134,7 +134,7 @@ object CollectionStrawMan4 { def iterator = new Iterator[A] { private[this] var current = self def hasNext = !current.isEmpty - def next = { val r = current.head; current = current.tail; r } + def next() = { val r = current.head; current = current.tail; r } } def fromIterable[B](c: Iterable[B]): List[B] = List.fromIterable(c) def apply(i: Int): A = { @@ -348,7 +348,7 @@ object CollectionStrawMan4 { def iterator: Iterator[A] = new Iterator[A] { private var current = start def hasNext = current < end - def next: A = { + def next(): A = { val r = apply(current) current += 1 r @@ -528,7 +528,7 @@ object CollectionStrawMan4 { object Iterator { val empty: Iterator[Nothing] = new Iterator[Nothing] { def hasNext = false - def next = throw new NoSuchElementException("next on empty iterator") + def next() = throw new NoSuchElementException("next on empty iterator") } def apply[A](xs: A*): Iterator[A] = new RandomAccessView[A] { val start = 0 diff --git a/tests/run/colltest5/CollectionStrawMan5_1.scala b/tests/run/colltest5/CollectionStrawMan5_1.scala index 15a1f5e3536a..183f24bb166b 100644 --- a/tests/run/colltest5/CollectionStrawMan5_1.scala +++ b/tests/run/colltest5/CollectionStrawMan5_1.scala @@ -149,7 +149,7 @@ object CollectionStrawMan5 { def iterator = new Iterator[A] { private[this] var current = self def hasNext = !current.isEmpty - def next = { val r = current.head; current = current.tail; r } + def next() = { val r = current.head; current = current.tail; r } } def fromIterable[B](c: Iterable[B]): List[B] = List.fromIterable(c) def apply(i: Int): A = { @@ -352,7 +352,7 @@ object CollectionStrawMan5 { def iterator: Iterator[A] = new Iterator[A] { private var current = start def hasNext = current < end - def next: A = { + def next(): A = { val r = apply(current) current += 1 r @@ -503,7 +503,7 @@ object CollectionStrawMan5 { object Iterator { val empty: Iterator[Nothing] = new Iterator[Nothing] { def hasNext = false - def next = throw new NoSuchElementException("next on empty iterator") + def next() = throw new NoSuchElementException("next on empty iterator") } def apply[A](xs: A*): Iterator[A] = new RandomAccessView[A] { val start = 0 diff --git a/tests/run/colltest6/CollectionStrawMan6_1.scala b/tests/run/colltest6/CollectionStrawMan6_1.scala index 294523af6e4f..8f5c38104dae 100644 --- a/tests/run/colltest6/CollectionStrawMan6_1.scala +++ b/tests/run/colltest6/CollectionStrawMan6_1.scala @@ -143,7 +143,7 @@ object CollectionStrawMan6 extends LowPriority { def iterator = new Iterator[A] { private[this] var current: Seq[A] = self def hasNext = !current.isEmpty - def next = { val r = current.head; current = current.tail; r } + def next() = { val r = current.head; current = current.tail; r } } /** `length is defined in terms of `iterator` */ @@ -892,7 +892,7 @@ object CollectionStrawMan6 extends LowPriority { def iterator: Iterator[A] = new Iterator[A] { private var current = 0 def hasNext = current < self.length - def next: A = { + def next(): A = { val r = apply(current) current += 1 r @@ -1011,7 +1011,7 @@ object CollectionStrawMan6 extends LowPriority { def take(n: Int): Iterator[A] = new Iterator[A] { private var i = 0 def hasNext = self.hasNext && i < n - def next = + def next() = if (hasNext) { i += 1 self.next() @@ -1036,7 +1036,7 @@ object CollectionStrawMan6 extends LowPriority { object Iterator { val empty: Iterator[Nothing] = new Iterator[Nothing] { def hasNext = false - def next = throw new NoSuchElementException("next on empty iterator") + def next() = throw new NoSuchElementException("next on empty iterator") } def apply[A](xs: A*): Iterator[A] = new IndexedView[A] { val length = xs.length From ded535dd2f680f831c41585b4a413047606d0fe7 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Fri, 9 Jun 2017 18:25:04 +0200 Subject: [PATCH 14/19] Reject trailing `_` syntax under -strict mode. The reason to do this only under -strict mode for now is so that we can still compile the same code under both Scala 2 and Dotty. If we rejected trailing `_` outright, Scala 2 code would need to get either explicitly eta-expanded or get an expected type to still work. But in Dotty, we can simply drop `_` for functions with arity >= 1. So to keep code dual compilable, we'd need to add boilerplate which under Dotty would be no longer needed. --- .../src/dotty/tools/dotc/typer/Typer.scala | 24 +++++++++++++++---- compiler/test/dotc/tests.scala | 1 + tests/neg/customArgs/trailingUnderscore.scala | 11 +++++++++ 3 files changed, 32 insertions(+), 4 deletions(-) create mode 100644 tests/neg/customArgs/trailingUnderscore.scala diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index 51a82b2f0e35..644f199d92ef 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -1538,15 +1538,31 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit val pt1 = if (defn.isFunctionType(pt)) pt else AnyFunctionProto var res = typed(qual, pt1) if (pt1.eq(AnyFunctionProto) && !defn.isFunctionClass(res.tpe.classSymbol)) { - def msg = i"not a function: ${res.tpe}; cannot be followed by `_'" + ctx.errorOrMigrationWarning(i"not a function: ${res.tpe}; cannot be followed by `_'", tree.pos) if (ctx.scala2Mode) { // Under -rewrite, patch `x _` to `(() => x)` - ctx.migrationWarning(msg, tree.pos) patch(Position(tree.pos.start), "(() => ") patch(Position(qual.pos.end, tree.pos.end), ")") res = typed(untpd.Function(Nil, untpd.TypedSplice(res))) } - else ctx.error(msg, tree.pos) + } + else if (ctx.settings.strict.value) { + lazy val (prefix, suffix) = res match { + case Block(mdef @ DefDef(_, _, vparams :: Nil, _, _) :: Nil, _: Closure) => + val arity = vparams.length + if (arity > 0) ("", "") else ("(() => ", "())") + case _ => + ("(() => ", ")") + } + def remedy = + if ((prefix ++ suffix).isEmpty) "simply leave out the trailing ` _`" + else s"use `$prefix$suffix` instead" + ctx.errorOrMigrationWarning(i"""The syntax ` _` is no longer supported; + |you can $remedy""", tree.pos) + if (ctx.scala2Mode) { + patch(Position(tree.pos.start), prefix) + patch(Position(qual.pos.end, tree.pos.end), suffix) + } } res } @@ -2053,7 +2069,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit // Reasons NOT to eta expand: // - we reference a constructor - // - we are in a patterm + // - we are in a pattern // - the current tree is a synthetic apply which is not expandable (eta-expasion would simply undo that) if (arity >= 0 && !tree.symbol.isConstructor && diff --git a/compiler/test/dotc/tests.scala b/compiler/test/dotc/tests.scala index f8ccb89793cf..01f7dcb0baaa 100644 --- a/compiler/test/dotc/tests.scala +++ b/compiler/test/dotc/tests.scala @@ -196,6 +196,7 @@ class tests extends CompilerTest { @Test def neg_valueclasses_doubledefs = compileFile(negCustomArgs, "valueclasses-doubledefs")(allowDoubleBindings) @Test def neg_valueclasses_doubledefs2 = compileFile(negCustomArgs, "valueclasses-doubledefs2")(allowDoubleBindings) @Test def neg_valueclasses_pavlov = compileFile(negCustomArgs, "valueclasses-pavlov")(allowDoubleBindings) + @Test def neg_trailingUnderscore = compileFile(negCustomArgs, "trailingUnderscore")(List("-strict")) val negTailcallDir = negDir + "tailcall/" @Test def neg_tailcall_t1672b = compileFile(negTailcallDir, "t1672b") diff --git a/tests/neg/customArgs/trailingUnderscore.scala b/tests/neg/customArgs/trailingUnderscore.scala new file mode 100644 index 000000000000..b1154edc644e --- /dev/null +++ b/tests/neg/customArgs/trailingUnderscore.scala @@ -0,0 +1,11 @@ +// to be compiled with -strict +object trailingUnderscore { + + def f(x: Int) = x + def g() = f(2) + def h = g() + + val x1 = f _ // error + val x2 = g _ // error + val x3 = h _ // error +} \ No newline at end of file From ea453325b1d948f5a173b3e310abd32bfa0c4e55 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Fri, 9 Jun 2017 18:25:35 +0200 Subject: [PATCH 15/19] Test cases for ()T/=>T overrides --- tests/neg/unitOverride.scala | 16 ++++++++++++++++ tests/pos-scala2/unitOverride.scala | 16 ++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 tests/neg/unitOverride.scala create mode 100644 tests/pos-scala2/unitOverride.scala diff --git a/tests/neg/unitOverride.scala b/tests/neg/unitOverride.scala new file mode 100644 index 000000000000..15bdd5880ede --- /dev/null +++ b/tests/neg/unitOverride.scala @@ -0,0 +1,16 @@ +trait C { + + def f: Unit + def g(): Unit + +} + +object Test extends C { + + val x: Any = ??? + x.toString // OK + + def f() = () // error: bad override + def g = () // error: bad override + +} diff --git a/tests/pos-scala2/unitOverride.scala b/tests/pos-scala2/unitOverride.scala new file mode 100644 index 000000000000..15bdd5880ede --- /dev/null +++ b/tests/pos-scala2/unitOverride.scala @@ -0,0 +1,16 @@ +trait C { + + def f: Unit + def g(): Unit + +} + +object Test extends C { + + val x: Any = ??? + x.toString // OK + + def f() = () // error: bad override + def g = () // error: bad override + +} From 416d290bf88746c16b0f37d51e94887658621c97 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Sat, 10 Jun 2017 11:16:44 +0200 Subject: [PATCH 16/19] Fix test --- compiler/test/dotc/tests.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/test/dotc/tests.scala b/compiler/test/dotc/tests.scala index 01f7dcb0baaa..ef0777f46911 100644 --- a/compiler/test/dotc/tests.scala +++ b/compiler/test/dotc/tests.scala @@ -196,7 +196,7 @@ class tests extends CompilerTest { @Test def neg_valueclasses_doubledefs = compileFile(negCustomArgs, "valueclasses-doubledefs")(allowDoubleBindings) @Test def neg_valueclasses_doubledefs2 = compileFile(negCustomArgs, "valueclasses-doubledefs2")(allowDoubleBindings) @Test def neg_valueclasses_pavlov = compileFile(negCustomArgs, "valueclasses-pavlov")(allowDoubleBindings) - @Test def neg_trailingUnderscore = compileFile(negCustomArgs, "trailingUnderscore")(List("-strict")) + @Test def neg_trailingUnderscore = compileFile(negCustomArgs, "trailingUnderscore", args = "-strict" :: Nil) val negTailcallDir = negDir + "tailcall/" @Test def neg_tailcall_t1672b = compileFile(negTailcallDir, "t1672b") From 85efd24a6795d1fe782818068d1374a03143116f Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Fri, 23 Jun 2017 15:24:19 +0200 Subject: [PATCH 17/19] Add reference docs Add sections to reference that explain the new rules for eta expansion and auto-application. --- .../dotty/tools/dotc/typer/EtaExpansion.scala | 2 +- docs/docs/reference/changed/eta-expansion.md | 44 ++++++++++ docs/docs/reference/dropped/auto-apply.md | 87 +++++++++++++++++++ docs/sidebar.yml | 4 + tests/neg/overrides.scala | 4 + 5 files changed, 140 insertions(+), 1 deletion(-) create mode 100644 docs/docs/reference/changed/eta-expansion.md create mode 100644 docs/docs/reference/dropped/auto-apply.md diff --git a/compiler/src/dotty/tools/dotc/typer/EtaExpansion.scala b/compiler/src/dotty/tools/dotc/typer/EtaExpansion.scala index 77f1006ffc47..e645535a0d42 100644 --- a/compiler/src/dotty/tools/dotc/typer/EtaExpansion.scala +++ b/compiler/src/dotty/tools/dotc/typer/EtaExpansion.scala @@ -79,7 +79,7 @@ object EtaExpansion { * val xN = argN * x0.f(x1, ..., xN) * - * But leave idempotent expressions alone. + * But leave pure expressions alone. * */ def liftApp(defs: mutable.ListBuffer[Tree], tree: Tree)(implicit ctx: Context): Tree = tree match { diff --git a/docs/docs/reference/changed/eta-expansion.md b/docs/docs/reference/changed/eta-expansion.md new file mode 100644 index 000000000000..0c076b3d1193 --- /dev/null +++ b/docs/docs/reference/changed/eta-expansion.md @@ -0,0 +1,44 @@ +--- +layout: doc-page +title: "Automatic Eta Expansion" +--- + +Previously, a method reference `m` was converted to a function value +only if the expected type was a function type. If that was not the +case, one had to write `m _` to force the conversion (which is called +eta-expansion). + +For methods with one or more parameters, this restriction has now been +dropped. Example: + + def m(x: Boolean, y: String)(z: Int): List[Int] + val f1 = m + val f2 = m(true, "abc") + +This creates two function values: + + f1: (Boolean, String) => Int => List[Int] + f2: Int => List[Int] + +The syntax `m _` is no longer needed and will be deprecated in the +future. + +Automatic eta expansion does not apply to "nullary" methods that take an empty parameter list. Given + + def next(): T + +, a simple reference to `next` does not auto-convert to a +function. One has to write explicitely `() => next()` to achieve that +(it's better to write it this way rather than `next _` because the latter +will be deprecated). + +The reason for excluding nullary methods from automatic eta expansion +is that Scala implicitly inserts the `()` argument, which would +conflict with eta expansion. Automatic `()` insertion is +[limited](auto-apply.md) in Dotty, but the fundamental ambiguity +remains. + +### Reference + +For more info, see [PR #2701](https://github.com/lampepfl/dotty/pull/2701). + diff --git a/docs/docs/reference/dropped/auto-apply.md b/docs/docs/reference/dropped/auto-apply.md new file mode 100644 index 000000000000..d6eb4083b928 --- /dev/null +++ b/docs/docs/reference/dropped/auto-apply.md @@ -0,0 +1,87 @@ +--- +layout: doc-page +title: "Auto-Application" +--- + +Previously an empty argument list `()` was implicitly inserted when +calling a nullary method without arguments. E.g. + + def next(): T = ... + next // is expanded to next() + +In Dotty, this idiom is an error. + + next + ^ + missing arguments for method next + +In Dotty, the application syntax has to follow exactly the parameter +syntax. Excluded from this rule are methods that are defined in Java +or that override methods defined in Java. The reason for being more +lenient with such methods is that otherwise everyone would have to +write + + xs.toString().length() + +instead of + + xs.toString.length + +The latter is idiomatic Scala because it conforms to the _uniform +access principle_. This principle states that one should be able to +change an object member from a field to a non-side-effecting method +and back without affecting clients that access the +member. Consequently, Scala encourages to define such "property" +methods without a `()` parameter list whereas side-effecting methods +should be defined with it. Methods defined in Java cannot make this +distinction; for them a `()` is always mandatory. So Scala fixes the +problem on the client side, by allowing the parameterless references. +But where Scala allows that freedom for all method references, Dotty +restricts it to references of external methods that are not defined +themselves in Dotty. + +For reasons of backwards compatibility, Dotty for the moment also +auto-inserts `()` for nullary methods that are defined in Scala 2, or +that override a method defined in Scala 2. It turns out that, because +the correspondence between definition and call was not enforced in +Scala so far, there are quite a few method definitions in Scala 2 +libraries that use `()` in an inconsistent way. For instance, we +find in `scala.math.Numeric` + + def toInt(): Int + +whereas `toInt` is written without parameters everywhere +else. Enforcing strict parameter correspondence for references to +such methods would project the inconsistencies to client code, which +is undesirable. So Dotty opts for more leniency when type-checking +references to such methods until most core libraries in Scala 2 have +been cleaned up. + +Stricter conformance rules also apply to overriding of nullary +methods. It is no longer allowed to override a parameterless method +by a nullary method or _vice versa_. Instead, both methods must agree +exactly in their parameter lists. + + class A { + def next(): Int + } + class B extends A { + /*!*/ def next: Int // overriding error: incompatible type + } + +Methods overriding Java or Scala-2 methods are again exempted from this +requirement. + +### Migrating code + +Existing Scala code with inconsistent parameters can still be compiled +in Dotty under `-language:Scala2`. When paired with the `-rewrite` +option, the code will be automatcally rewritten to conforrm to Dotty's +stricter checking. + +### Reference + +For more info, see [Issue #2570](https://github.com/lampepfl/dotty/issue/2570) and [PR #2716](https://github.com/lampepfl/dotty/pull/2716). + + + diff --git a/docs/sidebar.yml b/docs/sidebar.yml index 8a769aafe6c8..4be99acc1fbb 100644 --- a/docs/sidebar.yml +++ b/docs/sidebar.yml @@ -69,6 +69,8 @@ sidebar: url: docs/reference/changed/vararg-patterns.html - title: Pattern matching url: docs/reference/changed/pattern-matching.html + - title: Eta Expansion + url: docs/reference/changed/eta-expansion.html - title: Dropped Features subsection: - title: DelayedInit @@ -89,6 +91,8 @@ sidebar: url: docs/reference/dropped/limit22.html - title: XML literals url: docs/reference/dropped/xml.html + - title: Auto-Application + url: docs/reference/dropped/auto-apply.html - title: Contributing subsection: - title: Getting Started diff --git a/tests/neg/overrides.scala b/tests/neg/overrides.scala index 89e20e94302f..2d738285e4d1 100644 --- a/tests/neg/overrides.scala +++ b/tests/neg/overrides.scala @@ -40,6 +40,8 @@ class A[T] { def f(x: T)(y: T = x) = y + def next: T + } class B extends A[Int] { @@ -48,6 +50,8 @@ class B extends A[Int] { f(2)() + def next(): Int // error: incompatible type + } class X { From ed696856b3df7af404b881d0a5fb407148c168e0 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Fri, 23 Jun 2017 18:35:05 +0200 Subject: [PATCH 18/19] Fix test --- tests/neg/overrides.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/neg/overrides.scala b/tests/neg/overrides.scala index 2d738285e4d1..590a7db61f6a 100644 --- a/tests/neg/overrides.scala +++ b/tests/neg/overrides.scala @@ -40,7 +40,7 @@ class A[T] { def f(x: T)(y: T = x) = y - def next: T + def next: T = ??? } @@ -50,7 +50,7 @@ class B extends A[Int] { f(2)() - def next(): Int // error: incompatible type + override def next(): Int = ??? // error: incompatible type } From b7afd437f39955c288a9f72a299cbb43eab238e4 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Fri, 23 Jun 2017 19:35:35 +0200 Subject: [PATCH 19/19] Fix typo --- docs/docs/reference/dropped/auto-apply.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/docs/reference/dropped/auto-apply.md b/docs/docs/reference/dropped/auto-apply.md index d6eb4083b928..34a9a3e6f6c6 100644 --- a/docs/docs/reference/dropped/auto-apply.md +++ b/docs/docs/reference/dropped/auto-apply.md @@ -76,7 +76,7 @@ requirement. Existing Scala code with inconsistent parameters can still be compiled in Dotty under `-language:Scala2`. When paired with the `-rewrite` -option, the code will be automatcally rewritten to conforrm to Dotty's +option, the code will be automatcally rewritten to conform to Dotty's stricter checking. ### Reference