Skip to content

Commit 37e4f87

Browse files
mbovelsmarterdwijnandDecel
committed
Use AllowLambdaWildcardApply mode in ApproximatingTypeMap
Co-Authored-By: Guillaume Martres <63430+smarter@users.noreply.github.com> Co-Authored-By: Dale Wijnand <dale.wijnand@gmail.com> Co-Authored-By: Decel <8268812+Decel@users.noreply.github.com>
1 parent 259d74e commit 37e4f87

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6026,7 +6026,7 @@ object Types {
60266026
case _ =>
60276027
if args.exists(isRange) then
60286028
if variance > 0 then
6029-
tp.derivedAppliedType(tycon, args.map(rangeToBounds)) match
6029+
tp.derivedAppliedType(tycon, args.map(rangeToBounds))(using ctx.addMode(Mode.AllowLambdaWildcardApply)) match
60306030
case tp1: AppliedType if tp1.isUnreducibleWild && ctx.phase != checkCapturesPhase =>
60316031
// don't infer a type that would trigger an error later in
60326032
// Checking.checkAppliedType; fall through to default handling instead

tests/pos/16583.scala

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,27 @@ inline def labels[Labels <: Tuple](using ev: Tuple.Union[Labels] <:< String): Li
1212
def test = labels[("one", "two", "three")].mkString("<", ", ", ">")
1313

1414
def test2(tup: ("one", "two", "three")) = tup.toList
15+
16+
def toList(x: Tuple): List[Tuple.Union[x.type]] = ???
17+
def test3[Labels <: Tuple] = toList((???): Labels)
18+
// Previously would fail with:
19+
// Found: List[Tuple.Union[(?1 : Labels)]]
20+
// Required: List[
21+
// Labels match {
22+
// case EmptyTuple => Nothing
23+
// case h *: t => h | scala.Tuple.Fold[t, Nothing, [x, y] =>> x | y]
24+
// }
25+
// ]
26+
// Now, both the inferred return type and the type of the right-hand side should be Any.
27+
28+
type F2[X, Y]
29+
type F[X] = F2[X, X]
30+
def toF(x: Any): F[x.type] = ???
31+
def test4[T] = toF((???): T)
32+
// Previously would fail with:
33+
// def test3[T] = toF((???): T)
34+
// ^^^^^^^^^^^^^
35+
// Found: F[(?1 : T)]
36+
// Required: F2[T, T]
37+
// where: ?1 is an unknown value of type T
38+
// Now, both the inferred return type and the type of the right-hand side should be Any.

0 commit comments

Comments
 (0)