diff --git a/Analysis/include/Luau/ToString.h b/Analysis/include/Luau/ToString.h index b0ab0cd5..935aadce 100644 --- a/Analysis/include/Luau/ToString.h +++ b/Analysis/include/Luau/ToString.h @@ -11,6 +11,7 @@ LUAU_FASTINT(LuauTableTypeMaximumStringifierLength) LUAU_FASTINT(LuauTypeMaximumStringifierLength) +LUAU_FASTFLAG(LuauToStringSimpleCompositeTypesSingleLine) namespace Luau { @@ -39,6 +40,12 @@ struct ToStringNameMap struct ToStringOptions { + ToStringOptions(bool exhaustive = false) + : exhaustive(exhaustive) + , compositeTypesSingleLineLimit(FFlag::LuauToStringSimpleCompositeTypesSingleLine.value ? 5 : 0) + { + } + bool exhaustive = false; // If true, we produce complete output rather than comprehensible output bool useLineBreaks = false; // If true, we insert new lines to separate long results such as table entries/metatable. bool functionTypeArguments = false; // If true, output function type argument names when they are available diff --git a/Analysis/src/ToString.cpp b/Analysis/src/ToString.cpp index 2f0f38e1..67350438 100644 --- a/Analysis/src/ToString.cpp +++ b/Analysis/src/ToString.cpp @@ -17,6 +17,7 @@ LUAU_FASTFLAG(DebugLuauDeferredConstraintResolution) LUAU_FASTFLAGVARIABLE(LuauToStringPrettifyLocation, false) +LUAU_FASTFLAGVARIABLE(LuauToStringSimpleCompositeTypesSingleLine, false) /* * Enables increasing levels of verbosity for Luau type names when stringifying. diff --git a/tests/ToString.test.cpp b/tests/ToString.test.cpp index 25c09092..1bfc9872 100644 --- a/tests/ToString.test.cpp +++ b/tests/ToString.test.cpp @@ -216,6 +216,7 @@ TEST_CASE_FIXTURE(Fixture, "functions_are_always_parenthesized_in_unions_or_inte TEST_CASE_FIXTURE(Fixture, "simple_intersections_printed_on_one_line") { + ScopedFastFlag sff{"LuauToStringSimpleCompositeTypesSingleLine", true}; CheckResult result = check(R"( local a: string & number )"); @@ -228,6 +229,7 @@ TEST_CASE_FIXTURE(Fixture, "simple_intersections_printed_on_one_line") TEST_CASE_FIXTURE(Fixture, "complex_intersections_printed_on_multiple_lines") { + ScopedFastFlag sff{"LuauToStringSimpleCompositeTypesSingleLine", true}; CheckResult result = check(R"( local a: string & number & boolean )"); @@ -246,6 +248,7 @@ TEST_CASE_FIXTURE(Fixture, "complex_intersections_printed_on_multiple_lines") TEST_CASE_FIXTURE(Fixture, "overloaded_functions_always_printed_on_multiple_lines") { + ScopedFastFlag sff{"LuauToStringSimpleCompositeTypesSingleLine", true}; CheckResult result = check(R"( local a: ((string) -> string) & ((number) -> number) )"); @@ -262,6 +265,7 @@ TEST_CASE_FIXTURE(Fixture, "overloaded_functions_always_printed_on_multiple_line TEST_CASE_FIXTURE(Fixture, "simple_unions_printed_on_one_line") { + ScopedFastFlag sff{"LuauToStringSimpleCompositeTypesSingleLine", true}; CheckResult result = check(R"( local a: number | boolean )"); @@ -274,6 +278,7 @@ TEST_CASE_FIXTURE(Fixture, "simple_unions_printed_on_one_line") TEST_CASE_FIXTURE(Fixture, "complex_unions_printed_on_multiple_lines") { + ScopedFastFlag sff{"LuauToStringSimpleCompositeTypesSingleLine", true}; CheckResult result = check(R"( local a: string | number | boolean )");