Skip to content

Commit

Permalink
2002-07-24 Martin Baulig <martin@gnome.org>
Browse files Browse the repository at this point in the history
	* statement.cs (Foreach.ForeachHelperMethods): Added `Type element_type',
	initialize it to TypeManager.object_type in the constructor.
	(Foreach.GetEnumeratorFilter): Set `hm.element_type' to the return type
	of the `hm.get_current' method if we're using the collection pattern.
	(Foreach.EmitCollectionForeach): Use `hm.element_type' as the source type
	for the explicit conversion to make it work when we're using the collection
	pattern and the `Current' property has a different return type than `object'.
	Fixes #27713.

svn path=/trunk/mcs/; revision=6153
  • Loading branch information
Martin Baulig committed Jul 24, 2002
1 parent 170352e commit e1acf0f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
11 changes: 11 additions & 0 deletions mcs/mcs/ChangeLog
@@ -1,3 +1,14 @@
2002-07-24 Martin Baulig <martin@gnome.org>

* statement.cs (Foreach.ForeachHelperMethods): Added `Type element_type',
initialize it to TypeManager.object_type in the constructor.
(Foreach.GetEnumeratorFilter): Set `hm.element_type' to the return type
of the `hm.get_current' method if we're using the collection pattern.
(Foreach.EmitCollectionForeach): Use `hm.element_type' as the source type
for the explicit conversion to make it work when we're using the collection
pattern and the `Current' property has a different return type than `object'.
Fixes #27713.

2002-07-24 Martin Baulig <martin@gnome.org>

* delegate.cs (Delegate.VerifyMethod): Simply return null if the method
Expand Down
8 changes: 6 additions & 2 deletions mcs/mcs/statement.cs
Expand Up @@ -2790,10 +2790,12 @@ class ForeachHelperMethods {
public MethodInfo get_enumerator;
public MethodInfo move_next;
public MethodInfo get_current;
public Type element_type;

public ForeachHelperMethods (EmitContext ec)
{
this.ec = ec;
this.element_type = TypeManager.object_type;
}
}

Expand Down Expand Up @@ -2874,6 +2876,8 @@ static bool GetEnumeratorFilter (MemberInfo m, object criteria)
if (hm.get_current == null)
return false;

hm.element_type = hm.get_current.ReturnType;

return true;
}

Expand Down Expand Up @@ -2957,7 +2961,7 @@ bool EmitCollectionForeach (EmitContext ec, Type var_type, ForeachHelperMethods
{
ILGenerator ig = ec.ig;
LocalBuilder enumerator, disposable;
Expression empty = new EmptyExpression ();
Expression empty = new EmptyExpression (hm.element_type);
Expression conv;

//
Expand All @@ -2970,7 +2974,7 @@ bool EmitCollectionForeach (EmitContext ec, Type var_type, ForeachHelperMethods
conv = Expression.ConvertExplicit (ec, empty, var_type, loc);
if (conv == null)
return false;

enumerator = ig.DeclareLocal (TypeManager.ienumerator_type);
disposable = ig.DeclareLocal (TypeManager.idisposable_type);

Expand Down

0 comments on commit e1acf0f

Please sign in to comment.