dotnet/roslyn

VB local lowering improperly visits nodes that it synthesizes itself

Open

#4,684 创建于 2015年8月20日

在 GitHub 查看
 (0 评论) (0 反应) (0 负责人)C# (20,414 star) (4,257 fork)batch import
Area-CompilersBugConcept-Design Debthelp wanted

描述

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

贡献者指南