www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Status status = __traits(compilesReportError, {string b=10;}) =>

reply Timothee Cour <thelastmammoth gmail.com> writes:
is there any way to get error from speculative execution (`__traits(
compiles, ...)`)? would be useful in tests; If not currently how hard
would that be to implement? eg:

```

struct Status{bool ok; string msg;}

Status status = __traits(compilesReportError, {string b=10;})
assert(!status.ok);
assert(status.msg==`main.d(15) Error: cannot implicitly convert
expression 10 of type int to string`);
```
Feb 07 2018
next sibling parent reply Nicholas Wilson <iamthewilsonator hotmail.com> writes:
On Wednesday, 7 February 2018 at 20:29:44 UTC, Timothee Cour 
wrote:
 is there any way to get error from speculative execution 
 (`__traits(
 compiles, ...)`)? would be useful in tests; If not currently 
 how hard
 would that be to implement? eg:

 ```

 struct Status{bool ok; string msg;}

 Status status = __traits(compilesReportError, {string b=10;})
 assert(!status.ok);
 assert(status.msg==`main.d(15) Error: cannot implicitly convert
 expression 10 of type int to string`);
 ```
Probably not very hard. Would make for some nice diagnostics,but very flakey tests. Compiler errors are frequently changed.
Feb 07 2018
parent Timothee Cour <thelastmammoth gmail.com> writes:
understood, but that's responsibility of tester to make sure they're
not too flaky (eg using msg.canFind("FOO") (or, if regex weren't slow,
regex)



On Wed, Feb 7, 2018 at 1:13 PM, Nicholas Wilson via Digitalmars-d
<digitalmars-d puremagic.com> wrote:
 On Wednesday, 7 February 2018 at 20:29:44 UTC, Timothee Cour wrote:
 is there any way to get error from speculative execution (`__traits(
 compiles, ...)`)? would be useful in tests; If not currently how hard
 would that be to implement? eg:

 ```

 struct Status{bool ok; string msg;}

 Status status = __traits(compilesReportError, {string b=10;})
 assert(!status.ok);
 assert(status.msg==`main.d(15) Error: cannot implicitly convert
 expression 10 of type int to string`);
 ```
Probably not very hard. Would make for some nice diagnostics,but very flakey tests. Compiler errors are frequently changed.
Feb 07 2018
prev sibling parent Atila Neves <atila.neves gmail.com> writes:
On Wednesday, 7 February 2018 at 20:29:44 UTC, Timothee Cour 
wrote:
 is there any way to get error from speculative execution 
 (`__traits(
 compiles, ...)`)? would be useful in tests; If not currently 
 how hard
 would that be to implement? eg:

 ```

 struct Status{bool ok; string msg;}

 Status status = __traits(compilesReportError, {string b=10;})
 assert(!status.ok);
 assert(status.msg==`main.d(15) Error: cannot implicitly convert
 expression 10 of type int to string`);
 ```
static if(!__traits(compiles, $CODE)) { $CODE } It's the same technique I use in concepts to produce an error message if a struct you wanted to be, say isInputRange, isn't: https://github.com/atilaneves/concepts Atila
Feb 08 2018