Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Iteration prior to buffer construction constructs buffer too late. #21

Closed
amcgregor opened this issue Mar 23, 2016 · 1 comment
Closed

Comments

@amcgregor
Copy link
Member

Simplest test case:

# encoding: cinje

: def testcase
    : for i in ('hello', 'world')
        ${i}

Ignoring default imports, optimizations, and line mapping, the transformed result is currently:

def testcase():
    for i in ('hello', 'world'):
        _buffer = []
        __w, __ws = _buffer.extend, _buffer.append

        __w((
            '\t\t',
            _escape(i),
            '\n'
        ))

    yield "".join(_buffer)

Note the dangerous location of buffer construction. If the loop were empty, it would not be called, but the code transformer considers the buffer prepared after that point regardless. In the empty test case, the subsequent yield will explode as _buffer would be undefined. Additionally, the buffer is overwritten on each iteration here.

Temporary workaround: include some emitted content prior to a function's first iterator. An HTML comment works well.

Simple fix: force buffer construction after function declaration.

@amcgregor
Copy link
Member Author

Corrected in 0ff337d.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant