Skip to content
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

Do not attempt a blind type conversion when multicasting to subject #1458

Closed
glopesdev opened this issue Jul 6, 2023 · 0 comments · Fixed by #1459
Closed

Do not attempt a blind type conversion when multicasting to subject #1458

glopesdev opened this issue Jul 6, 2023 · 0 comments · Fixed by #1459
Labels
bug Something isn't working

Comments

@glopesdev
Copy link
Member

glopesdev commented Jul 6, 2023

The language compiler currently attempts to use any available explicit type conversion when there is a type mismatch in available method overloads. In most cases the conversion is only attempted if there is indeed an explicitly declared type conversion available in the type. However, in some cases a coercion is attempted without the check, and there is one specific situation that significantly compromises the type safety of the build system.

It happens when multicasting an observable sequence into a subject, where both the type of the sequence and the type of the subject are interface types. In most cases attempting the conversion directly in the expression tree matches the behavior of overload resolution. For example, when converting a concrete class to an interface, the compiler knows the list of interfaces implemented by the type, so if an interface is not allowed, a casting error will be reported.

However, if we hold a type which is already an interface type, there is no way of knowing how many other interfaces the specific instance behind the interface might implement (since C# allows for multiple arbitrary interface implementations). This means there is really no compile-time constraint on the explicit cast and the conversion is allowed, with its evaluation deferred to be performed at runtime.

In the case of multicasting to a subject, this behavior is overly permissive and should not be allowed since it is essentially the same as treating every single interface type as an object which can be multicast into any subject, thus compromising the value of type inference. Instead, overload resolution rules should be used to check whether there is an available conversion from the sequence type to the subject type.

For example, the following should not build:

@glopesdev glopesdev added the bug Something isn't working label Jul 6, 2023
@glopesdev glopesdev changed the title Do not allow automatic type conversion between interfaces Do not attempt a blind type conversion when multicasting to subject Jul 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant