[Issue 12768] @nogc algorithm.splitter
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Tue May 20 04:25:26 PDT 2014
https://issues.dlang.org/show_bug.cgi?id=12768
monarchdodra at gmail.com changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |monarchdodra at gmail.com
--- Comment #2 from monarchdodra at gmail.com ---
(In reply to bearophile_hugs from comment #1)
> The problem is not immediate to solve.
>
>
> You can fix splitter allocating the RangeError statically:
>
>
> auto splitter(C)(C[] s) if (isSomeChar!C) {
> static struct Result {
> private:
> import core.exception;
> C[] _s;
> size_t _frontLength;
> static err = new immutable(RangeError)();
I'm surprised this works. If the exception is Immutable, then how can we chain
it? If we catch "Exception", then we are making something immutable mutable. If
we mutate the exception, then not only do we break the type system, but it also
means the code isn't actually pure:
//----
void foo() pure
{
static err = new immutable(RangeError)("error");
throw err;
}
void main()
{
try
foo();
catch(Error e)
{
e.msg = "yo!";
}
foo(); //core.exception.RangeError at main.d(7): yo!
}
//----
If allocating a new typed error is a problem, I think it would be better to
just fallback to normal asserts: These work in @nogc.
--
More information about the Digitalmars-d-bugs
mailing list