Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e7a4a4c

Browse files
committed
Check for uncurried signature in expansion
1 parent 5c584e9 commit e7a4a4c

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/compiler/scala/tools/nsc/transform/UnCurry.scala

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,8 +347,15 @@ abstract class UnCurry extends InfoTransform
347347
val isVarargs = isVarArgsList(params)
348348
val args1 = if (isVarargs) transformVarargs(params.last.info.typeArgs.head.widen) else args
349349

350+
val params0 = fun.info.paramss.last.iterator
351+
350352
map2Conserve(args1, params) { (arg, param) =>
351-
if (!isByNameParamType(param.info)) arg
353+
val param0 = if (params0.hasNext) params0.next() else NoSymbol
354+
if (!isByNameParamType(param.info)) {
355+
if (param0 != NoSymbol && isByNameParamType(param0.info)) // pass 2, sig is uncurried in expansion
356+
byNameArgs += arg
357+
arg
358+
}
352359
else if (isByNameRef(arg)) {
353360
// thunk does not need to be forced because it's a reference to a by-name arg passed to a by-name param
354361
byNameArgs += arg

test/files/run/t11237.scala

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
trait Semigroup[F] { self =>
3+
def append(f1: F, f2: => F): F
4+
val z = 10
5+
}
6+
7+
case class Box(i: Int)
8+
9+
class R extends Runnable {
10+
def run() = {
11+
val boxSemigroup: Semigroup[Box] = (x1, x2) => Box(x1.i + x2.i)
12+
// disallowed, by-name must be inferred
13+
//val boxSemigroup: Semigroup[Box] = (x1: Box, x2: Box) => Box(Math.max(x1.i, x2.i))
14+
assert(boxSemigroup.append(Box(1), Box(2)) == Box(3))
15+
}
16+
}
17+
18+
object Test extends App {
19+
new R().run()
20+
}

0 commit comments

Comments
 (0)