-
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
Warn that a user-defined API on an inline array type won’t be used by the language for an element access expression #69064
Conversation
… the language for an element access expression Closes dotnet#68868.
@@ -7682,4 +7682,22 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ | |||
<data name="ERR_InlineArrayRequiredElementField" xml:space="preserve"> | |||
<value>Inline array element field cannot be declared required.</value> | |||
</data> | |||
<data name="WRN_InlineArrayIndexerNotUsed" xml:space="preserve"> | |||
<value>Indexer will not be used for element access expression.</value> |
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.
Consider explaining why, i.e., because it's an inline array. #Resolved
private int _element0; | ||
|
||
int Length => 4; | ||
string Slice(int i, int j) => ""int""; |
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.
Consider testing explicit interface implementation of Slice #Resolved
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.
Consider testing explicit interface implementation of Slice
Added UserDefinedSlice_Warning_03
conversion.Parameters[0].Type.Equals(this, TypeCompareKind.AllIgnoreOptions) && | ||
(returnTypeOriginalDefinition.Equals(span ??= DeclaringCompilation.GetWellKnownType(WellKnownType.System_Span_T), TypeCompareKind.AllIgnoreOptions) || | ||
returnTypeOriginalDefinition.Equals(readOnlySpan ??= DeclaringCompilation.GetWellKnownType(WellKnownType.System_ReadOnlySpan_T), TypeCompareKind.AllIgnoreOptions)) && | ||
Conversions.HasIdentityConversion(((NamedTypeSymbol)returnTypeOriginalDefinition).Construct(ImmutableArray.Create(elementType)), returnType)) |
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.
Conversions.HasIdentityConversion(((NamedTypeSymbol)returnTypeOriginalDefinition).Construct(ImmutableArray.Create(elementType)), returnType)
What's this check for? #Resolved
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.
What's this check for?
This checks that the return type of the conversion is indeed something that conflicts with built-in conversions.
For example, in UserDefinedConversion_Warning_03
it does not.
@cston, @dotnet/roslyn-compiler For the second review |
1 similar comment
@cston, @dotnet/roslyn-compiler For the second review |
@cston, @dotnet/roslyn-compiler For the second review |
@cston, @dotnet/roslyn-compiler For the second review |
Closes #68868.