diff --git a/community-build/community-projects/scodec b/community-build/community-projects/scodec index 9b0423b90de9..21e68cf7a2dd 160000 --- a/community-build/community-projects/scodec +++ b/community-build/community-projects/scodec @@ -1 +1 @@ -Subproject commit 9b0423b90de95fc968fafe4543e6b16ef9f81d08 +Subproject commit 21e68cf7a2ddcd0aece5ff005cad3c53db406068 diff --git a/community-build/community-projects/specs2 b/community-build/community-projects/specs2 index 005c5847ecf9..06c992d17048 160000 --- a/community-build/community-projects/specs2 +++ b/community-build/community-projects/specs2 @@ -1 +1 @@ -Subproject commit 005c5847ecf9439691505f0628d318b0fed9d341 +Subproject commit 06c992d1704846840a0ea3cab4780ea7305e2980 diff --git a/compiler/src/dotty/tools/dotc/config/MigrationVersion.scala b/compiler/src/dotty/tools/dotc/config/MigrationVersion.scala index f77aa0b06308..04b613680f9e 100644 --- a/compiler/src/dotty/tools/dotc/config/MigrationVersion.scala +++ b/compiler/src/dotty/tools/dotc/config/MigrationVersion.scala @@ -31,7 +31,7 @@ enum MigrationVersion(val warnFrom: SourceVersion, val errorFrom: SourceVersion) case ImportRename extends MigrationVersion(future, future) case ParameterEnclosedByParenthesis extends MigrationVersion(future, future) case XmlLiteral extends MigrationVersion(future, future) - case GivenSyntax extends MigrationVersion(future, never) + case GivenSyntax extends MigrationVersion(future, future) case ImplicitParamsWithoutUsing extends MigrationVersion(`3.7`, future) require(warnFrom.ordinal <= errorFrom.ordinal) diff --git a/compiler/src/dotty/tools/dotc/config/SourceVersion.scala b/compiler/src/dotty/tools/dotc/config/SourceVersion.scala index d662d3c0d412..aa2e467289b8 100644 --- a/compiler/src/dotty/tools/dotc/config/SourceVersion.scala +++ b/compiler/src/dotty/tools/dotc/config/SourceVersion.scala @@ -8,7 +8,7 @@ import Feature.isPreviewEnabled import util.Property enum SourceVersion: - case `3.0-migration`, `3.0` + case `3.0-migration`, `3.0` case `3.1-migration`, `3.1` case `3.2-migration`, `3.2` case `3.3-migration`, `3.3` @@ -44,8 +44,10 @@ enum SourceVersion: def enablesNamedTuples = isAtLeast(`3.7`) def enablesBetterFors(using Context) = isAtLeast(`3.7`) && isPreviewEnabled + def requiresNewSyntax = isAtLeast(future) + object SourceVersion extends Property.Key[SourceVersion]: - + /* The default source version used by the built compiler */ val defaultSourceVersion = `3.7` diff --git a/compiler/src/dotty/tools/dotc/core/CheckRealizable.scala b/compiler/src/dotty/tools/dotc/core/CheckRealizable.scala index 81b03d765676..7232f444c6e7 100644 --- a/compiler/src/dotty/tools/dotc/core/CheckRealizable.scala +++ b/compiler/src/dotty/tools/dotc/core/CheckRealizable.scala @@ -196,7 +196,7 @@ class CheckRealizable(using Context) { } } if sourceVersion.isAtLeast(future) then - // check fields only from version 3.x. + // check fields only from version 3.future. // Reason: An embedded field could well be nullable, which means it // should not be part of a path and need not be checked; but we cannot recognize // this situation until we have a typesystem that tracks nullability. diff --git a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala index f141da79da79..353a60123ae7 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala @@ -393,10 +393,9 @@ object Parsers { syntaxError(em"""This construct is not allowed under $option.${rewriteNotice(`3.0-migration`, option)}""", span) def rewriteToNewSyntax(span: Span = Span(in.offset)): Boolean = { - if (in.newSyntax) { - if (in.rewrite) return true - syntaxVersionError("-new-syntax", span) - } + if in.newSyntax then + if in.rewrite then return true + syntaxVersionError("-new-syntax or -language:future", span) false } @@ -2556,7 +2555,7 @@ object Parsers { } } - /** `if' `(' Expr `)' {nl} Expr [[semi] else Expr] + /** `if' `(' Expr `)' {nl} Expr [[semi] else Expr] -- Scala 2 compat * `if' Expr `then' Expr [[semi] else Expr] */ def ifExpr(start: Offset, mkIf: (Tree, Tree, Tree) => If): If = diff --git a/compiler/src/dotty/tools/dotc/parsing/Scanners.scala b/compiler/src/dotty/tools/dotc/parsing/Scanners.scala index 9987eaaa81b9..6de7bb615580 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Scanners.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Scanners.scala @@ -17,7 +17,7 @@ import scala.collection.mutable import scala.collection.immutable.SortedMap import rewrites.Rewrites.patch import config.Feature -import config.Feature.migrateTo3 +import config.Feature.{migrateTo3, sourceVersion} import config.SourceVersion.{`3.0`, `3.0-migration`} import config.MigrationVersion import reporting.{NoProfile, Profile, Message} @@ -184,7 +184,7 @@ object Scanners { val rewrite = ctx.settings.rewrite.value.isDefined val oldSyntax = ctx.settings.oldSyntax.value - val newSyntax = ctx.settings.newSyntax.value + val newSyntax = ctx.settings.newSyntax.value || sourceVersion.requiresNewSyntax val rewriteToIndent = ctx.settings.indent.value && rewrite val rewriteNoIndent = ctx.settings.noindent.value && rewrite diff --git a/tests/warn/abstract-givens-new.scala b/tests/neg/abstract-givens-new.scala similarity index 85% rename from tests/warn/abstract-givens-new.scala rename to tests/neg/abstract-givens-new.scala index c18ebe46acf7..1f0e641f9017 100644 --- a/tests/warn/abstract-givens-new.scala +++ b/tests/neg/abstract-givens-new.scala @@ -4,7 +4,7 @@ class C: trait T: given Int is C // ok - given intC: Int is C // warn + given intC: Int is C // error given intC2: (Int is C)() // ok given intC3: Int is C {} // also ok diff --git a/tests/neg/context-bounds-migration-future.check b/tests/neg/context-bounds-migration-future.check index f517a1e335c9..f56da5d6b28d 100644 --- a/tests/neg/context-bounds-migration-future.check +++ b/tests/neg/context-bounds-migration-future.check @@ -4,7 +4,3 @@ | method foo does not take more parameters | | longer explanation available when compiling with `-explain` --- Warning: tests/neg/context-bounds-migration-future.scala:6:6 -------------------------------------------------------- -6 |given [T]: C[T] = C[T]() - | ^ - | This old given syntax is no longer supported; use `=>` instead of `:` diff --git a/tests/neg/context-bounds-migration-future.scala b/tests/neg/context-bounds-migration-future.scala index 6d0e94c0b434..0816518d48a9 100644 --- a/tests/neg/context-bounds-migration-future.scala +++ b/tests/neg/context-bounds-migration-future.scala @@ -3,7 +3,7 @@ class C[T] def foo[X: C] = () -given [T]: C[T] = C[T]() +given [T] => C[T] = C[T]() def Test = foo(C[Int]()) // error diff --git a/tests/warn/old-givens.scala b/tests/neg/old-givens.scala similarity index 57% rename from tests/warn/old-givens.scala rename to tests/neg/old-givens.scala index 83e650df47d3..bd2acdfd2f8a 100644 --- a/tests/warn/old-givens.scala +++ b/tests/neg/old-givens.scala @@ -5,14 +5,14 @@ trait Ord[T]: class C[T] trait T: - given intC: C[Int] // warn + given intC: C[Int] // error given intC2: C[Int] () // OK - given [T]: Ord[T] with // warn // warn + given [T]: Ord[T] with // error // error def compare(x: T, y: T): Boolean = ??? - given [T](using Ord[T]): Ord[List[T]] with // warn // warn + given [T](using Ord[T]): Ord[List[T]] with // error // error def compare(x: List[T], y: List[T]): Boolean = ??? - def f[T: Ord : C]() = ??? // warn + def f[T: Ord : C]() = ??? // error diff --git a/tests/pos/hylolib-cb/BitArray.scala b/tests/pos/hylolib-cb/BitArray.scala index 0c8f98fb1ba4..2de41facf8e8 100644 --- a/tests/pos/hylolib-cb/BitArray.scala +++ b/tests/pos/hylolib-cb/BitArray.scala @@ -22,86 +22,79 @@ final class BitArray private ( /** Reserves enough storage to store `n` elements in `this`. */ def reserveCapacity(n: Int, assumeUniqueness: Boolean = false): BitArray = - if (n == 0) { + if n == 0 then this - } else { + else val k = 1 + ((n - 1) >> 5) - if (assumeUniqueness) { + if assumeUniqueness then _bits = _bits.reserveCapacity(k, assumeUniqueness) this - } else { + else new BitArray(_bits.reserveCapacity(k), _count) - } - } /** Adds a new element at the end of the array. */ def append(bit: Boolean, assumeUniqueness: Boolean = false): BitArray = val result = if assumeUniqueness && (count < capacity) then this else copy(count + 1) val p = BitArray.Position(count) - if (p.bucket >= _bits.count) { + if p.bucket >= _bits.count then result._bits = _bits.append(if bit then 1 else 0) - } else { + else result.setValue(bit, p) - } result._count += 1 result /** Removes and returns the last element, or returns `None` if the array is empty. */ def popLast(assumeUniqueness: Boolean = false): (BitArray, Option[Boolean]) = - if (isEmpty) { + if isEmpty then (this, None) - } else { + else val result = if assumeUniqueness then this else copy() val bit = result.at(BitArray.Position(count)) result._count -= 1 (result, Some(bit)) - } /** Removes all elements in the array, keeping allocated storage iff `keepStorage` is true. */ def removeAll( keepStorage: Boolean = false, assumeUniqueness: Boolean = false ): BitArray = - if (isEmpty) { + if isEmpty then this - } else if (keepStorage) { + else if keepStorage then val result = if assumeUniqueness then this else copy() result._bits.removeAll(keepStorage, assumeUniqueness = true) result._count = 0 result - } else { + else BitArray() - } /** Returns `true` iff all elements in `this` are `false`. */ def allFalse: Boolean = - if (isEmpty) { + if isEmpty then true - } else { + else val k = (count - 1) >> 5 def loop(i: Int): Boolean = - if (i == k) { + if i == k then val m = (1 << (count & 31)) - 1 (_bits.at(k) & m) == 0 - } else if (_bits.at(i) != 0) { + else if _bits.at(i) != 0 then false - } else { + else loop(i + 1) - } loop(0) - } /** Returns `true` iff all elements in `this` are `true`. */ def allTrue: Boolean = - if (isEmpty) { + if isEmpty then { true } else { val k = (count - 1) >> 5 def loop(i: Int): Boolean = - if (i == k) { + if i == k then { val m = (1 << (count & 31)) - 1 (_bits.at(k) & m) == m - } else if (_bits.at(i) != ~0) { + } else if _bits.at(i) != ~0 then { false } else { loop(i + 1) @@ -136,14 +129,14 @@ final class BitArray private ( assumeUniqueness: Boolean = false ): BitArray = require(this.count == other.count) - if (isEmpty) { + if isEmpty then { this } else { val result = if assumeUniqueness then this else copy() var u = assumeUniqueness val k = (count - 1) >> 5 - for (i <- 0 until k) { + for i <- 0 until k do { result._bits = result._bits.modifyAt( i, (n) => operation(n, other._bits.at(n)), assumeUniqueness = u @@ -184,7 +177,7 @@ final class BitArray private ( * O(1). */ def positionAfter(p: BitArray.Position): BitArray.Position = - if (p.offsetInBucket == 63) { + if p.offsetInBucket == 63 then { BitArray.Position(p.bucket + 1, 0) } else { BitArray.Position(p.bucket, p.offsetInBucket + 1) @@ -244,7 +237,7 @@ final class BitArray private ( /** Returns an independent copy of `this`. */ def copy(minimumCapacity: Int = 0): BitArray = - if (minimumCapacity > capacity) { + if minimumCapacity > capacity then { // If the requested capacity on the copy is greater than what we have, `reserveCapacity` will // create an independent value. reserveCapacity(minimumCapacity) @@ -313,7 +306,7 @@ object BitArray { /** Creates an array with the given `bits`. */ def apply[T](bits: Boolean*): BitArray = var result = new BitArray(HyArray[Int](), 0) - for (b <- bits) result = result.append(b, assumeUniqueness = true) + for b <- bits do result = result.append(b, assumeUniqueness = true) result } diff --git a/tests/pos/hylolib-cb/Collection.scala b/tests/pos/hylolib-cb/Collection.scala index 2fc04f02b9ac..f5d65e1f13c7 100644 --- a/tests/pos/hylolib-cb/Collection.scala +++ b/tests/pos/hylolib-cb/Collection.scala @@ -69,15 +69,15 @@ trait Collection[Self] { */ def isBefore(i: Position, j: Position): Boolean = val e = self.endPosition - if (i.eq(e)) { + if i.eq(e) then { false - } else if (j.eq(e)) { + } else if j.eq(e) then { true } else { def _isBefore(n: Position): Boolean = - if (n.eq(j)) { + if n.eq(j) then { true - } else if (n.eq(e)) { + } else if n.eq(e) then { false } else { _isBefore(self.positionAfter(n)) @@ -98,7 +98,7 @@ extension [Self: Collection as s](self: Self) { * O(1) */ def headAndTail: Option[(s.Element, Slice[Self])] = - if (self.isEmpty) { + if self.isEmpty then { None } else { val p = self.startPosition @@ -115,7 +115,7 @@ extension [Self: Collection as s](self: Self) { def reduce[T](partialResult: T, combine: (T, s.Element) => T): T = val e = self.endPosition def loop(p: s.Position, r: T): T = - if (p.eq(e)) { + if p.eq(e) then { r } else { loop(self.positionAfter(p), combine(r, self.at(p))) @@ -134,9 +134,9 @@ extension [Self: Collection as s](self: Self) { def forEach(action: (s.Element) => Boolean): Boolean = val e = self.endPosition def loop(p: s.Position): Boolean = - if (p.eq(e)) { + if p.eq(e) then { true - } else if (!action(self.at(p))) { + } else if !action(self.at(p)) then { false } else { loop(self.positionAfter(p)) @@ -190,9 +190,9 @@ extension [Self: Collection as s](self: Self) { def firstPositionWhere(predicate: (s.Element) => Boolean): Option[s.Position] = val e = self.endPosition def loop(p: s.Position): Option[s.Position] = - if (p.eq(e)) { + if p.eq(e) then { None - } else if (predicate(self.at(p))) { + } else if predicate(self.at(p)) then { Some(p) } else { loop(self.positionAfter(p)) @@ -238,12 +238,12 @@ extension [Self: Collection as s](self: Self) { * O(n) where n is the number of elements in `self`. */ def leastElement(isOrderedBefore: (s.Element, s.Element) => Boolean): Option[s.Element] = - if (self.isEmpty) { + if self.isEmpty then { None } else { val e = self.endPosition def _least(p: s.Position, least: s.Element): s.Element = - if (p.eq(e)) { + if p.eq(e) then { least } else { val x = self.at(p) @@ -264,11 +264,11 @@ extension [Self: Collection as s](self: Self)(using /** Returns `true` if `self` contains the same elements as `other`, in the same order. */ def elementsEqual[T](using o: Collection[T] { type Element = s.Element })(other: T): Boolean = def loop(i: s.Position, j: o.Position): Boolean = - if (i `eq` self.endPosition) { + if i `eq` self.endPosition then { j `eq` other.endPosition - } else if (j `eq` other.endPosition) { + } else if j `eq` other.endPosition then { false - } else if (self.at(i) `neq` other.at(j)) { + } else if self.at(i) `neq` other.at(j) then { false } else { loop(self.positionAfter(i), other.positionAfter(j)) diff --git a/tests/pos/hylolib-cb/HyArray.scala b/tests/pos/hylolib-cb/HyArray.scala index e4ccab000448..93dad7751adf 100644 --- a/tests/pos/hylolib-cb/HyArray.scala +++ b/tests/pos/hylolib-cb/HyArray.scala @@ -27,21 +27,21 @@ final class HyArray[Element: Value as elementIsCValue]( /** Reserves enough storage to store `n` elements in `this`. */ def reserveCapacity(n: Int, assumeUniqueness: Boolean = false): HyArray[Element] = - if (n <= capacity) { + if n <= capacity then { this } else { var newCapacity = max(1, capacity) - while (newCapacity < n) { newCapacity = newCapacity << 1 } + while newCapacity < n do { newCapacity = newCapacity << 1 } val newStorage = new scala.Array[AnyRef | Null](newCapacity) val s = _storage.asInstanceOf[scala.Array[AnyRef | Null]] var i = 0 - while (i < count) { + while i < count do { newStorage(i) = _storage(i).asInstanceOf[Element].copy().asInstanceOf[AnyRef] i += 1 } - if (assumeUniqueness) { + if assumeUniqueness then { _storage = newStorage this } else { @@ -69,7 +69,7 @@ final class HyArray[Element: Value as elementIsCValue]( /** Removes and returns the last element, or returns `None` if the array is empty. */ def popLast(assumeUniqueness: Boolean = false): (HyArray[Element], Option[Element]) = - if (isEmpty) { + if isEmpty then { (this, None) } else { val result = if assumeUniqueness then this else copy() @@ -82,9 +82,9 @@ final class HyArray[Element: Value as elementIsCValue]( keepStorage: Boolean = false, assumeUniqueness: Boolean = false ): HyArray[Element] = - if (isEmpty) { + if isEmpty then { this - } else if (keepStorage) { + } else if keepStorage then { val result = if assumeUniqueness then this else copy() Arrays.fill(result._storage, null) result._count = 0 @@ -123,8 +123,8 @@ final class HyArray[Element: Value as elementIsCValue]( override def toString: String = var s = "[" var i = 0 - while (i < count) { - if (i > 0) { s += ", " } + while i < count do { + if i > 0 then { s += ", " } s += s"${at(i)}" i += 1 } @@ -134,14 +134,14 @@ final class HyArray[Element: Value as elementIsCValue]( * allocating new storage. */ def copy(minimumCapacity: Int = 0): HyArray[Element] = - if (minimumCapacity > capacity) { + if minimumCapacity > capacity then { // If the requested capacity on the copy is greater than what we have, `reserveCapacity` will // create an independent value. reserveCapacity(minimumCapacity) } else { val clone = HyArray[Element]().reserveCapacity(max(minimumCapacity, count)) var i = 0 - while (i < count) { + while i < count do { clone._storage(i) = _storage(i).asInstanceOf[Element].copy().asInstanceOf[AnyRef] i += 1 } @@ -156,7 +156,7 @@ object HyArray { /** Creates an array with the given `elements`. */ def apply[T: Value](elements: T*): HyArray[T] = var a = new HyArray[T](null, 0) - for (e <- elements) a = a.append(e, assumeUniqueness = true) + for e <- elements do a = a.append(e, assumeUniqueness = true) a } diff --git a/tests/pos/hylolib-deferred-given/AnyCollection.scala b/tests/pos/hylolib-deferred-given/AnyCollection.scala index e2a946fca484..e13232c64954 100644 --- a/tests/pos/hylolib-deferred-given/AnyCollection.scala +++ b/tests/pos/hylolib-deferred-given/AnyCollection.scala @@ -48,7 +48,7 @@ given anyCollectionIsCollection: [T] => (tIsValue: Value[T]) => Collection[AnyCo //given elementIsValue: Value[Element] = tIsValue type Position = AnyValue - given positionIsValue: Value[Position] = anyValueIsValue + override given positionIsValue: Value[Position] = anyValueIsValue extension (self: AnyCollection[T]) { diff --git a/tests/pos/hylolib-deferred-given/BitArray.scala b/tests/pos/hylolib-deferred-given/BitArray.scala index d653f5e4d630..885f9b9ba60a 100644 --- a/tests/pos/hylolib-deferred-given/BitArray.scala +++ b/tests/pos/hylolib-deferred-given/BitArray.scala @@ -22,11 +22,11 @@ final class BitArray private ( /** Reserves enough storage to store `n` elements in `this`. */ def reserveCapacity(n: Int, assumeUniqueness: Boolean = false): BitArray = - if (n == 0) { + if n == 0 then { this } else { val k = 1 + ((n - 1) >> 5) - if (assumeUniqueness) { + if assumeUniqueness then { _bits = _bits.reserveCapacity(k, assumeUniqueness) this } else { @@ -38,7 +38,7 @@ final class BitArray private ( def append(bit: Boolean, assumeUniqueness: Boolean = false): BitArray = val result = if assumeUniqueness && (count < capacity) then this else copy(count + 1) val p = BitArray.Position(count) - if (p.bucket >= _bits.count) { + if p.bucket >= _bits.count then { result._bits = _bits.append(if bit then 1 else 0) } else { result.setValue(bit, p) @@ -48,7 +48,7 @@ final class BitArray private ( /** Removes and returns the last element, or returns `None` if the array is empty. */ def popLast(assumeUniqueness: Boolean = false): (BitArray, Option[Boolean]) = - if (isEmpty) { + if isEmpty then { (this, None) } else { val result = if assumeUniqueness then this else copy() @@ -62,9 +62,9 @@ final class BitArray private ( keepStorage: Boolean = false, assumeUniqueness: Boolean = false ): BitArray = - if (isEmpty) { + if isEmpty then { this - } else if (keepStorage) { + } else if keepStorage then { val result = if assumeUniqueness then this else copy() result._bits.removeAll(keepStorage, assumeUniqueness = true) result._count = 0 @@ -75,15 +75,15 @@ final class BitArray private ( /** Returns `true` iff all elements in `this` are `false`. */ def allFalse: Boolean = - if (isEmpty) { + if isEmpty then { true } else { val k = (count - 1) >> 5 def loop(i: Int): Boolean = - if (i == k) { + if i == k then { val m = (1 << (count & 31)) - 1 (_bits.at(k) & m) == 0 - } else if (_bits.at(i) != 0) { + } else if _bits.at(i) != 0 then { false } else { loop(i + 1) @@ -93,15 +93,15 @@ final class BitArray private ( /** Returns `true` iff all elements in `this` are `true`. */ def allTrue: Boolean = - if (isEmpty) { + if isEmpty then { true } else { val k = (count - 1) >> 5 def loop(i: Int): Boolean = - if (i == k) { + if i == k then { val m = (1 << (count & 31)) - 1 (_bits.at(k) & m) == m - } else if (_bits.at(i) != ~0) { + } else if _bits.at(i) != ~0 then { false } else { loop(i + 1) @@ -136,14 +136,14 @@ final class BitArray private ( assumeUniqueness: Boolean = false ): BitArray = require(this.count == other.count) - if (isEmpty) { + if isEmpty then { this } else { val result = if assumeUniqueness then this else copy() var u = assumeUniqueness val k = (count - 1) >> 5 - for (i <- 0 until k) { + for i <- 0 until k do { result._bits = result._bits.modifyAt( i, (n) => operation(n, other._bits.at(n)), assumeUniqueness = u @@ -184,7 +184,7 @@ final class BitArray private ( * O(1). */ def positionAfter(p: BitArray.Position): BitArray.Position = - if (p.offsetInBucket == 63) { + if p.offsetInBucket == 63 then { BitArray.Position(p.bucket + 1, 0) } else { BitArray.Position(p.bucket, p.offsetInBucket + 1) @@ -244,7 +244,7 @@ final class BitArray private ( /** Returns an independent copy of `this`. */ def copy(minimumCapacity: Int = 0): BitArray = - if (minimumCapacity > capacity) { + if minimumCapacity > capacity then { // If the requested capacity on the copy is greater than what we have, `reserveCapacity` will // create an independent value. reserveCapacity(minimumCapacity) @@ -313,7 +313,7 @@ object BitArray { /** Creates an array with the given `bits`. */ def apply[T](bits: Boolean*): BitArray = var result = new BitArray(HyArray[Int](), 0) - for (b <- bits) result = result.append(b, assumeUniqueness = true) + for b <- bits do result = result.append(b, assumeUniqueness = true) result } @@ -341,7 +341,7 @@ given bitArrayIsCollection: Collection[BitArray] { //given elementIsValue: Value[Boolean] = booleanIsValue type Position = BitArray.Position - given positionIsValue: Value[BitArray.Position] = bitArrayPositionIsValue + override given positionIsValue: Value[BitArray.Position] = bitArrayPositionIsValue extension (self: BitArray) { diff --git a/tests/pos/hylolib-deferred-given/Collection.scala b/tests/pos/hylolib-deferred-given/Collection.scala index 6b5e7a762dc8..d0577023a619 100644 --- a/tests/pos/hylolib-deferred-given/Collection.scala +++ b/tests/pos/hylolib-deferred-given/Collection.scala @@ -10,7 +10,7 @@ trait Collection[Self] { /** The type of a position in the collection. */ type Position - given positionIsValue: Value[Position] + given positionIsValue: Value[Position] = compiletime.deferred extension (self: Self) { @@ -71,15 +71,15 @@ trait Collection[Self] { */ def isBefore(i: Position, j: Position): Boolean = val e = self.endPosition - if (i.eq(e)) { + if i.eq(e) then { false - } else if (j.eq(e)) { + } else if j.eq(e) then { true } else { def _isBefore(n: Position): Boolean = - if (n.eq(j)) { + if n.eq(j) then { true - } else if (n.eq(e)) { + } else if n.eq(e) then { false } else { _isBefore(self.positionAfter(n)) @@ -100,7 +100,7 @@ extension [Self](self: Self)(using s: Collection[Self]) { * O(1) */ def headAndTail: Option[(s.Element, Slice[Self])] = - if (self.isEmpty) { + if self.isEmpty then { None } else { val p = self.startPosition @@ -117,7 +117,7 @@ extension [Self](self: Self)(using s: Collection[Self]) { def reduce[T](partialResult: T, combine: (T, s.Element) => T): T = val e = self.endPosition def loop(p: s.Position, r: T): T = - if (p.eq(e)) { + if p.eq(e) then { r } else { loop(self.positionAfter(p), combine(r, self.at(p))) @@ -136,9 +136,9 @@ extension [Self](self: Self)(using s: Collection[Self]) { def forEach(action: (s.Element) => Boolean): Boolean = val e = self.endPosition def loop(p: s.Position): Boolean = - if (p.eq(e)) { + if p.eq(e) then { true - } else if (!action(self.at(p))) { + } else if !action(self.at(p)) then { false } else { loop(self.positionAfter(p)) @@ -192,9 +192,9 @@ extension [Self](self: Self)(using s: Collection[Self]) { def firstPositionWhere(predicate: (s.Element) => Boolean): Option[s.Position] = val e = self.endPosition def loop(p: s.Position): Option[s.Position] = - if (p.eq(e)) { + if p.eq(e) then { None - } else if (predicate(self.at(p))) { + } else if predicate(self.at(p)) then { Some(p) } else { loop(self.positionAfter(p)) @@ -240,12 +240,12 @@ extension [Self](self: Self)(using s: Collection[Self]) { * O(n) where n is the number of elements in `self`. */ def leastElement(isOrderedBefore: (s.Element, s.Element) => Boolean): Option[s.Element] = - if (self.isEmpty) { + if self.isEmpty then { None } else { val e = self.endPosition def _least(p: s.Position, least: s.Element): s.Element = - if (p.eq(e)) { + if p.eq(e) then { least } else { val x = self.at(p) @@ -267,11 +267,11 @@ extension [Self](self: Self)(using /** Returns `true` if `self` contains the same elements as `other`, in the same order. */ def elementsEqual[T](using o: Collection[T] { type Element = s.Element })(other: T): Boolean = def loop(i: s.Position, j: o.Position): Boolean = - if (i `eq` self.endPosition) { + if i `eq` self.endPosition then { j `eq` other.endPosition - } else if (j `eq` other.endPosition) { + } else if j `eq` other.endPosition then { false - } else if (self.at(i) `neq` other.at(j)) { + } else if self.at(i) `neq` other.at(j) then { false } else { loop(self.positionAfter(i), other.positionAfter(j)) diff --git a/tests/pos/hylolib-deferred-given/HyArray.scala b/tests/pos/hylolib-deferred-given/HyArray.scala index e82ce06d920b..e93c826a11eb 100644 --- a/tests/pos/hylolib-deferred-given/HyArray.scala +++ b/tests/pos/hylolib-deferred-given/HyArray.scala @@ -28,21 +28,21 @@ final class HyArray[Element] private (using /** Reserves enough storage to store `n` elements in `this`. */ def reserveCapacity(n: Int, assumeUniqueness: Boolean = false): HyArray[Element] = - if (n <= capacity) { + if n <= capacity then { this } else { var newCapacity = max(1, capacity) - while (newCapacity < n) { newCapacity = newCapacity << 1 } + while newCapacity < n do { newCapacity = newCapacity << 1 } val newStorage = new scala.Array[AnyRef | Null](newCapacity) val s = _storage.asInstanceOf[scala.Array[AnyRef | Null]] var i = 0 - while (i < count) { + while i < count do { newStorage(i) = _storage(i).asInstanceOf[Element].copy().asInstanceOf[AnyRef] i += 1 } - if (assumeUniqueness) { + if assumeUniqueness then { _storage = newStorage this } else { @@ -70,7 +70,7 @@ final class HyArray[Element] private (using /** Removes and returns the last element, or returns `None` if the array is empty. */ def popLast(assumeUniqueness: Boolean = false): (HyArray[Element], Option[Element]) = - if (isEmpty) { + if isEmpty then { (this, None) } else { val result = if assumeUniqueness then this else copy() @@ -83,9 +83,9 @@ final class HyArray[Element] private (using keepStorage: Boolean = false, assumeUniqueness: Boolean = false ): HyArray[Element] = - if (isEmpty) { + if isEmpty then { this - } else if (keepStorage) { + } else if keepStorage then { val result = if assumeUniqueness then this else copy() Arrays.fill(result._storage, null) result._count = 0 @@ -124,8 +124,8 @@ final class HyArray[Element] private (using override def toString: String = var s = "[" var i = 0 - while (i < count) { - if (i > 0) { s += ", " } + while i < count do { + if i > 0 then { s += ", " } s += s"${at(i)}" i += 1 } @@ -135,14 +135,14 @@ final class HyArray[Element] private (using * allocating new storage. */ def copy(minimumCapacity: Int = 0): HyArray[Element] = - if (minimumCapacity > capacity) { + if minimumCapacity > capacity then { // If the requested capacity on the copy is greater than what we have, `reserveCapacity` will // create an independent value. reserveCapacity(minimumCapacity) } else { val clone = HyArray[Element]().reserveCapacity(max(minimumCapacity, count)) var i = 0 - while (i < count) { + while i < count do { clone._storage(i) = _storage(i).asInstanceOf[Element].copy().asInstanceOf[AnyRef] i += 1 } @@ -157,7 +157,7 @@ object HyArray { /** Creates an array with the given `elements`. */ def apply[T](using t: Value[T])(elements: T*): HyArray[T] = var a = new HyArray[T](null, 0) - for (e <- elements) a = a.append(e, assumeUniqueness = true) + for e <- elements do a = a.append(e, assumeUniqueness = true) a } @@ -185,7 +185,7 @@ given hyArrayIsCollection: [T] => (tIsValue: Value[T]) => Collection[HyArray[T]] //given elementIsValue: Value[T] = tIsValue type Position = Int - given positionIsValue: Value[Int] = intIsValue + override given positionIsValue: Value[Int] = intIsValue extension (self: HyArray[T]) { diff --git a/tests/pos/hylolib-deferred-given/Slice.scala b/tests/pos/hylolib-deferred-given/Slice.scala index 234b16dfc428..ed3a1cb2e4b8 100644 --- a/tests/pos/hylolib-deferred-given/Slice.scala +++ b/tests/pos/hylolib-deferred-given/Slice.scala @@ -32,7 +32,7 @@ given sliceIsCollection: [T] => (c: Collection[T]) => Collection[Slice[T]] { //given elementIsValue: Value[Element] = c.elementIsValue type Position = c.Position - given positionIsValue: Value[Position] = c.positionIsValue + override given positionIsValue: Value[Position] = c.positionIsValue extension (self: Slice[T]) { diff --git a/tests/pos/hylolib/BitArray.scala b/tests/pos/hylolib/BitArray.scala index 6ef406e5ad83..03c3c0663e20 100644 --- a/tests/pos/hylolib/BitArray.scala +++ b/tests/pos/hylolib/BitArray.scala @@ -22,11 +22,11 @@ final class BitArray private ( /** Reserves enough storage to store `n` elements in `this`. */ def reserveCapacity(n: Int, assumeUniqueness: Boolean = false): BitArray = - if (n == 0) { + if n == 0 then { this } else { val k = 1 + ((n - 1) >> 5) - if (assumeUniqueness) { + if assumeUniqueness then { _bits = _bits.reserveCapacity(k, assumeUniqueness) this } else { @@ -38,7 +38,7 @@ final class BitArray private ( def append(bit: Boolean, assumeUniqueness: Boolean = false): BitArray = val result = if assumeUniqueness && (count < capacity) then this else copy(count + 1) val p = BitArray.Position(count) - if (p.bucket >= _bits.count) { + if p.bucket >= _bits.count then { result._bits = _bits.append(if bit then 1 else 0) } else { result.setValue(bit, p) @@ -48,7 +48,7 @@ final class BitArray private ( /** Removes and returns the last element, or returns `None` if the array is empty. */ def popLast(assumeUniqueness: Boolean = false): (BitArray, Option[Boolean]) = - if (isEmpty) { + if isEmpty then { (this, None) } else { val result = if assumeUniqueness then this else copy() @@ -62,9 +62,9 @@ final class BitArray private ( keepStorage: Boolean = false, assumeUniqueness: Boolean = false ): BitArray = - if (isEmpty) { + if isEmpty then { this - } else if (keepStorage) { + } else if keepStorage then { val result = if assumeUniqueness then this else copy() result._bits.removeAll(keepStorage, assumeUniqueness = true) result._count = 0 @@ -75,15 +75,15 @@ final class BitArray private ( /** Returns `true` iff all elements in `this` are `false`. */ def allFalse: Boolean = - if (isEmpty) { + if isEmpty then { true } else { val k = (count - 1) >> 5 def loop(i: Int): Boolean = - if (i == k) { + if i == k then { val m = (1 << (count & 31)) - 1 (_bits.at(k) & m) == 0 - } else if (_bits.at(i) != 0) { + } else if _bits.at(i) != 0 then { false } else { loop(i + 1) @@ -93,15 +93,15 @@ final class BitArray private ( /** Returns `true` iff all elements in `this` are `true`. */ def allTrue: Boolean = - if (isEmpty) { + if isEmpty then { true } else { val k = (count - 1) >> 5 def loop(i: Int): Boolean = - if (i == k) { + if i == k then { val m = (1 << (count & 31)) - 1 (_bits.at(k) & m) == m - } else if (_bits.at(i) != ~0) { + } else if _bits.at(i) != ~0 then { false } else { loop(i + 1) @@ -136,14 +136,14 @@ final class BitArray private ( assumeUniqueness: Boolean = false ): BitArray = require(this.count == other.count) - if (isEmpty) { + if isEmpty then { this } else { val result = if assumeUniqueness then this else copy() var u = assumeUniqueness val k = (count - 1) >> 5 - for (i <- 0 until k) { + for i <- 0 until k do { result._bits = result._bits.modifyAt( i, (n) => operation(n, other._bits.at(n)), assumeUniqueness = u @@ -184,7 +184,7 @@ final class BitArray private ( * O(1). */ def positionAfter(p: BitArray.Position): BitArray.Position = - if (p.offsetInBucket == 63) { + if p.offsetInBucket == 63 then { BitArray.Position(p.bucket + 1, 0) } else { BitArray.Position(p.bucket, p.offsetInBucket + 1) @@ -244,7 +244,7 @@ final class BitArray private ( /** Returns an independent copy of `this`. */ def copy(minimumCapacity: Int = 0): BitArray = - if (minimumCapacity > capacity) { + if minimumCapacity > capacity then { // If the requested capacity on the copy is greater than what we have, `reserveCapacity` will // create an independent value. reserveCapacity(minimumCapacity) @@ -313,7 +313,7 @@ object BitArray { /** Creates an array with the given `bits`. */ def apply[T](bits: Boolean*): BitArray = var result = new BitArray(HyArray[Int](), 0) - for (b <- bits) result = result.append(b, assumeUniqueness = true) + for b <- bits do result = result.append(b, assumeUniqueness = true) result } diff --git a/tests/pos/hylolib/HyArray.scala b/tests/pos/hylolib/HyArray.scala index de5e83d3b1a3..b386b8ed4375 100644 --- a/tests/pos/hylolib/HyArray.scala +++ b/tests/pos/hylolib/HyArray.scala @@ -27,21 +27,21 @@ final class HyArray[Element: Value as elementIsCValue]( /** Reserves enough storage to store `n` elements in `this`. */ def reserveCapacity(n: Int, assumeUniqueness: Boolean = false): HyArray[Element] = - if (n <= capacity) { + if n <= capacity then { this } else { var newCapacity = max(1, capacity) - while (newCapacity < n) { newCapacity = newCapacity << 1 } + while newCapacity < n do { newCapacity = newCapacity << 1 } val newStorage = new scala.Array[AnyRef | Null](newCapacity) val s = _storage.asInstanceOf[scala.Array[AnyRef | Null]] var i = 0 - while (i < count) { + while i < count do { newStorage(i) = _storage(i).asInstanceOf[Element].copy().asInstanceOf[AnyRef] i += 1 } - if (assumeUniqueness) { + if assumeUniqueness then { _storage = newStorage this } else { @@ -60,13 +60,13 @@ final class HyArray[Element: Value as elementIsCValue]( def appendContents[C: Collection { type Element = HyArray.this.Element }]( source: C, assumeUniqueness: Boolean = false ): HyArray[Element] = - val result = if (assumeUniqueness) { this } else { copy(count + source.count) } + val result = if assumeUniqueness then { this } else { copy(count + source.count) } source.reduce(result): (r, e) => r.append(e, assumeUniqueness = true) /** Removes and returns the last element, or returns `None` if the array is empty. */ def popLast(assumeUniqueness: Boolean = false): (HyArray[Element], Option[Element]) = - if (isEmpty) { + if isEmpty then { (this, None) } else { val result = if assumeUniqueness then this else copy() @@ -79,9 +79,9 @@ final class HyArray[Element: Value as elementIsCValue]( keepStorage: Boolean = false, assumeUniqueness: Boolean = false ): HyArray[Element] = - if (isEmpty) { + if isEmpty then { this - } else if (keepStorage) { + } else if keepStorage then { val result = if assumeUniqueness then this else copy() Arrays.fill(result._storage, null) result._count = 0 @@ -120,8 +120,8 @@ final class HyArray[Element: Value as elementIsCValue]( override def toString: String = var s = "[" var i = 0 - while (i < count) { - if (i > 0) { s += ", " } + while i < count do { + if i > 0 then { s += ", " } s += s"${at(i)}" i += 1 } @@ -131,14 +131,14 @@ final class HyArray[Element: Value as elementIsCValue]( * allocating new storage. */ def copy(minimumCapacity: Int = 0): HyArray[Element] = - if (minimumCapacity > capacity) { + if minimumCapacity > capacity then { // If the requested capacity on the copy is greater than what we have, `reserveCapacity` will // create an independent value. reserveCapacity(minimumCapacity) } else { val clone = HyArray[Element]().reserveCapacity(max(minimumCapacity, count)) var i = 0 - while (i < count) { + while i < count do { clone._storage(i) = _storage(i).asInstanceOf[Element].copy().asInstanceOf[AnyRef] i += 1 } @@ -153,7 +153,7 @@ object HyArray { /** Creates an array with the given `elements`. */ def apply[T: Value](elements: T*): HyArray[T] = var a = new HyArray[T](null, 0) - for (e <- elements) a = a.append(e, assumeUniqueness = true) + for e <- elements do a = a.append(e, assumeUniqueness = true) a } diff --git a/tests/pos/parsercombinators-ctx-bounds.scala b/tests/pos/parsercombinators-ctx-bounds.scala index 50338dbc2fa5..c337e19faf3a 100644 --- a/tests/pos/parsercombinators-ctx-bounds.scala +++ b/tests/pos/parsercombinators-ctx-bounds.scala @@ -25,8 +25,9 @@ given apply: [C, E] => Combinator[Apply[C, E]] { } } -given combine[A: Combinator, B: [X] =>> Combinator[X] { type Context = A.Context }] - : Combinator[Combine[A, B]] with +given combine + : [A: Combinator, B: [X] =>> Combinator[X] { type Context = A.Context }] + => Combinator[Combine[A, B]]: type Context = A.Context type Element = (A.Element, B.Element) extension(self: Combine[A, B]) diff --git a/tests/pos/parsercombinators-givens-2.scala b/tests/pos/parsercombinators-givens-2.scala index 4b00c3801716..f708b2613ffa 100644 --- a/tests/pos/parsercombinators-givens-2.scala +++ b/tests/pos/parsercombinators-givens-2.scala @@ -26,16 +26,14 @@ given apply: [C, E] => Combinator[Apply[C, E]] { } } -given combine[A, B, C](using - f: Combinator[A] { type Context = C }, - s: Combinator[B] { type Context = C } -): Combinator[Combine[A, B]] with { +given combine: [A, B, C] + => (f: Combinator[A] { type Context = C }, s: Combinator[B] { type Context = C }) + => Combinator[Combine[A, B]]: type Context = f.Context type Element = (f.Element, s.Element) extension(self: Combine[A, B]) { def parse(context: Context): Option[Element] = ??? } -} extension [A] (buf: mutable.ListBuffer[A]) def popFirst() = if buf.isEmpty then None diff --git a/tests/pos/parsercombinators-givens.scala b/tests/pos/parsercombinators-givens.scala index 1fa8080b0688..71000ac8134d 100644 --- a/tests/pos/parsercombinators-givens.scala +++ b/tests/pos/parsercombinators-givens.scala @@ -26,16 +26,14 @@ given apply: [C, E] => Combinator[Apply[C, E]] { } } -given combine[A, B](using - tracked val f: Combinator[A], - tracked val s: Combinator[B] { type Context = f.Context } -): Combinator[Combine[A, B]] with { +given combine + : [A, B] + => (tracked val f: Combinator[A], tracked val s: Combinator[B] { type Context = f.Context }) + => Combinator[Combine[A, B]]: type Context = f.Context type Element = (f.Element, s.Element) - extension(self: Combine[A, B]) { + extension (self: Combine[A, B]) def parse(context: Context): Option[Element] = ??? - } -} extension [A] (buf: mutable.ListBuffer[A]) def popFirst() = if buf.isEmpty then None diff --git a/tests/pos/parsercombinators-this.scala b/tests/pos/parsercombinators-this.scala index 19ac878c888f..cf25aea94d25 100644 --- a/tests/pos/parsercombinators-this.scala +++ b/tests/pos/parsercombinators-this.scala @@ -28,8 +28,9 @@ given apply: [C, E] => Combinator { } } -given combine[A: Combinator, B: Combinator { type Context = A.Context }] - : Combinator with +given combine + : [A: Combinator, B: Combinator { type Context = A.Context }] + => Combinator: type Self = Combine[A, B] type Context = A.Context type Element = (A.Element, B.Element) diff --git a/tests/pos/typeclasses-arrow.scala b/tests/pos/typeclasses-arrow.scala index 4b2a25122b0d..bbe9d97e1a16 100644 --- a/tests/pos/typeclasses-arrow.scala +++ b/tests/pos/typeclasses-arrow.scala @@ -50,7 +50,7 @@ object Instances extends Common: case (_, Nil) => +1 case (x :: xs1, y :: ys1) => val fst = x.compareTo(y) - if (fst != 0) fst else xs1.compareTo(ys1) + if fst != 0 then fst else xs1.compareTo(ys1) given listMonad: List is Monad: extension [A](xs: List[A]) def flatMap[B](f: A => List[B]): List[B] = diff --git a/tests/pos/typeclasses-this.scala b/tests/pos/typeclasses-this.scala index ebe0dc348a06..198fb0142a8f 100644 --- a/tests/pos/typeclasses-this.scala +++ b/tests/pos/typeclasses-this.scala @@ -51,7 +51,7 @@ object Instances extends Common: case (_, Nil) => +1 case (x :: xs1, y :: ys1) => val fst = x.compareTo(y) - if (fst != 0) fst else xs1.compareTo(ys1) + if fst != 0 then fst else xs1.compareTo(ys1) given listMonad: (List is Monad): extension [A](xs: List[A]) def flatMap[B](f: A => List[B]): List[B] = diff --git a/tests/pos/typeclasses.scala b/tests/pos/typeclasses.scala index 40f992cbcb57..c009f4b38a97 100644 --- a/tests/pos/typeclasses.scala +++ b/tests/pos/typeclasses.scala @@ -46,7 +46,7 @@ object Instances extends Common: case (_, Nil) => +1 case (x :: xs1, y :: ys1) => val fst = x.compareTo(y) - if (fst != 0) fst else xs1.compareTo(ys1) + if fst != 0 then fst else xs1.compareTo(ys1) end listOrd given listMonad: List is Monad: @@ -80,7 +80,7 @@ object Instances extends Common: xss.flatMap(identity) def maximum[T](xs: List[T])(using T is Ord): T = - xs.reduceLeft((x, y) => if (x < y) y else x) + xs.reduceLeft((x, y) => if x < y then y else x) def descending[T](using asc: T is Ord): T is Ord = new: extension (x: T) def compareTo(y: T) = asc.compareTo(y)(x)