You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Compiler error CS1004: Duplicate '{0}' modifier is reported during binding, so if we just parse a syntax tree like below, lets say, via CSharpSyntaxTree.ParseText...
publicpublicclassC{}
... it wouldn't contain any diagnostics at all.
The behaviour is different for statements though. If a stetement contains duplicate modifiers, error CS1031: Type expected is reported during parsing on every duplicate modifier. So code like:
classC{voidM(){constconstconstinta=0;}}
... produces 2 CS1031: Type expected errors on 2 const modifiers: For whatever reason sharplab doesn't properly render diagnostic locations for this case, but if you want to see it threre - here is the link
No additional errors are reported at the binding stage for statements.
This two mechanisms are mixed together for local functions. Local finctions are statements, so CS1031: Type expected is reported during parsing. However, at the binding stage error CS1004: Duplicate '{0}' modifier is reported as well, so we have 2 diagnostics on the same token:
Over all, there are several flaws with the current design, described above:
No errors about duplicate declaration modifiers after parsing even though parser has all required information to report such errors
Not intuitive CS1031: Type expected error for statements with duplicate modifiers even when the statement type is specified
If there are several duplicate modifiers in a row, for declarations only 1 error is reported on the first duplicate modifier. For statements, there are several errors reported on every duplicate modifier
Errors are produced during parsing for statements, but during binding for declarations
Compiler error
CS1004: Duplicate '{0}' modifieris reported during binding, so if we just parse a syntax tree like below, lets say, viaCSharpSyntaxTree.ParseText...... it wouldn't contain any diagnostics at all.
The behaviour is different for statements though. If a stetement contains duplicate modifiers, error
CS1031: Type expectedis reported during parsing on every duplicate modifier. So code like:... produces 2

CS1031: Type expectederrors on 2constmodifiers:For whatever reason sharplab doesn't properly render diagnostic locations for this case, but if you want to see it threre - here is the link
No additional errors are reported at the binding stage for statements.
This two mechanisms are mixed together for local functions. Local finctions are statements, so
CS1031: Type expectedis reported during parsing. However, at the binding stage errorCS1004: Duplicate '{0}' modifieris reported as well, so we have 2 diagnostics on the same token:Sharplab link
Over all, there are several flaws with the current design, described above:
CS1031: Type expectederror for statements with duplicate modifiers even when the statement type is specifiedCS1004: Duplicate '{0}' modifier(see Improve diagnostics for duplicate modifiers on local functions #32106)