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

Fix Type.IsPublic for pointer and byref types #65156

Merged
merged 11 commits into from
Feb 21, 2022

Conversation

buyaa-n
Copy link
Contributor

@buyaa-n buyaa-n commented Feb 10, 2022

Fixes #12355

Type.IsPublic returns false for pointer and byref types generated from a public type. Because RuntimeTypeHandle::GetAttributes returns 0 (NotPublic) for TypeDesc types (except generic type variables). Updated the code to return attributes from underlying element type (for pointer and byref types only)

@ghost
Copy link

ghost commented Feb 10, 2022

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

Issue Details

Fixes #12355

Type.IsPublic returns false for pointer and byref types generated from a public type. Because RuntimeTypeHandle::GetAttributes returns 0 (NotPublic) for TypeDesc types (except generic type variables). Updated the code to return attributes from underlying element type (for pointer and byref types only)

Author: buyaa-n
Assignees: -
Labels:

area-System.Reflection

Milestone: -

Copy link
Member

@lambdageek lambdageek left a comment

Choose a reason for hiding this comment

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

Mono changes LGTM

@buyaa-n buyaa-n force-pushed the makePointer_isPublic branch from 760ec25 to b6aa2c8 Compare February 16, 2022 01:46
@buyaa-n buyaa-n force-pushed the makePointer_isPublic branch from b6aa2c8 to 11076ec Compare February 16, 2022 02:57
Copy link
Member

@steveharter steveharter left a comment

Choose a reason for hiding this comment

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

LGTM; some minor test feedback

@steveharter
Copy link
Member

@buyaa-n note some CI failures with the new tests

@jkotas
Copy link
Member

jkotas commented Feb 16, 2022

Does System.Reflection.MetadataLoadContext need this fix as well?

@buyaa-n
Copy link
Contributor Author

buyaa-n commented Feb 16, 2022

@buyaa-n note some CI failures with the new tests

Looking, thanks

Does System.Reflection.MetadataLoadContext need this fix as well?

Will check, thanks

@buyaa-n
Copy link
Contributor Author

buyaa-n commented Feb 16, 2022

A question about the CI test failure: for Assert.True(typeof(delegate*<string, int>).IsPublic); the mono and CoreCLR behavior was different even before this change, CoreCLR somehow always return Public for this function pointer
mono always return not public for function pointer:

if (m_type_is_byref (type) || type->type == MONO_TYPE_PTR || type->type == MONO_TYPE_FNPTR)
return TYPE_ATTRIBUTE_NOT_PUBLIC;

I beleive we need same behavior for this, but i am not sure which value is expected, I guess it should be public, but want to confirm, please let me know what you think @steveharter @jkotas @GrabYourPitchforks @lambdageek

@buyaa-n
Copy link
Contributor Author

buyaa-n commented Feb 17, 2022

Does System.Reflection.MetadataLoadContext need this fix as well?

MLC just returning TypeAttributes.AnsiClass, should we change it @steveharter?

protected sealed override TypeAttributes ComputeAttributeFlags() => TypeAttributes.AnsiClass;

protected sealed override TypeAttributes ComputeAttributeFlags() => TypeAttributes.AnsiClass;

@jkotas
Copy link
Member

jkotas commented Feb 17, 2022

MLC just returning TypeAttributes.AnsiClass

The value of TypeAttributes.AnsiClass is 0. It is better to think about it as returning default. It would be actually better to write it as returning default instead TypeAttributes.AnsiClass.

@buyaa-n
Copy link
Contributor Author

buyaa-n commented Feb 17, 2022

The value of TypeAttributes.AnsiClass is 0. It is better to think about it as returning default. It would be actually better to write it as returning default instead TypeAttributes.AnsiClass.

Right 0, so it was same as what GetAttributes() method was returning, so i need to update MLC, thanks !

if (typeHandle.IsTypeDesc()) {
if (typeHandle.IsGenericVariable()) {
return tdPublic;
}
return 0;

@buyaa-n buyaa-n force-pushed the makePointer_isPublic branch from 8dce35f to 0b042b8 Compare February 18, 2022 21:51
@buyaa-n buyaa-n force-pushed the makePointer_isPublic branch from c721a18 to a17a004 Compare February 18, 2022 23:36
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.

LGTM. Thank you!

@buyaa-n
Copy link
Contributor Author

buyaa-n commented Feb 21, 2022

Thank you all the your review and suggestions! Build failure unrelated, merging

@buyaa-n buyaa-n merged commit 3e01d11 into dotnet:main Feb 21, 2022
@buyaa-n buyaa-n deleted the makePointer_isPublic branch February 21, 2022 23:35
@ghost ghost locked as resolved and limited conversation to collaborators Mar 24, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Type.IsPublic returns wrong answer for pointer and byref types
5 participants