Skip to content

Forbid types with required members from substituting for where T : new()#60788

Merged
333fred merged 5 commits intodotnet:features/required-membersfrom
333fred:forbid-new
Apr 27, 2022
Merged

Forbid types with required members from substituting for where T : new()#60788
333fred merged 5 commits intodotnet:features/required-membersfrom
333fred:forbid-new

Conversation

@333fred
Copy link
Copy Markdown
Member

@333fred 333fred commented Apr 15, 2022

@333fred 333fred requested a review from a team as a code owner April 15, 2022 22:07
@ghost ghost added the Area-Compilers label Apr 15, 2022
@333fred
Copy link
Copy Markdown
Member Author

333fred commented Apr 15, 2022

@jcouv @RikkiGibson for review.


void M1<T>() where T : struct
{
M2<T>();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could we someday:

  • add a warning wave for this call here, then
  • add the ability to specify where T : struct, new() to suppress the warning, then
  • add a diagnostic onto M1<C>() (would probably need to be a warning?)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

No idea. I would love to, but no idea.

}
}
return synthesizedIfMissing;
return synthesizedIfMissing && !hasAnyRequiredMembers;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It seems like we're making the assumption that the synthesized parameterless constructor will never have 'HasSetsRequiredMembers'. Is that fine?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I can't see how it wouldn't be.

@jcouv
Copy link
Copy Markdown
Member

jcouv commented Apr 25, 2022

    private static bool HasPublicParameterlessConstructor(NamedTypeSymbol type, bool synthesizedIfMissing)

This method should be renamed (maybe "SatisfiesParameterlessConstructor"?) and doc comment updated.


In reply to: 1109109969


Refers to: src/Compilers/CSharp/Portable/Symbols/ConstraintsHelper.cs:1377 in aac7cbe. [](commit_id = aac7cbe, deletion_comment = False)

@jcouv jcouv self-assigned this Apr 25, 2022
Copy link
Copy Markdown
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.

Done with review pass (iteration 1)

@333fred
Copy link
Copy Markdown
Member Author

333fred commented Apr 26, 2022

@jcouv @RikkiGibson please take another look.

Copy link
Copy Markdown
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 3)

@333fred 333fred enabled auto-merge (squash) April 26, 2022 18:40
333fred added 2 commits April 27, 2022 10:06
…o forbid-new

* upstream/features/required-members: (156 commits)
  Pass fallback options (dotnet#60803)
  Rename `CodeStyleHostLanguageServices.cs.cs` to `CodeStyleHostLanguageServices.cs` (dotnet#60955)
  Allow VSMac to access LSP options (dotnet#60943)
  Add configs for 17.3 branch and update main version (dotnet#60942)
  Restore nugetKind config to publish data
  Remove unnecessary publish data config
  Remove non-servicing 15.x publish config
  Let 'arcade' packageFeeds imply all feeds are 'arcade'
  Remove non-servicing branches from our PublishData
  Handle unexpected keyword rather than identifier for lambda parameter name (dotnet#60825)
  Correctly return E_NOTIMPL when asked for file code models for non-source
  Move the resources to top (dotnet#60899)
  Add back deprecated packages to arcade publishing config.
  Simplify
  Rename parameter
  Simplify visibility logic in tagger
  Simplify visibility logic in tagger
  Try out some fixes
  Update StructConstructorTests.cs
  Use more descriptive variable name
  ...
@333fred 333fred merged commit dbca19f into dotnet:features/required-members Apr 27, 2022
@333fred 333fred deleted the forbid-new branch April 27, 2022 21:27
@333fred 333fred added the Feature - Required Members Required properties and fields label Sep 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area-Compilers Feature - Required Members Required properties and fields

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants