Skip to content

Commit 89e3513

Browse files
Simplify
1 parent 1cb5d53 commit 89e3513

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

src/Compilers/CSharp/Portable/Binder/Binder_Lambda.cs

+8-4
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ private UnboundLambda AnalyzeAnonymousFunction(
122122
if (parameterSyntaxListOpt != null)
123123
{
124124
var parameterSyntaxList = parameterSyntaxListOpt.Value;
125-
var hasExplicitlyTypedParameterList = parameterSyntaxList.All(static p => p.Type != null);
125+
var hasExplicitlyTypedParameterList = parameterSyntaxList.Any(static p => p.Type != null);
126126

127127
var typesBuilder = ArrayBuilder<TypeWithAnnotations>.GetInstance();
128128
var refKindsBuilder = ArrayBuilder<RefKind>.GetInstance();
@@ -176,7 +176,11 @@ private UnboundLambda AnalyzeAnonymousFunction(
176176
continue;
177177
}
178178

179-
var type = p.Type is not null ? BindType(p.Type, diagnostics) : default;
179+
var type = p.Type is not null
180+
? BindType(p.Type, diagnostics)
181+
: hasExplicitlyTypedParameterList
182+
? TypeWithAnnotations.Create(CreateErrorType())
183+
: default;
180184

181185
var refKind = ParameterHelpers.GetModifiers(p.Modifiers, out _, out var paramsKeyword, out _, out var scope);
182186
var isParams = paramsKeyword.Kind() != SyntaxKind.None;
@@ -189,7 +193,7 @@ private UnboundLambda AnalyzeAnonymousFunction(
189193
owner: null, p, ordinal: i, lastParameterIndex: n - 1, isParams: isParams, type,
190194
refKind, containingSymbol: null, thisKeyword: default, paramsKeyword: paramsKeyword, firstDefault, diagnostics);
191195

192-
var isLastParameter = parameterCount == parameterSyntaxListOpt.Value.Count;
196+
var isLastParameter = parameterCount == parameterSyntaxList.Count;
193197
if (isLastParameter && paramsKeyword.Kind() != SyntaxKind.None && !type.IsDefault && type.IsSZArray())
194198
{
195199
ReportUseSiteDiagnosticForSynthesizedAttribute(Compilation,
@@ -206,7 +210,7 @@ private UnboundLambda AnalyzeAnonymousFunction(
206210
defaultValueBuilder.Add(p.Default);
207211
}
208212

209-
discardsOpt = computeDiscards(parameterSyntaxListOpt.Value, underscoresCount);
213+
discardsOpt = computeDiscards(parameterSyntaxList, underscoresCount);
210214

211215
// Only include the types if *all* the parameters had types. Otherwise, if there were no parameter
212216
// types (or a mix of typed and untyped parameters) include no types. Note, in the latter case we will

src/Compilers/CSharp/Portable/BoundTree/UnboundLambda.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -465,15 +465,15 @@ public Binder GetWithParametersBinder(LambdaSymbol lambdaSymbol, Binder binder)
465465
=> Data.GetWithParametersBinder(lambdaSymbol, binder);
466466

467467
/// <summary>
468-
/// Whether or not the original syntax had explicit parameter list specified where all parameters had an
468+
/// Whether or not the original syntax had explicit parameter list specified where any parameter had an
469469
/// explicit type syntax included. Examples of where this is true are: `() => ...` `(int a) => ...` `(int a,
470470
/// ref int b) => ...` and so on.
471471
///
472472
/// Examples of where this is false is `a => ...` `(a) => ...` `(a, b) => ...` `(ref a) => ...`.
473473
///
474-
/// Note 1: in the case where some parameters have types and some do not, this will return false. That case is an
475-
/// error case and an error will already be reported to the user. In this case, we treat the parameter list as
476-
/// if no parameters were provided.
474+
/// Note 1: in the case where some parameters have types and some do not, this will return true. That case is
475+
/// an error case and an error will already be reported to the user. In this case, we treat the parameter list
476+
/// as if it's a mix of provided types (where there is syntax), and error types (where there is not).
477477
///
478478
/// Note 2: `(ref a) => ...` is legal. So this property should not be used to determine if a parameter should
479479
/// have its ref/scoped/attributes checked.

src/Compilers/CSharp/Test/Syntax/Parsing/LambdaAttributeParsingTests.cs

-1
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,6 @@ public void LambdaAttribute_05()
235235
string source = "[A] (ref x) => x";
236236
UsingExpression(source, TestOptions.RegularPreview);
237237

238-
239238
N(SyntaxKind.ParenthesizedLambdaExpression);
240239
{
241240
N(SyntaxKind.AttributeList);

0 commit comments

Comments
 (0)