Skip to content

Commit

Permalink
Use "file local types" instead of "file types" (dotnet#62514)
Browse files Browse the repository at this point in the history
  • Loading branch information
RikkiGibson authored and adamperlin committed Jul 19, 2022
1 parent 82c18d3 commit 9cb5e97
Show file tree
Hide file tree
Showing 42 changed files with 280 additions and 280 deletions.
6 changes: 3 additions & 3 deletions src/Compilers/CSharp/Portable/Binder/Binder_Constraints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -411,9 +411,9 @@ private static void CheckConstraintTypeVisibility(
diagnostics.Add(ErrorCode.ERR_BadVisBound, location, containingSymbol, constraintType.Type);
}

if (constraintType.Type.IsFileTypeOrUsesFileTypes())
if (constraintType.Type.HasFileLocalTypes())
{
// if the containing symbol of the constraint is a member, we need to ensure the nearest containing type is a file type.
// if the containing symbol of the constraint is a member, we need to ensure the nearest containing type is a file-local type.
var possibleFileType = containingSymbol switch
{
TypeSymbol typeSymbol => typeSymbol,
Expand All @@ -422,7 +422,7 @@ private static void CheckConstraintTypeVisibility(
_ => throw ExceptionUtilities.UnexpectedValue(containingSymbol)
};
Debug.Assert(possibleFileType?.IsDefinition != false);
if (possibleFileType?.IsFileTypeOrUsesFileTypes() == false)
if (possibleFileType?.HasFileLocalTypes() == false)
{
diagnostics.Add(ErrorCode.ERR_FileTypeDisallowedInSignature, location, constraintType.Type, containingSymbol);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Compilers/CSharp/Portable/Binder/Binder_Lookup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1308,14 +1308,14 @@ internal static ImmutableArray<Symbol> GetCandidateMembers(NamespaceOrTypeSymbol

private bool IsInScopeOfAssociatedSyntaxTree(Symbol symbol)
{
while (symbol is not null and not SourceMemberContainerTypeSymbol { IsFile: true })
while (symbol is not null and not SourceMemberContainerTypeSymbol { IsFileLocal: true })
{
symbol = symbol.ContainingType;
}

if (symbol is null)
{
// the passed-in symbol was not contained in a file type.
// the passed-in symbol was not contained in a file-local type.
return true;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Compilers/CSharp/Portable/Binder/Binder_Symbols.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1818,7 +1818,7 @@ Symbol resultSymbol(

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
// a lookup of a file-local type is "better" than a lookup of a non-file-local type; no need to further diagnose
// 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.
Expand Down Expand Up @@ -2300,7 +2300,7 @@ private BestSymbolInfo GetBestSymbolInfo(ArrayBuilder<Symbol> symbols, out BestS

private static BestSymbolLocation GetLocation(CSharpCompilation compilation, Symbol symbol)
{
if (symbol is SourceMemberContainerTypeSymbol { IsFile: true })
if (symbol is SourceMemberContainerTypeSymbol { IsFileLocal: true })
{
return BestSymbolLocation.FromFile;
}
Expand Down
10 changes: 5 additions & 5 deletions src/Compilers/CSharp/Portable/CSharpResources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -7125,19 +7125,19 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ
<value>'{2}' cannot satisfy the 'new()' constraint on parameter '{1}' in the generic type or or method '{0}' because '{2}' has required members.</value>
</data>
<data name="ERR_FileTypeDisallowedInSignature" xml:space="preserve">
<value>File type '{0}' cannot be used in a member signature in non-file type '{1}'.</value>
<value>File-local type '{0}' cannot be used in a member signature in non-file-local type '{1}'.</value>
</data>
<data name="ERR_FileTypeNoExplicitAccessibility" xml:space="preserve">
<value>File type '{0}' cannot use accessibility modifiers.</value>
<value>File-local type '{0}' cannot use accessibility modifiers.</value>
</data>
<data name="ERR_FileTypeBase" xml:space="preserve">
<value>File type '{0}' cannot be used as a base type of non-file type '{1}'.</value>
<value>File-local type '{0}' cannot be used as a base type of non-file-local type '{1}'.</value>
</data>
<data name="ERR_FileTypeNested" xml:space="preserve">
<value>File type '{0}' must be defined in a top level type; '{0}' is a nested type.</value>
<value>File-local type '{0}' must be defined in a top level type; '{0}' is a nested type.</value>
</data>
<data name="ERR_GlobalUsingStaticFileType" xml:space="preserve">
<value>File type '{0}' cannot be used in a 'global using static' directive.</value>
<value>File-local 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>
Expand Down
2 changes: 1 addition & 1 deletion src/Compilers/CSharp/Portable/Symbols/NamedTypeSymbol.cs
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ public override string MetadataName
}

/// <summary>
/// If this type is a file type, returns the syntax tree where this type is visible. Otherwise, returns null.
/// If this type is a file-local type, returns the syntax tree where this type is visible. Otherwise, returns null.
/// </summary>
internal abstract SyntaxTree? AssociatedSyntaxTree { get; }
#nullable disable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ INamedTypeSymbol INamedTypeSymbol.TupleUnderlyingType

bool INamedTypeSymbol.IsSerializable => UnderlyingNamedTypeSymbol.IsSerializable;

bool INamedTypeSymbol.IsFile => UnderlyingNamedTypeSymbol.AssociatedSyntaxTree is not null;
bool INamedTypeSymbol.IsFileLocal => UnderlyingNamedTypeSymbol.AssociatedSyntaxTree is not null;

INamedTypeSymbol INamedTypeSymbol.NativeIntegerUnderlyingType => UnderlyingNamedTypeSymbol.NativeIntegerUnderlyingType.GetPublicSymbol();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ internal static void AddDelegateMembers(
diagnostics.Add(ErrorCode.ERR_BadVisDelegateReturn, delegateType.Locations[0], delegateType, invoke.ReturnType);
}

var delegateTypeIsFile = delegateType.IsFileTypeOrUsesFileTypes();
if (!delegateTypeIsFile && invoke.ReturnType.IsFileTypeOrUsesFileTypes())
var delegateTypeIsFile = delegateType.HasFileLocalTypes();
if (!delegateTypeIsFile && invoke.ReturnType.HasFileLocalTypes())
{
diagnostics.Add(ErrorCode.ERR_FileTypeDisallowedInSignature, delegateType.Locations[0], invoke.ReturnType, delegateType);
}
Expand All @@ -110,7 +110,7 @@ internal static void AddDelegateMembers(
// Inconsistent accessibility: parameter type '{1}' is less accessible than delegate '{0}'
diagnostics.Add(ErrorCode.ERR_BadVisDelegateParam, delegateType.Locations[0], delegateType, parameterSymbol.Type);
}
else if (!delegateTypeIsFile && parameterSymbol.Type.IsFileTypeOrUsesFileTypes())
else if (!delegateTypeIsFile && parameterSymbol.Type.HasFileLocalTypes())
{
diagnostics.Add(ErrorCode.ERR_FileTypeDisallowedInSignature, delegateType.Locations[0], parameterSymbol.Type, delegateType);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ private DeclarationModifiers MakeModifiers(TypeKind typeKind, BindingDiagnosticB
Symbol containingSymbol = this.ContainingSymbol;
DeclarationModifiers defaultAccess;

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

if (containingSymbol.Kind == SymbolKind.Namespace)
Expand Down Expand Up @@ -826,9 +826,9 @@ internal override ManagedKind GetManagedKind(ref CompoundUseSiteInfo<AssemblySym

internal bool IsNew => HasFlag(DeclarationModifiers.New);

internal bool IsFile => HasFlag(DeclarationModifiers.File);
internal bool IsFileLocal => HasFlag(DeclarationModifiers.File);

internal sealed override SyntaxTree? AssociatedSyntaxTree => IsFile ? declaration.Declarations[0].Location.SourceTree : null;
internal sealed override SyntaxTree? AssociatedSyntaxTree => IsFileLocal ? declaration.Declarations[0].Location.SourceTree : null;

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private bool HasFlag(DeclarationModifiers flag) => (_declModifiers & flag) != 0;
Expand Down Expand Up @@ -1744,7 +1744,7 @@ protected void AfterMembersChecks(BindingDiagnosticBag diagnostics)
}
}

if (IsFile && (object?)ContainingType != null)
if (IsFileLocal && (object?)ContainingType != null)
{
diagnostics.Add(ErrorCode.ERR_FileTypeNested, location, this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ protected sealed override DeclarationModifiers Modifiers

protected void TypeChecks(TypeSymbol type, BindingDiagnosticBag diagnostics)
{
if (type.IsFileTypeOrUsesFileTypes() && !ContainingType.IsFileTypeOrUsesFileTypes())
if (type.HasFileLocalTypes() && !ContainingType.HasFileLocalTypes())
{
diagnostics.Add(ErrorCode.ERR_FileTypeDisallowedInSignature, this.ErrorLocation, type, ContainingType);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,19 +280,19 @@ protected void CheckEffectiveAccessibility(TypeWithAnnotations returnType, Immut

protected void CheckFileTypeUsage(TypeWithAnnotations returnType, ImmutableArray<ParameterSymbol> parameters, BindingDiagnosticBag diagnostics)
{
if (ContainingType.IsFileTypeOrUsesFileTypes())
if (ContainingType.HasFileLocalTypes())
{
return;
}

if (returnType.Type.IsFileTypeOrUsesFileTypes())
if (returnType.Type.HasFileLocalTypes())
{
diagnostics.Add(ErrorCode.ERR_FileTypeDisallowedInSignature, Locations[0], returnType.Type, ContainingType);
}

foreach (var param in parameters)
{
if (param.Type.IsFileTypeOrUsesFileTypes())
if (param.Type.HasFileLocalTypes())
{
diagnostics.Add(ErrorCode.ERR_FileTypeDisallowedInSignature, Locations[0], param.Type, ContainingType);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ static bool containsOnlyOblivious(TypeSymbol type)
diagnostics.Add(ErrorCode.ERR_BadVisBaseClass, baseTypeLocation, this, baseType);
}

if (baseType.IsFileTypeOrUsesFileTypes() && !this.IsFileTypeOrUsesFileTypes())
if (baseType.HasFileLocalTypes() && !this.HasFileLocalTypes())
{
diagnostics.Add(ErrorCode.ERR_FileTypeBase, baseTypeLocation, baseType, this);
}
Expand All @@ -402,7 +402,7 @@ static bool containsOnlyOblivious(TypeSymbol type)
diagnostics.Add(ErrorCode.ERR_BadVisBaseInterface, interfaceLocations[i], this, i);
}

if (i.IsFileTypeOrUsesFileTypes() && !this.IsFileTypeOrUsesFileTypes())
if (i.HasFileLocalTypes() && !this.HasFileLocalTypes())
{
diagnostics.Add(ErrorCode.ERR_FileTypeBase, interfaceLocations[i], i, this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,7 @@ UsingsAndDiagnostics buildUsings(
else
{
var importedType = (NamedTypeSymbol)imported;
if (usingDirective.GlobalKeyword != default(SyntaxToken) && importedType.IsFileTypeOrUsesFileTypes())
if (usingDirective.GlobalKeyword != default(SyntaxToken) && importedType.HasFileLocalTypes())
{
diagnostics.Add(ErrorCode.ERR_GlobalUsingStaticFileType, usingDirective.Name.Location, imported);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ private static void CheckMembers(NamespaceSymbol @namespace, Dictionary<string,
{
switch (nts, other)
{
case (SourceNamedTypeSymbol left, SourceNamedTypeSymbol right) when isFileTypeInSeparateFileFrom(left, right) || isFileTypeInSeparateFileFrom(right, left):
case (SourceNamedTypeSymbol left, SourceNamedTypeSymbol right) when isFileLocalTypeInSeparateFileFrom(left, right) || isFileLocalTypeInSeparateFileFrom(right, left):
// no error
break;
case (SourceNamedTypeSymbol { IsPartial: true }, SourceNamedTypeSymbol { IsPartial: true }):
Expand All @@ -400,14 +400,14 @@ private static void CheckMembers(NamespaceSymbol @namespace, Dictionary<string,
}
}

static bool isFileTypeInSeparateFileFrom(SourceNamedTypeSymbol possibleFileType, SourceNamedTypeSymbol otherSymbol)
static bool isFileLocalTypeInSeparateFileFrom(SourceNamedTypeSymbol possibleFileLocalType, SourceNamedTypeSymbol otherSymbol)
{
if (!possibleFileType.IsFile)
if (!possibleFileLocalType.IsFileLocal)
{
return false;
}

var leftTree = possibleFileType.MergedDeclaration.Declarations[0].Location.SourceTree;
var leftTree = possibleFileLocalType.MergedDeclaration.Declarations[0].Location.SourceTree;
if (otherSymbol.MergedDeclaration.NameLocations.Any((loc, leftTree) => (object)loc.SourceTree == leftTree, leftTree))
{
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ private TypeWithAnnotations ComputeType(Binder binder, SyntaxNode syntax, Bindin
diagnostics.Add((this.IsIndexer ? ErrorCode.ERR_BadVisIndexerReturn : ErrorCode.ERR_BadVisPropertyType), Location, this, type.Type);
}

if (type.Type.IsFileTypeOrUsesFileTypes() && !ContainingType.IsFileTypeOrUsesFileTypes())
if (type.Type.HasFileLocalTypes() && !ContainingType.HasFileLocalTypes())
{
diagnostics.Add(ErrorCode.ERR_FileTypeDisallowedInSignature, Location, type.Type, ContainingType);
}
Expand Down Expand Up @@ -533,7 +533,7 @@ internal override void AfterAddingTypeMembersChecks(ConversionsBase conversions,
{
diagnostics.Add(ErrorCode.ERR_BadVisIndexerParam, Location, this, param.Type);
}
else if (param.Type.IsFileTypeOrUsesFileTypes() && !this.ContainingType.IsFileTypeOrUsesFileTypes())
else if (param.Type.HasFileLocalTypes() && !this.ContainingType.HasFileLocalTypes())
{
diagnostics.Add(ErrorCode.ERR_FileTypeDisallowedInSignature, Location, param.Type, this.ContainingType);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,12 @@ internal static bool TryParseAnonymousTypeParameterName(string typeParameterName
return false;
}

// A full metadata name for a generic file type looks like:
// A full metadata name for a generic file-local type looks like:
// <ContainingFile>FN__ClassName`A
// where 'N' is the syntax tree ordinal, 'A' is the arity,
// and 'ClassName' is the source name of the type.
//
// The "unmangled" name of a generic file type looks like:
// The "unmangled" name of a generic file-local type looks like:
// <ContainingFile>FN__ClassName
private static readonly Regex s_fileTypeOrdinalPattern = new Regex(@"<([a-zA-Z_0-9]*)>F(\d)+__", RegexOptions.Compiled);

Expand Down
4 changes: 2 additions & 2 deletions src/Compilers/CSharp/Portable/Symbols/TypeSymbolExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1361,9 +1361,9 @@ public static bool IsPartial(this TypeSymbol type)
return type is SourceNamedTypeSymbol { IsPartial: true };
}

public static bool IsFileTypeOrUsesFileTypes(this TypeSymbol type)
public static bool HasFileLocalTypes(this TypeSymbol type)
{
var foundType = type.VisitType(predicate: (type, _, _) => type is SourceMemberContainerTypeSymbol { IsFile: true }, arg: (object?)null);
var foundType = type.VisitType(predicate: (type, _, _) => type is SourceMemberContainerTypeSymbol { IsFileLocal: true }, arg: (object?)null);
return foundType is not null;
}

Expand Down
20 changes: 10 additions & 10 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.

Loading

0 comments on commit 9cb5e97

Please sign in to comment.