Improving assert-printing in DMD

deadalnix via Digitalmars-d digitalmars-d at puremagic.com
Tue Sep 29 20:45:13 PDT 2015


On Tuesday, 29 September 2015 at 21:02:42 UTC, Nordlöw wrote:
> As a follow-up to
>
> https://github.com/D-Programming-Language/phobos/pull/3207#issuecomment-144073495
>
> I starting digging in DMD for logic controlling behaviour of 
> assert(), especially whether it's possible to add automatic 
> printing of `lhs` and `rhs` upon assertion failure if 
> `AssertExp` is a binary expression say `lhs == rhs`.
>
> After grepping for `AssertExp` the only possible place I could 
> think of was
>
> ToElemVisitor::visit(AssertExp *ae)
>
> inside
>
> elem *toElem(Expression *e, IRState *irs)
>
> in file e2ir.c.
>
> Questions:
>
> 1. Is this the right place where this lhs-rhs-printing logic 
> should be added? If so could somebody tell me how to make this 
> happen?
>
> 2. Is it possible to from within DMD generate expressions that 
> do
>
> `import std.stdio : write`
>
> and then calls write on the `lhs` and `rsh`...or this a 
> completely wrong approach to solving this problem?

I do think wiring this in the compiler is probably not the right 
way forward. Most language have some library functions like :

expect(exprssion).toBeTrue();
expect(function/delegate).toThrow!ExceptionType

And so on.

This allow to get nice error and do not need wiring int he 
language. This is extensible and all. I'd rather have something 
like this.


More information about the Digitalmars-d mailing list