Skip to content

Commit d217690

Browse files
authored
Merge pull request #7670 from dotty-staging/change-extended
Fix #7669: Implement `extended with` syntax for extension methods.
2 parents c900e88 + f41f4b8 commit d217690

Some content is hidden

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

52 files changed

+328
-298
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ object Contexts {
593593
def setDebug: this.type = setSetting(base.settings.Ydebug, true)
594594
}
595595

596-
given ops: (c: Context)
596+
given ops: extension (c: Context) with
597597
def addNotNullInfo(info: NotNullInfo) =
598598
c.withNotNullInfos(c.notNullInfos.extendWith(info))
599599

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

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,16 @@ object Flags {
2222

2323
type Flag = opaques.Flag
2424

25-
given /*FlagOps*/ {
25+
given extension (x: FlagSet) with
2626

27-
def (x: FlagSet) bits: Long = opaques.toBits(x)
27+
def bits: Long = opaques.toBits(x)
2828

2929
/** The union of the given flag sets.
3030
* Combining two FlagSets with `|` will give a FlagSet
3131
* that has the intersection of the applicability to terms/types
3232
* of the two flag sets. It is checked that the intersection is not empty.
3333
*/
34-
def (x: FlagSet) | (y: FlagSet): FlagSet =
34+
def | (y: FlagSet): FlagSet =
3535
if (x.bits == 0) y
3636
else if (y.bits == 0) x
3737
else {
@@ -42,48 +42,48 @@ object Flags {
4242
}
4343

4444
/** The intersection of the given flag sets */
45-
def (x: FlagSet) & (y: FlagSet): FlagSet = FlagSet(x.bits & y.bits)
45+
def & (y: FlagSet): FlagSet = FlagSet(x.bits & y.bits)
4646

4747
/** The intersection of a flag set with the complement of another flag set */
48-
def (x: FlagSet) &~ (y: FlagSet): FlagSet = {
48+
def &~ (y: FlagSet): FlagSet = {
4949
val tbits = x.bits & KINDFLAGS
5050
if ((tbits & y.bits) == 0) x
5151
else FlagSet(tbits | ((x.bits & ~y.bits) & ~KINDFLAGS))
5252
}
5353

54-
def (x: FlagSet) ^ (y: FlagSet) =
54+
def ^ (y: FlagSet) =
5555
FlagSet((x.bits | y.bits) & KINDFLAGS | (x.bits ^ y.bits) & ~KINDFLAGS)
5656

5757
/** Does the given flag set contain the given flag?
5858
* This means that both the kind flags and the carrier bits have non-empty intersection.
5959
*/
60-
def (x: FlagSet) is (flag: Flag): Boolean = {
60+
def is (flag: Flag): Boolean = {
6161
val fs = x.bits & flag.bits
6262
(fs & KINDFLAGS) != 0 && (fs & ~KINDFLAGS) != 0
6363
}
6464

6565
/** Does the given flag set contain the given flag
6666
* and at the same time contain none of the flags in the `butNot` set?
6767
*/
68-
def (x: FlagSet) is (flag: Flag, butNot: FlagSet): Boolean = x.is(flag) && !x.isOneOf(butNot)
68+
def is (flag: Flag, butNot: FlagSet): Boolean = x.is(flag) && !x.isOneOf(butNot)
6969

7070
/** Does the given flag set have a non-empty intersection with another flag set?
7171
* This means that both the kind flags and the carrier bits have non-empty intersection.
7272
*/
73-
def (x: FlagSet) isOneOf (flags: FlagSet): Boolean = {
73+
def isOneOf (flags: FlagSet): Boolean = {
7474
val fs = x.bits & flags.bits
7575
(fs & KINDFLAGS) != 0 && (fs & ~KINDFLAGS) != 0
7676
}
7777

7878
/** Does the given flag set have a non-empty intersection with another flag set,
7979
* and at the same time contain none of the flags in the `butNot` set?
8080
*/
81-
def (x: FlagSet) isOneOf (flags: FlagSet, butNot: FlagSet): Boolean = x.isOneOf(flags) && !x.isOneOf(butNot)
81+
def isOneOf (flags: FlagSet, butNot: FlagSet): Boolean = x.isOneOf(flags) && !x.isOneOf(butNot)
8282

8383
/** Does a given flag set have all of the flags of another flag set?
8484
* Pre: The intersection of the term/type flags of both sets must be non-empty.
8585
*/
86-
def (x: FlagSet) isAllOf (flags: FlagSet): Boolean = {
86+
def isAllOf (flags: FlagSet): Boolean = {
8787
val fs = x.bits & flags.bits
8888
((fs & KINDFLAGS) != 0 || flags.bits == 0) &&
8989
(fs >>> TYPESHIFT) == (flags.bits >>> TYPESHIFT)
@@ -93,36 +93,36 @@ object Flags {
9393
* and at the same time contain none of the flags in the `butNot` set?
9494
* Pre: The intersection of the term/type flags of both sets must be non-empty.
9595
*/
96-
def (x: FlagSet) isAllOf (flags: FlagSet, butNot: FlagSet): Boolean = x.isAllOf(flags) && !x.isOneOf(butNot)
96+
def isAllOf (flags: FlagSet, butNot: FlagSet): Boolean = x.isAllOf(flags) && !x.isOneOf(butNot)
9797

98-
def (x: FlagSet) isEmpty: Boolean = (x.bits & ~KINDFLAGS) == 0
98+
def isEmpty: Boolean = (x.bits & ~KINDFLAGS) == 0
9999

100100
/** Is a given flag set a subset of another flag set? */
101-
def (x: FlagSet) <= (y: FlagSet): Boolean = (x.bits & y.bits) == x.bits
101+
def <= (y: FlagSet): Boolean = (x.bits & y.bits) == x.bits
102102

103103
/** Does the given flag set apply to terms? */
104-
def (x: FlagSet) isTermFlags: Boolean = (x.bits & TERMS) != 0
104+
def isTermFlags: Boolean = (x.bits & TERMS) != 0
105105

106106
/** Does the given flag set apply to terms? */
107-
def (x: FlagSet) isTypeFlags: Boolean = (x.bits & TYPES) != 0
107+
def isTypeFlags: Boolean = (x.bits & TYPES) != 0
108108

109109
/** The given flag set with all flags transposed to be type flags */
110-
def (x: FlagSet) toTypeFlags: FlagSet = if (x.bits == 0) x else FlagSet(x.bits & ~KINDFLAGS | TYPES)
110+
def toTypeFlags: FlagSet = if (x.bits == 0) x else FlagSet(x.bits & ~KINDFLAGS | TYPES)
111111

112112
/** The given flag set with all flags transposed to be term flags */
113-
def (x: FlagSet) toTermFlags: FlagSet = if (x.bits == 0) x else FlagSet(x.bits & ~KINDFLAGS | TERMS)
113+
def toTermFlags: FlagSet = if (x.bits == 0) x else FlagSet(x.bits & ~KINDFLAGS | TERMS)
114114

115115
/** The given flag set with all flags transposed to be common flags */
116-
def (x: FlagSet) toCommonFlags: FlagSet = if (x.bits == 0) x else FlagSet(x.bits | KINDFLAGS)
116+
def toCommonFlags: FlagSet = if (x.bits == 0) x else FlagSet(x.bits | KINDFLAGS)
117117

118118
/** The number of non-kind flags in the given flag set */
119-
def (x: FlagSet) numFlags: Int = java.lang.Long.bitCount(x.bits & ~KINDFLAGS)
119+
def numFlags: Int = java.lang.Long.bitCount(x.bits & ~KINDFLAGS)
120120

121121
/** The lowest non-kind bit set in the given flag set */
122-
def (x: FlagSet) firstBit: Int = java.lang.Long.numberOfTrailingZeros(x.bits & ~KINDFLAGS)
122+
def firstBit: Int = java.lang.Long.numberOfTrailingZeros(x.bits & ~KINDFLAGS)
123123

124124
/** The list of non-empty names of flags with given index idx that are set in the given flag set */
125-
private def (x: FlagSet) flagString(idx: Int): List[String] =
125+
private def flagString(idx: Int): List[String] =
126126
if ((x.bits & (1L << idx)) == 0) Nil
127127
else {
128128
def halfString(kind: Int) =
@@ -134,7 +134,7 @@ object Flags {
134134
}
135135

136136
/** The list of non-empty names of flags that are set in teh given flag set */
137-
def (x: FlagSet) flagStrings(privateWithin: String): Seq[String] = {
137+
def flagStrings(privateWithin: String): Seq[String] = {
138138
var rawStrings = (2 to MaxFlag).flatMap(x.flagString(_)) // DOTTY problem: cannot drop with (_)
139139
if (!privateWithin.isEmpty && !x.is(Protected))
140140
rawStrings = rawStrings :+ "private"
@@ -149,8 +149,8 @@ object Flags {
149149
}
150150

151151
/** The string representation of the given flag set */
152-
def (x: FlagSet) flagsString: String = x.flagStrings("").mkString(" ")
153-
}
152+
def flagsString: String = x.flagStrings("").mkString(" ")
153+
end given
154154

155155
def termFlagSet(x: Long) = FlagSet(TERMS | x)
156156

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,7 @@ object StdNames {
435435
val eval: N = "eval"
436436
val eqlAny: N = "eqlAny"
437437
val ex: N = "ex"
438+
val extended: N = "extended"
438439
val extension: N = "extension"
439440
val experimental: N = "experimental"
440441
val f: N = "f"

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2006,7 +2006,7 @@ object Types {
20062006

20072007
val idx = typeParams.indexOf(param)
20082008

2009-
if (idx < args.length) {
2009+
if (0 <= idx && idx < args.length) {
20102010
val argInfo = args(idx) match {
20112011
case arg: TypeBounds =>
20122012
val v = param.paramVariance

0 commit comments

Comments
 (0)