Skip to content

Commit a09f385

Browse files
authored
Merge pull request #3974 from dotty-staging/pretypeArgs
Use WildcardType in place of a type variable in `pretypeArgs`
2 parents 5c4d7d2 + e92d890 commit a09f385

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1459,7 +1459,7 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
14591459
fn.get.isInstanceOf[untpd.Match] &&
14601460
formalsForArg.exists(_.isRef(defn.PartialFunctionClass))
14611461
val commonFormal =
1462-
if (isPartial) defn.PartialFunctionOf(commonParamTypes.head, newTypeVar(TypeBounds.empty))
1462+
if (isPartial) defn.PartialFunctionOf(commonParamTypes.head, WildcardType)
14631463
else defn.FunctionOf(commonParamTypes, WildcardType)
14641464
overload.println(i"pretype arg $arg with expected type $commonFormal")
14651465
pt.typedArg(arg, commonFormal)(ctx.addMode(Mode.ImplicitsEnabled))

tests/pos/overloaded.scala

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,40 @@ object overloaded {
2929
val r2 = map(x => x.toInt)
3030
val t2: Seq[Int] = r2
3131

32+
val rp1 = map { case x => x.toUpper }
33+
val tp1: String = rp1
34+
val rp2 = map { case x => x.toInt }
35+
val tp2: Seq[Int] = rp2
36+
3237
def flatMap(f: Char => String): String = ???
3338
def flatMap[U](f: Char => Seq[U]): Seq[U] = ???
3439
val r3 = flatMap(x => x.toString)
3540
val t3: String = r3
3641
val r4 = flatMap(x => List(x))
3742
val t4: Seq[Char] = r4
3843

44+
val rp3 = flatMap { case x => x.toString }
45+
val tp3: String = rp3
46+
val rp4 = flatMap { case x => List(x) }
47+
val tp4: Seq[Char] = rp4
48+
3949
def bar(f: (Char, Char) => Unit): Unit = ???
4050
def bar(f: Char => Unit) = ???
4151
bar((x, y) => ())
4252
bar (x => ())
53+
// bar { case (x, y) => () } // error: cannot test if value types are references
54+
bar { case x => () }
4355

4456
def combine(f: (Char, Int) => Int): Int = ???
4557
def combine(f: (String, Int) => String): String = ???
4658
val r5 = combine((x: Char, y) => x + y)
4759
val t5: Int = r5
4860
val r6 = combine((x: String, y) => x ++ y.toString)
4961
val t6: String = r6
62+
63+
// Errors: The argument types of an anonymous function must be fully known
64+
// val rp5 = combine { case (x: Char, y) => x + y }
65+
// val tp5: Int = rp5
66+
// val rp6 = combine { case (x: String, y) => x ++ y.toString }
67+
// val tp6: String = rp6
5068
}

0 commit comments

Comments
 (0)