paul1956 / CSharpToVB

New version of CSharpToVB converter
MIT License
25 stars 9 forks source link

Iterator Function Problem #60

Closed DualBrain closed 3 years ago

DualBrain commented 3 years ago

The following example:

    static IEnumerable<(string, string)> SourceFilesFromMustachePaths(string languageName, IEnumerable<(string, string, string)> pathsData)
    {
        foreach ((string name, string template, string hash) in pathsData)
        {
            yield return (name, SourceFileFromMustachePath(languageName, name, template, hash));
        }
    }

Currently ends up with something like:

Private Shared Function SourceFilesFromMustachePaths(pathsData As IEnumerable(Of (String, String, String))) As IEnumerable(Of (String, String))
    ' TODO: Visual Basic does not support For Each Variable statement.
' Original statement:
' foreach ((string name, string template, string hash) in pathsData)
'             {
'                 yield return (name, SourceFileFromMustachePath(name, template, hash));
'             }

End Function

This isn't about tuple deconstructions in a foreach (filed separate issue on that); but rather that the Function is incorrectly converted to "regular" Function instead of an Iterator. This has caught me a little off guard a couple of times; so wondering if it would be possible to detect the yield before it being remarked to correctly tag the Function as being an Iterator. Basically the problem currently is I'm so focused on the lines that failed (remarked out) that I don't realize until after "stepping back" that Iterator is missing from the Function definition... in the mean time, I'm scratching my head reviewing the now manually converted code I just wrote wondering why I'm still having an error. ;-)

paul1956 commented 3 years ago

That was because I never looked at the statements and saw the yield. Once I parse the statements this gets fixed for free. So fixed in 5.0.0.19