             {type: 'X'}
           else
             v = vars[name]
-            assert v, "Symbol '#{name}' referenced before assignment"
+            if not v
+              throw new CompilerError node,
+                "Symbol '#{name}' is referenced before assignment."
             v.used = true
             v
         when 'lambda'

          t1 = visit node[1]
          for c in node[2...] when c isnt null
            t = visit c
            assert t.type is 'X', 'Only data can be used as an index'
          t1
        when 'expr'
          a = node[1...]

  while node[0] isnt 'body' then node = node.parent
  node

# Used to report the AST node where the error happened
@CompilerError =
  class CompilerError extends Error
    constructor: (@astNode, @message, args...) ->
      assert @astNode instanceof Array
      assert typeof @message is 'string'
      assert not args.length

# # Public interface to this module

