-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Enable a default implementation of an interface property/indexer to be provided as part of its declaration. #18110
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1090,6 +1090,24 @@ private static void ReportImplicitImplementationMatchDiagnostics(Symbol interfac | |
ReportAnyMismatchedConstraints(interfaceMethod, implementingType, implicitImplMethod, diagnostics); | ||
} | ||
} | ||
|
||
if (implicitImpl.ContainingType.IsInterface && implementingType.ContainingModule != implicitImpl.ContainingModule) | ||
{ | ||
// PROTOTYPE(DefaultInterfaceImplementation): Should we check language version as well? | ||
// Usually, it is done based on specific syntax that targets a new feature, but in this case | ||
// no special syntax is used. Also, partial types can have declarations coming from different | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can use CSharpCompilation.LanguageVersion. Partial types cannot have declarations coming from different trees with different language versions. The compiler checks up front that all input trees have the same language version. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Still there is no special syntax at this site. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I agree that there is no special syntax at this site. But there is a new language feature being used. In any case I agree with your decision to document it as an open issue with a PROTOTYPE comment. |
||
// trees with different options. We could use options from the tree the result of | ||
// GetInterfaceLocation() is based on. | ||
|
||
// The default implementation is coming from a different module, which means that we probably won't check | ||
// for the required runtime capability | ||
if (!implementingType.ContainingAssembly.RuntimeSupportsDefaultInterfaceImplementation) | ||
{ | ||
diagnostics.Add(ErrorCode.ERR_RuntimeDoesNotSupportDefaultInterfaceImplementationForMember, | ||
GetInterfaceLocation(interfaceMember, implementingType), | ||
implicitImpl, interfaceMember, implementingType); | ||
} | ||
} | ||
} | ||
|
||
if (MemberSignatureComparer.ConsideringTupleNamesCreatesDifference(implicitImpl, interfaceMember)) | ||
|
@@ -1115,24 +1133,6 @@ private static void ReportImplicitImplementationMatchDiagnostics(Symbol interfac | |
} | ||
} | ||
} | ||
|
||
if (implicitImpl.ContainingType.IsInterface && implementingType.ContainingModule != implicitImpl.ContainingModule) | ||
{ | ||
// PROTOTYPE(DefaultInterfaceImplementation): Should we check language version as well? | ||
// Usually, it is done based on specific syntax that targets a new feature, but in this case | ||
// no special syntax is used. Also, partial types can have declarations coming from different | ||
// trees with different options. We could use options from the tree the result of | ||
// GetInterfaceLocation() is based on. | ||
|
||
// The default implementation is coming from a different module, which means that we probably won't check | ||
// for the required runtime capability | ||
if (!implementingType.ContainingAssembly.RuntimeSupportsDefaultInterfaceImplementation) | ||
{ | ||
diagnostics.Add(ErrorCode.ERR_RuntimeDoesNotSupportDefaultInterfaceImplementationForMember, | ||
GetInterfaceLocation(interfaceMember, implementingType), | ||
implicitImpl, interfaceMember, implementingType); | ||
} | ||
} | ||
} | ||
|
||
/// <summary> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this correct if one accessor is abstract and one virtual?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I see that is left as a future work item.