124
\$\begingroup\$

Your challenge: write a "program", for a language of your choice, that causes the compiler/interpreter/runtime to produce error output when compiling/running your program which is identical to your program's source code.

Rules:

  • Your program may be specific to a particular version or implementation of your language's compiler/interpreter/runtime environment. If so, please specify the particulars.
  • Only standard compiler/interpreter/runtime options are permitted. You cannot pass some weird flag to your compiler to get a specific result.
  • The program does not need to be syntactically or semantically valid, but I may give a bounty to the best syntactically valid submission.
  • The program must not produce any output of its own (e.g. by calling a print or output function). All output generated upon attempting to compile/run the program must originate from the compiler/interpreter/runtime.
  • The complete output of the compiler/interpreter/runtime must be exactly identical to your program source code.
  • The compiler/interpreter/runtime must generate at least one error message when invoked with your program.

This is a popularity contest. Most creative answer, as determined by upvotes, wins. If you can give a good case for using a standard loophole, you may do so.

\$\endgroup\$
7
  • 9
    \$\begingroup\$ What is "error output"? And what does it mean to "generate an error message"? More specifically: 1) Does the output have to be to stderr? 2) If the runtime logs an error to syslog and doesn't write anything to stderr, what should be compared to the source of the program? 3) If the runtime throws an exception internally when given an empty program, but requires a flag to actually print the exception and so ends up exiting with a non-zero exit code but no output, has an error message been generated? \$\endgroup\$ Aug 16, 2014 at 9:24
  • 1
    \$\begingroup\$ I tried doing this in java and got a p3 oscilator. This was the shortest phase: (Compile from q.java): Error: Could not find or load main class Q \$\endgroup\$ Jun 1, 2015 at 12:57
  • 3
    \$\begingroup\$ Ha, because of a syntactic ambiguity in the first sentence, I thought the challenge here was to produce a program which normally produces no output, but if you pass its own code to it as input, it produces an error. \$\endgroup\$ Apr 10, 2017 at 6:32
  • 2
    \$\begingroup\$ When reporting an error, APL always prints a customizable error name, optionally an error message, the name of the program that caused the error, the (bracketed) line number where the error occurred, the line of code that caused the error, and a line with a caret indicating where parsing stopped. Any hope for participation here? \$\endgroup\$
    – Adám
    May 7, 2017 at 21:50
  • 1
    \$\begingroup\$ @SteveBennett Why haven't you made that challenge yet? \$\endgroup\$ May 28, 2017 at 1:53

128 Answers 128

1 2 3 4
5
0
\$\begingroup\$

33

Very simple. : isn't a valid command, so it's easy to make an unrecognised token error quine. The error is just where the : is in the code.

33 (1:8): Unrecognised token
\$\endgroup\$
0
\$\begingroup\$

GNU Smalltalk REPL

REPL is always acceptable, and I only learned the Smalltalk REPL and don't know how to save programs in a file. (I think TIO does not have Smalltalk yet.)

stdin:1: expected expression

This will work when you start the REPL for the first time.

\$\endgroup\$
0
\$\begingroup\$

Red 0.6.3

*** Error: not a Red program!

Newline included. Save as a .red file and run with red <filename>.red.

\$\endgroup\$
0
\$\begingroup\$

Pxem (pxemi.2.min.posixism), Filename: 14 bytes + Content: 0 bytes = 14 bytes.

  • Filename (has trailing LF!): .a B4 .[wxyz]
  • Content: empty.

Try it online!

\$\endgroup\$
0
\$\begingroup\$

PPL, 79 bytes

Reference error on line 3, column 3

  a()
  ^

The identifier a is not defined

I haven't implemented syntax checking properly, so only reference errors and type errors are thrown (plus syntax checking in rare cases). Pretty simple answer, frankly. Attempts to call the nonexisting a function (just a without the call does not work because my interpreter does not check for invalid expressions in some cases) I know my language is not very good but I'm too lazy to work on it.

\$\endgroup\$
0
\$\begingroup\$

Snap! (scratchblocks syntax)

Hmm...
a custom block definition is missing
\$\endgroup\$
0
\$\begingroup\$

JavaScript

Thought I would make an updated JS answer.

Firefox:

Uncaught SyntaxError: unexpected token: identifier
Google Chrome:
Uncaught SyntaxError: Unexpected identifier 'SyntaxError'

\$\endgroup\$
0
\$\begingroup\$

Applescript, 70 bytes

0:2: syntax error: A “:” can’t go after this identifier. (-2740)

Run with osascript -e "0:2: syntax error: A “:” can’t go after this identifier. (-2740)"

\$\endgroup\$
1 2 3 4
5

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.