Skip to content

Commit a1dc168

Browse files
committed
Replace delegate for by given as in compiler and tests.
1 parent 0227ebe commit a1dc168

File tree

67 files changed

+225
-223
lines changed

Some content is hidden

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

67 files changed

+225
-223
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ object Flags {
2222

2323
type Flag = opaques.Flag
2424

25-
delegate FlagOps {
25+
given FlagOps {
2626

2727
def (x: FlagSet) bits: Long = opaques.toBits(x)
2828

compiler/src/dotty/tools/dotc/interactive/Completion.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ object Completion {
121121
if (buffer.mode != Mode.None) {
122122
path match {
123123
case Select(qual, _) :: _ => buffer.addMemberCompletions(qual)
124-
case Import(_, expr, _) :: _ => buffer.addMemberCompletions(expr) // TODO: distinguish delegate from non-delegate
124+
case Import(_, expr, _) :: _ => buffer.addMemberCompletions(expr) // TODO: distinguish given from plain imports
125125
case (_: Thicket) :: Import(_, expr, _) :: _ => buffer.addMemberCompletions(expr)
126126
case _ => buffer.addScopeCompletions
127127
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1206,7 +1206,7 @@ trait Implicits { self: Typer =>
12061206
case fail: SearchFailureType =>
12071207

12081208
def hiddenImplicitNote(s: SearchSuccess) =
1209-
em"\n\nNote: delegate ${s.ref.symbol.showLocated} was not considered because it was not imported with `import delegate`."
1209+
em"\n\nNote: given instance ${s.ref.symbol.showLocated} was not considered because it was not imported with `import given`."
12101210

12111211
def FindHiddenImplicitsCtx(ctx: Context): Context =
12121212
if (ctx == NoContext) ctx

compiler/src/dotty/tools/dotc/typer/ImportInfo.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ object ImportInfo {
2828
* @param selectors The selector clauses
2929
* @param symNameOpt Optionally, the name of the import symbol. None for root imports.
3030
* Defined for all explicit imports from ident or select nodes.
31-
* @param importGiven true if this is a delegate import
31+
* @param importGiven true if this is a given import
3232
* @param isRootImport true if this is one of the implicit imports of scala, java.lang,
3333
* scala.Predef or dotty.DottyPredef in the start context, false otherwise.
3434
*/

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

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

950950
def whyNoForwarder(mbr: SingleDenotation): String = {
951951
val sym = mbr.symbol
952-
if (sym.isOneOf(GivenOrImplicit) != exp.impliedOnly) s"is ${if (exp.impliedOnly) "not " else ""}a delegate"
952+
if (sym.isOneOf(GivenOrImplicit) != exp.impliedOnly) s"is ${if (exp.impliedOnly) "not " else ""}a given instance"
953953
else if (!sym.isAccessibleFrom(path.tpe)) "is not accessible"
954954
else if (sym.isConstructor || sym.is(ModuleClass) || sym.is(Bridge)) SKIP
955955
else if (cls.derivesFrom(sym.owner) &&

compiler/test/dotty/tools/repl/ReplCompilerTests.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ class ReplCompilerTests extends ReplTest {
129129
}
130130

131131
@Test def i5897 =
132-
fromInitialState { implicit state => run("delegate for Int = 10") }
132+
fromInitialState { implicit state => run("given as Int = 10") }
133133
.andThen { implicit state =>
134134
assertEquals(
135135
"def Int_given: Int",
@@ -151,7 +151,7 @@ class ReplCompilerTests extends ReplTest {
151151
| def (x: T) > (y: T) = compare(x, y) > 0
152152
|}
153153
|
154-
|delegate IntOrd for Ord[Int] {
154+
|given IntOrd as Ord[Int] {
155155
| def compare(x: Int, y: Int) =
156156
| if (x < y) -1 else if (x > y) +1 else 0
157157
|}

library/src/scala/Eql.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ object Eql {
1616
object derived extends Eql[Any, Any]
1717

1818
/** A fall-back instance to compare values of any types.
19-
* Even though this method is not declared a delegate, the compiler will
19+
* Even though this method is not declared as given, the compiler will
2020
* synthesize implicit arguments as solutions to `Eql[T, U]` queries if
2121
* the rules of multiversal equality require it.
2222
*/

library/src/scala/quoted/Liftable.scala

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ trait Liftable[T] {
1717
*/
1818
object Liftable {
1919

20-
delegate Liftable_Boolean_delegate for Liftable[Boolean] = new PrimitiveLiftable
21-
delegate Liftable_Byte_delegate for Liftable[Byte] = new PrimitiveLiftable
22-
delegate Liftable_Short_delegate for Liftable[Short] = new PrimitiveLiftable
23-
delegate Liftable_Int_delegate for Liftable[Int] = new PrimitiveLiftable
24-
delegate Liftable_Long_delegate for Liftable[Long] = new PrimitiveLiftable
25-
delegate Liftable_Float_delegate for Liftable[Float] = new PrimitiveLiftable
26-
delegate Liftable_Double_delegate for Liftable[Double] = new PrimitiveLiftable
27-
delegate Liftable_Char_delegate for Liftable[Char] = new PrimitiveLiftable
28-
delegate Liftable_String_delegate for Liftable[String] = new PrimitiveLiftable
20+
given Liftable_Boolean_delegate as Liftable[Boolean] = new PrimitiveLiftable
21+
given Liftable_Byte_delegate as Liftable[Byte] = new PrimitiveLiftable
22+
given Liftable_Short_delegate as Liftable[Short] = new PrimitiveLiftable
23+
given Liftable_Int_delegate as Liftable[Int] = new PrimitiveLiftable
24+
given Liftable_Long_delegate as Liftable[Long] = new PrimitiveLiftable
25+
given Liftable_Float_delegate as Liftable[Float] = new PrimitiveLiftable
26+
given Liftable_Double_delegate as Liftable[Double] = new PrimitiveLiftable
27+
given Liftable_Char_delegate as Liftable[Char] = new PrimitiveLiftable
28+
given Liftable_String_delegate as Liftable[String] = new PrimitiveLiftable
2929

3030
private class PrimitiveLiftable[T <: Unit | Null | Int | Boolean | Byte | Short | Int | Long | Float | Double | Char | String] extends Liftable[T] {
3131
/** Lift a primitive value `n` into `'{ n }` */

library/src/scala/quoted/Type.scala

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ package quoted {
1717

1818
/** Some basic type tags, currently incomplete */
1919
object Type {
20-
delegate UnitTag for Type[Unit] = new TaggedType[Unit]
21-
delegate BooleanTag for Type[Boolean] = new TaggedType[Boolean]
22-
delegate ByteTag for Type[Byte] = new TaggedType[Byte]
23-
delegate CharTag for Type[Char] = new TaggedType[Char]
24-
delegate ShortTag for Type[Short] = new TaggedType[Short]
25-
delegate IntTag for Type[Int] = new TaggedType[Int]
26-
delegate LongTag for Type[Long] = new TaggedType[Long]
27-
delegate FloatTag for Type[Float] = new TaggedType[Float]
28-
delegate DoubleTag for Type[Double] = new TaggedType[Double]
20+
given UnitTag as Type[Unit] = new TaggedType[Unit]
21+
given BooleanTag as Type[Boolean] = new TaggedType[Boolean]
22+
given ByteTag as Type[Byte] = new TaggedType[Byte]
23+
given CharTag as Type[Char] = new TaggedType[Char]
24+
given ShortTag as Type[Short] = new TaggedType[Short]
25+
given IntTag as Type[Int] = new TaggedType[Int]
26+
given LongTag as Type[Long] = new TaggedType[Long]
27+
given FloatTag as Type[Float] = new TaggedType[Float]
28+
given DoubleTag as Type[Double] = new TaggedType[Double]
2929
}
3030

3131
}

library/src/scala/tasty/reflect/TreeUtils.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ trait TreeUtils
286286
/** Bind the `rhs` to a `val` and use it in `body` */
287287
def let(rhs: Term)(body: Ident => Term): Term = {
288288
import scala.quoted.QuoteContext
289-
delegate for QuoteContext = new QuoteContext(this)
289+
given as QuoteContext = new QuoteContext(this)
290290
type T // TODO probably it is better to use the Sealed contruct rather than let the user create their own existential type
291291
implicit val rhsTpe: quoted.Type[T] = rhs.tpe.seal.asInstanceOf[quoted.Type[T]]
292292
val rhsExpr = rhs.seal.cast[T]

library/src/scalaShadowing/language.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ object language {
107107
* }}}
108108
*
109109
* Implicit values of other types are not affected, and neither are implicit
110-
* classes. In particular, delegates of the scala.Conversion class can be
110+
* classes. In particular, given instances of the scala.Conversion class can be
111111
* defined without having to import the language feature.
112112
*
113113
* The language import is also required to enable _uses_ of implicit conversions
@@ -119,13 +119,13 @@ object language {
119119
* class A
120120
* class B
121121
* object B {
122-
* delegate a2b for Conversion[A, B] { ... }
122+
* given a2b as Conversion[A, B] { ... }
123123
* }
124124
* object C {
125-
* delegate b2a for Conversion[B, A] { ... }
125+
* given b2a as Conversion[B, A] { ... }
126126
* }
127-
* import delegate B._
128-
* import delegate C._
127+
* import given B._
128+
* import given C._
129129
* val x: A = new B // language import required
130130
* val x: B = new A // no import necessary since a2b is co-defined with B
131131
* }}}

tests/neg-custom-args/conditionalWarnings.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
object Test {
44
@deprecated def foo = ???
55

6-
delegate for Conversion[String, Int] = _.length
6+
given as Conversion[String, Int] = _.length
77

88
foo // error
99

tests/neg-custom-args/implicit-conversions.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,25 @@ class B
33

44
object A {
55

6-
delegate for Conversion[A, B] {
6+
given as Conversion[A, B] {
77
def apply(x: A): B = ???
88
}
99

10-
delegate for Conversion[B, A] {
10+
given as Conversion[B, A] {
1111
def apply(x: B): A = ???
1212
}
1313
}
1414

1515
class C
1616

1717
object D {
18-
delegate for Conversion[A, C] {
18+
given as Conversion[A, C] {
1919
def apply(x: A): C = ???
2020
}
2121
}
2222

2323
object Test {
24-
import delegate D._
24+
import given D._
2525

2626
val x1: A = new B
2727
val x2: B = new A // error under -Xfatal-warnings -feature

tests/neg/cannot-reduce-delegate-match.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ object Test {
66
}
77

88
{
9-
delegate for Int = 9
9+
given as Int = 9
1010
bar()
1111
}
1212

tests/neg/derive-eq.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
case class One() derives Eql
33
case class Two() derives Eql
44

5-
delegate for Eql[One, Two] = Eql.derived
5+
given as Eql[One, Two] = Eql.derived
66

77
enum Lst[T] derives Eql {
88
case Cons(x: T, xs: Lst[T])

tests/neg/exports.check

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111
25 | export printUnit.bitmap // error: no eligible member
1212
| ^^^^^^
1313
| no eligible member bitmap at this.printUnit
14-
| this.printUnit.bitmap cannot be exported because it is a delegate
15-
-- Error: tests/neg/exports.scala:26:30 --------------------------------------------------------------------------------
16-
26 | export delegate printUnit.status // error: no eligible member
17-
| ^^^^^^
18-
| no eligible member status at this.printUnit
19-
| this.printUnit.status cannot be exported because it is not a delegate
14+
| this.printUnit.bitmap cannot be exported because it is a given instance
15+
-- Error: tests/neg/exports.scala:26:27 --------------------------------------------------------------------------------
16+
26 | export given printUnit.status // error: no eligible member
17+
| ^^^^^^
18+
| no eligible member status at this.printUnit
19+
| this.printUnit.status cannot be exported because it is not a given instance
2020
-- [E120] Duplicate Symbol Error: tests/neg/exports.scala:23:33 --------------------------------------------------------
2121
23 | export printUnit.{stat => _, _} // error: double definition
2222
| ^

tests/neg/exports.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
type PrinterType
66
def print(bits: BitMap): Unit = ???
77
def status: List[String] = ???
8-
delegate bitmap for BitMap
8+
given bitmap as BitMap
99
}
1010

1111
class Scanner {
@@ -23,7 +23,7 @@
2323
export printUnit.{stat => _, _} // error: double definition
2424
export scanUnit._ // error: double definition
2525
export printUnit.bitmap // error: no eligible member
26-
export delegate printUnit.status // error: no eligible member
26+
export given printUnit.status // error: no eligible member
2727

2828
def status: List[String] = printUnit.status ++ scanUnit.status
2929
}

tests/neg/extmethod-overload.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
object Test {
2-
delegate A {
2+
given A {
33
def (x: Int) |+| (y: Int) = x + y
44
}
5-
delegate B {
5+
given B {
66
def (x: Int) |+| (y: String) = x + y.length
77
}
88
assert((1 |+| 2) == 3) // error ambiguous

tests/neg/i5455.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ object Library {
1111
def toInt(n: Nat): Int = n
1212

1313
}
14-
delegate NatOps {
14+
given NatOps {
1515
def (x: Nat) * (y: Nat): Nat = x * y
1616
def (x: Nat) toInt: Int = x
1717
}

tests/neg/implicit-params.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ object Test {
1111

1212
def h(x: Int) given () = x // error
1313

14-
delegate C for C(11)
15-
delegate D for D(11)
14+
given C as C(11)
15+
given D as D(11)
1616

1717
f(1)
1818
f(1) given C

tests/neg/implied-for.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ class B extends T
33
class C extends T
44

55
object A {
6-
delegate b for B
7-
delegate c for C
6+
given b as B
7+
given c as C
88
}
99

1010
object Test extends App {
1111
import A._
12-
import delegate A.{for B}
12+
import given A.{for B}
1313

1414
val x: B = b // OK
1515
println(c) // error: not found

tests/neg/import-implied.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
class TC
22
object A {
3-
delegate tc for TC
3+
given tc as TC
44
def foo given TC = ()
55
}
66
object B {
@@ -11,19 +11,19 @@ object B {
1111
}
1212
object C {
1313
import A._
14-
import delegate A.tc
14+
import given A.tc
1515
foo // ok
1616
foo given tc // ok
1717
}
1818
object D {
1919
import A.foo
20-
import delegate A._
20+
import given A._
2121
foo // ok
2222
foo given tc // ok
2323
}
2424
object E {
2525
import A._
26-
import delegate A._
26+
import given A._
2727
foo // ok
2828
foo given tc // ok
2929
}

tests/neg/machine-state-encoding-with-implicit-match.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ final class Off extends State
77
@implicitNotFound("State must be Off")
88
class IsOff[S <: State]
99
object IsOff {
10-
delegate isOff for IsOff[Off] = new IsOff[Off]
10+
given isOff as IsOff[Off] = new IsOff[Off]
1111
}
1212

1313
@implicitNotFound("State must be On")
1414
class IsOn[S <: State]
1515
object IsOn {
16-
delegate isOn for IsOn[On] = new IsOn[On]
16+
given isOn as IsOn[On] = new IsOn[On]
1717
}
1818

1919
class Machine[S <: State] {

tests/neg/overloading-specifity.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ object Generic {
1212

1313
object Test extends App {
1414
trait Context
15-
//delegate ctx for Context
15+
//given ctx as Context
1616

1717
object a {
1818
def foo[T](implicit gen: Generic): Show[T] = new Show[T](1)

tests/new/test.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ trait T {
44

55
object Test0 {
66
trait A[T]
7-
delegate a[T] for A[T]
7+
given a[T] as A[T]
88

99
class B[T]
10-
delegate b[T] for B[T]
10+
given b[T] as B[T]
1111
}
1212

1313
class C extends T

tests/pos-macros/i6803b/Macro_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ object AsObject {
88
final class LineNo(val lineNo: Int)
99
object LineNo {
1010
def unsafe(i: Int): LineNo = new LineNo(i)
11-
inline delegate x for LineNo = ${impl}
11+
inline given x as LineNo = ${impl}
1212
private def impl given (qctx: QuoteContext): Expr[LineNo] = {
1313
import qctx.tasty._
1414
'{unsafe(${rootPosition.startLine})}

tests/pos/combine.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
trait Semigroup[A] {
22
def (x: A) combine (y: A): A
33
}
4-
delegate for Semigroup[Int] = ???
5-
delegate [A, B] for Semigroup[(A, B)] given Semigroup[A], Semigroup[B] = ???
4+
given as Semigroup[Int] = ???
5+
given [A, B] as Semigroup[(A, B)] given Semigroup[A], Semigroup[B] = ???
66
object Test extends App {
77
((1, 1)) combine ((2, 2)) // doesn't compile
88
((1, 1): (Int, Int)) combine (2, 2) // compiles

tests/pos/derive-eq.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
case class One() derives Eql
33
case class Two() derives Eql
44

5-
delegate for Eql[One, Two] = Eql.derived
5+
given as Eql[One, Two] = Eql.derived
66

77
enum Lst[T] derives Eql {
88
case Cons(x: T, xs: Lst[T])

0 commit comments

Comments
 (0)