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)

0 commit comments

Comments
 (0)