-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Interfaces don't forward static members to other interfaces #62855
Comments
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label. |
Thanks for taking the time to file this issue. Unfortunately it's hard to determine exactly what the problem is here because the sample is incomplete. Could you provide a complete sample, including |
I don't have the project anymore but WindowArgs was just a non generic readonly record struct to pass in the creation args to the IWindow. |
Updating the repro to the following: public interface ICreatable<out T> where T : ICreatable<T>
{
static abstract T Create();
}
public interface ICreatable<out T, in TArgs> where T : ICreatable<T, TArgs>
{
static abstract T Create(TArgs args);
}
public interface IWindow : ICreatable<IWindow, WindowArgs>
{
uint Width { get; }
uint Height { get; }
}
public record struct WindowArgs(int i) {} Produces a very different error:
The error difference is likely cause I'm using the C# 11 compiler vs you using the C# 10 compiler. At a glance that error seems to make sense in this context but I will let @333fred say for sure. |
This error is as-designed. Interfaces with static abstract members cannot be used as type arguments, as that presents a type safety hole that could cause a static member that does not actually exist to be invoked (causing a runtime exception). |
@333fred please reopen this. your failing to understand the issue. public interface A
{
public void Instance();
public static abstract void Static();
}
public interface B : A //B implements A so classes that implement B should be requires to implement A also
{
}
public class C : B // B should have the interface of A also but static members from A are not carried to B like instance members.
{
} static interface members are not forwarded to other interfaces |
@Shadowblitz16 looking at your example I'm not sure what you are saying. Can you show a us an example of where you expect to be able to use |
@333fred sorry I am trying to be a clear as possible forgive my communication issues, I have autism so its hard for me. basically the way I see static interface members is that they are just like instance members but are static. The issue is for example with instance members if B implements A and C implements B since B implements A, C is required to implement A also regardless if B redefineds A's members. This doesn't seem to be the case with abstract static interface members. |
@Shadowblitz16 there is no difference there with |
@333fred I just want a static interface where I am not forced to implement it in the next interface or abstract class. |
But then where will the implementation of that interface member be found? |
You are not forced to implement it in the next interface.
The feature is not designed to allow this. |
Description
Interfaces don't forward static members to other interfaces
for example this doesn't work...
It complains when I pass
IWindow
toICreatable
Reproduction Steps
Expected behavior
It would forward the static member to the IWindow interface so that any class or struct that eventually implements IWindow has to implement ICreatable too
Actual behavior
It errors...
Regression?
Idk
Known Workarounds
None that I know of.
Configuration
Other information
No response
The text was updated successfully, but these errors were encountered: