-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Extensions: Adjust accessibility and file-type checks for extension members #77657
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,7 +30,7 @@ internal SynthesizedExtensionMarker(SourceMemberContainerTypeSymbol extensionTyp | |
| return; | ||
| } | ||
|
|
||
| private static DeclarationModifiers GetDeclarationModifiers() => DeclarationModifiers.Public | DeclarationModifiers.Static; | ||
| private static DeclarationModifiers GetDeclarationModifiers() => DeclarationModifiers.Private | DeclarationModifiers.Static; | ||
|
Member
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. I don't have any objection to this change. Please update the spec accordingly: |
||
|
|
||
| internal override bool HasSpecialName => true; // PROTOTYPE: reconcile with spec | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -378,26 +378,42 @@ protected void CheckEffectiveAccessibility(TypeWithAnnotations returnType, Immut | |
| } | ||
| } | ||
|
|
||
| if (!IsStatic && this.GetIsNewExtensionMember() && ContainingType.ExtensionParameter is { } extensionParameter) | ||
|
Member
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. Checking (also applies to similar place in SourcePropertySymbol.cs) #Resolved
Contributor
Author
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.
It might appear this way. However, strictly speaking, |
||
| { | ||
| if (!extensionParameter.TypeWithAnnotations.IsAtLeastAsVisibleAs(this, ref useSiteInfo)) | ||
|
Member
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. Consider combining the nested ifs into one condition with |
||
| { | ||
| // Inconsistent accessibility: parameter type '{1}' is less accessible than method '{0}' | ||
| diagnostics.Add(code, GetFirstLocation(), this, extensionParameter.Type); | ||
| } | ||
| } | ||
|
|
||
| diagnostics.Add(GetFirstLocation(), useSiteInfo); | ||
| } | ||
|
|
||
| protected void CheckFileTypeUsage(TypeWithAnnotations returnType, ImmutableArray<ParameterSymbol> parameters, BindingDiagnosticBag diagnostics) | ||
| { | ||
| if (ContainingType.HasFileLocalTypes()) | ||
| NamedTypeSymbol containingType = ContainingType; | ||
|
|
||
| if (containingType is { IsExtension: true, ContainingType: { } enclosing }) | ||
| { | ||
| containingType = enclosing; | ||
| } | ||
|
|
||
| if (containingType.HasFileLocalTypes()) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| if (returnType.Type.HasFileLocalTypes()) | ||
| { | ||
| diagnostics.Add(ErrorCode.ERR_FileTypeDisallowedInSignature, GetFirstLocation(), returnType.Type, ContainingType); | ||
| diagnostics.Add(ErrorCode.ERR_FileTypeDisallowedInSignature, GetFirstLocation(), returnType.Type, containingType); | ||
| } | ||
|
|
||
| foreach (var param in parameters) | ||
| { | ||
| if (param.Type.HasFileLocalTypes()) | ||
| { | ||
| diagnostics.Add(ErrorCode.ERR_FileTypeDisallowedInSignature, GetFirstLocation(), param.Type, ContainingType); | ||
| diagnostics.Add(ErrorCode.ERR_FileTypeDisallowedInSignature, GetFirstLocation(), param.Type, containingType); | ||
| } | ||
| } | ||
| } | ||
|
|
||
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.
nit: consider using the same pattern you used elsewhere in this PR (
containingType is { IsExtension: true, ContainingType: { } extensionEnclosingType } ? extensionEnclosingType : containingType) or even introducing a helper method.