From dedc595025df26e50d87d88c30f9f35f69596fce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Strehovsk=C3=BD?= Date: Tue, 11 Apr 2023 16:30:55 +0900 Subject: [PATCH] Validate constraints on created MethodTables We have too many IL tests in the src/tests tree that validate invalid things throw `TypeLoadException`. Things that don't meet constraints are one group of those. --- .../Compiler/CompilerTypeSystemContext.Validation.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/coreclr/tools/Common/Compiler/CompilerTypeSystemContext.Validation.cs b/src/coreclr/tools/Common/Compiler/CompilerTypeSystemContext.Validation.cs index 8112602651d7d2..fa77552b375c41 100644 --- a/src/coreclr/tools/Common/Compiler/CompilerTypeSystemContext.Validation.cs +++ b/src/coreclr/tools/Common/Compiler/CompilerTypeSystemContext.Validation.cs @@ -153,9 +153,16 @@ private static TypeDesc EnsureLoadableTypeUncached(TypeDesc type) { ThrowHelper.ThrowTypeLoadException(ExceptionStringID.ClassLoadGeneral, type); } + } - // TODO: validate constraints + // Don't validate constraints with crossgen2 - the type system is not set up correctly + // and doesn't see generic interfaces on arrays. +#if !READYTORUN + if (!defType.IsCanonicalSubtype(CanonicalFormKind.Any) && !defType.CheckConstraints()) + { + ThrowHelper.ThrowTypeLoadException(ExceptionStringID.ClassLoadGeneral, type); } +#endif // Check the type doesn't have bogus MethodImpls or overrides and we can get the finalizer. defType.GetFinalizer();