Shopify/liquid — pull request #398 by jasonhl (2014-07-24 18:35:07+00:00)
Title: Reorder constructor to avoid referencing uninitialized variable when environment contains a self-referencing proc

Updating Shopify to use the latest liquid caused exceptions in production. Stack trace:

```
GEM_ROOT]/bundler/gems/liquid-32e4f2d3b1f4/lib/liquid/context.rb:244 → variable
[GEM_ROOT]/bundler/gems/liquid-32e4f2d3b1f4/lib/liquid/context.rb:193 → resolve
[GEM_ROOT]/bundler/gems/liquid-32e4f2d3b1f4/lib/liquid/context.rb:153 → []
[PROJECT_ROOT]/app/controllers/shop_controller.rb:345 → block in set_collection_variables
[GEM_ROOT]/bundler/gems/liquid-32e4f2d3b1f4/lib/liquid/context.rb:289 → call
[GEM_ROOT]/bundler/gems/liquid-32e4f2d3b1f4/lib/liquid/context.rb:289 → lookup_and_evaluate
[GEM_ROOT]/bundler/gems/liquid-32e4f2d3b1f4/lib/liquid/context.rb:299 → block (2 levels) in squash_instance_assigns_with_environments
[GEM_ROOT]/bundler/gems/liquid-32e4f2d3b1f4/lib/liquid/context.rb:297 → each
[GEM_ROOT]/bundler/gems/liquid-32e4f2d3b1f4/lib/liquid/context.rb:297 → block in squash_instance_assigns_with_environments
[GEM_ROOT]/bundler/gems/liquid-32e4f2d3b1f4/lib/liquid/context.rb:296 → each_key
[GEM_ROOT]/bundler/gems/liquid-32e4f2d3b1f4/lib/liquid/context.rb:296 → squash_instance_assigns_with_environments
[GEM_ROOT]/bundler/gems/liquid-32e4f2d3b1f4/lib/liquid/context.rb:27 → initialize
...
```

The root of the issue is that `Context::squash_instance_assigns_with_environments` is called within `Context::initialize`. If the environment has a self-referential Proc, i.e. one which evaluates another variable in the environment, it ends up looking at the `parsed_variables` member. Unfortunately, due to the order in the `initialize` method, that member has not been initialized. Kaboom.

Added a test to cover this form of Context initialization and changed the order of the controller initialize.

@Shopify/liquid