-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Using Covariance generates not loadable assembly - covariant or contravariant type parameter was used illegally #111167
Comments
For non-static method, the compiler does report error about constraint: public interface IInterface<TEntity, in TContext>
where TEntity : IInterface<TEntity, TContext>
{
public void Method<TEntityProperty>() // CS1961
where TEntityProperty : IInterface<TEntityProperty, TContext>
{ }
} However, there's no error for a static method with manual public static void Method<TEntityProperty>(IInterface<TEntity, TContext> @this)
where TEntityProperty : IInterface<TEntityProperty, TContext>
{
} |
An error is reported for a virtual or abstract static method, but not for a non-virtual one. This is consistent with what the feature spec is saying (https://github.com/dotnet/csharplang/blob/main/proposals/csharp-11.0/static-abstracts-in-interfaces.md#variance-safety-18232):
Need to confirm whether the spec rules should be tighter or runtime check should be relaxed. |
@trylek, @davidwrighton Is runtime behavior justified? Is there a real variance safety issue around non-virtual static members? Given #39612, it looks like the fix might be incomplete, or a change was made with intention to affect only virtual statics, but affected all statics. |
Hmm... maybe. Looking at the source around this faiulre... runtime/src/coreclr/vm/typedesc.cpp Line 828 in 4515505
|
The issue is in both net8.0 and net9.0
the test:
Compiler gives no errors.
The test gives error :
By removing the "in" in type parameter TContext eliminates that error
The text was updated successfully, but these errors were encountered: