Skip to content

.length() gets applied to the wrong object #17

Closed

Description

@Naddiseo

Testcase:

class Klass {
    void method() {
        String foo = "asdf";
        dummy(foo.length());
    }
}

Generated output:


#!/usr/bin/env python
""" generated source for module test """
class Klass(object):
    """ generated source for class Klass """
    def method(self):
        """ generated source for method method """
        foo = "asdf"
        len(dummy(foo))

As you can see, the len() should be applied to foo not dummy()

Activity

  1. ghost assigned on May 2, 2012
  2. natural commented on May 2, 2012

    @natural
    Owner

    This is a problem in the output substitution regular expression. The regex in question (match, substitute) looks like this:

    (r'(\s)(\S*?)(\.length\(\))', r'\1len(\2)')
    

    I'm tempted to just rip out the regex and say that you're on your own... this really should be fixed at the AST level. I'll think about it and get back with you when I've made up my mind.

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions