Code Analysis Code Analysis
Code Analysis Code Analysis
DocFX + Singulink = ♥

Search Results for

    SCA1013: Interface Member Left to Its Default Implementation

    Implement every interface member in a struct of a non-copyable type.

    Example

    interface IReleasable
    {
        void Release() { }                         // a default implementation
    }
    
    [NonCopyable]
    struct Lease : IReleasable { }                 // SCA1013: a call of Release runs on a boxed copy
    
    [NonCopyable]
    struct Lease : IReleasable { public void Release() { } }   // OK
    

    How to Fix

    Implement the member in the struct.

    Details

    A struct of a non-copyable type leaves a member of one of its interfaces to the interface's default implementation, including one that a derived interface gives. A call of that member runs on a boxed copy of the value, even through a constrained type parameter, where nothing shows the box.

    • An interface member with a body that is not virtual, such as sealed void Log() { }, cannot be implemented by the struct. So a struct of a non-copyable type cannot implement an interface that has one, and gets a warning.
    • A generic struct that is non-copyable only through its type arguments has no declaration of its own. It gets the warning where it is bound to a type parameter that is constrained to the interface.

    See Also

    These articles explain the rule behind this warning:

    • Fields, Interfaces and Async Members - the declarations that copy a value by themselves.
    © Singulink. All rights reserved.