Skip to content

Commit

Permalink
Add test for var local-func return type
Browse files Browse the repository at this point in the history
Support for using `var` in a local function return type was already
removed in PR dotnet#7916. This PR adds a test to verify that.

Closes dotnet#10392.
  • Loading branch information
agocke committed Jun 14, 2016
1 parent e2d1c5d commit faeb291
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/Compilers/CSharp/Test/Semantic/Semantics/LocalFunctionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,43 @@ Action local(dynamic z)
VerifyOutput(src, "012");
}

[Fact]
public void VarLocalFunction()
{
var src = @"
class C
{
void M()
{
var local() => 0;
int x = local();
}
}";
VerifyDiagnostics(src,
// (6,9): error CS0825: The contextual keyword 'var' may only appear within a local variable declaration or in script code
// var local() => 0;
Diagnostic(ErrorCode.ERR_TypeVarNotFound, "var").WithLocation(6, 9));
}

[Fact]
public void VarLocalFunction2()
{
var comp = CreateCompilationWithMscorlib(@"
class C
{
private class var
{
}
void M()
{
var local() => new var();
var x = local();
}
}", parseOptions: DefaultParseOptions);
comp.VerifyDiagnostics();
}

[Fact]
public void EndToEnd()
{
Expand Down

0 comments on commit faeb291

Please sign in to comment.