Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
svick opened this issue Sep 19, 2016 · 1 comment

Comments

@svick
Copy link
Contributor

svick commented Sep 19, 2016

The C# specification says this about 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.:

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.

@svick
Copy link
Contributor Author

svick commented Mar 27, 2017

This issue was moved to dotnet/csharplang#359

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants