D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 16569 - Assertion failure on splitter.back on empty string
Summary: Assertion failure on splitter.back on empty string
Status: RESOLVED INVALID
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: x86_64 Linux
: P1 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-10-01 17:53 UTC by Uranuz
Modified: 2020-03-21 03:56 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Uranuz 2016-10-01 17:53:35 UTC
import std.stdio;
import std.algorithm;
import std.range;
import std.string;

void main()
{
	string str = "";
	
	writeln( splitter(str, '.').back );
}

core.exception.AssertError@std/algorithm/iteration.d(3132): Assertion failure
----------------
??:? _d_assert [0x43dd1f]
??:? void std.algorithm.iteration.__assert(int) [0x4432b0]
??:? pure @property @safe immutable(char)[] std.algorithm.iteration.splitter!("a == b", immutable(char)[], char).splitter(immutable(char)[], char).Result.back() [0x43b8d6]
??:? _Dmain [0x43ae41]
??:? _D2rt6dmain211_d_run_mainUiPPaPUAAaZiZ6runAllMFZ9__lambda1MFZv [0x43e33e]
??:? void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).tryExec(scope void delegate()) [0x43e288]
??:? void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).runAll() [0x43e2fa]
??:? void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).tryExec(scope void delegate()) [0x43e288]
??:? _d_run_main [0x43e1f9]
??:? main [0x43d049]
Comment 1 basile-z 2016-10-01 18:18:00 UTC
It's not a bug. splitter returns a range, in your case this range is empty. 
The way of iterating/using a range is always to test for emptiness before using front/back or popFront/Back:

auto rng = str.splitter('.');
if (!rng.empty)
    writeln(rng.back);