2
return (Func<object, Task<object>>)(async (dynamic data) =>
{
    methodCall(data.data, data.more);
    return null;
});

From what I gather the above code is doing, it is explicitly casting the lambda function as a delegate, and then returning that delegate (in this case, it is returning to an edgejs function).

When the parens are removed, 8 errors are received from the build process.

Syntax error, ',' expected

; expected

} expected

The name async does not exist in the current context

The name dynamic does not exist in the current context

The name data does not exist in the current context

The name data does not exist in the current context

The name data does not exist in the current context

Community
  • 1
  • 1
Wickie Lee
  • 109
  • 1
  • 7

1 Answers1

2

Likely, it's because async is a contextual keyword that only has special meaning when appearing as a modifier in a method or lambda signature. Without the parens, the parser thinks async is a method name, resulting in an error because the compiler cannot find a method with that name (and, further, a parse error on the => because the parser is no longer consuming a lambda expression at that point).

BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
  • Ahhhh, alright. That would make sense. Thanks for the answer! Relatively new to async in .Net, so that clears everything up extremely well. Didn't realize that async was a contextual keyword. – Wickie Lee Feb 01 '17 at 17:55
  • 2
    It's contextual so that anyone who used `async` as a variable name in the last decade an a half won't suddenly have their code broken if they upgrade. – Jon Hanna Feb 01 '17 at 18:01
  • 2
    @Robocrypt adding keywords to an existing language is a delicate thing because it's a breaking change. That is why new features usually try to reuse existing keywords or use contextual ones jointly with syntaxes that make the probability of breaking existing code nonexistent or very very low. Examples of the former: `in`, `out` and of the later: `yield`, `async`, `await`, `var`, etc. – InBetween Feb 01 '17 at 18:01