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

Exact tuple type is lost during transformations #16104

Closed
WojciechMazur opened this issue Sep 26, 2022 · 0 comments · Fixed by #16113
Closed

Exact tuple type is lost during transformations #16104

WojciechMazur opened this issue Sep 26, 2022 · 0 comments · Fixed by #16113
Assignees
Labels
area:typer itype:bug regression This worked in a previous version but doesn't anymore
Milestone

Comments

@WojciechMazur
Copy link
Contributor

WojciechMazur commented Sep 26, 2022

Regression found in Open CB #167 for giiita/refuel

It seems that during the transformation information about the exact tuple type is lost. In this case Tuple27 is trimmed to Tuple23

Compiler version

Works in 3.1.1
Fails since 3.1.2

Bisect points to: 584c05b

Minimized code

There are 2 failing cases, but they seem to be related. I'm providing both of them to allow for proper testing of the fix

Case 1

Input

trait JsonVal

val value = ("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, "k", "l", "m", "n", "o", "p", "q")
val tree: JsonVal = ???

def Case1 = {
  sealed trait Read[T]
  object ReadOf:
    final inline def tuple[T <: Tuple]: Read[T] = ???

  given JsonTreeToEntry: scala.Conversion[JsonVal, JsonRowEntry] = ???
  trait JsonRowEntry:
    def readAs[E](using Read[E]): util.Try[E] = ???

  extension [T, U](leftSideValue: T) 
    def shouldBe(rhs: U)(using CanEqual[T, U]) = ???

  tree
  .readAs(using ReadOf.tuple[String *: String *: String *: String *: String *: String *: String *: String *: String *: String *: Int *: Int *: Int *: Int *: Int *: Int *: Int *: Int *: Int *: Int *: String *: String *: String *: String *: String *: String *: String *: EmptyTuple])
  .fold(_ => ???, _.shouldBe(value))
}

Output

[error] ./test.scala:22:36: Values of types (String, String, String, String, String, String, String, String, String, String
[error]   , 
[error] Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, String, String, String) and (String, String, String, String, String, String, String, String, String, String
[error]   , 
[error] Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, String, String, String, String
[error]   , 
[error] String, String, String) cannot be compared with == or !=.

Tuple(10xString, 10xInt, 3xString) cannot be compared with Tuple(10xString, 10xInt, 7xString)


Case 2

Input

trait JsonVal

val value = ("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, "k", "l", "m", "n", "o", "p", "q")
val tree: JsonVal = ???

def Case2 = {
  sealed trait Write[T]
  object WriteOf:
    final inline def tuple[T <: Tuple]: Write[T] = ???

  given EntryToJson[T]: scala.Conversion[T, JsonStructureEntry[T]] = ???
  class JsonStructureEntry[T](t: T):
    def writeAs[X >: T](using Write[X]): util.Try[JsonVal] = ??? 

  value
  .writeAs(using WriteOf.tuple[String *: String *: String *: String *: String *: String *: String *: String *: String *: String *: Int *: Int *: Int *: Int *: Int *: Int *: Int *: Int *: Int *: Int *: String *: String *: String *: String *: String *: String *: String *: EmptyTuple])
  .fold(_ => ???, _ == tree)
}

Output

[error] ./test.scala:35:18: Found:    Write[String *: String *: String *: String *: String *: String *: String *: 
[error]   String
[error]  *: String *: String *: Int *: Int *: Int *: Int *: Int *: Int *: Int *: Int *: 
[error]   Int
[error]  *: Int *: String *: String *: String *: String *: String *: String *: String *:
[error]    
[error] EmptyTuple]
[error] Required: Write[(String, String, String, String, String, String, String, String, String, 
[error]   String
[error] , Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, String, String, String)]
[error]   .writeAs(using WriteOf.tuple[String *: String *: String *: String *: String *: String *: String *: String *: String *: String *: Int *: Int *: Int *: Int *: Int *: Int *: Int *: Int *: Int *: Int *: String *: String *: String *: String *: String *: String *: String *: EmptyTuple])
[error]                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Found Write[Tuple(10xString, 10xInt, 3xString)], required Write[Tuple(10xString, 10xInt, 7xString)]

Expectation

Should compile

@WojciechMazur WojciechMazur added itype:bug area:typer regression This worked in a previous version but doesn't anymore labels Sep 26, 2022
@WojciechMazur WojciechMazur changed the title Regression in typer for large tuples Exact tuple type is lost during transformations Sep 26, 2022
odersky added a commit to dotty-staging/dotty that referenced this issue Sep 27, 2022
Was truncating tuples of size > 22 before.

Fixes scala#16104
mpollmeier pushed a commit to mpollmeier/dotty that referenced this issue Oct 16, 2022
Was truncating tuples of size > 22 before.

Fixes scala#16104
Kordyjan pushed a commit to dotty-staging/dotty that referenced this issue Oct 17, 2022
Was truncating tuples of size > 22 before.

Fixes scala#16104
@Kordyjan Kordyjan added this to the 3.2.2 milestone Aug 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:typer itype:bug regression This worked in a previous version but doesn't anymore
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants