(Inspired by this comment on an old question.)
An error quine (also known as a "Kimian quine") is a program which, when compiled or run, causes the compiler/interpreter/runtime to print an error message that has identical text to the program itself, and nothing else. For the purposes of this challenge, we're defining "error" broadly, to include warnings too.
In this challenge, we're looking for a quine which is also an error quine. When executed, the program must print its own source code normally (i.e. not as an error/warning message); this must be a proper quine (i.e. some part of the program must encode a different part of the output). Additionally, compiling and executing the program must also cause the program's source code – and nothing else – to be printed as error or warning messages by the implementation. (Note that this means that you will not be able to use compile-time errors, in languages where those prevent the program from executing normally.) So in other words, the program's source code will be printed twice, once via each method.
- In most cases, it'll be obvious what is and isn't an error/warning message; we aren't distinguishing between the two here. In ambiguous cases, define an error/warning message as any text that's output by the implementation either: 1. as a consequence of something other than executing a command (or whatever the closest equivalent is in the language); or 2. that wasn't part of the input to the command that produced it as output.
- The error/warning part of the quine doesn't need to be a proper quine (although in most cases it will be by chance, as most error and warning messages contain considerable amounts of fixed text).
- It's acceptable for the program to output multiple errors/warnings, which form the program's source when concatenated together. It's not acceptable to output errors/warnings that don't appear in the source.
- Unlike in many challenges, the switches given to the compiler, and the program filename, are likely to be highly relevant in this challenge. Given that the challenge may not be possible otherwise, I'm willing to be flexible here, although if you run the implementation in an unusual way, remember that PPCG rules charge a byte penalty for doing so (equal to the number of additional characters that you'd need to add on the command line over the shortest "normal" way to run a program), and thus you'll need to specify the size of the penalty in your post. (For example, if the interpreter you're using reads the program from a file, and has no particular restrictions on the filename, the shortest normal way to run the program would be from a file with a 1-character filename; thus, if you need a 100-character filename to make your program work, you'd incur a byte penalty of +99.)
- The compiler/interpreter version you use may well be relevant, so as part of your submission, please state a specific compiler or interpreter on which your program works, and which version is required. (For example, a C submission might state "C (gcc 6.2.0)" in the header.)
- Note that this task may not be possible in all languages. In the languages where it is, the easiest method will likely be to find an error or warning message for which it's possible to customize some subset of the text (via changing the name of something that gets quoted in the message; filenames are a common choice here, but not the only one). I'll be particularly impressed (and surprised) if someone finds a way to do this using only error and warning messages whose text is fixed.
This is a code-golf challenge, so an entry is considered to be better if it has a smaller byte count. As such, once you've got your program working at all, you want to optimize it to bring the number of bytes down as far as possible. (However, don't be discouraged if there's already a shorter entry, especially if it's in a different language; what we're really looking for here is to shorten a particular algorithm or idea behind a program as much as possible, but seeing multiple solutions in different languages or that rely on different principles is always worthwhile.)