Skip to content

Fix Type.IsPublic for pointer and byref types - #65156

Merged
buyaa-n merged 11 commits into
dotnet:mainfrom
buyaa-n:makePointer_isPublic
Feb 21, 2022
Merged

buyaa-n merged 11 commits into
dotnet:mainfrom
buyaa-n:makePointer_isPublic

Conversation

@buyaa-n

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

Copy link
Copy Markdown
Contributor

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

ghost commented Feb 10, 2022

Copy link
Copy Markdown

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: -

Comment thread src/coreclr/vm/typehandle.cpp Resolved

@lambdageek lambdageek left a comment

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.

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

@steveharter steveharter left a comment

Copy link
Copy Markdown
Contributor

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
Copy Markdown
Contributor

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

@jkotas

jkotas commented Feb 16, 2022

Copy link
Copy Markdown
Member

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

@buyaa-n

buyaa-n commented Feb 16, 2022

Copy link
Copy Markdown
Contributor Author

@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

buyaa-n commented Feb 16, 2022 •

Copy link
Copy Markdown
Contributor Author

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

buyaa-n commented Feb 17, 2022

Copy link
Copy Markdown
Contributor Author

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

jkotas commented Feb 17, 2022

Copy link
Copy Markdown
Member

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

buyaa-n commented Feb 17, 2022

Copy link
Copy Markdown
Contributor Author

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;

Comment thread src/mono/mono/metadata/icall.c Resolved
@buyaa-n
buyaa-n force-pushed the makePointer_isPublic branch from 8dce35f to 0b042b8 Compare February 18, 2022 21:51
Comment thread src/coreclr/vm/runtimehandles.cpp Resolved
@buyaa-n
buyaa-n force-pushed the makePointer_isPublic branch from c721a18 to a17a004 Compare February 18, 2022 23:36

@jkotas jkotas left a comment

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.

LGTM. Thank you!

@buyaa-n

buyaa-n commented Feb 21, 2022

Copy link
Copy Markdown
Contributor Author

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