From faeb2918c1038b3d95600434cd9d4a0695801c5e Mon Sep 17 00:00:00 2001 From: Andy Gocke Date: Wed, 20 Apr 2016 11:04:09 -0700 Subject: [PATCH] Add test for var local-func return type Support for using `var` in a local function return type was already removed in PR #7916. This PR adds a test to verify that. Closes #10392. --- .../Semantic/Semantics/LocalFunctionTests.cs | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/LocalFunctionTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/LocalFunctionTests.cs index 2df13937c2972..b41df3834647d 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/LocalFunctionTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/LocalFunctionTests.cs @@ -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() {