Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion compiler/src/dotty/tools/dotc/typer/Applications.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1717,7 +1717,19 @@ trait Applications extends Compatibility {
def typedUnApply(tree: untpd.Apply, selType0: Type)(using Context): Tree = {
record("typedUnApply")
val Apply(qual, unadaptedArgs) = tree
val selType = selType0.stripNamedTuple
// Use the types of the args if available, which can be more precise than the selector type,
// which is important if using `@unchecked`
val selType1 = selType0 match
case AppliedType(selCon, selArgs) if selArgs.size == unadaptedArgs.size =>
val newSelTypes = selArgs.zip(unadaptedArgs).map((sa, ua) => ua match
case Typed(_, tpt: AppliedTypeTree) =>
typed(tpt)
if tpt.hasType then tpt.tpe else sa
case _ => sa
)
AppliedType(selCon, newSelTypes)
case _ => selType0
val selType = selType1.stripNamedTuple

def notAnExtractor(tree: Tree): Tree =
// prefer inner errors
Expand Down
11 changes: 11 additions & 0 deletions tests/pos/match-precise-type-unchecked.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import scala.collection.*
import scala.util.*

val (ss: Seq[Success[Int] @unchecked], fs: Seq[Failure[Int] @unchecked]) =
Seq.empty[Try[Int]].partition(_.isSuccess)

val (ss2: Seq[Success[Int]], fs2: Seq[Failure[Int]]) = Seq.empty[Try[Int]].partition(_.isSuccess) match
case (s: Seq[Success[Int] @unchecked], f: Seq[Failure[Int] @unchecked]) => (s, f)

val (ss3: Seq[Success[Int]], fs3: Seq[Failure[Int]]) = Seq.empty[Try[Int]].partition(_.isSuccess) match
case x @ (s: Seq[Success[Int] @unchecked], f: Seq[Failure[Int] @unchecked]) => x
Loading