Skip to content

Match type not working unless ascribed #11236

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

Closed
nicolasstucki opened this issue Jan 28, 2021 · 1 comment · Fixed by #11242
Closed

Match type not working unless ascribed #11236

nicolasstucki opened this issue Jan 28, 2021 · 1 comment · Fixed by #11242

Comments

@nicolasstucki
Copy link
Contributor

Minimized code

class Test {
  val tup: Char #: Int #: String #: TupleK = ???
  val x: String #: TupleK = (tup.tail: Int #: String #: TupleK).tail
  val y: String #: TupleK = tup.tail.tail
  val z: Unit = tup.tail.tail
}

trait TupleK

object TupleK {
  type Tail[X <: NonEmptyTupleK] <: TupleK = X match {
    case _ #: xs => xs
  }
}

trait NonEmptyTupleK extends TupleK {
  /*inline*/ def tail[This >: this.type <: NonEmptyTupleK]: TupleK.Tail[This] = ???
}

abstract class #:[+H, +T <: TupleK] extends NonEmptyTupleK

Output

-- [E008] Not Found Error: tests/run/tuples1c.scala:5:37 -----------------------
5 |  val y: String #: TupleK = tup.tail.tail
  |                            ^^^^^^^^^^^^^
  |value tail is not a member of TupleK.Tail[This] - did you mean TupleK.Tail[This].wait?
  |
  |where:    This is a type variable with constraint >: (Test.this.tup : Char #: Int #: String #: TupleK) and <: NonEmptyTupleK
-- [E008] Not Found Error: tests/run/tuples1c.scala:6:25 -----------------------
6 |  val z: Unit = tup.tail.tail
  |                ^^^^^^^^^^^^^
  |value tail is not a member of TupleK.Tail[This] - did you mean TupleK.Tail[This].wait?
  |
  |where:    This is a type variable with constraint >: (Test.this.tup : Char #: Int #: String #: TupleK) and <: NonEmptyTupleK
2 errors found

Expectation

They compile with the inline, the should also compile without it.

@nicolasstucki
Copy link
Contributor Author

This is a blocker for #9984.

odersky added a commit to dotty-staging/dotty that referenced this issue Jan 28, 2021
The `couldInstantiateTypeVar` method instantiated only type variables
that were the constructor of an applied type. But sometimes we
might also need to instantiate the argument(s), since doing so can
influence the members of the applied type. This happens in two cases

 1. The applied type's rhs is a match type
 2. The applied type's result is one of its type parameters

i11236.scala tests the first case, the additions to i9567.scala the second.

Fixes scala#11236
nicolasstucki pushed a commit to dotty-staging/dotty that referenced this issue Jan 29, 2021
The `couldInstantiateTypeVar` method instantiated only type variables
that were the constructor of an applied type. But sometimes we
might also need to instantiate the argument(s), since doing so can
influence the members of the applied type. This happens in two cases

 1. The applied type's rhs is a match type
 2. The applied type's result is one of its type parameters

i11236.scala tests the first case, the additions to i9567.scala the second.

Fixes scala#11236
@Kordyjan Kordyjan added this to the 3.0.0 milestone Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants