Skip to content

Commit a59a626

Browse files
committed
Simplify use of toFunctionType
Make `isJava` by default false. [Cherry-picked eb8fba4][modified]
1 parent 83729ec commit a59a626

File tree

5 files changed

+10
-9
lines changed

5 files changed

+10
-9
lines changed

compiler/src/dotty/tools/dotc/cc/CheckCaptures.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ class CheckCaptures extends Recheck, SymTransformer:
630630

631631
private def toDepFun(args: List[Type], resultType: Type, isContextual: Boolean)(using Context): Type =
632632
MethodType.companion(isContextual = isContextual)(args, resultType)
633-
.toFunctionType(isJava = false, alwaysDependent = true)
633+
.toFunctionType(alwaysDependent = true)
634634

635635
/** Turn `expected` into a dependent function when `actual` is dependent. */
636636
private def alignDependentFunction(expected: Type, actual: Type)(using Context): Type =
@@ -774,7 +774,7 @@ class CheckCaptures extends Recheck, SymTransformer:
774774
adaptFun(actual, rinfo.paramInfos, rinfo.resType, expected, covariant, insertBox,
775775
(aargs1, ares1) =>
776776
rinfo.derivedLambdaType(paramInfos = aargs1, resType = ares1)
777-
.toFunctionType(isJava = false, alwaysDependent = true))
777+
.toFunctionType(alwaysDependent = true))
778778
case actual: MethodType =>
779779
adaptFun(actual, actual.paramInfos, actual.resType, expected, covariant, insertBox,
780780
(aargs1, ares1) =>

compiler/src/dotty/tools/dotc/cc/Setup.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ extends tpd.TreeTraverser:
4040
MethodType.companion(
4141
isContextual = defn.isContextFunctionClass(tycon.classSymbol),
4242
)(argTypes, resType)
43-
.toFunctionType(isJava = false, alwaysDependent = true)
43+
.toFunctionType(alwaysDependent = true)
4444

4545
/** If `tp` is an unboxed capturing type or a function returning an unboxed capturing type,
4646
* convert it to be boxed.
@@ -57,7 +57,7 @@ extends tpd.TreeTraverser:
5757
case tp1 @ RefinedType(_, _, rinfo: MethodType) if defn.isFunctionType(tp1) =>
5858
val boxedRinfo = recur(rinfo)
5959
if boxedRinfo eq rinfo then tp
60-
else boxedRinfo.toFunctionType(isJava = false, alwaysDependent = true)
60+
else boxedRinfo.toFunctionType(alwaysDependent = true)
6161
case tp1: MethodOrPoly =>
6262
val res = tp1.resType
6363
val boxedRes = recur(res)
@@ -233,7 +233,7 @@ extends tpd.TreeTraverser:
233233
tp.derivedAppliedType(tycon1, args.mapConserve(arg => this(arg)))
234234
case tp @ RefinedType(core, rname, rinfo: MethodType) if defn.isFunctionType(tp) =>
235235
val rinfo1 = apply(rinfo)
236-
if rinfo1 ne rinfo then rinfo1.toFunctionType(isJava = false, alwaysDependent = true)
236+
if rinfo1 ne rinfo then rinfo1.toFunctionType(alwaysDependent = true)
237237
else tp
238238
case tp: MethodType =>
239239
tp.derivedLambdaType(

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1858,11 +1858,12 @@ object Types {
18581858

18591859
/** Turn type into a function type.
18601860
* @pre this is a method type without parameter dependencies.
1861+
* @param isJava translate repeated params as as java `Array`s?
18611862
* @param dropLast the number of trailing parameters that should be dropped
18621863
* when forming the function type.
18631864
* @param alwaysDependent if true, always create a dependent function type.
18641865
*/
1865-
def toFunctionType(isJava: Boolean, dropLast: Int = 0, alwaysDependent: Boolean = false)(using Context): Type = this match {
1866+
def toFunctionType(isJava: Boolean = false, dropLast: Int = 0, alwaysDependent: Boolean = false)(using Context): Type = this match {
18661867
case mt: MethodType if !mt.isParamDependent && !mt.hasErasedParams =>
18671868
val formals1 = if (dropLast == 0) mt.paramInfos else mt.paramInfos dropRight dropLast
18681869
val isContextual = mt.isContextualMethod && !ctx.erasedTypes

compiler/src/dotty/tools/dotc/transform/Recheck.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ abstract class Recheck extends Phase, SymTransformer:
324324

325325
def recheckClosure(tree: Closure, pt: Type)(using Context): Type =
326326
if tree.tpt.isEmpty then
327-
tree.meth.tpe.widen.toFunctionType(tree.meth.symbol.is(JavaDefined))
327+
tree.meth.tpe.widen.toFunctionType(isJava = tree.meth.symbol.is(JavaDefined))
328328
else
329329
recheck(tree.tpt)
330330

compiler/src/dotty/tools/dotc/transform/Splicing.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ class Splicing extends MacroTransform:
197197
if tree.isTerm then
198198
if isCaptured(tree.symbol) then
199199
val tpe = tree.tpe.widenTermRefExpr match {
200-
case tpw: MethodicType => tpw.toFunctionType(isJava = false)
200+
case tpw: MethodicType => tpw.toFunctionType()
201201
case tpw => tpw
202202
}
203203
spliced(tpe)(capturedTerm(tree))
@@ -291,7 +291,7 @@ class Splicing extends MacroTransform:
291291

292292
private def capturedTerm(tree: Tree)(using Context): Tree =
293293
val tpe = tree.tpe.widenTermRefExpr match
294-
case tpw: MethodicType => tpw.toFunctionType(isJava = false)
294+
case tpw: MethodicType => tpw.toFunctionType()
295295
case tpw => tpw
296296
capturedTerm(tree, tpe)
297297

0 commit comments

Comments
 (0)