Fix potential NoSuchElementException on Nil.head

No test included because I had no idea on how to reproduce the behavior
in a test - the exception occurs for me only in a misconfigured compiler
but not in a correctly configured one.