Skip to content

Commit be138ad

Browse files
committed
Make sure that toFunctionType deos not have a method type as return type
Without this change we got types like `Int => (n: Int): Int`, now we get `Int => Int => Int`. The first type happened to work fine but is not consistent.
1 parent 761614c commit be138ad

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1442,9 +1442,13 @@ object Types {
14421442
val formals1 = if (dropLast == 0) mt.paramInfos else mt.paramInfos dropRight dropLast
14431443
val isImplicit = mt.isImplicitMethod && !ctx.erasedTypes
14441444
val isErased = mt.isErasedMethod && !ctx.erasedTypes
1445+
val result1 = mt.nonDependentResultApprox match {
1446+
case res: MethodType => res.toFunctionType()
1447+
case res => res
1448+
}
14451449
val funType = defn.FunctionOf(
14461450
formals1 mapConserve (_.underlyingIfRepeated(mt.isJavaMethod)),
1447-
mt.nonDependentResultApprox, isImplicit, isErased)
1451+
result1, isImplicit, isErased)
14481452
if (mt.isResultDependent) RefinedType(funType, nme.apply, mt)
14491453
else funType
14501454
}

compiler/src/dotty/tools/dotc/tastyreflect/QuotedOpsImpl.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import dotty.tools.dotc.core.Flags._
66
import dotty.tools.dotc.core.Symbols.defn
77
import dotty.tools.dotc.core.StdNames.nme
88
import dotty.tools.dotc.core.quoted.PickledQuotes
9-
import dotty.tools.dotc.core.Types.MethodType
9+
import dotty.tools.dotc.core.Types
1010

1111
trait QuotedOpsImpl extends scala.tasty.reflect.QuotedOps with CoreImpl {
1212

@@ -25,12 +25,12 @@ trait QuotedOpsImpl extends scala.tasty.reflect.QuotedOps with CoreImpl {
2525
val expectedType = QuotedTypeDeco(implicitly[scala.quoted.Type[T]]).unseal.tpe
2626

2727
def etaExpand(term: Term): Term = term.tpe.widen match {
28-
case mtpe: MethodType =>
28+
case mtpe: Types.MethodType if !mtpe.isParamDependent =>
2929
val closureResType = mtpe.resType match {
30-
case t: MethodType => t.toFunctionType()
30+
case t: Types.MethodType => t.toFunctionType()
3131
case t => t
3232
}
33-
val closureTpe = MethodType(mtpe.paramNames, mtpe.paramInfos, closureResType)
33+
val closureTpe = Types.MethodType(mtpe.paramNames, mtpe.paramInfos, closureResType)
3434
val closureMethod = ctx.newSymbol(ctx.owner, nme.ANON_FUN, Synthetic | Method, closureTpe)
3535
tpd.Closure(closureMethod, tss => etaExpand(new tpd.TreeOps(term).appliedToArgs(tss.head)))
3636
case _ => term

tests/run/tasty-seal-method/quoted_2.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,17 @@ object Test {
99
assert(zeroLastArgs(f1(2)) == 1)
1010
assert(zeroLastArgs(f2(2, 3)) == 2)
1111
assert(zeroLastArgs(f3(2)(4, 5)) == 5)
12+
assert(zeroLastArgs(f4(2, 3)(4, 5)) == 9)
13+
assert(zeroLastArgs(f6(2, 3)(4, 5)(6, 7)) == 20)
1214

1315
assert(zeroAllArgs(-1) == -1)
1416
assert(zeroAllArgs(f) == 41)
1517
assert(zeroAllArgs(f0()) == 42)
1618
assert(zeroAllArgs(f1(2)) == 1)
1719
assert(zeroAllArgs(f2(2, 3)) == 2)
1820
assert(zeroAllArgs(f3(2)(4, 5)) == 3)
21+
assert(zeroAllArgs(f4(2, 3)(4, 5)) == 4)
22+
assert(zeroAllArgs(f6(2, 3)(4, 5)(6, 7)) == 6)
1923
}
2024

2125
def f: Int = 41
@@ -24,5 +28,6 @@ object Test {
2428
def f2(i: Int, j: Int): Int = 2 + i + j
2529
def f3(i: Int)(j: Int, k: Int): Int = 3 + i + j
2630
def f4(i: Int, j: Int)(k: Int, l: Int): Int = 4 + i + j + k + l
31+
def f6(i: Int, j: Int)(k: Int, l: Int)(m: Int, n: Int): Int = 6 + i + j + k + l + m + n
2732

2833
}

0 commit comments

Comments
 (0)