Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions docs/compilers/CSharp/Compiler Breaking Changes - DotNet 7.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# This document lists known breaking changes in Roslyn after .NET 6 all the way to .NET 7.

## Required spaces in #line span directives

***Introduced in .NET SDK 6.0.400, Visual Studio 2022 version 17.3.***

When the `#line` span directive was introduced in C# 10, it required no particular spacing.
For example, this would be valid: `#line(1,2)-(3,4)5"file.cs"`.

In Visual Studio 17.3, the compiler requires spaces before the first parenthesis, the character
offset, and the file name.
So the above example fails to parse unless spaces are added: `#line (1,2)-(3,4) 5 "file.cs"`.

## Checked operators on System.IntPtr and System.UIntPtr

***Introduced in .NET SDK 7.0.100, Visual Studio 2022 version 17.3.***
Expand Down
6 changes: 3 additions & 3 deletions src/Compilers/CSharp/Portable/CSharpResources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -6670,9 +6670,6 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ
<data name="IDS_FeatureInferredDelegateType" xml:space="preserve">
<value>inferred delegate type</value>
</data>
<data name="IDS_FeatureLineSpanDirective" xml:space="preserve">
<value>line span directive</value>
</data>
<data name="IDS_FeatureAutoDefaultStructs" xml:space="preserve">
<value>auto default struct fields</value>
</data>
Expand All @@ -6682,6 +6679,9 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ
<data name="ERR_LineSpanDirectiveEndLessThanStart" xml:space="preserve">
<value>The #line directive end position must be greater than or equal to the start position</value>
</data>
<data name="ERR_LineSpanDirectiveRequiresSpace" xml:space="preserve">
<value>The #line span directive requires space before the first parenthesis, before the character offset, and before the file name</value>
</data>
<data name="WRN_DoNotCompareFunctionPointers" xml:space="preserve">
<value>Comparison of function pointers might yield an unexpected result, since pointers to the same function may be distinct.</value>
</data>
Expand Down
1 change: 1 addition & 0 deletions src/Compilers/CSharp/Portable/Errors/ErrorCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2071,6 +2071,7 @@ internal enum ErrorCode

ERR_CannotBeConvertedToUTF8 = 9026,
ERR_MisplacedUnchecked = 9027,
ERR_LineSpanDirectiveRequiresSpace = 9028,

ERR_RequiredNameDisallowed = 9029,
ERR_OverrideMustHaveRequired = 9030,
Expand Down
3 changes: 1 addition & 2 deletions src/Compilers/CSharp/Portable/Errors/MessageID.cs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ internal enum MessageID
IDS_FeatureLambdaReturnType = MessageBase + 12804,
IDS_AsyncMethodBuilderOverride = MessageBase + 12805,
IDS_FeatureImplicitImplementationOfNonPublicMembers = MessageBase + 12806,
IDS_FeatureLineSpanDirective = MessageBase + 12807,
// IDS_FeatureLineSpanDirective = MessageBase + 12807, // feature no longer gated on LangVer
IDS_FeatureImprovedInterpolatedStrings = MessageBase + 12808,
IDS_FeatureFileScopedNamespace = MessageBase + 12809,
IDS_FeatureParameterlessStructConstructors = MessageBase + 12810,
Expand Down Expand Up @@ -396,7 +396,6 @@ internal static LanguageVersion RequiredVersion(this MessageID feature)
case MessageID.IDS_AsyncMethodBuilderOverride: // semantic check
case MessageID.IDS_FeatureConstantInterpolatedStrings: // semantic check
case MessageID.IDS_FeatureImplicitImplementationOfNonPublicMembers: // semantic check
case MessageID.IDS_FeatureLineSpanDirective:
case MessageID.IDS_FeatureFileScopedNamespace: // syntax check
case MessageID.IDS_FeatureParameterlessStructConstructors: // semantic check
case MessageID.IDS_FeatureStructFieldInitializers: // semantic check
Expand Down
26 changes: 21 additions & 5 deletions src/Compilers/CSharp/Portable/Parser/DirectiveParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -406,13 +406,12 @@ private LineSpanDirectiveTriviaSyntax ParseLineSpanDirective(SyntaxToken hash, S
{
Debug.Assert(CurrentToken.Kind == SyntaxKind.OpenParenToken);

if (isActive)
{
lineKeyword = CheckFeatureAvailability(lineKeyword, MessageID.IDS_FeatureLineSpanDirective);
Copy link
Contributor

@cston cston Jun 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MessageID.IDS_FeatureLineSpanDirective

Can this MessageID be removed? #Resolved

}

bool reportError = isActive;
var start = ParseLineDirectivePosition(ref reportError, out int startLine, out int startCharacter);
if (noTriviaBetween(lineKeyword, start.GetFirstToken()))
{
start = this.AddError(start, ErrorCode.ERR_LineSpanDirectiveRequiresSpace);
}

var minus = EatToken(SyntaxKind.MinusToken, reportError: reportError);
if (minus.IsMissing) reportError = false;
Expand All @@ -428,11 +427,28 @@ private LineSpanDirectiveTriviaSyntax ParseLineSpanDirective(SyntaxToken hash, S
ParseLineDirectiveNumericLiteral(ref reportError, minValue: 1, maxValue: MaxCharacterValue, out _) :
null;

if (noTriviaBetween(end.GetLastToken(), characterOffset))
{
characterOffset = this.AddError(characterOffset, ErrorCode.ERR_LineSpanDirectiveRequiresSpace);
}

var file = EatToken(SyntaxKind.StringLiteralToken, ErrorCode.ERR_MissingPPFile, reportError: reportError);
if (file.IsMissing) reportError = false;

if (noTriviaBetween(characterOffset ?? end.GetLastToken(), file))
{
file = this.AddError(file, ErrorCode.ERR_LineSpanDirectiveRequiresSpace);
}

var endOfDirective = this.ParseEndOfDirective(ignoreErrors: !reportError);
return SyntaxFactory.LineSpanDirectiveTrivia(hash, lineKeyword, start, minus, end, characterOffset, file, endOfDirective, isActive);

static bool noTriviaBetween(SyntaxToken token1, SyntaxToken token2)
{
return token1 is { IsMissing: false }
&& token2 is { IsMissing: false }
&& LanguageParser.NoTriviaBetween(token1, token2);
}
}

private LineDirectivePositionSyntax ParseLineDirectivePosition(ref bool reportError, out int line, out int character)
Expand Down
2 changes: 1 addition & 1 deletion src/Compilers/CSharp/Portable/Parser/LanguageParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4596,7 +4596,7 @@ private void ParseParameterNullCheck(
GetExpectedTokenError(kind, t1.Kind));
}

private static bool NoTriviaBetween(SyntaxToken token1, SyntaxToken token2)
internal static bool NoTriviaBetween(SyntaxToken token1, SyntaxToken token2)
=> token1.GetTrailingTriviaWidth() == 0 && token2.GetLeadingTriviaWidth() == 0;

#nullable disable
Expand Down
10 changes: 5 additions & 5 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading