-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
There was a problem with how some text wrapped. I noticed it in the printing of big tuple types and I started to write unit tests for those, but there turned out to also be a checkfile that demonstrates the fix: tests/neg/i14127.check: - | Int - |, Int, Int)] was found for parameter x [...] - | Int - |, Int, Int)]: + | Int, Int, Int)] was found for parameter [...] + | Int, Int, Int)]: The fix is to make appendIndented, which is used by append, use Fluid instead of switching to Vertical. It seems to me that, pre-layout, Vertical means "I want my elements to be vertical", i.e. wrap every one, and it's layout that takes that into account. Fluid instead means "wrap where necessary, pack where possible". Post-layout, instead, it looks like Fluid means one-per-line, as it's consumed by print. So the fix is to switch appendIndented from Vertical to Fluid. Following that I made some improvements like not needless boxing non-splittable text, like Str, into Closed and merging non-closed Fluid text during concat (`~`). That fixed the extra wrapping, but it meant that the ", " separator could be the text that is wrapped and indented, which didn't look nice. So I changed Text.apply to close the separator to the previous element. That encouraged lines ending with ", ", that is with a trailing space, so I made print strip trailing spaces. The change from Vertical to Fluid made the last parenthesis in tests/neg/i9185.check not wrap, which is fine, but that pulled the trailing "failed with" up to the previous line. As that's not code, I decided to move it down and a line away from the code.
- Loading branch information
Showing
13 changed files
with
163 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package dotty.tools | ||
package dotc | ||
|
||
import core.*, Decorators.*, Symbols.* | ||
import printing.Texts.* | ||
|
||
import org.junit.Test | ||
|
||
class TupleShowTests extends DottyTest: | ||
def IntType = defn.IntType | ||
def LongType = defn.LongType | ||
def ShortType = defn.ShortType | ||
def Types_10 = List.fill(5)(IntType) ::: List.fill(5)(LongType) | ||
def Types_20 = Types_10 ::: Types_10 | ||
|
||
val tup0 = defn.tupleType(Nil) | ||
val tup1 = defn.tupleType(IntType :: Nil) | ||
val tup2 = defn.tupleType(IntType :: LongType :: Nil) | ||
val tup3 = defn.tupleType(IntType :: LongType :: ShortType :: Nil) | ||
val tup21 = defn.tupleType(Types_20 ::: IntType :: Nil) | ||
val tup22 = defn.tupleType(Types_20 ::: IntType :: LongType :: Nil) | ||
val tup23 = defn.tupleType(Types_20 ::: IntType :: LongType :: ShortType :: Nil) | ||
val tup24 = defn.tupleType(Types_20 ::: IntType :: LongType :: ShortType :: ShortType :: Nil) | ||
|
||
@Test def tup0_show = chkEq("EmptyTuple.type", i"$tup0") | ||
@Test def tup1_show = chkEq("Tuple1[Int]", i"$tup1") | ||
@Test def tup2_show = chkEq("(Int, Long)", i"$tup2") | ||
@Test def tup3_show = chkEq("(Int, Long, Short)", i"$tup3") | ||
@Test def tup21_show = chkEq(res21, i"$tup21") | ||
@Test def tup22_show = chkEq(res22, i"$tup22") | ||
@Test def tup23_show = chkEq(res23, i"$tup23") | ||
@Test def tup24_show = chkEq(res24, i"$tup24") | ||
|
||
@Test def tup3_text = | ||
val obt = tup3.toText(ctx.printer) | ||
val exp = Fluid(List( | ||
Str(")"), | ||
Str("Short"), | ||
Closed(List(Str(", "), Str("Long"))), | ||
Closed(List(Str(", "), Str("Int"))), | ||
Str("("), | ||
)) | ||
chkEq(exp, obt) | ||
|
||
@Test def tup3_layout10 = | ||
val obt = tup3.toText(ctx.printer).layout(10) | ||
val exp = Fluid(List( | ||
Str(" Short)"), | ||
Str(" Long, "), | ||
Str("(Int, "), | ||
)) | ||
chkEq(exp, obt) | ||
|
||
@Test def tup3_show10 = chkEq("(Int,\n Long,\n Short)", tup3.toText(ctx.printer).mkString(10, false)) | ||
|
||
val res21 = """|(Int, Int, Int, Int, Int, Long, Long, Long, Long, Long, Int, Int, Int, Int, | ||
| Int, Long, Long, Long, Long, Long, Int)""".stripMargin | ||
|
||
val res22 = """|(Int, Int, Int, Int, Int, Long, Long, Long, Long, Long, Int, Int, Int, Int, | ||
| Int, Long, Long, Long, Long, Long, Int, Long)""".stripMargin | ||
|
||
val res23 = """|(Int, Int, Int, Int, Int, Long, Long, Long, Long, Long, Int, Int, Int, Int, | ||
| Int, Long, Long, Long, Long, Long, Int, Long, Short)""".stripMargin | ||
|
||
val res24 = """|(Int, Int, Int, Int, Int, Long, Long, Long, Long, Long, Int, Int, Int, Int, | ||
| Int, Long, Long, Long, Long, Long, Int, Long, Short, Short)""".stripMargin | ||
|
||
def chkEq[A](expected: A, obtained: A) = assert(expected == obtained, diff(s"$expected", s"$obtained")) | ||
|
||
def diff(exp: String, obt: String) = | ||
val min = math.min(exp.length, obt.length) | ||
val pre = | ||
var i = 0 | ||
while i < min && exp(i) == obt(i) do i += 1 | ||
exp.substring(0, i) | ||
val suf = | ||
val max = min - pre.length - 1 | ||
var i = 0 | ||
while i <= max && exp(exp.length - 1 - i) == obt(obt.length - 1 - i) do i += 1 | ||
exp.substring(exp.length - i) | ||
|
||
import scala.io.AnsiColor.* | ||
val ellip = BLACK + BOLD + "..." + RESET | ||
val compactPre = if pre.length <= 20 then pre else ellip + pre.substring(pre.length - 20) | ||
val compactSuf = if suf.length <= 20 then suf else suf.substring(0, 20) + ellip | ||
def extractDiff(s: String) = s.substring(pre.length, s.length - suf.length) | ||
s"""|Comparison Failure: | ||
| expected: $compactPre${CYAN }${extractDiff(exp)}$RESET$compactSuf | ||
| obtained: $compactPre$MAGENTA${extractDiff(obt)}$RESET$compactSuf | ||
|""".stripMargin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,8 @@ | ||
-- Error: tests/neg/i14127.scala:6:55 ---------------------------------------------------------------------------------- | ||
6 | *: Int *: Int *: Int *: Int *: Int *: EmptyTuple)]] // error | ||
| ^ | ||
|No given instance of type deriving.Mirror.Of[(Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, | ||
| Int | ||
|, Int, Int)] was found for parameter x of method summon in object Predef. Failed to synthesize an instance of type deriving.Mirror.Of[(Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, | ||
| Int | ||
|, Int, Int)]: | ||
|No given instance of type deriving.Mirror.Of[(Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, | ||
| Int, Int, Int)] was found for parameter x of method summon in object Predef. Failed to synthesize an instance of type deriving.Mirror.Of[(Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, | ||
| Int, Int, Int)]: | ||
| * class *: is not a generic product because it reduces to a tuple with arity 23, expected arity <= 22 | ||
| * class *: is not a generic sum because it does not have subclasses |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters