Shortest Code to Legitimately Slack Off
TikZ (pdfTeX 3.14159265-2.6-1.40.17), 85 79 74 24 22 21 bytes
A bunch of bytes saved thanks to wchargin
One byte saved thanks to Chris H
\input tikz
\tikz\pic
I actually encountered this one by accident when I was working on homework. I spent quite a while waiting for it to compile before I realized what was happening.
This has two parts:
\input tikz
This loads the TikZ package
and:
\tikz\pic
This starts a \tikz
environment and a draw command.
What is going on
The pdflatex compiler has trouble with \tikz\pic
, and enters interactive mode causing it to stall indefinitely.
C, 18 bytes
#include __FILE__
Compilers will usually give up after recursing about 200 times.
Does DOM construction count as a compilation step? If so, then x.htm
:
<iframe src=x.htm>
Java, 102 95 89 88 78 bytes
class A<T>{}class B<T>extends A<A<?super B<B<T>>>>{A<?super B<A>>a=new B<>();}
This terminates with a StackOverflowError
which happens because the generic resolution system can't decide a root against which to resolve the other generics.
Credits where due.
What happens here?
A<T>
is just there to have a 1-letter parent. It's generic. I could have usedList
, but the imports and repetition of 4 letters are too long.B<T>
declares a basic generic.B extends A
is required to have a hierarchy betweenB
andA
.extends A<A>
creates a self reference onA<T>
.A<? super B>
triggers the lookup for generics onA<T>
B<B<T>>
creates a self-reference onB<T>
.A<...> a=new B<>()
forces the usage of the generics, instead of simply the definition of those, forcing the resolution when compilingB
, and not afterwards.A<?super B
creates a non-self-reference, so we have both a reference to one type and to another in the generics ofA
.B<A>
creates a non-self-reference, so we have both a reference to one type and to another in the generics ofB
.
Now, the type A
has generics type A
and B
, but which is to be chosen? Forget about self, let's try to resolve B
. Ping.
Okay, B
has generics type A
and B
, but which is to be chosen? Forget about self, let's try to resolve A
. Pong.
This kind of recursion can't really be avoided because there are legitimate cases like A<B<A<B<A<B<Object>>>>>>
: for example a JSON object: List<Map<String,Map<String,List<Map<String,List<String>>>>>>
.
Compilation result
$ javac NoCompile.java
The system is out of resources.
Consult the following stack trace for details.
java.lang.StackOverflowError
at com.sun.tools.javac.code.Types$UnaryVisitor.visit(Types.java:3260)
at com.sun.tools.javac.code.Types$23.visitClassType(Types.java:2587)
at com.sun.tools.javac.code.Types$23.visitClassType(Types.java:2579)
at com.sun.tools.javac.code.Type$ClassType.accept(Type.java:554)
at com.sun.tools.javac.code.Types$UnaryVisitor.visit(Types.java:3260)
at com.sun.tools.javac.code.Types$23.visitClassType(Types.java:2592)
at com.sun.tools.javac.code.Types$23.visitClassType(Types.java:2579)
at com.sun.tools.javac.code.Type$ClassType.accept(Type.java:554)
On my system, the stack trace stops after showing 1024 lines, which are actually the 4 same lines repeated 256 times, thus proving an infinite recursion. I'll spare you that whole trace.
Savings
- 102 → 95 bytes: replaced
interface
+implements
withclass
+extends
. - 95 → 89 bytes: replaced
Long
withA
(twice). - 89 → 88 bytes: used diamond operator (
new B<A>()
→new B<>()
) . - 88 → 78 bytes: moved the variable declaration to a class member, thanks to VoteToClose.