Skip to content

Investigate whether the function pointer spacing exception belongs in SA1014 or SA1023 #153

Open

Description

@bjornhellander

This came up during the c# 9 review (#147).

In delegate* <int, void>, the space between * and < could be reported by two rules: SA1014 ("opening generic bracket should not be preceded by a space") and SA1023 ("dereference symbol should not be followed by a space"). To avoid duplicate diagnostics, SA1014 currently skips its "preceded" check when the < follows the * (SA1014OpeningGenericBracketsMustBeSpacedCorrectly.cs, token.GetPreviousToken().IsKind(SyntaxKind.AsteriskToken)). The space is left to SA1023.

Investigate whether the exception should be moved to SA1023 instead.

Arguments for keeping it in SA1014 (current behavior):

  • SA1023 has reported this space since function pointers were added upstream (SA1023CSharp9UnitTests.TestFunctionPointerTypeInvalidSpacingAsync, delegate* <int*>). Moving it changes that tested behavior, and users with SA1014 disabled would no longer get the diagnostic.
  • SA1023 already decides what may follow the *: no space before <, but a space before managed/unmanaged.
  • It matches how other spacing rules split overlaps: the rule for the later token skips its "preceded" check when the earlier token's rule covers the space (e.g. SA1008 after another (, or after keywords handled by SA1000).

Arguments for moving it to SA1023:

  • SA1014 would then report a space before < the same way everywhere in a function pointer: after *, after managed/unmanaged and after unmanaged[Cdecl].

Affected tests: SA1014CSharp9UnitTests.TestFunctionPointerWithSpaceAfterAsteriskAsync and SA1023CSharp9UnitTests.TestFunctionPointerTypeInvalidSpacingAsync.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions