Skip to content

Commit d54c611

Browse files
committed
Address review comments
1 parent e09e1cc commit d54c611

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

compiler/src/dotty/tools/dotc/ast/Desugar.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -914,7 +914,7 @@ object desugar {
914914
ctx.error(em"No extension method $allowed", mdef.sourcePos)
915915
mdef
916916
}
917-
else cpy.DefDef(mdef)(tparams = tparams ++ mdef.tparams, vparamss = leadingParams :: Nil)
917+
else cpy.DefDef(mdef)(tparams = tparams ++ mdef.tparams, vparamss = leadingParams :: mdef.vparamss)
918918
.withFlags(Extension)
919919
case mdef: Import =>
920920
mdef

tests/neg/extension-methods.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,9 @@ object Test {
1010
"".l2 // error
1111
1.l1 // error
1212

13-
13+
given [T](xs: List[T]) {
14+
def (x: Int) f1: T = ??? // error: No extension method allowed here, since collective parameters are given
15+
def f2[T]: T = ??? // error: T is already defined as type T
16+
def f3(xs: List[T]) = ??? // error: xs is already defined as value xs
17+
}
1418
}

tests/run/extmethods2.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,14 @@ object Test extends App {
1919
given ListOps[T](xs: List[T]) {
2020
def second: T = xs.tail.head
2121
def third: T = xs.tail.tail.head
22+
def concat(ys: List[T]) = xs ++ ys
23+
def zipp[U](ys: List[U]): List[(T, U)] = xs.zip(ys)
2224
}
2325
given (xs: List[Int]) {
2426
def prod = (1 /: xs)(_ * _)
2527
}
28+
29+
2630
}
2731

2832
object B {
@@ -33,6 +37,9 @@ object Test extends App {
3337
assert(A.ListOps.second[Int](xs) == 2)
3438
assert(A.ListOps.third(xs) == 3)
3539
assert(xs.prod == 6)
40+
assert(xs.concat(xs).length == 6)
41+
assert(xs.zipp(xs).map(_ + _).prod == 36)
42+
assert(xs.zipp[Int, Int](xs).map(_ + _).prod == 36)
3643
}
3744
}
3845

0 commit comments

Comments
 (0)