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

Disallow declaration of indexers in absence of proper DefaultMemberAttribute. #75099

Merged
merged 5 commits into from
Sep 30, 2024

Conversation

AlekseyTs
Copy link
Contributor

Fixes #75032.

@AlekseyTs AlekseyTs requested a review from a team as a code owner September 12, 2024 23:04
@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged Issues and PRs which have not yet been triaged by a lead label Sep 12, 2024
@@ -1713,7 +1713,7 @@ internal override void AddSynthesizedAttributes(PEModuleBuilder moduleBuilder, r

AddSynthesizedAttribute(ref attributes, compilation.TrySynthesizeAttribute(
WellKnownMember.System_Reflection_DefaultMemberAttribute__ctor,
ImmutableArray.Create(defaultMemberNameConstant)));
ImmutableArray.Create(defaultMemberNameConstant), isOptionalUse: true));
Copy link
Member

@333fred 333fred Sep 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess my question is, why is this ok to not emit? #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.

It is not ok, but this is what we were doing for many years. If we start reporting an error (like VB), we are going to break runtime build, at least. I don't think this is worth it. The scenario is very uncommon.

Copy link
Member

@333fred 333fred Sep 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My feeling is, this (where the error would be reported) is a test-only component of NativeAOT that is fairly new. It seems likely to me that it should be including this attribute, and not having it could end up masking a bug. /cc @agocke

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What’s the actual proposal? That the compiler emits an error for this case and the runtime fixes the test code?

I’m fine with that.

Is it possible that anyone could hit the error without hitting the assert? If so the question really is what happens if you get a bug from windows or office about the new error. Will you change the compiler or tell them to fix their code? Whatever is the answer to that question is the path I would take.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That the compiler emits an error for this case and the runtime fixes the test code?

That's what I would do, yes.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible that anyone could hit the error without hitting the assert?

Sure. The runtime does right now 🙂.

@AlekseyTs AlekseyTs requested a review from a team September 13, 2024 13:16
@AlekseyTs AlekseyTs changed the title Suppress an assert when an indexer is declared, but DefaultMemberNameAttribute is missing. Suppress an assert when an indexer is declared, but DefaultMemberAttribute is missing. Sep 18, 2024
@AlekseyTs AlekseyTs changed the title Suppress an assert when an indexer is declared, but DefaultMemberAttribute is missing. Disallow declaration of indexers in absence of proper DefaultMemberAttribute. Sep 30, 2024
@AlekseyTs AlekseyTs requested a review from a team September 30, 2024 16:31
@AlekseyTs
Copy link
Contributor Author

@dotnet/roslyn-compiler For the second review

}
}

if (Indexers.FirstOrDefault() is PropertySymbol indexerSymbol)
{
Binder.GetWellKnownTypeMember(DeclaringCompilation, WellKnownMember.System_Reflection_DefaultMemberAttribute__ctor, diagnostics, indexerSymbol.TryGetFirstLocation() ?? GetFirstLocation());
Copy link
Member

@jcouv jcouv Sep 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indexerSymbol.TryGetFirstLocation() ?? GetFirstLocation()

nit: I didn't follow the intricacy of the Location logic. Do we have a test where indexerSymbol.TryGetFirstLocation() is null? #Resolved

Copy link
Contributor Author

@AlekseyTs AlekseyTs Sep 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a defense in depth, theoretically the API can return null, even though we don't expect it to. This pattern is also used elsewhere in this function.

Copy link
Member

@jcouv jcouv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM Thanks (iteration 5) with a clarifying question

@jcouv jcouv self-assigned this Sep 30, 2024
@AlekseyTs AlekseyTs merged commit ba7fe35 into dotnet:main Sep 30, 2024
24 checks passed
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone Sep 30, 2024
333fred added a commit to 333fred/roslyn that referenced this pull request Oct 1, 2024
…terns

* upstream/main: (267 commits)
  Support long chains of `else if` statements (dotnet#74317)
  Update dependencies from https://github.com/dotnet/source-build-externals build 20240930.2
  Fix the path to the proposal (dotnet#75302)
  Fix TSA tooling (dotnet#75307)
  Clarify the bug template to request a code snippet (dotnet#75306)
  Bump razor for serialization changes (dotnet#75282)
  Disallow declaration of indexers in absence of proper DefaultMemberAttribute. (dotnet#75099)
  stoub
  use ref
  Simpler
  Simplify
  Switch to a threadlocal storage to prevent locks
  add comment
  don't mess with user caret in smart rename
  Update LanguageServer references
  Localized file check-in by OneLocBuild Task: Build definition ID 327: Build ID 2548898
  Use common helper method
  Localized file check-in by OneLocBuild Task: Build definition ID 327: Build ID 2548278
  Field-backed properties: additional tests (dotnet#75283)
  Revert "Updates content exclusion for on-the-fly-docs (dotnet#75172)" (dotnet#75279) (dotnet#75284)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Assert failure when building runtime: Synthesized attribute constructor missing
4 participants