Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into addUsing
Browse files Browse the repository at this point in the history
  • Loading branch information
CyrusNajmabadi committed Nov 29, 2022
2 parents b7061e4 + 3594256 commit 3b2153c
Show file tree
Hide file tree
Showing 93 changed files with 3,787 additions and 2,961 deletions.
12 changes: 6 additions & 6 deletions docs/features/incremental-generators.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,12 @@ The simplest transformation is `Select`. This maps the value in one provider
into a new provider by applying a transform to it.

```ascii
IValueProvider<TSource> IValueProvider<TResult>
┌─────────────┐ ┌─────────────┐
│ │ Select<TSource,TResult1> │ │
│ TSource ├──────────────────────────►│ TResult │
│ │ │ │
└─────────────┘ └─────────────┘
IValueProvider<TSource> IValueProvider<TResult>
┌─────────────┐ ┌─────────────┐
│ │ Select<TSource,TResult> │ │
│ TSource ├──────────────────────────►│ TResult │
│ │ │ │
└─────────────┘ └─────────────┘
```

Generator transformations can be thought of as being conceptually somewhat similar to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,7 @@ public async Task TestOfferToConvertToBlockEvenIfExpressionBodyPreferredIfPriorT
using System;
class C
{
int Goo { {|IDE0027:get {|CS8059:=> {|CS8059:throw|} new NotImplementedException()|};|} }
int Goo { {|IDE0027:get {|CS8059:=>|} {|CS8059:throw|} new NotImplementedException();|} }
}";
var fixedCode = @"
using System;
Expand All @@ -756,8 +756,8 @@ public async Task TestOfferToConvertToBlockEvenIfExpressionBodyPreferredIfPriorT
using System;
class C
{
int Goo { {|IDE0027:get {|CS8059:=> {|CS8059:throw|} new NotImplementedException()|};|} }
int Bar { {|IDE0027:get {|CS8059:=> {|CS8059:throw|} new NotImplementedException()|};|} }
int Goo { {|IDE0027:get {|CS8059:=>|} {|CS8059:throw|} new NotImplementedException();|} }
int Bar { {|IDE0027:get {|CS8059:=>|} {|CS8059:throw|} new NotImplementedException();|} }
}";
var fixedCode = @"
using System;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ public async Task TestOfferToConvertToBlockEvenIfExpressionBodyPreferredIfPriorT
using System;
class C
{
{|IDE0021:public C() {|CS8059:=> {|CS8059:throw|} new NotImplementedException()|};|}
{|IDE0021:public C() {|CS8059:=>|} {|CS8059:throw|} new NotImplementedException();|}
}";
var fixedCode = @"
using System;
Expand All @@ -262,8 +262,8 @@ public async Task TestOfferToConvertToBlockEvenIfExpressionBodyPreferredIfPriorT
using System;
class C
{
{|IDE0021:public C() {|CS8059:=> {|CS8059:throw|} new NotImplementedException()|};|}
{|IDE0021:public C(int i) {|CS8059:=> {|CS8059:throw|} new NotImplementedException()|};|}
{|IDE0021:public C() {|CS8059:=>|} {|CS8059:throw|} new NotImplementedException();|}
{|IDE0021:public C(int i) {|CS8059:=>|} {|CS8059:throw|} new NotImplementedException();|}
}";
var fixedCode = @"
using System;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ public async Task TestOfferToConvertToBlockEvenIfExpressionBodyPreferredIfPriorT
using System;
class C
{
{|IDE0022:void M() {|CS8026:=> {|CS8026:throw|} new NotImplementedException()|};|}
{|IDE0022:void M() {|CS8026:=>|} {|CS8026:throw|} new NotImplementedException();|}
}";
var fixedCode = @"
using System;
Expand Down
5 changes: 5 additions & 0 deletions src/Compilers/CSharp/Portable/Binder/Binder_Expressions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4707,6 +4707,9 @@ private BoundObjectInitializerExpression BindObjectInitializerExpression(
initializerSyntax.Kind() == SyntaxKind.WithInitializerExpression);
Debug.Assert((object)initializerType != null);

if (initializerSyntax.Kind() == SyntaxKind.ObjectInitializerExpression)
MessageID.IDS_FeatureObjectInitializer.CheckFeatureAvailability(diagnostics, initializerSyntax, initializerSyntax.OpenBraceToken.GetLocation());

// We use a location specific binder for binding object initializer field/property access to generate object initializer specific diagnostics:
// 1) CS1914 (ERR_StaticMemberInObjectInitializer)
// 2) CS1917 (ERR_ReadonlyValueTypeInObjectInitializer)
Expand Down Expand Up @@ -5205,6 +5208,8 @@ private BoundCollectionInitializerExpression BindCollectionInitializerExpression
Debug.Assert(initializerSyntax.Expressions.Any());
Debug.Assert((object)initializerType != null);

MessageID.IDS_FeatureCollectionInitializer.CheckFeatureAvailability(diagnostics, initializerSyntax, initializerSyntax.OpenBraceToken.GetLocation());

var initializerBuilder = ArrayBuilder<BoundExpression>.GetInstance();

// SPEC: The collection object to which a collection initializer is applied must be of a type that implements System.Collections.IEnumerable or
Expand Down
5 changes: 5 additions & 0 deletions src/Compilers/CSharp/Portable/Binder/Binder_Lambda.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,11 @@ private UnboundLambda AnalyzeAnonymousFunction(
if (isLastParameter && paramsKeyword.Kind() != SyntaxKind.None)
{
hasParamsArray = true;

ReportUseSiteDiagnosticForSynthesizedAttribute(Compilation,
WellKnownMember.System_ParamArrayAttribute__ctor,
diagnostics,
paramsKeyword.GetLocation());
}
}

