# Buggy code
def from_lexer(cls, message, state, token):
    source_pos = token.getsourcepos()
    if token.source_pos:
        lineno = source_pos.lineno
        colno = source_pos.colno
    else:
        lineno = -1
        colno = -1

    if state.source:
        lines = state.source.splitlines()
        if lines[-1] == "":
            del lines[-1]

        if lineno < 1:
            lineno = len(lines)
        if colno < 1:
            colno = len(lines[-1])

        source = lines[lineno - 1]
    return cls(message, state.filename, lineno, colno, source)


# Traceback (hy.errors.HyCompileError)
Traceback (most recent call last):
File "/home/johnzhuang/.virtualenvs/hy/lib/python3.6/site-packages/hy/importer.py", line 180, in hy_eval
_ast, expr = hy_compile(hytree, module_name, get_expr=True)
File "/home/johnzhuang/.virtualenvs/hy/lib/python3.6/site-packages/hy/compiler.py", line 2213, in hy_compile
result = compiler.compile(tree)
File "/home/johnzhuang/.virtualenvs/hy/lib/python3.6/site-packages/hy/compiler.py", line 460, in compile
ret = self.compile_atom(_type, tree)
File "/home/johnzhuang/.virtualenvs/hy/lib/python3.6/site-packages/hy/compiler.py", line 447, in compile_atom
else _compile_table[atom_type](self, atom))
File "/home/johnzhuang/.virtualenvs/hy/lib/python3.6/site-packages/hy/compiler.py", line 1731, in compile_expression
ret = self.compile_atom(fn, expression)
File "/home/johnzhuang/.virtualenvs/hy/lib/python3.6/site-packages/hy/compiler.py", line 447, in compile_atom
else _compile_table[atom_type](self, atom))
File "/home/johnzhuang/.virtualenvs/hy/lib/python3.6/site-packages/hy/compiler.py", line 819, in compile_do
return self._compile_branch(expression)
File "/home/johnzhuang/.virtualenvs/hy/lib/python3.6/site-packages/hy/compiler.py", line 545, in _compile_branch
return _branch(self.compile(expr) for expr in exprs)
File "/home/johnzhuang/.virtualenvs/hy/lib/python3.6/site-packages/hy/compiler.py", line 318, in _branch
results = list(results)
File "/home/johnzhuang/.virtualenvs/hy/lib/python3.6/site-packages/hy/compiler.py", line 545, in <genexpr>
return _branch(self.compile(expr) for expr in exprs)
File "/home/johnzhuang/.virtualenvs/hy/lib/python3.6/site-packages/hy/compiler.py", line 460, in compile
ret = self.compile_atom(_type, tree)
File "/home/johnzhuang/.virtualenvs/hy/lib/python3.6/site-packages/hy/compiler.py", line 447, in compile_atom
else _compile_table[atom_type](self, atom))
File "/home/johnzhuang/.virtualenvs/hy/lib/python3.6/site-packages/hy/compiler.py", line 1731, in compile_expression
ret = self.compile_atom(fn, expression)
File "/home/johnzhuang/.virtualenvs/hy/lib/python3.6/site-packages/hy/compiler.py", line 447, in compile_atom
else _compile_table[atom_type](self, atom))
File "/home/johnzhuang/.virtualenvs/hy/lib/python3.6/site-packages/hy/compiler.py", line 372, in checker
return fn(self, expression)
File "/home/johnzhuang/.virtualenvs/hy/lib/python3.6/site-packages/hy/compiler.py", line 873, in compile_try_expression
name)
File "/home/johnzhuang/.virtualenvs/hy/lib/python3.6/site-packages/hy/compiler.py", line 1002, in _compile_catch_expression
body = self._compile_branch(expr)
File "/home/johnzhuang/.virtualenvs/hy/lib/python3.6/site-packages/hy/compiler.py", line 545, in _compile_branch
return _branch(self.compile(expr) for expr in exprs)
File "/home/johnzhuang/.virtualenvs/hy/lib/python3.6/site-packages/hy/compiler.py", line 318, in _branch
results = list(results)
File "/home/johnzhuang/.virtualenvs/hy/lib/python3.6/site-packages/hy/compiler.py", line 545, in <genexpr>
return _branch(self.compile(expr) for expr in exprs)
File "/home/johnzhuang/.virtualenvs/hy/lib/python3.6/site-packages/hy/compiler.py", line 460, in compile
ret = self.compile_atom(_type, tree)
File "/home/johnzhuang/.virtualenvs/hy/lib/python3.6/site-packages/hy/compiler.py", line 447, in compile_atom
else _compile_table[atom_type](self, atom))
File "/home/johnzhuang/.virtualenvs/hy/lib/python3.6/site-packages/hy/compiler.py", line 1731, in compile_expression
ret = self.compile_atom(fn, expression)
File "/home/johnzhuang/.virtualenvs/hy/lib/python3.6/site-packages/hy/compiler.py", line 447, in compile_atom
else _compile_table[atom_type](self, atom))
File "/home/johnzhuang/.virtualenvs/hy/lib/python3.6/site-packages/hy/compiler.py", line 372, in checker
return fn(self, expression)
File "/home/johnzhuang/.virtualenvs/hy/lib/python3.6/site-packages/hy/compiler.py", line 858, in compile_try_expression
body += self.compile(expr.pop(0))
File "/home/johnzhuang/.virtualenvs/hy/lib/python3.6/site-packages/hy/compiler.py", line 472, in compile
raise_empty(HyCompileError, e, sys.exc_info()[2])
File "<string>", line 1, in raise_empty
hy.errors.HyCompileError: Internal Compiler Bug 😱
⤷ ImportError: cannot require names: [HySymbol('let')]
Compilation traceback:
File "/home/johnzhuang/.virtualenvs/hy/lib/python3.6/site-packages/hy/compiler.py", line 460, in compile
ret = self.compile_atom(_type, tree)
File "/home/johnzhuang/.virtualenvs/hy/lib/python3.6/site-packages/hy/compiler.py", line 447, in compile_atom
else _compile_table[atom_type](self, atom))
File "/home/johnzhuang/.virtualenvs/hy/lib/python3.6/site-packages/hy/compiler.py", line 1731, in compile_expression
ret = self.compile_atom(fn, expression)
File "/home/johnzhuang/.virtualenvs/hy/lib/python3.6/site-packages/hy/compiler.py", line 447, in compile_atom
else _compile_table[atom_type](self, atom))
File "/home/johnzhuang/.virtualenvs/hy/lib/python3.6/site-packages/hy/compiler.py", line 1486, in compile_require
require(module, self.module_name, assignments=assignments)
File "/home/johnzhuang/.virtualenvs/hy/lib/python3.6/site-packages/hy/macros.py", line 106, in require
raise ImportError("cannot require names: " + repr(list(unseen)))

# Fixed code
def from_lexer(cls, message, state, token):
    lineno = None
    colno = None
    source = state.source
    source_pos = token.getsourcepos()

    if source_pos:
        lineno = source_pos.lineno
        colno = source_pos.colno
    elif source:
        # Use the end of the last line of source for `PrematureEndOfInput`.
        # We get rid of empty lines and spaces so that the error matches
        # with the last piece of visible code.
        lines = source.rstrip().splitlines()
        lineno = lineno or len(lines)
        colno = colno or len(lines[lineno - 1])
    else:
        lineno = lineno or 1
        colno = colno or 1

    return cls(message, None, state.filename, source, lineno, colno)