Skip to content

Commit ee92673

Browse files
committed
Simplify typedArgs code
1 parent 7356d47 commit ee92673

File tree

4 files changed

+13
-13
lines changed

4 files changed

+13
-13
lines changed

compiler/src/dotty/tools/dotc/typer/ErrorReporting.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ object ErrorReporting {
4747
case _: WildcardType | _: IgnoredProto => ""
4848
case tp => em" and expected result type $tp"
4949
}
50-
em"arguments (${tp.typedArgs.tpes}%, %)$result"
50+
em"arguments (${tp.unforcedTypedArgs.tpes}%, %)$result"
5151
case _ =>
5252
em"expected type $tp"
5353
}

compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,12 @@ object ProtoTypes {
285285
state.typedArg.size == args.length
286286
}
287287

288+
private def isUndefined(tp: Type): Boolean = tp match {
289+
case _: WildcardType => true
290+
case defn.FunctionOf(args, result, _, _) => args.exists(isUndefined) || isUndefined(result)
291+
case _ => false
292+
}
293+
288294
private def cacheTypedArg(arg: untpd.Tree, typerFn: untpd.Tree => Tree, force: Boolean)(implicit ctx: Context): Tree = {
289295
var targ = state.typedArg(arg)
290296
if (targ == null) {
@@ -317,21 +323,15 @@ object ProtoTypes {
317323

318324
/** The typed arguments. This takes any arguments already typed using
319325
* `typedArg` into account.
320-
* @param force if true try to typecheck arguments even if they are functions
321-
* with unknown parameter types - this will then cause a
322-
* "missing parameter type" error
323326
*/
324-
protected[this] def typedArgs(force: Boolean): List[Tree] =
327+
def unforcedTypedArgs: List[Tree] =
325328
if (state.typedArgs.size == args.length) state.typedArgs
326329
else {
327-
val args1 = args.mapconserve(cacheTypedArg(_, typer.typed(_), force))
328-
if (force || !args1.contains(WildcardType)) state.typedArgs = args1
330+
val args1 = args.mapconserve(cacheTypedArg(_, typer.typed(_), force = false))
331+
if (!args1.exists(arg => isUndefined(arg.tpe))) state.typedArgs = args1
329332
args1
330333
}
331334

332-
def typedArgs: List[Tree] = typedArgs(force = true)
333-
def unforcedTypedArgs: List[Tree] = typedArgs(force = false)
334-
335335
/** Type single argument and remember the unadapted result in `myTypedArg`.
336336
* used to avoid repeated typings of trees when backtracking.
337337
*/
@@ -397,7 +397,7 @@ object ProtoTypes {
397397
* [](args): resultType, where args are known to be typed
398398
*/
399399
class FunProtoTyped(args: List[tpd.Tree], resultType: Type)(typer: Typer, isContextual: Boolean)(implicit ctx: Context) extends FunProto(args, resultType)(typer, isContextual)(ctx) {
400-
override def typedArgs(force: Boolean): List[tpd.Tree] = args
400+
override def unforcedTypedArgs: List[tpd.Tree] = args
401401
override def withContext(ctx: Context): FunProtoTyped = this
402402
}
403403

tests/run/overloads.check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ ok: Funcs.foo('a') = 2
1313
ok: Funcs.foo(97) = 3
1414
ok: M1.f(3) = 11
1515
ok: M2.f(3) = 22
16-
ok: M3.f("abc", _.length) = cba
16+
ok: M3.f("abc", _.reverse) = cba
1717
ok: M3.f(2, _ + 2) = 4

tests/run/overloads.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ object overloads {
8484
// check("M1.f(" + y +")", M1.f(y), 12);
8585
// check("M2.f(" + y +")", M2.f(y), 21);
8686

87-
check("M3.f(\"abc\", _.length)", M3.f("abc", _.reverse), "cba")
87+
check("M3.f(\"abc\", _.reverse)", M3.f("abc", _.reverse), "cba")
8888
check("M3.f(2, _ + 2)", M3.f(2, _ + 2), 4)
8989

9090
}

0 commit comments

Comments
 (0)