diff --git a/compiler/src/dotty/tools/dotc/typer/Applications.scala b/compiler/src/dotty/tools/dotc/typer/Applications.scala index 16516a61f99b..286f1e6d9929 100644 --- a/compiler/src/dotty/tools/dotc/typer/Applications.scala +++ b/compiler/src/dotty/tools/dotc/typer/Applications.scala @@ -1718,7 +1718,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 diff --git a/tests/pos/match-precise-type-unchecked.scala b/tests/pos/match-precise-type-unchecked.scala new file mode 100644 index 000000000000..579e4d4a28d5 --- /dev/null +++ b/tests/pos/match-precise-type-unchecked.scala @@ -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 diff --git a/tests/semanticdb/metac.expect b/tests/semanticdb/metac.expect index 2c97be5ed2b7..c0a1124e50b0 100644 --- a/tests/semanticdb/metac.expect +++ b/tests/semanticdb/metac.expect @@ -5059,8 +5059,8 @@ _empty_/Txn# => trait Txn [typeparam T <: Txn[T]] extends Object { self: Txn[T] _empty_/Txn#[T] => typeparam T <: Txn[T] _empty_/Txn#``(). => primary ctor [typeparam T <: Txn[T]](): Txn[T] local0 => val local out: Repr[Out] -local1 => val local inObj: Obj[In] & Repr[In] -local2 => val local outObj: Obj[Out] & Repr[Out] +local1 => val local inObj: Obj[In] +local2 => val local outObj: Obj[Out] Occurrences: [1:6..1:9): Txn <- _empty_/Txn#