Skip to content

Commit

Permalink
Allow a method's type parameter to be used in nameof() in parameter d…
Browse files Browse the repository at this point in the history
…efault value

Fixes dotnet#42
  • Loading branch information
gafter committed Feb 16, 2015
1 parent 08c5fbf commit 0f3ba43
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Compilers/CSharp/Portable/Binder/Binder_Expressions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -846,7 +846,7 @@ private BoundExpression BindDefaultExpression(DefaultExpressionSyntax node, Diag
options |= LookupOptions.MustBeInvocableIfMember;
}

if (!IsInMethodBody)
if (!IsInMethodBody && this.EnclosingNameofArgument == null)
{
Debug.Assert((options & LookupOptions.NamespacesOrTypesOnly) == 0);
options |= LookupOptions.MustNotBeMethodTypeParameter;
Expand Down
13 changes: 13 additions & 0 deletions src/Compilers/CSharp/Test/Semantic/Semantics/NameOfTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1155,5 +1155,18 @@ public static void Main()
var compilation = CreateCompilationWithMscorlib45(source);
var comp = CompileAndVerify(source, expectedOutput: @"N1N2");
}

[Fact, WorkItem(42, "github.com/dotnet/roslyn")]
public void NameofTypeParameterInParameterInitializer()
{
var source =
@"class Test {
void M<T>(
T t = default(T), // ok
string s = nameof(T) // ok
) { }
}";
var compilation = CreateCompilationWithMscorlib45(source).VerifyDiagnostics();
}
}
}

0 comments on commit 0f3ba43

Please sign in to comment.