Skip to content

Inline temporary variable produces invalid code when used with collection expressions #80081

@Dreamescaper

Description

@Dreamescaper

Version Used:
Version 17.14.13 (August 2025)

Steps to Reproduce:
Having the following code:

class Command: List<int>;

var commands = new[] {1,2,3,4,5,6,7,8 }
    .Chunk(3)
    .Select(chunk => {
        Command command = [..chunk];
        return command;
     })
     .ToList();

'Inline temporary variable' suggest the following code:

var commands = new[] {1,2,3,4,5,6,7,8 };
    .Chunk(3)
    .Select(chunk => {
         return (Command)[.. chunk];
     })
     .ToList();

Unfortunately, this code is invalid.

Diagnostic Id:

'Inline temporary variable' refactoring.

Expected Behavior:

I think it should suggest (Command)([.. batch]) option.

Actual Behavior:

'Inline temporary variable' suggests invalid code.

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions