dotnet / dotnet/csharpstandard

12.13.1 More details on short-circuiting and dynamic evaluation

Open
#119 7 comments 0 reactions 0 assignees View on GitHub
type: clarity
Dominant language
C#
Stars
815
Forks
99
Avg merge
1d 14h
Merged PRs (30d)
16

Description

The standard has the normal indication of `dynamic` behaviour:

> If an operand of a conditional logical operator has the compile-time type dynamic, then the expression is dynamically bound (§13.3.3). In this case the compile-time type of the expression is dynamic, and the resolution described below will take place at run-time using the run-time type of those operands that have the compile-time type dynamic.

But in the case of `&&` or `||`, the timing gets a little interesting. The first operand is evaluated before overload resolution is performed

``` csharp
dynamic x = false;
string y = "";
bool z = x && y;
Console.WriteLine(z); // False
```

We never do overload resolution because the first operand evaluates to `false`.

It's not clear to me that the standard predicts this behaviour clearly.

See http://stackoverflow.com/questions/27508991 for the motivation for this issue.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.