dotnet/roslyn

VB local lowering improperly visits nodes that it synthesizes itself

オープン

#4,684 opened on 2015/08/20

 (0 件のコメント) (0 件のリアクション) (0 人の担当者)C# (4,257 件のフォーク)batch import
Area-CompilersBugConcept-Design Debthelp wanted

Repository metrics

Stars
 (20,414 個のスター)
PR merge metrics
 (PR metrics pending)

説明

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

コントリビューターガイド