Skip to content

Commit 0933b9c

Browse files
committed
Disallow old anonymous extension syntax
Disallow the previous syntax ``` given (x: T) ... extension methods ``` Require instead ``` given extension (x: T) ... extension methods ``` This avoids the confusion with given instances for types in parentheses and makes i7515.scala compile. To allow building with 0.20rc1, we allow the old extension syntax if it comes with a name. E.g. the following is still allowed, but will be dropped once we have bootstrapped with this commit present. ``` given ops: (x: T) ... extension methods ```
1 parent 05a72c5 commit 0933b9c

27 files changed

+109
-108
lines changed

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

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

599-
given (c: Context)
599+
given ops: (c: Context)
600600
def addNotNullInfo(info: NotNullInfo) =
601601
c.withNotNullInfos(c.notNullInfos.extendWith(info))
602602

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ class Definitions {
9292
* ImplicitFunctionN traits follow this template:
9393
*
9494
* trait ImplicitFunctionN[T0,...,T{N-1}, R] extends Object {
95-
* def apply given ($x0: T0, ..., $x{N_1}: T{N-1}): R
95+
* def apply(given $x0: T0, ..., $x{N_1}: T{N-1}): R
9696
* }
9797
*
9898
* ErasedFunctionN traits follow this template:

compiler/src/dotty/tools/dotc/core/tasty/TastyFormat.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ Standard-Section: "ASTs" TopLevelStat*
167167
POLYtype Length result_Type NamesTypes -- A polymorphic method type `[NamesTypes]result`, used in refinements
168168
METHODtype Length result_Type NamesTypes -- A method type `(NamesTypes)result`, needed for refinements
169169
ERASEDMETHODtype Length result_Type NamesTypes -- A method type `erased (NamesTypes)result`, needed for refinements
170-
GIVENMETHODtype Length result_Type NamesTypes -- A method type `given (NamesTypes)result`, needed for refinements
170+
GIVENMETHODtype Length result_Type NamesTypes -- A method type `(given NamesTypes)result`, needed for refinements
171171
ERASEDGIVENMETHODtype Length result_Type NamesTypes -- A method type `given(erased NamesTypes)result`, needed for refinements
172172
IMPLICITMETHODtype Length result_Type NamesTypes -- A method type `(implicit NamesTypes)result`, needed for refinements
173173
// TODO: remove ERASEDIMPLICITMETHODtype

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3442,7 +3442,7 @@ object Parsers {
34423442
if isExtension then
34433443
checkExtensionParams(paramsStart, vparamss)
34443444

3445-
parseParams(isExtension = !hasGivenSig)
3445+
parseParams(isExtension = false)
34463446
val parents =
34473447
if in.token == COLON then
34483448
in.nextToken()

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ object Nullables with
137137
// TODO: Add constant pattern if the constant type is not nullable
138138
case _ => false
139139

140-
given (infos: List[NotNullInfo])
140+
given notNullInfoOps: (infos: List[NotNullInfo])
141141

142142
/** Do the current not-null infos imply that `ref` is not null?
143143
* Not-null infos are as a history where earlier assertions and retractions replace
@@ -161,7 +161,7 @@ object Nullables with
161161
then infos
162162
else info :: infos
163163

164-
given (tree: Tree)
164+
given treeOps: (tree: Tree)
165165

166166
/* The `tree` with added nullability attachment */
167167
def withNotNullInfo(info: NotNullInfo): tree.type =
@@ -251,7 +251,7 @@ object Nullables with
251251
tree.computeNullable()
252252
}.traverse(tree)
253253

254-
given (tree: Assign)
254+
given assignOps: (tree: Assign)
255255
def computeAssignNullable()(given Context): tree.type = tree.lhs match
256256
case TrackedRef(ref) =>
257257
tree.withNotNullInfo(NotNullInfo(Set(), Set(ref))) // TODO: refine with nullability type info

docs/docs/reference/changed-features/numeric-literals.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ no code that can be executed at runtime. That's why we define an intermediary cl
201201
method in the `FromDigits` given instance. That method is defined in terms of a macro
202202
implementation method `fromDigitsImpl`. Here is its definition:
203203
```scala
204-
private def fromDigitsImpl(digits: Expr[String]) given (ctx: QuoteContext): Expr[BigFloat] =
204+
private def fromDigitsImpl(digits: Expr[String])(given ctx: QuoteContext): Expr[BigFloat] =
205205
digits match {
206206
case Const(ds) =>
207207
try {

docs/docs/reference/contextual/relationship-implicits.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Given instances can be mapped to combinations of implicit objects, classes and i
2121
```
2222
2. Parameterized given instances are mapped to combinations of classes and implicit methods. E.g.,
2323
```scala
24-
given listOrd[T](given (ord: Ord[T]): Ord[List[T]] { ... }
24+
given listOrd[T](given ord: Ord[T]): Ord[List[T]] { ... }
2525
```
2626
maps to
2727
```scala

docs/docs/reference/metaprogramming/macros.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ quote but no splice between the parameter binding of `T` and its
170170
usage. But the code can be made phase correct by adding a binding
171171
of a `Type[T]` tag:
172172
```scala
173-
def reflect[T, U](f: Expr[T] => Expr[U]) given (t: Type[T]): Expr[T => U] =
173+
def reflect[T, U](f: Expr[T] => Expr[U])(given t: Type[T]): Expr[T => U] =
174174
'{ (x: $t) => ${ f('x) } }
175175
```
176176
In this version of `reflect`, the type of `x` is now the result of

docs/docs/reference/other-new-features/tupled-function.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ The compiler will synthesize an instance of `TupledFunction[F, G]` if:
2828
* `F` is a function type of arity `N`
2929
* `G` is a function with a single tuple argument of size `N` and it's types are equal to the arguments of `F`
3030
* The return type of `F` is equal to the return type of `G`
31-
* `F` and `G` are the same kind of function (both are `(...) => R` or both are `given (...) => R`)
31+
* `F` and `G` are the same kind of function (both are `(...) => R` or both are `(given ...) => R`)
3232
* If only one of `F` or `G` is instantiated the second one is inferred.
3333

3434
Examples
@@ -43,7 +43,7 @@ Examples
4343
* @tparam Args the tuple type with the same types as the function arguments of F
4444
* @tparam R the return type of F
4545
*/
46-
def (f: F) tupled[F, Args <: Tuple, R] given (tf: TupledFunction[F, Args => R]): Args => R = tf.tupled(f)
46+
def (f: F) tupled[F, Args <: Tuple, R](given tf: TupledFunction[F, Args => R]): Args => R = tf.tupled(f)
4747
```
4848