Expand Down
30 changes: 28 additions & 2 deletions src/Compilers/CSharp/Portable/Binder/Binder_Statements.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3466,9 +3466,28 @@ private static bool IsValidExpressionBody(SyntaxNode expressionSyntax, BoundExpr
/// <summary>
/// Binds an expression-bodied member with expression e as either { return e; } or { e; }.
/// </summary>
internal virtual BoundBlock BindExpressionBodyAsBlock(ArrowExpressionClauseSyntax expressionBody,
BindingDiagnosticBag diagnostics)
internal virtual BoundBlock BindExpressionBodyAsBlock(
ArrowExpressionClauseSyntax expressionBody,
BindingDiagnosticBag diagnostics)
{
var messageId = expressionBody.Parent switch
{
ConstructorDeclarationSyntax or DestructorDeclarationSyntax => MessageID.IDS_FeatureExpressionBodiedDeOrConstructor,
AccessorDeclarationSyntax => MessageID.IDS_FeatureExpressionBodiedAccessor,
BaseMethodDeclarationSyntax => MessageID.IDS_FeatureExpressionBodiedMethod,
IndexerDeclarationSyntax => MessageID.IDS_FeatureExpressionBodiedIndexer,
PropertyDeclarationSyntax => MessageID.IDS_FeatureExpressionBodiedProperty,
// No need to check if expression bodies are allowed if we have a local function. Local functions
// themselves are checked for availability, and if they are available then expression bodies must
// also be available.
LocalFunctionStatementSyntax => (MessageID?)null,
// null in speculative scenarios.
null => null,
_ => throw ExceptionUtilities.UnexpectedValue(expressionBody.Parent.Kind()),
};

messageId?.CheckFeatureAvailability(diagnostics, expressionBody, expressionBody.ArrowToken.GetLocation());

Binder bodyBinder = this.GetBinder(expressionBody);
Debug.Assert(bodyBinder != null);

Expand Down Expand Up @@ -3560,10 +3579,17 @@ private BoundNode BindSimpleProgram(CompilationUnitSyntax compilationUnit, Bindi
private BoundNode BindSimpleProgramCompilationUnit(CompilationUnitSyntax compilationUnit, BindingDiagnosticBag diagnostics)
{
ArrayBuilder<BoundStatement> boundStatements = ArrayBuilder<BoundStatement>.GetInstance();
var first = true;
foreach (var statement in compilationUnit.Members)
{
if (statement is GlobalStatementSyntax topLevelStatement)
{
if (first)
{
first = false;
MessageID.IDS_TopLevelStatements.CheckFeatureAvailability(diagnostics, topLevelStatement);
}

var boundStatement = BindStatement(topLevelStatement.Statement, diagnostics);
boundStatements.Add(boundStatement);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,15 @@ public override Conversion GetMethodGroupDelegateConversion(BoundMethodGroup sou

Debug.Assert(methodSymbol == ((NamedTypeSymbol)destination).DelegateInvokeMethod);

// If synthesizing a delegate with `params` array, check that `ParamArrayAttribute` is available.
if (methodSymbol.OriginalDefinition is SynthesizedDelegateInvokeMethod { Parameters: [.., { IsParams: true }] })
{
Binder.GetWellKnownTypeMember(Compilation,
WellKnownMember.System_ParamArrayAttribute__ctor,
out var memberUseSiteInfo);
useSiteInfo.Add(memberUseSiteInfo);
}

var resolution = ResolveDelegateOrFunctionPointerMethodGroup(_binder, source, methodSymbol, isFunctionPointer, callingConventionInfo, ref useSiteInfo);
var conversion = (resolution.IsEmpty || resolution.HasAnyErrors) ?
Conversion.NoConversion :
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -593,9 +593,9 @@ public override SingleNamespaceOrTypeDeclaration VisitRecordDeclaration(RecordDe

private SingleNamespaceOrTypeDeclaration VisitTypeDeclaration(TypeDeclarationSyntax node, DeclarationKind kind)
{
SingleTypeDeclaration.TypeDeclarationFlags declFlags = node.AttributeLists.Any() ?
SingleTypeDeclaration.TypeDeclarationFlags.HasAnyAttributes :
SingleTypeDeclaration.TypeDeclarationFlags.None;
var declFlags = node.AttributeLists.Any()
? SingleTypeDeclaration.TypeDeclarationFlags.HasAnyAttributes
: SingleTypeDeclaration.TypeDeclarationFlags.None;

if (node.BaseList != null)
{
Expand All @@ -618,6 +618,16 @@ private SingleNamespaceOrTypeDeclaration VisitTypeDeclaration(TypeDeclarationSyn
declFlags |= SingleTypeDeclaration.TypeDeclarationFlags.HasAnyNontypeMembers;
}

// If we have `record class` or `record struct` check that this is supported in the language. Note: we don't
// have to do any check for the simple `record` case as the parser itself would never produce such a node
// unless the language version was sufficient (since it actually will not produce the node at all on
// previous versions).
if (node is RecordDeclarationSyntax record &&
record.ClassOrStructKeyword.Kind() != SyntaxKind.None)
{
MessageID.IDS_FeatureRecordStructs.CheckFeatureAvailability(diagnostics, record, record.ClassOrStructKeyword.GetLocation());
}

var modifiers = node.Modifiers.ToDeclarationModifiers(diagnostics: diagnostics);
var quickAttributes = GetQuickAttributes(node.AttributeLists);

Expand Down
Loading

0 comments on commit 3b2153c

Please sign in to comment.