Skip to content

Inconsistency with member selection of generic tuples with know TupleN #14215

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 5, 2022 · 1 comment · Fixed by #14242
Closed

Inconsistency with member selection of generic tuples with know TupleN #14215

nicolasstucki opened this issue Jan 5, 2022 · 1 comment · Fixed by #14242
Milestone

Comments

@nicolasstucki
Copy link
Contributor

Compiler version

3.1.0

Minimized code

def f[T <: Tuple2[Int, Int]](tup: T): T = tup

def test: Unit =
  (1, 2)._1
  f((1, 2))._1

  (1 *: 2 *: EmptyTuple)._1 // error: `*:` does not have a member `_1` based on our current encoding it is considered ok
  f(1 *: 2 *: EmptyTuple)._1 // error: should not fail as `f` returns a subtype of `Tuple2` and should have the member `_1`
  f[Int *: Int *: EmptyTuple](1 *: 2 *: EmptyTuple)._1 // error

  f[Int *: Int *: EmptyTuple]((1, 2))._1 // error
  f[Tuple2[Int, Int]](1 *: 2 *: EmptyTuple)._1

Output

-- [E008] Not Found Error: Foo.scala:7:25 --------------------------------------
7 |  (1 *: 2 *: EmptyTuple)._1 // error: `*:` does not have a member `_1` based on our current encoding it is considered ok
  |  ^^^^^^^^^^^^^^^^^^^^^^^^^
  |  value _1 is not a member of (Int, Int)
-- [E008] Not Found Error: Foo.scala:8:26 --------------------------------------
8 |  f(1 *: 2 *: EmptyTuple)._1 // error: should not fail as `f` returns a subtype of `Tuple2` and should have the member `_1`
  |  ^^^^^^^^^^^^^^^^^^^^^^^^^^
  |  value _1 is not a member of (Int, Int)
-- [E008] Not Found Error: Foo.scala:9:52 --------------------------------------
9 |  f[Int *: Int *: EmptyTuple](1 *: 2 *: EmptyTuple)._1 // error
  |  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |  value _1 is not a member of Int *: Int *: EmptyTuple
-- [E008] Not Found Error: Foo.scala:11:38 -------------------------------------
11 |  f[Int *: Int *: EmptyTuple]((1, 2))._1 // error
   |  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |  value _1 is

Expectation

Ideally, they should all work.

@nicolasstucki
Copy link
Contributor Author

The main issue is that Tuple2[Int, Int] <:< Int *: Int *: EmptyTuple because we extend Tuple2 explicitly and from another side we also assume that Int *: Int *: EmptyTuple <:< Tuple2[Int, Int]; therefore Tuple2[Int, Int] =:= Int *: Int *: EmptyTuple. But Int *: Int *: EmptyTuple does not have access to the members of Tuple2[Int, Int]. This creates inconsistency depending on how/when we check for the members.

nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Jan 10, 2022
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Jan 10, 2022
olsdavis pushed a commit to olsdavis/dotty that referenced this issue Apr 4, 2022
@Kordyjan Kordyjan added this to the 3.1.2 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.

2 participants