Make sure that generated code ends up inside the right lexical scope.