Skip to content

Commit

Permalink
Respond to PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
agocke committed Jan 26, 2017
1 parent dfc6aba commit 580f286
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ public LocalFunctionSymbol(
/// </summary>
internal Binder ScopeBinder { get; }

/// <summary>
/// Binder used to bind local function parameters.
/// </summary>
internal Binder ParameterBinder => _binder;

internal void GetDeclarationDiagnostics(DiagnosticBag addTo)
{
// Force attribute binding for diagnostics
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ private enum ParameterSyntaxKind : byte
private ThreeState _lazyHasOptionalAttribute;
private ConstantValue _lazyDefaultSyntaxValue;

private Binder LocalFunctionParameterBinder
=> (ContainingSymbol as LocalFunctionSymbol)?.ParameterBinder;

internal SourceComplexParameterSymbol(
Symbol owner,
int ordinal,
Expand All @@ -42,8 +45,7 @@ internal SourceComplexParameterSymbol(
SyntaxReference syntaxRef,
ConstantValue defaultSyntaxValue,
bool isParams,
bool isExtensionMethodThis,
Binder parameterBinderOpt = null)
bool isExtensionMethodThis)
: base(owner, parameterType, ordinal, refKind, name, locations)
{
Debug.Assert((syntaxRef == null) || (syntaxRef.GetSyntax().IsKind(SyntaxKind.Parameter)));
Expand All @@ -68,11 +70,8 @@ internal SourceComplexParameterSymbol(
}

_lazyDefaultSyntaxValue = defaultSyntaxValue;
ParameterBinder = parameterBinderOpt;
}

protected virtual Binder ParameterBinder { get; }

internal override SyntaxReference SyntaxReference
{
get
Expand Down Expand Up @@ -200,7 +199,7 @@ private ConstantValue GetDefaultSyntaxValue(DiagnosticBag diagnosticsOpt = null)
var diagnostics = DiagnosticBag.GetInstance();
if (Interlocked.CompareExchange(
ref _lazyDefaultSyntaxValue,
MakeDefaultExpression(diagnostics, ParameterBinder),
MakeDefaultExpression(diagnostics, LocalFunctionParameterBinder),
ConstantValue.Unset)
== ConstantValue.Unset)
{
Expand Down Expand Up @@ -457,7 +456,7 @@ internal sealed override CustomAttributesBag<CSharpAttributeData> GetAttributesB
else
{
var attributeSyntax = this.GetAttributeDeclarations();
bagCreatedOnThisThread = LoadAndValidateAttributes(attributeSyntax, ref _lazyCustomAttributesBag, addToDiagnostics: diagnosticsOpt, binderOpt: ParameterBinder);
bagCreatedOnThisThread = LoadAndValidateAttributes(attributeSyntax, ref _lazyCustomAttributesBag, addToDiagnostics: diagnosticsOpt, binderOpt: LocalFunctionParameterBinder);
}

if (bagCreatedOnThisThread)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ public static SourceParameterSymbol Create(
return new SourceSimpleParameterSymbol(owner, parameterType, ordinal, refKind, name, locations);
}

var useExistingBinder = owner is MethodSymbol method && method.MethodKind == MethodKind.LocalFunction;

return new SourceComplexParameterSymbol(
owner,
ordinal,
Expand All @@ -71,8 +69,7 @@ public static SourceParameterSymbol Create(
syntax.GetReference(),
ConstantValue.Unset,
isParams,
isExtensionMethodThis,
parameterBinderOpt: useExistingBinder ? context : null);
isExtensionMethodThis);
}

protected SourceParameterSymbol(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,27 @@ public static IMethodSymbol FindLocalFunction(this CommonTestBase.CompilationVer
[CompilerTrait(CompilerFeature.LocalFunctions)]
public class CodeGenLocalFunctionTests : CSharpTestBase
{
[Fact]
public void NameofRecursiveDefaultParameter()
{
var comp = CreateCompilationWithMscorlib(@"
using System;
class C
{
public static void Main()
{
void Local(string s = nameof(Local))
{
Console.WriteLine(s);
}
Local();
}
}", options: TestOptions.ReleaseExe);
comp.VerifyDiagnostics();
comp.DeclarationDiagnostics.Verify();
CompileAndVerify(comp, expectedOutput: "Local");
}

[Fact]
[WorkItem(16399, "https://github.com/dotnet/roslyn/issues/16399")]
public void RecursiveGenericLocalFunctionIterator()
Expand Down

0 comments on commit 580f286

Please sign in to comment.