dotnet / dotnet/csharpstandard

Specification says dynamic is convertible to any type, but it's not convertible to pointer

Open
#282 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
815
Forks
99
Avg merge
1d 14h
Merged PRs (30d)
16

Description

_From @svick on September 19, 2016 19:22_

[The C# specification says this about Explicit dynamic conversions](https://github.com/ljw1004/csharpspec/blob/gh-pages/conversions.md#explicit-dynamic-conversions):

> An implicit dynamic conversion exists from an expression of type `dynamic` to any type `T`.

Except this is not true, an implicit conversion does not exist from an expression of type `dynamic` to a pointer type. E.g.:

``` c#
unsafe
{
dynamic d = null;
void* x = d;
}
```

This produces the following error:

> CS0029 Cannot implicitly convert type 'dynamic' to 'void*'

I think the compile error is correct and that the specification is unclear: when it says "any type", it means "any safe type". While everything related to unsafe code is generally in its own separate section, I think it would be clearer if it was spelled out that `dynamic` is not convertible to pointer types, possibly like this:

> An implicit dynamic conversion exists from an expression of type `dynamic` to any value type, reference type or type parameter `T`.

_Copied from original issue: dotnet/roslyn#13905_

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.