Skip to content

Enforce new given syntax under -source future #23446

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

4 changes: 0 additions & 4 deletions tests/neg/context-bounds-migration-future.check
Original file line number Diff line number Diff line change
Expand Up @@ -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 `:`
2 changes: 1 addition & 1 deletion tests/neg/context-bounds-migration-future.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions tests/warn/old-givens.scala → tests/neg/old-givens.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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

2 changes: 1 addition & 1 deletion tests/pos/hylolib-deferred-given/AnyCollection.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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]) {

Expand Down
2 changes: 1 addition & 1 deletion tests/pos/hylolib-deferred-given/BitArray.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Expand Down
2 changes: 1 addition & 1 deletion tests/pos/hylolib-deferred-given/Collection.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Expand Down
2 changes: 1 addition & 1 deletion tests/pos/hylolib-deferred-given/HyArray.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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]) {

Expand Down
2 changes: 1 addition & 1 deletion tests/pos/hylolib-deferred-given/Slice.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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]) {

Expand Down
5 changes: 3 additions & 2 deletions tests/pos/parsercombinators-ctx-bounds.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
8 changes: 3 additions & 5 deletions tests/pos/parsercombinators-givens-2.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 5 additions & 7 deletions tests/pos/parsercombinators-givens.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions tests/pos/parsercombinators-this.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading