Bug 10989 – [CTFE] Uncaught exception messages are not pretty printed if message wasn't literal

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-09-07T15:40:00Z
Last change time
2015-02-18T03:41:51Z
Keywords
CTFE, diagnostic, pull
Assigned to
nobody
Creator
dmitry.olsh

Comments

Comment #0 by dmitry.olsh — 2013-09-07T15:40:59Z
import std.string; enum foo = (){ throw new Exception(format("Something %d wicked happened!", 42)); return 0; }(); On a recent DMD from git master: D:\D\ctfe_ex.d(4): Error: Uncaught CTFE exception object.Exception(['S', 'o', 'm', 'e', 't', 'h', 'i', 'n', 'g', ' ', '4', '2', ' ', 'w', 'i', 'c', 'k', 'e', 'd', ' ', 'h', 'a', 'p', 'p', 'e', 'n', 'e', 'd', '!'][0u..29u]) D:\D\ctfe_ex.d(6): called from here: (*int() { throw new Exception(format("Something %d wicked happened!", 42), "D:\\D\\ctfe_ex.d", 4u, null); return 0; } Note that the following using plain literal neatly formats the string: enum foo = (){ throw new Exception("Something wicked happened!"); return 0; }(); D:\D\ctfe_ex.d(2): Error: Uncaught CTFE exception object.Exception("Something wicked happened!") The point is it should always pretty print it unless it contains bad UTF-8.
Comment #1 by clugdbug — 2013-09-10T23:23:00Z
Patch: --- a/src/ctfeexpr.c +++ b/src/ctfeexpr.c @@ -157,7 +157,7 @@ char *ThrownExceptionExp::toChars() void ThrownExceptionExp::generateUncaughtError() { thrown->error("Uncaught CTFE exception %s(%s)", thrown->type->toChars(), - (*thrown->value->elements)[0]->toChars()); + (*thrown->value->elements)[0]->toString()->toChars()); /* Also give the line where the throw statement was. We won't have it * in the case where the ThrowStatement is generated inter Reduced test case: enum foo = () { throw new Exception(['a', 'b', 'c']); return 0; }();
Comment #2 by clugdbug — 2013-09-16T00:56:33Z
Comment #3 by github-bugzilla — 2013-09-16T15:44:16Z
Commit pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/8779d47334e6b1f7cfab13a8955cdceb733d403a Fix bug 10989 [CTFE] Uncaught exception messages are not pretty printed Convert it to a StringExp before printing.
Comment #4 by electrolysis.jp+d — 2015-01-05T10:41:28Z
This bug is still alive, at least around the first test case, though Don's reduced one shows a nicer message. Result: ctfe_ex.d(4): Error: uncaught CTFE exception object.Exception(['S', 'o', 'm', 'e', 't', 'h', 'i', 'n', 'g', ' ', '4', '2', ' ', 'w', 'i', 'c', 'k', 'e', 'd', ' ', 'h', 'a', 'p', 'p', 'e', 'n', 'e', 'd', '!'][0..29]) ctfe_ex.d(6): called from here: (*() => 0)()
Comment #5 by sinkuupump — 2015-01-05T13:35:34Z
I dustmited the test case, and found the cause inside the std.array.Appender. https://gist.githubusercontent.com/sinkuu/7ee9db68c3229d075a6f/raw/fd1e241428c0ade08e8214e512486d5e0071c2cb/gistfile1.d Reduced test case: enum foo = { string msg = "Something 42 wicked happened!"; char[] arr; arr.length = msg.length; arr = arr[0 .. $]; arr[] = msg; throw new Exception(cast(string)arr); return 0; }();
Comment #6 by k.hara.pg — 2015-01-05T15:09:19Z
Comment #7 by github-bugzilla — 2015-01-06T07:06:34Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/73e48f02b6eca202f7bacc0023555d5608f7019c fix Issue 10989 - [CTFE] Uncaught exception messages are not pretty printed if message wasn't literal Fix the remained case. https://github.com/D-Programming-Language/dmd/commit/94db1fa80e004a456a68b014a9f0498c216a77ed Merge pull request #4252 from 9rnsr/fix10989 Issue 10989 - [CTFE] Uncaught exception messages are not pretty printed if message wasn't literal
Comment #8 by github-bugzilla — 2015-02-18T03:41:51Z
Commits pushed to 2.067 at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/73e48f02b6eca202f7bacc0023555d5608f7019c fix Issue 10989 - [CTFE] Uncaught exception messages are not pretty printed if message wasn't literal https://github.com/D-Programming-Language/dmd/commit/94db1fa80e004a456a68b014a9f0498c216a77ed Merge pull request #4252 from 9rnsr/fix10989