4949
`TupledFunction` can be used to generalize the `Function.untupled` methods to functions of any arities ([full example](https://github.com/lampepfl/dotty/blob/master/tests/run/tupled-function-untupled.scala))
@@ -58,7 +58,7 @@ def (f: F) tupled[F, Args <: Tuple, R] given (tf: TupledFunction[F, Args => R]):
5858
* @tparam Args the tuple type with the same types as the function arguments of F
5959
* @tparam R the return type of F
6060
*/
61-
def (f: Args => R) untupled[F, Args <: Tuple, R] given (tf: TupledFunction[F, Args => R]): F = tf.untupled(f)
61+
def (f: Args => R) untupled[F, Args <: Tuple, R](given tf: TupledFunction[F, Args => R]): F = tf.untupled(f)
6262
```
6363

6464
`TupledFunction` can also be used to generalize the [`Tuple1.compose`](https://github.com/lampepfl/dotty/blob/master/tests/run/tupled-function-compose.scala) and [`Tuple1.andThen`](https://github.com/lampepfl/dotty/blob/master/tests/run/tupled-function-andThen.scala) methods to compose functions of larger arities and with functions that return tuples.
@@ -72,7 +72,7 @@ def (f: Args => R) untupled[F, Args <: Tuple, R] given (tf: TupledFunction[F, Ar
7272
* @tparam GArgs the tuple type with the same types as the function arguments of G
7373
* @tparam R the return type of F
7474
*/
75-
def (f: F) compose[F, G, FArgs <: Tuple, GArgs <: Tuple, R](g: G) given (tg: TupledFunction[G, GArgs => FArgs], tf: TupledFunction[F, FArgs => R]): GArgs => R = {
75+
def (f: F) compose[F, G, FArgs <: Tuple, GArgs <: Tuple, R](g: G)(given tg: TupledFunction[G, GArgs => FArgs], tf: TupledFunction[F, FArgs => R]): GArgs => R = {
7676
(x: GArgs) => tf.tupled(f)(tg.tupled(g)(x))
7777
}
7878
```

library/src/scala/tasty/reflect/CommentOps.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package scala.tasty.reflect
22

33
trait CommentOps extends Core {
44

5-
given (self: Comment) {
5+
given CommentOps: (self: Comment) {
66

77
/** Raw comment string */
88
def raw: String = internal.Comment_raw(self)

library/src/scala/tasty/reflect/ConstantOps.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package reflect
33

44
trait ConstantOps extends Core {
55

6-
given (const: Constant) {
6+
given ConstantOps: (const: Constant) {
77
def value: Any = internal.Constant_value(const)
88
}
99

library/src/scala/tasty/reflect/ContextOps.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package reflect
33

44
trait ContextOps extends Core {
55

6-
given (self: Context) {
6+
given ContextOps: (self: Context) {
77
/** Returns the owner of the context */
88
def owner: Symbol = internal.Context_owner(self)
99

library/src/scala/tasty/reflect/FlagsOps.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package scala.tasty.reflect
22

33
trait FlagsOps extends Core {
44

5-
given (self: Flags) {
5+
given FlagsOps: (self: Flags) {
66

77
/** Is the given flag set a subset of this flag sets */
88
def is(that: Flags): Boolean = internal.Flags_is(self)(that)

library/src/scala/tasty/reflect/IdOps.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package reflect
33

44
trait IdOps extends Core {
55

6-
given (id: Id) {
6+
given IsOps: (id: Id) {
77

88
/** Position in the source code */
99
def pos(given ctx: Context): Position = internal.Id_pos(id)

library/src/scala/tasty/reflect/ImplicitsOps.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ trait ImplicitsOps extends Core {
1010
internal.matchImplicitSearchSuccess(isr)
1111
}
1212

13-
given (self: ImplicitSearchSuccess) {
13+
given successOps: (self: ImplicitSearchSuccess) {
1414
def tree(given ctx: Context): Term = internal.ImplicitSearchSuccess_tree(self)
1515
}
1616

@@ -19,7 +19,7 @@ trait ImplicitsOps extends Core {
1919
internal.matchImplicitSearchFailure(isr)
2020
}
2121

22-
given (self: ImplicitSearchFailure) {
22+
given failureOps: (self: ImplicitSearchFailure) {
2323
def explanation(given ctx: Context): String = internal.ImplicitSearchFailure_explanation(self)
2424
}
2525

library/src/scala/tasty/reflect/ImportSelectorOps.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package reflect
33

44
trait ImportSelectorOps extends Core {
55

6-
given (self: SimpleSelector) {
6+
given SimpleSelectorOps: (self: SimpleSelector) {
77
def selection(given ctx: Context): Id =
88
internal.SimpleSelector_selection(self)
99
}
@@ -13,7 +13,7 @@ trait ImportSelectorOps extends Core {
1313
internal.matchSimpleSelector(importSelector).map(_.selection)
1414
}
1515

16-
given (self: RenameSelector) {
16+
given RenameSelectorOps: (self: RenameSelector) {
1717
def from(given ctx: Context): Id =
1818
internal.RenameSelector_from(self)
1919

@@ -26,7 +26,7 @@ trait ImportSelectorOps extends Core {
2626
internal.matchRenameSelector(importSelector).map(x => (x.from, x.to))
2727
}
2828

29-
given (self: OmitSelector) {
29+
given OmitSelectorOps: (self: OmitSelector) {
3030
def omitted(given ctx: Context): Id =
3131
internal.SimpleSelector_omitted(self)
3232
}

library/src/scala/tasty/reflect/PositionOps.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package scala.tasty.reflect
22

33
trait PositionOps extends Core {
44

5-
given (pos: Position) {
5+
given PositionOps: (pos: Position) {
66

77
/** The start offset in the source file */
88
def start: Int = internal.Position_start(pos)
@@ -33,7 +33,7 @@ trait PositionOps extends Core {
3333

3434
}
3535

36-
given (sourceFile: SourceFile) {
36+
given SourceFileOps: (sourceFile: SourceFile) {
3737

3838
/** Path to this source file */
3939
def jpath: java.nio.file.Path = internal.SourceFile_jpath(sourceFile)

library/src/scala/tasty/reflect/SignatureOps.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ trait SignatureOps extends Core {
99
Some((sig.paramSigs, sig.resultSig))
1010
}
1111

12-
given (sig: Signature) {
12+
given SignatureOps: (sig: Signature) {
1313

1414
/** The signatures of the method parameters.
1515
*

library/src/scala/tasty/reflect/SymbolOps.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ trait SymbolOps extends Core { selfSymbolOps: FlagsOps =>
1414
internal.Symbol_noSymbol
1515
}
1616

17-
given (self: Symbol) {
17+
given SymbolOps: (self: Symbol) {
1818

1919
/** Owner of this symbol. The owner is the symbol in which this symbol is defined */
2020
def owner(given ctx: Context): Symbol = internal.Symbol_owner(self)

0 commit comments

Comments
 (0)