-
Notifications
You must be signed in to change notification settings - Fork 4.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
Type test for ref struct is incorrect #63085
Comments
In order to perform a runtime type test, a value type must be boxes, but ref-structs cannot be boxed. Perhaps instead of producing a warning for |
@jaredpar, @MadsTorgersen What do you think? |
I think it should be an error. That way we preserve our ability to do it right later without changing semantics. Also the current result is just plain wrong! |
@AaronRobinsonMSFT @davidwrighton
This is a good point. Is there a way to safely type test a
Generally agree with this in the short term. |
This comment was marked as off-topic.
This comment was marked as off-topic.
Boo. I didn't realize these all compile down to IL. @jaredpar I get your question now. |
@AaronRobinsonMSFT Scenario that you are trying is different and compiler behaves differently. It handles identity case specially, I think. |
I'd like to share some context how I come to this issue, if it will help. interface ILogger {
void Trace([InterpolatedStringHandlerArgument("")]LogInterpolatedHandler<TraceLevel> handler);
void Debug([InterpolatedStringHandlerArgument("")]LogInterpolatedHandler<DebugLevel> handler);
...
} I come up with if block |
Seems we have 2 questions here.
|
|
If
ref struct G<T>
defined,this
type test inside the struct for any resolved generic returns false (and compiler not even add test in IL).It also shows warning CS0184 and does not allow to use it in pattern math type test.
Version Used: C# 10
Steps to Reproduce:
Compile and run next code:
Use next code:
On SharpLib.IO
Expected Behavior:
Program should output:
No CS0184 warning should not be shown, if uncomment, TestPattern method should compile without errors.
Actual Behavior:
Program outputs:
CS0184 warning shown, TestPattern method can not be compiled without changes
The text was updated successfully, but these errors were encountered: