Skip to content

Commit

Permalink
Fixing issue #176
Browse files Browse the repository at this point in the history
  • Loading branch information
masonwheeler committed Oct 30, 2018
1 parent 1fc0c51 commit 40e49ac
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/Boo.Lang.Compiler/TypeSystem/Core/ArrayType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,16 +144,25 @@ public virtual bool IsSubclassOf(IType other)
TypeSystemServices services = My<TypeSystemServices>.Instance;
if (other == services.ArrayType || services.ArrayType.IsSubclassOf(other))
return true;
// Arrays also implement generic IEnumerable of their element type
if (other.ConstructedInfo != null &&
other.ConstructedInfo.GenericDefinition == services.IEnumerableGenericType &&

// Arrays also implement several generic collection interfaces of their element type
if (other.ConstructedInfo != null && other.IsInterface &&
IsSupportedInterfaceType(services, other.ConstructedInfo.GenericDefinition) &&
IsSubclassOfGenericEnumerable(other))
return true;

return false;
}

protected bool IsSupportedInterfaceType(TypeSystemServices services, IType definition)
{
return definition == services.IEnumerableGenericType
|| definition == services.IListGenericType
|| definition == services.ICollectionGenericType
|| definition == services.IReadOnlyListGenericType
|| definition == services.IReadOnlyCollectionGenericType;
}

protected virtual bool IsSubclassOfGenericEnumerable(IType enumerableType)
{
return IsAssignableFrom(enumerableType.ConstructedInfo.GenericArguments[0], _elementType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,15 @@ public class TypeSystemServices

public IType ICallableType;
public IType ICollectionGenericType;
public IType IReadOnlyCollectionGenericType;
public IType ICollectionType;
public IType IDisposableType;

public IType IEnumerableGenericType;
public IType IEnumerableType;

public IType IListGenericType;
public IType IReadOnlyListGenericType;
public IType IListType;

public IType NullableGenericType;
Expand Down Expand Up @@ -196,7 +198,9 @@ public TypeSystemServices(CompilerContext context)
IEnumerableGenericType = Map(Types.IEnumerableGeneric);
IEnumeratorGenericType = Map(typeof(IEnumerator<>));
ICollectionGenericType = Map(typeof(ICollection<>));
IReadOnlyCollectionGenericType = Map(typeof(IReadOnlyCollection<>));
IListGenericType = Map(typeof (IList<>));
IReadOnlyListGenericType = Map(typeof(IReadOnlyList<>));
IListType = Map(typeof (IList));
NullableGenericType = Map(Types.Nullable);
IAstMacroType = Map(typeof(IAstMacro));
Expand Down

0 comments on commit 40e49ac

Please sign in to comment.