diff --git a/src/Compilers/CSharp/Portable/Binder/Binder_Expressions.cs b/src/Compilers/CSharp/Portable/Binder/Binder_Expressions.cs index 6d5d7d16e57d266d06dfa344f62e06dee8e1c322..4f31b9f616276ac36c21882181036a12a76b65a3 100644 --- a/src/Compilers/CSharp/Portable/Binder/Binder_Expressions.cs +++ b/src/Compilers/CSharp/Portable/Binder/Binder_Expressions.cs @@ -689,11 +689,10 @@ private static bool IsThrowExpressionInProperContext(ThrowExpressionSyntax node) var binaryParent = (BinaryExpressionSyntax)parent; return node == binaryParent.Right; } - case SyntaxKind.ArrowExpressionClause: // => - { - var arrowClauseParent = (ArrowExpressionClauseSyntax)parent; - return node == arrowClauseParent.Expression; - } + case SyntaxKind.ArrowExpressionClause: + case SyntaxKind.ParenthesizedLambdaExpression: + case SyntaxKind.SimpleLambdaExpression: + return true; // We do not support && and || because // 1. The precedence would not syntactically allow it // 2. It isn't clear what the semantics should be diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/LambdaTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/LambdaTests.cs index 85bc1618915546fe0f985e6bdf0d769190ca6492..4d435b5c894b2b9c7c268374f21b3101e2fec37a 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/LambdaTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/LambdaTests.cs @@ -2355,5 +2355,55 @@ class B var comp = CreateCompilationWithMscorlibAndSystemCore(src, options: TestOptions.DebugExe); CompileAndVerify(comp, expectedOutput: "1"); } + + [Fact] + public void ThrowExpression_Lambda() + { + var src = @"using System; +class C +{ + public static void Main() + { + Action a = () => throw new Exception(""1""); + try + { + a(); + } + catch (Exception ex) + { + Console.Write(ex.Message); + } + Func b = x => throw new Exception(""2""); + try + { + b(0); + } + catch (Exception ex) + { + Console.Write(ex.Message); + } + b = (int x) => throw new Exception(""3""); + try + { + b(0); + } + catch (Exception ex) + { + Console.Write(ex.Message); + } + b = (x) => throw new Exception(""4""); + try + { + b(0); + } + catch (Exception ex) + { + Console.Write(ex.Message); + } + } +}"; + var comp = CreateCompilationWithMscorlibAndSystemCore(src, options: TestOptions.DebugExe); + CompileAndVerify(comp, expectedOutput: "1234"); + } } }