Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unapply loses stable prefix when in pattern position #20360

Open
EugeneFlesselle opened this issue May 7, 2024 · 1 comment
Open

unapply loses stable prefix when in pattern position #20360

EugeneFlesselle opened this issue May 7, 2024 · 1 comment
Labels

Comments

@EugeneFlesselle
Copy link
Contributor

Compiler version

3.5.0-RC1

Minimized code

trait Wrap:
  type Value
  val value: Value

object Wrap:
  def unapply(w: Wrap): Some[w.Value] = Some(w.value)

object Test:
  val w: Wrap = ???

  val Some(n1) = Wrap.unapply(w)
  val _: w.Value = n1 // ok

  val Wrap(n2) = w
  val _: w.Value = n2 // Error Found: (Test.n2 : Wrap#Value)

Expectation

Expected no errors

@EugeneFlesselle
Copy link
Contributor Author

In (w: w.type) match case Wrap(n) => ... we type the pattern with a selector type of Wrap, i.e. we have lost the reference to w.type. This is due to a widening in typedMatch:

val selType = rawSelectorTpe match
case c: ConstantType if tree.isInline => c
case otherTpe => otherTpe.widen
adapting this fixes the issue, but causes a bunch of other tests to fail.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants