File tree Expand file tree Collapse file tree 1 file changed +12
-8
lines changed Expand file tree Collapse file tree 1 file changed +12
-8
lines changed Original file line number Diff line number Diff line change @@ -1412,6 +1412,12 @@ if (isInputRange!T)
1412
1412
// if the format spec is valid
1413
1413
enum formatTestMode = is (Writer == NoOpSink);
1414
1414
1415
+ static if (! formatTestMode && isInfinite! T)
1416
+ {
1417
+ static assert (! isInfinite! T, " Cannot format an infinite range. " ~
1418
+ " Convert it to a finite range first using `std.range.take` or `std.range.takeExactly`." );
1419
+ }
1420
+
1415
1421
// Formatting character ranges like string
1416
1422
if (f.spec == ' s' )
1417
1423
{
@@ -1582,18 +1588,16 @@ if (isInputRange!T)
1582
1588
throw new FormatException(text(" Incorrect format specifier for range: %" , f.spec));
1583
1589
}
1584
1590
1585
- // https://issues.dlang.org/show_bug.cgi?id=20218
1586
1591
@safe pure unittest
1587
1592
{
1588
- void notCalled ()
1589
- {
1590
- import std.range : repeat;
1593
+ import std.range : repeat;
1594
+ import std.format : format;
1591
1595
1592
- auto value = 1. repeat;
1596
+ auto value = 1. repeat;
1593
1597
1594
- // test that range is not evaluated to completion at compiletime
1595
- format! " %s" (value);
1596
- }
1598
+ // This should fail to compile — so we assert that it *doesn't* compile
1599
+ static assert ( ! __traits(compiles, format! " %s" (value)),
1600
+ " Test failed: formatting an infinite range should not compile. " );
1597
1601
}
1598
1602
1599
1603
// character formatting with ecaping
You can’t perform that action at this time.
0 commit comments