Skip to content

Commit

Permalink
Use AllowLambdaWildcardApply mode in ApproximatingTypeMap
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
4 people committed May 25, 2023
1 parent da514ce commit b9bfde7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6026,7 +6026,7 @@ object Types {
case _ =>
if args.exists(isRange) then
if variance > 0 then
tp.derivedAppliedType(tycon, args.map(rangeToBounds)) match
tp.derivedAppliedType(tycon, args.map(rangeToBounds))(using ctx.addMode(Mode.AllowLambdaWildcardApply)) match
case tp1: AppliedType if tp1.isUnreducibleWild && ctx.phase != checkCapturesPhase =>
// don't infer a type that would trigger an error later in
// Checking.checkAppliedType; fall through to default handling instead
Expand Down
24 changes: 24 additions & 0 deletions tests/pos/16583.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,27 @@ inline def labels[Labels <: Tuple](using ev: Tuple.Union[Labels] <:< String): Li
def test = labels[("one", "two", "three")].mkString("<", ", ", ">")

def test2(tup: ("one", "two", "three")) = tup.toList

def toList(x: Tuple): List[Tuple.Union[x.type]] = ???
def test3[Labels <: Tuple] = toList((???): Labels)
// Previously would fail with:
// Found: List[Tuple.Union[(?1 : Labels)]]
// Required: List[
// Labels match {
// case EmptyTuple => Nothing
// case h *: t => h | scala.Tuple.Fold[t, Nothing, [x, y] =>> x | y]
// }
// ]
// Now, both the inferred return type and the type of the right-hand side are List[Any].

type F2[X, Y]
type F[X] = F2[X, X]
def toF(x: Any): F[x.type] = ???
def test4[T] = toF((???): T)
// Previously would fail with:
// def test3[T] = toF((???): T)
// ^^^^^^^^^^^^^
// Found: F[(?1 : T)]
// Required: F2[T, T]
// where: ?1 is an unknown value of type T
// Now, both the inferred return type and the type of the right-hand side are Any.

0 comments on commit b9bfde7

Please sign in to comment.