-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Relax CS0030 to not error on conversion of IDynamicInterfaceCastable #3575
Comments
This sounds like a language change request afaict. Would you like me to move this to dotnet/csharplang? I think we'd have to spec this as how the language works in order for the compielr to know that it shoudl allow this sort of thing. |
Ah, okay - yes, please do move this where it belongs. |
Done :) Are you the write dotnet/runtime representative to communicate on this with for the LDM? |
Given that the compiler cannot guarantee this cast is valid, should there be a warning? |
I don't think so. The compiler check is merely convenience because it can detect the case with the type data. In this case it is no different than if the object was typed as |
Version Used:
.NET Core 5.0.100-preview.7.20316.2
Steps to Reproduce:
For .NET 5, the
IDynamicInterfaceCastable
(dotnet/runtime#36654) was added (dotnet/runtime#37042) to allow participation in a cast at run time where the implementing class is cast to an interface that is not in its class metadata.As a result, an explicit cast the compiler recognizes as impossible could actually be possible if the object implements
IDynamicInterfaceCastable
.Expected Behavior:
No error if the type implements
IDynamicInterfaceCastable
.Actual Behavior:
error CS0030: Cannot convert type 'testApp.Castable' to 'testApp.ITest'
The user needs to first cast to
object
, then the desired interface:cc @AaronRobinsonMSFT @jkoritzinsky
The text was updated successfully, but these errors were encountered: