Skip to content

Explicit cast as range end operand causes incorrect SA1003 and SA1008 #3386

@jnm2

Description

@jnm2

Checked using 1.2.0-beta.354 and 1.2.0-beta.333, no config file:

using System;

class C
{
    void M(long p)
    {
        // No warning
        Console.WriteLine((int)p);

        // ⚠ SA1008 Opening parenthesis should be preceded by a space.
        // ⚠ SA1003 Operator '(int)' should be preceded by whitespace.
        //                  ↓
        Console.WriteLine(..(int)p);
    }
}

The messages are confusing, because https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1008.md seems to actually say there should not be a space there.

To show how backwards this is:

using System;

class C
{
    void M(long p)
    {
        // These warnings are good
        // ⚠ SA1008 Opening parenthesis should not be preceded by a space.
        // ⚠ SA1003 Operator '(int)' should not be preceded by whitespace.
        //               ↓ ↓
        Console.WriteLine( (int)p);

        // No warning (but there should be!)
        Console.WriteLine(.. (int)p);
    }
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions