Skip to content

Mix of variable assignment and declaration in initialization clause of 'for' statement can lead to CS1002 errors #77247

@Hafthor

Description

@Hafthor

Version Used: C# 13 / SDK 9.0.200

Steps to Reproduce:

  1. New C# console app project
  2. Program.cs for(int a=0,b,c;;);
  3. Build yields "Program.cs(1,12): CS1002 : ; expected" along with other related errors. Did not appear as error by IDE (VS or Rider).

Diagnostic Id: CS1002 : ; expected

Expected Behavior: should be able to mix declarations and assignments in initialization clause in 'for' statement

Actual Behavior: compilation errors - seems like if you include any assignments, then only the last variable is allowed to be declaration only.

RoslynBug20250215.zip

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions