dotnet/roslyn

VB local lowering improperly visits nodes that it synthesizes itself

開放

#4,684 建立於 2015年8月20日

 (0 則留言) (0 個反應) (0 位負責人)C# (4,257 個分叉)batch import
Area-CompilersBugConcept-Design Debthelp wanted

倉庫指標

星標
 (20,414 顆星)
PR 合併指標
 (平均合併 6天 17小時) (30 天內合併 256 個 PR)

描述

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

貢獻者指南