Skip to content

Do not simplify away field as clause - it breaks compilation #43123

@GrahamTheCoder

Description

@GrahamTheCoder

Version Used:
codeanalysis 3.5.0

Steps to Reproduce:

On a Visual Basic

  1. Call Reduce on a single variable field with an As clause and an initializer
<Workspace>
    <Project Language="Visual Basic" CommonReferences="true">
        <Document>
            Imports System
            Imports I = System.Int32
            Module Program
                Public Dim {|SimplifyParent:x As Integer = 5|}
            End Module
        </Document>
    </Project>
</Workspace>

Expected Behavior:
Same output as input

Actual Behavior:
As clause gets removed.
If option strict is on: Removing the as clause causes a compile error
If option strict is off: It changes the inferred type of the field to be Object in all cases

Other details:
This shot up my priority list when I realized the option to workaround this bug had been removed, though I'd much prefer we fix this bug than bring the option back.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-IDEBugIDE-CodeStyleBuilt-in analyzers, fixes, and refactoringsResolution-FixedThe bug has been fixed and/or the requested behavior has been implemented

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions