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

Make TypeBuilder.CreateType return non nullable #72180

Merged
merged 16 commits into from
Jul 26, 2022

Conversation

JosieBigler
Copy link
Contributor

@JosieBigler JosieBigler commented Jul 14, 2022

There is no situation when TypeBuilder.CreateType will return null when
being called by user-code.

Fixes #68840

There is no situation when TypeBuilder.CreateType will return null when
being called by user-code.

issue dotnet#68840
@ghost ghost added the community-contribution Indicates that the PR has been added by a community member label Jul 14, 2022
@ghost
Copy link

ghost commented Jul 14, 2022

Tagging subscribers to this area: @dotnet/area-system-reflection
See info in area-owners.md if you want to be subscribed.

Issue Details

There is no situation when TypeBuilder.CreateType will return null when
being called by user-code.

issue #68840

Author: JosieBigler
Assignees: -
Labels:

area-System.Reflection

Milestone: -

@dnfadmin
Copy link

dnfadmin commented Jul 14, 2022

CLA assistant check
All CLA requirements met.

@ghost
Copy link

ghost commented Jul 14, 2022

Tagging subscribers to this area: @dotnet/area-system-reflection-emit
See info in area-owners.md if you want to be subscribed.

Issue Details

There is no situation when TypeBuilder.CreateType will return null when
being called by user-code.

issue #68840

Author: JosieBigler
Assignees: -
Labels:

area-System.Reflection, area-System.Reflection.Emit, community-contribution

Milestone: -

@stephentoub
Copy link
Member

Should EnumBuilder.CreateType be annotated differently as well?

What about CreateTypeInfo?

Can we remove the ! from

return new GeneratedTypeInfo(_tb.CreateType()!, _methodInfos.ToArray());
?

@JosieBigler
Copy link
Contributor Author

@stephentoub I've removed the ! from DispatchProxyGenerator.cs.

It looks like we can change CreateTypeInfo . There are a few more null-forgiving operators associated with CreateTypeInfo mostly in the System.Private.Xml Do you want me to remove the ! from there as well? Or Should these changes stay confined to System.Reflection?

@jkotas
Copy link
Member

jkotas commented Jul 26, 2022

There are a few more null-forgiving operators associated with CreateTypeInfo mostly in the System.Private.Xml Do you want me to remove the ! from there as well?

Yes, you can remove the no-unnecessary ! from everywhere. Also, you should be able to delete the unnecessary AsType calls: replace CreateTypeInfo()!.AsType() with just CreateType().

}

[return: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]
internal TypeInfo? CreateTypeInfoImpl()
Copy link
Member

Choose a reason for hiding this comment

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

CreateTypeInfoImpl is identical to CreateTypeImpl. Could you please delete CreateTypeImpl and make CreateTypeInfo to call CreateTypeImpl instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed to only have 1 internal method with a signature of internal TypeInfo? CreateTypeInfoImpl().

@jkotas
Copy link
Member

jkotas commented Jul 26, 2022

Could you please merge from main to resolve conflict in TypeBuilderAddInterfaceImplementation.cs?

@@ -239,7 +239,7 @@ public void BakeMethods()

if (!_useLRE)
{
typBaked = _typeBldr!.CreateTypeInfo()!.AsType();
typBaked = _typeBldr.CreateType();
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
typBaked = _typeBldr.CreateType();
typBaked = _typeBldr!.CreateType();

I think this needs to stay.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added back the ! to _typeBldr.

Copy link
Member

@jkotas jkotas left a comment

Choose a reason for hiding this comment

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

LGMT. Thank you!

@jkotas jkotas merged commit da46270 into dotnet:main Jul 26, 2022
@lonix1
Copy link

lonix1 commented Jul 27, 2022

@JosieBigler You never thought it would get this complicated when you volunteered... 😄 Seriously though, well done and thanks!

@ghost ghost locked as resolved and limited conversation to collaborators Aug 26, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Reflection.Emit community-contribution Indicates that the PR has been added by a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Under what conditions can TypeBuilder.CreateType() return null
6 participants