diff options
author | Gergely Kalapos <gergo@kalapos.net> | 2017-05-21 18:33:50 +0300 |
---|---|---|
committer | Jan Kotas <jkotas@microsoft.com> | 2017-05-21 18:33:50 +0300 |
commit | a80c986dd46eb4ccaa05310d10c606570900b944 (patch) | |
tree | 70ca8420c66e7e2ee400d80ef857394c11e882c4 /src | |
parent | 96e254c2763011780c87e701c78d513e7793b6d3 (diff) |
[ILVerify] Handling of assignment of interface to object - with CastingHelper (#3666)
* Handling interface->object assignment + test
* Adapted logic in CanCastToClass and use CastingHelper.CanCastTo in IsAssignable(TypeDesc src, TypeDesc dst)
Diffstat (limited to 'src')
-rw-r--r-- | src/Common/src/TypeSystem/Common/CastingHelper.cs | 5 | ||||
-rw-r--r-- | src/ILCompiler.TypeSystem/tests/CastingTests.cs | 1 | ||||
-rw-r--r-- | src/ILVerify/src/ILImporter.StackValue.cs | 18 |
3 files changed, 8 insertions, 16 deletions
diff --git a/src/Common/src/TypeSystem/Common/CastingHelper.cs b/src/Common/src/TypeSystem/Common/CastingHelper.cs index b7576923c..cf1dd0cc2 100644 --- a/src/Common/src/TypeSystem/Common/CastingHelper.cs +++ b/src/Common/src/TypeSystem/Common/CastingHelper.cs @@ -352,6 +352,11 @@ namespace Internal.TypeSystem return thisType.CanCastTo(otherType.Instantiation[0]); } + if (curType.IsInterface) + { + return otherType.IsObject; + } + do { if (curType == otherType) diff --git a/src/ILCompiler.TypeSystem/tests/CastingTests.cs b/src/ILCompiler.TypeSystem/tests/CastingTests.cs index 573bc1822..6e439984c 100644 --- a/src/ILCompiler.TypeSystem/tests/CastingTests.cs +++ b/src/ILCompiler.TypeSystem/tests/CastingTests.cs @@ -51,6 +51,7 @@ namespace TypeSystemTests Assert.True(classImplementingIFooType.CanCastTo(iFooType)); Assert.True(classImplementingIFooIndirectlyType.CanCastTo(iFooType)); + Assert.True(iFooType.CanCastTo(objectType)); Assert.False(objectType.CanCastTo(iFooType)); } diff --git a/src/ILVerify/src/ILImporter.StackValue.cs b/src/ILVerify/src/ILImporter.StackValue.cs index be22e953a..076e2e57a 100644 --- a/src/ILVerify/src/ILImporter.StackValue.cs +++ b/src/ILVerify/src/ILImporter.StackValue.cs @@ -184,21 +184,7 @@ namespace Internal.IL return false; } - var t = src; - - while (t != null) - { - if (t == dst) - return true; - t = t.BaseType; - } - - if (dst.IsInterface || dst.IsArray) - throw new NotImplementedException($"{nameof(IsAssignable)} is only partially implemented."); - - // TODO: Other cases - variance, etc. - - return false; + return CastingHelper.CanCastTo(src, dst); } bool IsAssignable(StackValue src, StackValue dst) @@ -216,7 +202,7 @@ namespace Internal.IL if (src.Type == null) return true; - return IsAssignable(src.Type, dst.Type); + return CastingHelper.CanCastTo(src.Type, dst.Type); case StackValueKind.ValueType: |