fork download
  1. module main;
  2. import std.stdio;
  3.  
  4. interface AbsCalculator {
  5. int abs(int n)
  6. out (result) {
  7. assert(result >= 0);
  8. }
  9. }
  10.  
  11. class CorrectAbsCalculator : AbsCalculator {
  12. int abs(int n) {
  13. return n < 0 ? -n : n;
  14. }
  15. }
  16.  
  17. class BuggyAbsCalculator : AbsCalculator {
  18. int abs(int n) {
  19. return n;
  20. }
  21. }
  22.  
  23. void main() {
  24. auto a = new CorrectAbsCalculator();
  25. writeln(a.abs(-1));
  26. auto b = new BuggyAbsCalculator();
  27. writeln(b.abs(-1));
  28. }
Runtime error #stdin #stdout #stderr 0s 2628KB
stdin
Standard input is empty
stdout
1
stderr
core.exception.AssertError@prog.d(7): Assertion failure
----------------
./prog(main+0) [0x8073498]
./prog(_D4main13AbsCalculator3absMFiZ8__ensureMFKxiZv+0x18) [0x8072f68]
./prog(int main.BuggyAbsCalculator.abs(int)+0x2d) [0x8072fed]
./prog(_Dmain+0x34) [0x8073034]
./prog(_D2rt6dmain211_d_run_mainUiPPaPUAAaZiZ6runAllMFZ9__lambda1MFZv+0x12) [0x807556a]
./prog(void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).tryExec(scope void delegate())+0x18) [0x80754e0]
./prog(void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).runAll()+0x27) [0x807552f]
./prog(void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).tryExec(scope void delegate())+0x18) [0x80754e0]
./prog(_d_run_main+0x166) [0x8075476]
./prog(main+0x14) [0x80734ac]
/lib/i386-linux-gnu/libc.so.6(__libc_start_main+0xf3) [0xb7623723]