incorrect parsing of for loop with multiple initializations
Closed this issue · 1 comments
davidraleigh commented
Maybe there's an option I'm missing, so apologies if that's the case. When there are comma separated variables initialized in the for loop they are not preserved by sharpen.
Java:
for (int i = 0, n = 40; i < n; i++) {
Resulting C#:
for (int i = 0; i < n; i++)
I was looking into the source code and maybe there is a problem with the following CSharpBuilder.java class method:
public boolean visit(VariableDeclarationExpression node) {
pushExpression(new CSDeclarationExpression(createVariableDeclaration((VariableDeclarationFragment) node
.fragments().get(0))));
return false;
}
It seems like get(0)
ensures that you'll only ever get one item instead of multiple items. It's hard for me to debug whatever exactly is going on. Below is a test case you can run and the current results I'm getting:
public class testCase {
public static void main (String args[]) {
System.out.println ("Hello World!");
for (int i = 0, n = 40; i < n; i++) {
n *= 2;
System.out.println("Hello " + i);
}
}
}
becomes:
using Sharpen;
public class testCase
{
public static void Main(string[] args)
{
System.Console.Out.WriteLine("Hello World!");
for (int i = 0; i < n; i++)
{
n *= 2;
System.Console.Out.WriteLine("Hello " + i);
}
}
}
davidraleigh commented
This is already sorted out in the imazen/sharpen develop branch