Skip to content

Commit

Permalink
Address prototype comments in file types branch (#62335)
Browse files Browse the repository at this point in the history
  • Loading branch information
RikkiGibson committed Jul 5, 2022
1 parent 53b193b commit 730e0d6
Show file tree
Hide file tree
Showing 33 changed files with 451 additions and 204 deletions.
15 changes: 14 additions & 1 deletion docs/compilers/CSharp/Compiler Breaking Changes - DotNet 7.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# This document lists known breaking changes in Roslyn after .NET 6 all the way to .NET 7.

## Types cannot be named `file`

***Introduced in Visual Studio 2022 version 17.4.*** Starting in C# 11, types cannot be named `file`. The compiler will report an error on all such type names. To work around this, the type name and all usages must be escaped with an `@`:

```csharp
class file {} // Error CS9056
class @file {} // No error
```

This was done as `file` is now a modifier for type declarations.

You can learn more about this change in the associated [csharplang issue](https://github.com/dotnet/csharplang/issues/6011).

## Required spaces in #line span directives

***Introduced in .NET SDK 6.0.400, Visual Studio 2022 version 17.3.***
Expand Down Expand Up @@ -426,4 +439,4 @@ class @required {} // No error

This was done as `required` is now a member modifier for properties and fields.

You can learn more about this change in the associated [csharplang issue](https://github.com/dotnet/csharplang/issues/3630).
You can learn more about this change in the associated [csharplang issue](https://github.com/dotnet/csharplang/issues/3630).
1 change: 1 addition & 0 deletions docs/contributing/Compiler Test Plan.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ This document provides guidance for thinking about language interactions and tes
# Type and members
- Access modifiers (public, protected, internal, protected internal, private protected, private), static, ref
- type declarations (class, record class/struct with or without positional members, struct, interface, type parameter)
- file-local types
- methods
- fields (required and not)
- properties (including get/set/init accessors, required and not)
Expand Down
2 changes: 1 addition & 1 deletion eng/config/globalconfigs/Common.globalconfig
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ dotnet_diagnostic.RS0006.severity = error
dotnet_diagnostic.RS0012.severity = warning
dotnet_diagnostic.RS0014.severity = warning
dotnet_diagnostic.RS0015.severity = warning
dotnet_diagnostic.RS0016.severity = none # PROTOTYPE(ft): re-enable before feature merge
dotnet_diagnostic.RS0016.severity = error
dotnet_diagnostic.RS0017.severity = error
dotnet_diagnostic.RS0018.severity = warning
dotnet_diagnostic.RS0022.severity = error
Expand Down
3 changes: 3 additions & 0 deletions src/CodeStyle/Core/Analyzers/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Microsoft.CodeAnalysis.Internal.Editing.DeclarationModifiers.IsPartial.get -> bo
Microsoft.CodeAnalysis.Internal.Editing.DeclarationModifiers.IsReadOnly.get -> bool
Microsoft.CodeAnalysis.Internal.Editing.DeclarationModifiers.IsRef.get -> bool
Microsoft.CodeAnalysis.Internal.Editing.DeclarationModifiers.IsRequired.get -> bool
Microsoft.CodeAnalysis.Internal.Editing.DeclarationModifiers.IsFile.get -> bool
Microsoft.CodeAnalysis.Internal.Editing.DeclarationModifiers.IsSealed.get -> bool
Microsoft.CodeAnalysis.Internal.Editing.DeclarationModifiers.IsStatic.get -> bool
Microsoft.CodeAnalysis.Internal.Editing.DeclarationModifiers.IsUnsafe.get -> bool
Expand All @@ -58,6 +59,7 @@ Microsoft.CodeAnalysis.Internal.Editing.DeclarationModifiers.WithIsOverride(bool
Microsoft.CodeAnalysis.Internal.Editing.DeclarationModifiers.WithIsReadOnly(bool isReadOnly) -> Microsoft.CodeAnalysis.Internal.Editing.DeclarationModifiers
Microsoft.CodeAnalysis.Internal.Editing.DeclarationModifiers.WithIsRef(bool isRef) -> Microsoft.CodeAnalysis.Internal.Editing.DeclarationModifiers
Microsoft.CodeAnalysis.Internal.Editing.DeclarationModifiers.WithIsRequired(bool isRequired) -> Microsoft.CodeAnalysis.Internal.Editing.DeclarationModifiers
Microsoft.CodeAnalysis.Internal.Editing.DeclarationModifiers.WithIsFile(bool isFile) -> Microsoft.CodeAnalysis.Internal.Editing.DeclarationModifiers
Microsoft.CodeAnalysis.Internal.Editing.DeclarationModifiers.WithIsSealed(bool isSealed) -> Microsoft.CodeAnalysis.Internal.Editing.DeclarationModifiers
Microsoft.CodeAnalysis.Internal.Editing.DeclarationModifiers.WithIsStatic(bool isStatic) -> Microsoft.CodeAnalysis.Internal.Editing.DeclarationModifiers
Microsoft.CodeAnalysis.Internal.Editing.DeclarationModifiers.WithIsUnsafe(bool isUnsafe) -> Microsoft.CodeAnalysis.Internal.Editing.DeclarationModifiers
Expand Down Expand Up @@ -87,6 +89,7 @@ static Microsoft.CodeAnalysis.Internal.Editing.DeclarationModifiers.Partial.get
static Microsoft.CodeAnalysis.Internal.Editing.DeclarationModifiers.ReadOnly.get -> Microsoft.CodeAnalysis.Internal.Editing.DeclarationModifiers
static Microsoft.CodeAnalysis.Internal.Editing.DeclarationModifiers.Ref.get -> Microsoft.CodeAnalysis.Internal.Editing.DeclarationModifiers
static Microsoft.CodeAnalysis.Internal.Editing.DeclarationModifiers.Required.get -> Microsoft.CodeAnalysis.Internal.Editing.DeclarationModifiers
static Microsoft.CodeAnalysis.Internal.Editing.DeclarationModifiers.File.get -> Microsoft.CodeAnalysis.Internal.Editing.DeclarationModifiers
static Microsoft.CodeAnalysis.Internal.Editing.DeclarationModifiers.Sealed.get -> Microsoft.CodeAnalysis.Internal.Editing.DeclarationModifiers
static Microsoft.CodeAnalysis.Internal.Editing.DeclarationModifiers.Static.get -> Microsoft.CodeAnalysis.Internal.Editing.DeclarationModifiers
static Microsoft.CodeAnalysis.Internal.Editing.DeclarationModifiers.TryParse(string value, out Microsoft.CodeAnalysis.Internal.Editing.DeclarationModifiers modifiers) -> bool
Expand Down
3 changes: 2 additions & 1 deletion src/Compilers/CSharp/Portable/Binder/Binder_Symbols.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1819,7 +1819,8 @@ public int Compare(Symbol fst, Symbol snd)
if (best.IsFromFile && !secondBest.IsFromFile)
{
// a lookup of a file type is "better" than a lookup of a non-file type; no need to further diagnose
// PROTOTYPE(ft): some "single symbol" diagnostics are missed here for similar reasons
// https://github.com/dotnet/roslyn/issues/62331
// some "single symbol" diagnostics are missed here for similar reasons
// that make us miss diagnostics when reporting WRN_SameFullNameThisAggAgg.
//
return first;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ internal BuckStopsHereBinder(CSharpCompilation compilation, SyntaxTree? associat
/// In speculative scenarios, the syntax tree from the original compilation used as the speculation context.
/// This is <see langword="null"/> in some scenarios, such as the binder used for <see cref="CSharpCompilation.Conversions" />
/// or the binder used to bind usings in <see cref="CSharpCompilation.UsingsFromOptionsAndDiagnostics"/>.
/// PROTOTYPE(ft): what about in EE scenarios?
/// https://github.com/dotnet/roslyn/issues/62332: what about in EE scenarios?
/// </summary>
internal readonly SyntaxTree? AssociatedSyntaxTree;

Expand Down
3 changes: 3 additions & 0 deletions src/Compilers/CSharp/Portable/CSharpResources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -7139,6 +7139,9 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ
<data name="ERR_GlobalUsingStaticFileType" xml:space="preserve">
<value>File type '{0}' cannot be used in a 'global using static' directive.</value>
</data>
<data name="ERR_FileTypeNameDisallowed" xml:space="preserve">
<value>Types and aliases cannot be named 'file'.</value>
</data>
<data name="IDS_FeatureUnsignedRightShift" xml:space="preserve">
<value>unsigned right shift</value>
</data>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ public static UsingsFromOptionsAndDiagnostics FromOptions(CSharpCompilation comp
}

var diagnostics = new DiagnosticBag();
// PROTOTYPE(ft): should usings from compilation options be allowed to bring file types into scope?
// it doesn't seem to work for non-file types within the compilaton, so can probably do the same for file types.
var usingsBinder = new InContainerBinder(compilation.GlobalNamespace, new BuckStopsHereBinder(compilation, associatedSyntaxTree: null));
var boundUsings = ArrayBuilder<NamespaceOrTypeAndUsingDirective>.GetInstance();
var uniqueUsings = PooledHashSet<NamespaceOrTypeSymbol>.GetInstance();
Expand Down
12 changes: 6 additions & 6 deletions src/Compilers/CSharp/Portable/Errors/ErrorCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2099,12 +2099,12 @@ internal enum ErrorCode
ERR_FixedFieldMustNotBeRef = 9049,
ERR_RefFieldCannotReferToRefStruct = 9050,

// PROTOTYPE(ft): compress these before feature merge
ERR_FileTypeDisallowedInSignature = 9300,
ERR_FileTypeNoExplicitAccessibility = 9301,
ERR_FileTypeBase = 9302,
ERR_FileTypeNested = 9303,
ERR_GlobalUsingStaticFileType = 9304
ERR_FileTypeDisallowedInSignature = 9051,
ERR_FileTypeNoExplicitAccessibility = 9052,
ERR_FileTypeBase = 9053,
ERR_FileTypeNested = 9054,
ERR_GlobalUsingStaticFileType = 9055,
ERR_FileTypeNameDisallowed = 9056,

#endregion

Expand Down
2 changes: 1 addition & 1 deletion src/Compilers/CSharp/Portable/Errors/MessageID.cs
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ internal enum MessageID
IDS_FeatureRelaxedShiftOperator = MessageBase + 12825,
IDS_FeatureRequiredMembers = MessageBase + 12826,
IDS_FeatureRefFields = MessageBase + 12827,
IDS_FeatureFileTypes = MessageBase + 12850, // PROTOTYPE(ft): pack ID before merge
IDS_FeatureFileTypes = MessageBase + 12828,
}

// Message IDs may refer to strings that need to be localized.
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 @@ -1251,7 +1251,7 @@ private void ParseModifiers(SyntaxListBuilder tokens, bool forAccessors, bool fo
}

case DeclarationModifiers.File:
if (!IsFeatureEnabled(MessageID.IDS_FeatureFileTypes) && !ShouldContextualKeywordBeTreatedAsModifier(parsingStatementNotDeclaration: false))
if ((!IsFeatureEnabled(MessageID.IDS_FeatureFileTypes) || forTopLevelStatements) && !ShouldContextualKeywordBeTreatedAsModifier(parsingStatementNotDeclaration: false))
{
return;
}
Expand Down
1 change: 1 addition & 0 deletions src/Compilers/CSharp/Portable/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Microsoft.CodeAnalysis.CSharp.SyntaxKind.InterpolatedSingleLineRawStringStartTok
Microsoft.CodeAnalysis.CSharp.SyntaxKind.MultiLineRawStringLiteralToken = 8519 -> Microsoft.CodeAnalysis.CSharp.SyntaxKind
Microsoft.CodeAnalysis.CSharp.SyntaxKind.RequiredKeyword = 8447 -> Microsoft.CodeAnalysis.CSharp.SyntaxKind
Microsoft.CodeAnalysis.CSharp.SyntaxKind.ScopedKeyword = 8448 -> Microsoft.CodeAnalysis.CSharp.SyntaxKind
Microsoft.CodeAnalysis.CSharp.SyntaxKind.FileKeyword = 8449 -> Microsoft.CodeAnalysis.CSharp.SyntaxKind
Microsoft.CodeAnalysis.CSharp.SyntaxKind.SingleLineRawStringLiteralToken = 8518 -> Microsoft.CodeAnalysis.CSharp.SyntaxKind
static Microsoft.CodeAnalysis.CSharp.SyntaxFactory.ConstructorDeclaration(Microsoft.CodeAnalysis.SyntaxList<Microsoft.CodeAnalysis.CSharp.Syntax.AttributeListSyntax!> attributeLists, Microsoft.CodeAnalysis.SyntaxTokenList modifiers, Microsoft.CodeAnalysis.SyntaxToken identifier, Microsoft.CodeAnalysis.CSharp.Syntax.ParameterListSyntax! parameterList, Microsoft.CodeAnalysis.CSharp.Syntax.ConstructorInitializerSyntax? initializer, Microsoft.CodeAnalysis.CSharp.Syntax.BlockSyntax! body) -> Microsoft.CodeAnalysis.CSharp.Syntax.ConstructorDeclarationSyntax!
*REMOVED*static Microsoft.CodeAnalysis.CSharp.SyntaxFactory.ConstructorDeclaration(Microsoft.CodeAnalysis.SyntaxList<Microsoft.CodeAnalysis.CSharp.Syntax.AttributeListSyntax!> attributeLists, Microsoft.CodeAnalysis.SyntaxTokenList modifiers, Microsoft.CodeAnalysis.SyntaxToken identifier, Microsoft.CodeAnalysis.CSharp.Syntax.ParameterListSyntax! parameterList, Microsoft.CodeAnalysis.CSharp.Syntax.ConstructorInitializerSyntax! initializer, Microsoft.CodeAnalysis.CSharp.Syntax.BlockSyntax! body) -> Microsoft.CodeAnalysis.CSharp.Syntax.ConstructorDeclarationSyntax!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,8 @@ private DeclarationModifiers MakeModifiers(TypeKind typeKind, BindingDiagnosticB
{
Symbol containingSymbol = this.ContainingSymbol;
DeclarationModifiers defaultAccess;
// PROTOTYPE(ft): confirm whether 'file' types can be nested

// note: we give a specific diagnostic when a file type is nested
var allowedModifiers = DeclarationModifiers.AccessibilityMask | DeclarationModifiers.File;

if (containingSymbol.Kind == SymbolKind.Namespace)
Expand Down Expand Up @@ -476,7 +477,8 @@ internal static void ReportReservedTypeName(string? name, CSharpCompilation comp
}

if (reportIfContextual(SyntaxKind.RecordKeyword, MessageID.IDS_FeatureRecords, ErrorCode.WRN_RecordNamedDisallowed)
|| reportIfContextual(SyntaxKind.RequiredKeyword, MessageID.IDS_FeatureRequiredMembers, ErrorCode.ERR_RequiredNameDisallowed))
|| reportIfContextual(SyntaxKind.RequiredKeyword, MessageID.IDS_FeatureRequiredMembers, ErrorCode.ERR_RequiredNameDisallowed)
|| reportIfContextual(SyntaxKind.FileKeyword, MessageID.IDS_FeatureFileTypes, ErrorCode.ERR_FileTypeNameDisallowed))
{
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,6 @@ private TypeWithAnnotations ComputeType(Binder binder, SyntaxNode syntax, Bindin

if (type.Type.IsFileTypeOrUsesFileTypes() && !ContainingType.IsFileTypeOrUsesFileTypes())
{
// PROTOTYPE(ft): should explicit interface implementations be allowed to use file types in signatures?
diagnostics.Add(ErrorCode.ERR_FileTypeDisallowedInSignature, Location, type.Type, ContainingType);
}

Expand Down
5 changes: 5 additions & 0 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.

5 changes: 5 additions & 0 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.

5 changes: 5 additions & 0 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.

5 changes: 5 additions & 0 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.

5 changes: 5 additions & 0 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.

5 changes: 5 additions & 0 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.

5 changes: 5 additions & 0 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.

5 changes: 5 additions & 0 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.

5 changes: 5 additions & 0 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.

5 changes: 5 additions & 0 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf

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

Loading

0 comments on commit 730e0d6

Please sign in to comment.