Skip to content
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

Merged
merged 3 commits into from
Jul 20, 2023

Conversation

AlekseyTs
Copy link
Contributor

Closes #68868.

… the language for an element access expression

Closes dotnet#68868.
@AlekseyTs AlekseyTs requested review from jjonescz and cston July 17, 2023 11:36
@AlekseyTs AlekseyTs requested a review from a team as a code owner July 17, 2023 11:36
@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged Issues and PRs which have not yet been triaged by a lead label Jul 17, 2023
@AlekseyTs
Copy link
Contributor Author

CC @tannergooding

@@ -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>
Copy link
Member

@jjonescz jjonescz Jul 17, 2023

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"";
Copy link
Member

@jjonescz jjonescz Jul 17, 2023

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

Copy link
Contributor Author

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))
Copy link
Member

@jjonescz jjonescz Jul 17, 2023

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

Copy link
Contributor Author

@AlekseyTs AlekseyTs Jul 17, 2023

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.

@AlekseyTs AlekseyTs requested a review from a team July 17, 2023 14:54
@AlekseyTs AlekseyTs requested a review from a team July 17, 2023 17:12
@AlekseyTs
Copy link
Contributor Author

@cston, @dotnet/roslyn-compiler For the second review

1 similar comment
@AlekseyTs
Copy link
Contributor Author

@cston, @dotnet/roslyn-compiler For the second review

@jaredpar jaredpar added this to the 17.8 milestone Jul 18, 2023
@AlekseyTs
Copy link
Contributor Author

@cston, @dotnet/roslyn-compiler For the second review

@AlekseyTs
Copy link
Contributor Author

@cston, @dotnet/roslyn-compiler For the second review

@AlekseyTs AlekseyTs merged commit 71b07c9 into dotnet:main Jul 20, 2023
25 checks passed
@ghost ghost modified the milestones: 17.8, Next Jul 20, 2023
@allisonchou allisonchou modified the milestones: Next, 17.8 P1 Jul 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers New Feature - Inline Arrays untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
5 participants