File tree 5 files changed +53
-8
lines changed
tests/baseservices/typeequivalence
5 files changed +53
-8
lines changed Original file line number Diff line number Diff line change @@ -2659,14 +2659,6 @@ MethodTableBuilder::EnumerateClassMethods()
2659
2659
METHOD_IMPL_TYPE implType;
2660
2660
LPSTR strMethodName;
2661
2661
2662
- #ifdef FEATURE_TYPEEQUIVALENCE
2663
- // TypeEquivalent structs must not have methods
2664
- if (bmtProp->fIsTypeEquivalent && fIsClassValueType)
2665
- {
2666
- BuildMethodTableThrowException(IDS_CLASSLOAD_EQUIVALENTSTRUCTMETHODS);
2667
- }
2668
- #endif
2669
-
2670
2662
//
2671
2663
// Go to the next method and retrieve its attributes.
2672
2664
//
@@ -2686,6 +2678,14 @@ MethodTableBuilder::EnumerateClassMethods()
2686
2678
BuildMethodTableThrowException(IDS_CLASSLOAD_BADFORMAT);
2687
2679
}
2688
2680
2681
+ #ifdef FEATURE_TYPEEQUIVALENCE
2682
+ // TypeEquivalent structs must not have non-static methods
2683
+ if (!IsMdStatic(dwMemberAttrs) && bmtProp->fIsTypeEquivalent && fIsClassValueType)
2684
+ {
2685
+ BuildMethodTableThrowException(IDS_CLASSLOAD_EQUIVALENTSTRUCTMETHODS);
2686
+ }
2687
+ #endif
2688
+
2689
2689
bool isVtblGap = false;
2690
2690
if (IsMdRTSpecialName(dwMemberAttrs) || IsMdVirtual(dwMemberAttrs) || IsDelegate())
2691
2691
{
Original file line number Diff line number Diff line change
1
+ <Project Sdk =" Microsoft.NET.Sdk" >
2
+ <PropertyGroup >
3
+ <OutputType >Library</OutputType >
4
+ <CLRTestKind >SharedLibrary</CLRTestKind >
5
+ </PropertyGroup >
6
+ <ItemGroup >
7
+ <Compile Include =" Types.cs" />
8
+ </ItemGroup >
9
+ </Project >
Original file line number Diff line number Diff line change
1
+ // Licensed to the .NET Foundation under one or more agreements.
2
+ // The .NET Foundation licenses this file to you under the MIT license.
3
+
4
+ using System ;
5
+ using System . Runtime . InteropServices ;
6
+
7
+ [ assembly: PrimaryInteropAssembly ( 1 , 0 ) ]
8
+
9
+ public struct ValueTypeWithStaticMethod
10
+ {
11
+ public int F ;
12
+ public static void M ( ) { }
13
+ }
14
+
15
+ public struct ValueTypeWithInstanceMethod
16
+ {
17
+ public int F ;
18
+ public void M ( ) { }
19
+ }
Original file line number Diff line number Diff line change 5
5
using System . Linq ;
6
6
using System . Text ;
7
7
using System . Reflection ;
8
+ using System . Runtime . CompilerServices ;
8
9
using System . Runtime . InteropServices ;
9
10
10
11
using Xunit ;
@@ -253,6 +254,20 @@ private static unsafe void TestTypeEquivalenceWithTypePunning()
253
254
}
254
255
}
255
256
257
+ [ MethodImpl ( MethodImplOptions . NoInlining ) ]
258
+ private static void TestLoadingValueTypesWithMethod ( )
259
+ {
260
+ Console . WriteLine ( $ "{ nameof ( TestLoadingValueTypesWithMethod ) } ") ;
261
+ Console . WriteLine ( $ "-- { typeof ( ValueTypeWithStaticMethod ) . Name } ") ;
262
+ Assert . Throws < TypeLoadException > ( ( ) => LoadInvalidType ( ) ) ;
263
+ }
264
+
265
+ [ MethodImpl ( MethodImplOptions . NoInlining ) ]
266
+ private static void LoadInvalidType ( )
267
+ {
268
+ Console . WriteLine ( $ "-- { typeof ( ValueTypeWithInstanceMethod ) . Name } ") ;
269
+ }
270
+
256
271
public static int Main ( string [ ] noArgs )
257
272
{
258
273
if ( ! OperatingSystem . IsWindows ( ) )
@@ -270,6 +285,7 @@ public static int Main(string[] noArgs)
270
285
TestGenericClassNonEquivalence ( ) ;
271
286
TestGenericInterfaceEquivalence ( ) ;
272
287
TestTypeEquivalenceWithTypePunning ( ) ;
288
+ TestLoadingValueTypesWithMethod ( ) ;
273
289
}
274
290
catch ( Exception e )
275
291
{
Original file line number Diff line number Diff line change 15
15
<ProjectReference Include =" ../impl/TypeImpl.csproj" />
16
16
<ProjectReference Include =" ../impl/PunningLib.ilproj" />
17
17
<ProjectReference Include =" $(TestSourceDir)Common/CoreCLRTestLibrary/CoreCLRTestLibrary.csproj" />
18
+ <ProjectReference Include =" ../pia/PIAContract.csproj" />
18
19
</ItemGroup >
19
20
<Import Project =" $([MSBuild]::GetPathOfFileAbove(TypeEquivalence.targets))" />
20
21
</Project >
You can’t perform that action at this time.
0 commit comments