Skip to content

Commit

Permalink
Merge pull request #58546 from dotnet/merges/main-to-features/semi-au…
Browse files Browse the repository at this point in the history
…to-props

Merge main to features/semi-auto-props
  • Loading branch information
dotnet-bot authored Jan 2, 2022
2 parents 83b7470 + cb400a9 commit c413257
Show file tree
Hide file tree
Showing 48 changed files with 2,078 additions and 907 deletions.
2 changes: 1 addition & 1 deletion docs/Language Feature Status.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ efforts behind them.
| [Relax ordering of `ref` and `partial` modifiers](https://github.com/dotnet/csharplang/issues/946) | [ref-partial](https://github.com/dotnet/roslyn/tree/features/ref-partial) | In Progress | [alrz](https://github.com/alrz) | [gafter](https://github.com/gafter) | [jcouv](https://github.com/jcouv) |
| [Generic attributes](https://github.com/dotnet/csharplang/issues/124) | [generic-attributes](https://github.com/dotnet/roslyn/tree/features/generic-attributes) | [Merged into 17.0p4 (preview langver)](https://github.com/dotnet/roslyn/issues/36285) | [AviAvni](https://github.com/AviAvni) | [RikkiGibson](https://github.com/RikkiGibson), [jcouv](https://github.com/jcouv) | [mattwar](https://github.com/mattwar) |
| [Default in deconstruction](https://github.com/dotnet/roslyn/pull/25562) | [decon-default](https://github.com/dotnet/roslyn/tree/features/decon-default) | [Implemented](https://github.com/dotnet/roslyn/issues/25559) | [jcouv](https://github.com/jcouv) | [gafter](https://github.com/gafter) | [jcouv](https://github.com/jcouv) |
| [Semi-auto-properties](https://github.com/dotnet/csharplang/issues/140) | [semi-auto-properties](https://github.com/dotnet/roslyn/tree/features/features/semi-auto-properties) | [In Progress](https://github.com/dotnet/roslyn/issues/57012) | [Youssef1313](https://github.com/Youssef1313) | TBD | [CyrusNajmabadi](https://github.com/CyrusNajmabadi) |
| [Semi-auto-properties](https://github.com/dotnet/csharplang/issues/140) | [semi-auto-props](https://github.com/dotnet/roslyn/tree/features/semi-auto-props) | [In Progress](https://github.com/dotnet/roslyn/issues/57012) | [Youssef1313](https://github.com/Youssef1313) | [333fred](https://github.com/333fred), [RikkiGibson](https://github.com/RikkiGibson) | [CyrusNajmabadi](https://github.com/CyrusNajmabadi) |
| [Required members](https://github.com/dotnet/csharplang/issues/3630) | [required-members](https://github.com/dotnet/roslyn/tree/features/required-members) | [In Progress](https://github.com/dotnet/roslyn/issues/57046) | [333fred](https://github.com/333fred) | [jcouv](https://github.com/jcouv), [RikkiGibson](https://github.com/RikkiGibson) | [333fred](https://github.com/333fred) |
| [Top Level statement attribute specifiers](https://github.com/dotnet/csharplang/issues/5045) | [main-attributes](https://github.com/dotnet/roslyn/tree/features/features/main-attributes) | [In Progress](https://github.com/dotnet/roslyn/issues/57047) | [chsienki](https://github.com/chsienki) | TBD | [jaredpar](https://github.com/jaredpar) |
| [Primary Constructors](https://github.com/dotnet/csharplang/issues/2691) | [primary-constructors](https://github.com/dotnet/roslyn/tree/features/features/primary-constructors) | [In Progress](https://github.com/dotnet/roslyn/issues/57048) | TBD | TBD | [MadsTorgersen](https://github.com/MadsTorgersen) |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ private InfoCache(INamedTypeSymbol indexType)
public static bool TryCreate(Compilation compilation, [NotNullWhen(true)] out InfoCache? infoCache)
{
var indexType = compilation.GetBestTypeByMetadataName("System.Index");
if (indexType == null)
if (indexType == null || !indexType.IsAccessibleWithin(compilation.Assembly))
{
infoCache = null;
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ private InfoCache(INamedTypeSymbol rangeType, INamedTypeSymbol stringType)
public static bool TryCreate(Compilation compilation, [NotNullWhen(true)] out InfoCache? infoCache)
{
var rangeType = compilation.GetBestTypeByMetadataName("System.Range");
if (rangeType == null)
if (rangeType == null || !rangeType.IsAccessibleWithin(compilation.Assembly))
{
infoCache = null;
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,43 @@ void Goo(string[] s)
ReferenceAssemblies = ReferenceAssemblies.NetCore.NetCoreApp20,
TestCode = source,
FixedCode = source,
LanguageVersion = LanguageVersion.CSharp8,
}.RunAsync();
}

[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsUseIndexOperator)]
public async Task TestMissingWithInaccessibleSystemIndex()
{
var source =
@"
class C
{
void Goo(string[] s)
{
var v = s[s.Length - 1];
}
}";

await new VerifyCS.Test
{
ReferenceAssemblies = ReferenceAssemblies.NetCore.NetCoreApp20,
TestState =
{
Sources = { source },
AdditionalProjects =
{
["AdditionalProject"] =
{
Sources =
{
"namespace System { internal struct Index { } }"
}
}
},
AdditionalProjectReferences = { "AdditionalProject" },
},
FixedCode = source,
LanguageVersion = LanguageVersion.CSharp8,
}.RunAsync();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,43 @@ void Goo(string s)
ReferenceAssemblies = ReferenceAssemblies.NetCore.NetCoreApp20,
TestCode = source,
FixedCode = source,
LanguageVersion = LanguageVersion.CSharp7,
LanguageVersion = LanguageVersion.CSharp8,
}.RunAsync();
}

[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsUseRangeOperator)]
public async Task TestNotWithInaccessibleSystemRange()
{
var source =
@"
class C
{
void Goo(string s)
{
var v = s.Substring(1, s.Length - 1);
}
}";

await new VerifyCS.Test
{
ReferenceAssemblies = ReferenceAssemblies.NetCore.NetCoreApp20,
TestState =
{
Sources = { source },
AdditionalProjects =
{
["AdditionalProject"] =
{
Sources =
{
"namespace System { internal struct Range { } }"
}
}
},
AdditionalProjectReferences = { "AdditionalProject" },
},
FixedCode = source,
LanguageVersion = LanguageVersion.CSharp8,
}.RunAsync();
}

Expand Down
48 changes: 28 additions & 20 deletions src/Compilers/CSharp/Portable/Compilation/MemberSemanticModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1998,24 +1998,7 @@ protected void EnsureNullabilityAnalysisPerformedIfNecessary()

BoundNode bind(CSharpSyntaxNode root, out Binder binder)
{
if (root is CompilationUnitSyntax)
{
// Top level statements are unique among our nodes: if there are no syntax nodes before local functions,
// then that means the start of the span of the top-level statement is the same as the start of the local
// function. Therefore, GetEnclosingBinder can't tell the difference, and it will get the binder for the
// local function, not for the CompilationUnitSyntax. This is desirable in almost all cases but this one:
// There are no locals or invocations before this, meaning there's nothing to call GetDeclaredSymbol,
// GetTypeInfo, or GetSymbolInfo on. GetDeclaredSymbol(CompilationUnitSyntax) goes down another path that
// does not need to do any binding whatsoever, so it also doesn't care about this behavior. The only place
// that actually needs to get the enclosing binding for a CompilationUnitSyntax in such a scenario is this
// method. So, if our root is the CompilationUnitSyntax, directly get the binder for it.
binder = RootBinder.GetBinder(root);
Debug.Assert(binder is SimpleProgramBinder);
}
else
{
binder = GetEnclosingBinder(GetAdjustedNodePosition(root));
}
binder = GetBinderToBindNode(root);
return Bind(binder, root, BindingDiagnosticBag.Discarded);
}

Expand All @@ -2038,6 +2021,31 @@ void rewriteAndCache()
}
}

private Binder GetBinderToBindNode(CSharpSyntaxNode nodeToBind)
{
Binder binder;
if (nodeToBind is CompilationUnitSyntax)
{
// Top level statements are unique among our nodes: if there are no syntax nodes before local functions,
// then that means the start of the span of the top-level statement is the same as the start of the local
// function. Therefore, GetEnclosingBinder can't tell the difference, and it will get the binder for the
// local function, not for the CompilationUnitSyntax. This is desirable in almost all cases but this one:
// There are no locals or invocations before this, meaning there's nothing to call GetDeclaredSymbol,
// GetTypeInfo, or GetSymbolInfo on. GetDeclaredSymbol(CompilationUnitSyntax) goes down another path that
// does not need to do any binding whatsoever, so it also doesn't care about this behavior. The only place
// that actually needs to get the enclosing binding for a CompilationUnitSyntax in such a scenario is this
// method. So, if our root is the CompilationUnitSyntax, directly get the binder for it.
binder = RootBinder.GetBinder(nodeToBind);
Debug.Assert(binder is SimpleProgramBinder);
}
else
{
binder = GetEnclosingBinder(GetAdjustedNodePosition(nodeToBind));
}

return binder;
}

#nullable enable
/// <summary>
/// Rewrites the given bound node with nullability information, and returns snapshots for later speculative analysis at positions inside this member.
Expand Down Expand Up @@ -2105,7 +2113,7 @@ internal ImmutableArray<BoundNode> GetBoundNodes(CSharpSyntaxNode node)
// If we didn't find in the cached bound nodes, find a binding root and bind it.
// This will cache bound nodes under the binding root.
CSharpSyntaxNode nodeToBind = GetBindingRoot(node);
var statementBinder = GetEnclosingBinder(GetAdjustedNodePosition(nodeToBind));
var statementBinder = GetBinderToBindNode(nodeToBind);
Binder incrementalBinder = new IncrementalBinder(this, statementBinder);

using (_nodeMapLock.DisposableWrite())
Expand All @@ -2126,7 +2134,7 @@ internal ImmutableArray<BoundNode> GetBoundNodes(CSharpSyntaxNode node)
// In this case, however, we only add the single bound node we found to the map, not any child bound nodes,
// to avoid duplicates in the map if a parent of this node comes through this code path also.

var binder = GetEnclosingBinder(GetAdjustedNodePosition(node));
var binder = GetBinderToBindNode(node);
incrementalBinder = new IncrementalBinder(this, binder);

using (_nodeMapLock.DisposableRead())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ private void EnsureSignatureIsLoaded()
type = NullableTypeDecoder.TransformType(type, _handle, moduleSymbol, accessSymbol: this, nullableContext: _containingType);
type = TupleTypeDecoder.DecodeTupleTypesIfApplicable(type, _handle, moduleSymbol);

_lazyIsVolatile = customModifiersArray.Any(m => !m.IsOptional && m.Modifier.SpecialType == SpecialType.System_Runtime_CompilerServices_IsVolatile);
_lazyIsVolatile = customModifiersArray.Any(m => !m.IsOptional && ((CSharpCustomModifier)m).ModifierSymbol.SpecialType == SpecialType.System_Runtime_CompilerServices_IsVolatile);

TypeSymbol fixedElementType;
int fixedSize;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -449,12 +449,9 @@ internal static void ReportReservedTypeName(string? name, CSharpCompilation comp
return;
}

if (name == SyntaxFacts.GetText(SyntaxKind.RecordKeyword))
if (name == SyntaxFacts.GetText(SyntaxKind.RecordKeyword) && compilation.LanguageVersion >= MessageID.IDS_FeatureRecords.RequiredVersion())
{
if (compilation.LanguageVersion >= MessageID.IDS_FeatureRecords.RequiredVersion())
{
diagnostics.Add(ErrorCode.WRN_RecordNamedDisallowed, location);
}
diagnostics.Add(ErrorCode.WRN_RecordNamedDisallowed, location);
}
else if (IsReservedTypeName(name))
{
Expand Down
Loading

0 comments on commit c413257

Please sign in to comment.