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 arrays of System.Void #94835

Merged
merged 1 commit into from
Nov 17, 2023
Merged

Disallow arrays of System.Void #94835

merged 1 commit into from
Nov 17, 2023

Conversation

jkotas
Copy link
Member

@jkotas jkotas commented Nov 16, 2023

The CoreCLR type loader allowed creating arrays of System.Void. Many operations with these invalid array types failed, often in inscrutable ways. For example, GetInterfaces() call failed with type load exception of IEnumerable<void> type. The exact failure modes are different between runtimes.

It is better to disallow creating these invalid array types in the first place, across all runtimes, to make the behavior robust and consistent.

Related to #88620

Fixes #94086

@ghost ghost assigned jkotas Nov 16, 2023
@jkotas jkotas added the breaking-change Issue or PR that represents a breaking API or functional change over a prerelease. label Nov 16, 2023
@dotnet-issue-labeler dotnet-issue-labeler bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Nov 16, 2023
@ghost ghost added the needs-breaking-change-doc-created Breaking changes need an issue opened with https://github.com/dotnet/docs/issues/new?template=dotnet label Nov 16, 2023
@ghost
Copy link

ghost commented Nov 16, 2023

Added needs-breaking-change-doc-created label because this PR has the breaking-change label.

When you commit this breaking change:

  1. Create and link to this PR and the issue a matching issue in the dotnet/docs repo using the breaking change documentation template, then remove this needs-breaking-change-doc-created label.
  2. Ask a committer to mail the .NET Breaking Change Notification DL.

Tagging @dotnet/compat for awareness of the breaking change.

@jkotas jkotas added area-TypeSystem-coreclr and removed needs-breaking-change-doc-created Breaking changes need an issue opened with https://github.com/dotnet/docs/issues/new?template=dotnet needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Nov 16, 2023
@jkotas
Copy link
Member Author

jkotas commented Nov 16, 2023

/azp run runtime-coreclr outerloop

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

The CoreCLR type loader allowed creating arrays of System.Void. Many operations with these invalid array types failed, often in inscrutable ways. For example, GetInterfaces() call failed with type load exception of IEnumerable type. The exact failure modes are different between runtimes.

It is better to disallow creating these invalid array types in the first place, across all runtimes, to make the behavior robust and consistent.

Related to dotnet#88620

Fixes dotnet#94086
@@ -1170,12 +1170,8 @@ mono_class_create_bounded_array (MonoClass *eclass, guint32 rank, gboolean bound
klass->rank = GUINT32_TO_UINT8 (rank);
klass->element_class = eclass;

if (m_class_get_byval_arg (eclass)->type == MONO_TYPE_TYPEDBYREF) {
Copy link
Member Author

Choose a reason for hiding this comment

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

TypedReference is byreflike type, so it is not necessary to check for it explicitly here.

@jkotas jkotas marked this pull request as ready for review November 17, 2023 01:38
@VSadov
Copy link
Member

VSadov commented Nov 17, 2023

I thought this was always disallowed.

Copy link
Member

@VSadov VSadov left a comment

Choose a reason for hiding this comment

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

LGTM !!

@VSadov
Copy link
Member

VSadov commented Nov 17, 2023

For example, GetInterfaces() call failed with type load exception of IEnumerable<void> type.

Does that work with open generic types or pointers?

@jkotas
Copy link
Member Author

jkotas commented Nov 17, 2023

Does that work with open generic types or pointers?

Yes, it does. Pointers are special cased here:

@vargaz
Copy link
Contributor

vargaz commented Nov 17, 2023

The mono changes look ok to me.

@jkotas jkotas merged commit 8b04e1a into dotnet:main Nov 17, 2023
185 of 188 checks passed
@jkotas
Copy link
Member Author

jkotas commented Nov 18, 2023

Breaking change issue dotnet/docs#38311

@adamsitnik adamsitnik added this to the 9.0.0 milestone Nov 20, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Dec 20, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-TypeSystem-coreclr breaking-change Issue or PR that represents a breaking API or functional change over a prerelease.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Mono] System.Runtime.Tests fail with TypeLoadException
5 participants