Bad conversion - doesn't wrap args in parenthesis #60

Closed
dnadolny opened this Issue Aug 29, 2013 · 1 comment

Projects

None yet

2 participants

@dnadolny
Contributor

I have the Java code:

class TryMe {
  private void someMethod(String str) {}

  private void useIt() {
    int n = 5;
    someMethod(Integer.toString(n + 1).length() * 5);
  }
}

When converted, you get:

class TryMe {
  private def someMethod(str: String) {
  }

  private def useIt() {
    val n = 5
    someMethod(java.lang.Integer toString n + 1.length * 5)
  }
}

This is incorrect, and in this case gives a compiler error on 1.length (although you can't rely on having an error). The n + 1 needs to be wrapped in brackets since that is the argument to toString.

I believe the problem is in ScalaDumpVisitor.scala line 744. If the method is one in the SHORT_FORM list and it has less than 2 arguments, the resulting scala will use a space rather than a dot and parenthesis. I think the condition needs to be strengthened: if there is an argument, the code for that argument must not contain a space.

@timowest timowest added a commit that referenced this issue Sep 11, 2013
@timowest Fix toString conversion #60 77c78d9
@timowest
Owner

Released in 0.3.1

@timowest timowest closed this Sep 11, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment