Compiler fails to report a possible boxing of a ref struct #76682
Labels
Area-Compilers
Feature - Ref Fields
untriaged
Issues and PRs which have not yet been triaged by a lead
Consider the following code:
Observed:
ToString
call inTest1
ToString
call inTest2
andTest3
At the same time IL for
Test1
looks like this:It utilizes a constrained call of
Object::ToString
on a ref struct. A constrained call boxes the struct receiver when the struct doesn't override/implement the target method.In a general case, it is quite possible that
S1
won't overrideToString
at runtime. For example, when it is defined in a different assembly, etc. That is one of the reasons why compiler doesn't call the override directly even when it is present at compile time. In that case, the call will be boxing a ref struct. Presumably that will cause an exception.We should consider reporting a compilation error for a situation like this.
See dotnet/runtime#111166 as well.
The text was updated successfully, but these errors were encountered: