dotnet/roslyn

VB local lowering improperly visits nodes that it synthesizes itself

Open

#4,684 opened on Aug 20, 2015

View on GitHub
 (0 comments) (0 reactions) (0 assignees)C# (4,257 forks)batch import
Area-CompilersBugConcept-Design Debthelp wanted

Repository metrics

Stars
 (20,414 stars)
PR merge metrics
 (Avg merge 6d 17h) (256 merged PRs in 30d)

Description

The Roslyn VB compiler's lowering phase has lots of places where it builds a node and then lowers it. The design guidelines are that subexpressions are visited first (once) and then an appropriate node is built over it (and not visited). Generally speaking nodes that are built by the lowering phase should never be visited by the lowering phase. If further transformation are required then the appropriate helper should be called directly.

Here is one example of this antipattern in the code:

            '  create assignment operator
            Dim assignmentOperator As BoundExpression = New BoundAssignmentOperator(node.Syntax, assignmentTarget,
                                                                 valueBeingAssigned, True)

            '  if there are any temporaries, wrap it in 
            If temporaries IsNot Nothing Then
                If temporaries.Count > 0 Then
                    assignmentOperator = New BoundSequence(node.Syntax,
                                                           StaticCast(Of LocalSymbol).From(temporaries.ToImmutableAndFree()),
                                                           ImmutableArray.Create(Of BoundExpression)(assignmentOperator),
                                                           Nothing,
                                                           If(assignmentOperator.Type.IsVoidType(),
                                                              assignmentOperator.Type,
                                                              Compilation.GetSpecialType(SpecialType.System_Void)))
                Else
                    temporaries.Free()
                End If
            End If

            '  create assignment statement
            Return Visit(New BoundExpressionStatement(node.Syntax, assignmentOperator))

Migrated from TFS/DevDiv 1040877

Contributor guide