You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
classX{voidM<T>(To)// where T : class does not make a difference{varx=oasX;if(x!=null);}}
Invoke the "Inline Temporary Variable" refactoring on variable x.
Actual Behavior:
The refactoring preview shows that the generated code is going to be invalid. The refactoring can still be applied, yielding
classX{voidM<T>(To){if(oisXx);}}
The following compiler error results: error CS8121: An expression of type T cannot be handled by a pattern of type X.
Expected Behavior:
Ideally, the compiler would support the code generated by the refactoring, as I understand the is pattern match in this case to be semantically equivalent to the original code.
At the very least, though, the refactoring should not be offered by the IDE.
The text was updated successfully, but these errors were encountered:
This was reported before and is per spec as (X)o is not permitted. Perhaps the analyzer should check convertibility of the expression in the same sense of direct cast to cover corner-cases until this is fixed in the compiler (if possible). /cc @CyrusNajmabadi
Thanks @alrz. A very unfortunate language limitation, especially given that the refactoring is offered (so even the IDE does not expect this limitation 😄).
Version Used:
VS 2017 RTM
Steps to Reproduce:
x
.Actual Behavior:
The refactoring preview shows that the generated code is going to be invalid. The refactoring can still be applied, yielding
The following compiler error results:
error CS8121: An expression of type T cannot be handled by a pattern of type X.
Expected Behavior:
Ideally, the compiler would support the code generated by the refactoring, as I understand the is pattern match in this case to be semantically equivalent to the original code.
At the very least, though, the refactoring should not be offered by the IDE.
The text was updated successfully, but these errors were encountered: