Permalink
Browse files

Disallow statics of spans and class instance members of span (#9061)

Functional fix for #8516 to cover some additional cases. IL tests will be coming later in a separate PR.
  • Loading branch information...
kouvel authored and jkotas committed Jan 24, 2017
1 parent 97e7020 commit 969cea6a2ffff6c53a615d2fd398f9a7b8c73290
Showing with 16 additions and 1 deletion.
  1. +3 −0 src/dlls/mscorrc/mscorrc.rc
  2. +2 −1 src/dlls/mscorrc/resource.h
  3. +11 −0 src/vm/methodtablebuilder.cpp
@@ -1230,6 +1230,9 @@ BEGIN
IDS_CLASSLOAD_NOTINTERFACE "Could not load type '%1' from assembly '%2' because it attempts to implement a class as an interface."
IDS_CLASSLOAD_VALUEINSTANCEFIELD "Could not load the value type '%1' from assembly '%2' because it has an instance field of itself."
IDS_CLASSLOAD_BYREFLIKE_STATICFIELD "A value type containing a by-ref instance field, such as Span<T>, cannot be used as the type for a static field."
IDS_CLASSLOAD_BYREFLIKE_NOTVALUECLASSFIELD "A value type containing a by-ref instance field, such as Span<T>, cannot be used as the type for a class instance field."
IDS_CLASSLOAD_BAD_NAME "Type name '%1' from assembly '%2' is invalid."
IDS_CLASSLOAD_RANK_TOOLARGE "'%1' from assembly '%2' has too many dimensions."
IDS_CLASSLOAD_BAD_MANAGED_RVA "Managed method '%3' on type '%1' from assembly '%2' is not supported."
@@ -947,4 +947,5 @@
#define IDS_NATIVE_IMAGE_CANNOT_BE_LOADED_MULTIPLE_TIMES 0x263a
#define IDS_CLASSLOAD_BYREFLIKE_STATICFIELD 0x263b
#define IDS_CLASSLOAD_BYREFLIKE_NOTVALUECLASSFIELD 0x263c
@@ -4222,6 +4222,17 @@ VOID MethodTableBuilder::InitializeFieldDescs(FieldDesc *pFieldDescList,
// Inherit IsByRefLike characteristic from fields
if (!IsSelfRef(pByValueClass) && pByValueClass->IsByRefLike())
{
if (fIsStatic)
{
// By-ref-like types cannot be used for static fields
BuildMethodTableThrowException(IDS_CLASSLOAD_BYREFLIKE_STATICFIELD);
}
if (!IsValueClass())
{
// Non-value-classes cannot contain by-ref-like instance fields
BuildMethodTableThrowException(IDS_CLASSLOAD_BYREFLIKE_NOTVALUECLASSFIELD);
}
bmtFP->fIsByRefLikeType = true;
}

0 comments on commit 969cea6

Please sign in to comment.