Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
55757b3
Infer type in get accessor declaration
rik-smeets May 20, 2018
e204163
Add test with expression bodied getter with a different accessibility
rik-smeets May 20, 2018
9f1646a
Use pattern matching when inferring type in arrow expression clause a…
rik-smeets May 20, 2018
f347121
Add tests for generating methods from within expression bodies getter…
rik-smeets May 20, 2018
005add1
Use pattern matching inside switch statement
rik-smeets May 20, 2018
896de85
Use pattern matching directly on parent symbol when inferring type in…
rik-smeets May 20, 2018
7f3b037
Use local function to determine symbol return type, preventing some d…
rik-smeets May 21, 2018
5b50b1c
Add tests for generating methods and variables from within local func…
rik-smeets May 21, 2018
33d2074
Pass CancellationToken to GetDeclaredSymbol and remove redundant null…
rik-smeets May 21, 2018
def52e3
Fix type inference in block bodied local functions
rik-smeets May 27, 2018
0248697
Use constants for indexes
rik-smeets May 27, 2018
56d7514
Extract local function to private method
rik-smeets May 27, 2018
37c8639
Consistent naming in all new generating variable tests
rik-smeets May 27, 2018
a53f504
Use already existing method to get member type
rik-smeets May 27, 2018
0130a24
Fix type inferrence for local function inside lambda expression
rik-smeets May 27, 2018
ae5eaf3
Remove some redundant code and use pattern matching on memberSymbol too
rik-smeets May 27, 2018
5a65f66
Merge pull request #26997 from rik-smeets/infer-type-in-expression-bo…
jinujoseph Jun 4, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Remove some redundant code and use pattern matching on memberSymbol too
  • Loading branch information
rik-smeets committed May 30, 2018
commit ae5eaf318f621f5a9e4127c4a6ef3294442a7170
Original file line number Diff line number Diff line change
Expand Up @@ -1857,23 +1857,14 @@ private void InferTypeForReturnStatement(
return;
}

var ancestor = returnStatement.AncestorsAndSelf().FirstOrDefault(e => e is ParenthesizedLambdaExpressionSyntax || e is SimpleLambdaExpressionSyntax ||
e is AnonymousMethodExpressionSyntax || e is LocalFunctionStatementSyntax);
var ancestor = returnStatement.AncestorsAndSelf().FirstOrDefault(e => e is AnonymousFunctionExpressionSyntax || e is LocalFunctionStatementSyntax);

// If we're in a lambda, then use the return type of the lambda to figure out what to
// infer. i.e. Func<int,string> f = i => { return Goo(); }
if (ancestor is ParenthesizedLambdaExpressionSyntax lambda)
if (ancestor is LambdaExpressionSyntax lambdaExpression)
{
types = InferTypeInLambdaExpression(lambda);
isAsync = lambda.AsyncKeyword.Kind() != SyntaxKind.None;

return;

}
else if (ancestor is SimpleLambdaExpressionSyntax simpleLambda)
{
types = InferTypeInLambdaExpression(simpleLambda);

// If we're in a lambda, then use the return type of the lambda to figure out what to
// infer. i.e. Func<int,string> f = i => { return Goo(); }
types = InferTypeInLambdaExpression(lambdaExpression);
isAsync = lambdaExpression.AsyncKeyword.Kind() != SyntaxKind.None;
return;
}
else if (ancestor is AnonymousMethodExpressionSyntax delegateExpression)
Expand Down Expand Up @@ -1902,23 +1893,18 @@ private void InferTypeForReturnStatement(

var memberSymbol = GetDeclaredMemberSymbolFromOriginalSemanticModel(SemanticModel, returnStatement.GetAncestorOrThis<MemberDeclarationSyntax>());

if (memberSymbol.IsKind(SymbolKind.Method))
{
var method = memberSymbol as IMethodSymbol;

isAsync = method.IsAsync;
types = SpecializedCollections.SingletonEnumerable(new TypeInferenceInfo(method.ReturnType));
return;
}
else if (memberSymbol.IsKind(SymbolKind.Property))
{
types = SpecializedCollections.SingletonEnumerable(new TypeInferenceInfo((memberSymbol as IPropertySymbol).Type));
return;
}
else if (memberSymbol.IsKind(SymbolKind.Field))
switch (memberSymbol)
{
types = SpecializedCollections.SingletonEnumerable(new TypeInferenceInfo((memberSymbol as IFieldSymbol).Type));
return;
case IMethodSymbol method:
isAsync = method.IsAsync;
types = SpecializedCollections.SingletonEnumerable(new TypeInferenceInfo(method.ReturnType));
return;
case IPropertySymbol property:
types = SpecializedCollections.SingletonEnumerable(new TypeInferenceInfo(property.Type));
return;
case IFieldSymbol field:
types = SpecializedCollections.SingletonEnumerable(new TypeInferenceInfo(field.Type));
return;
}
}

Expand Down