Skip to content
Closed
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 @@ -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
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
4 changes: 2 additions & 2 deletions tests/semanticdb/metac.expect
Original file line number Diff line number Diff line change
Expand Up @@ -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#`<init>`(). => primary ctor <init> [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]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isnt this suspicious - it is now a less precise type? unless Obj is already Repr

local2 => val local outObj: Obj[Out]
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the source is case (inObj: Obj[In], outObj: Obj[Out]) so this makes sense to me


Occurrences:
[1:6..1:9): Txn <- _empty_/Txn#
Expand Down
Loading