Odd List error

Discussion about the open-source Phalanger [?] project.

Odd List error

Postby tleslie » August 8th, 2012, 10:46 pm

I have:



$lll = new System\Collections\Generic\List<:MvcAppCustomViewEngine\Models\Person:>;
$lll = $model;

$qqq = new System\Collections\Generic\List<:System\String:>;
$qqq->Add("Exit");
$qqq->Add("Exit");
$qqq->Add("Exit");

$d1 = new MvcAppCustomViewEngine\Models\Person;
$d2 = new MvcAppCustomViewEngine\Models\Person;
$d1 = $lll[0];
$d2 = $lll[1];

$pp = new MvcAppCustomViewEngine\Models\Person;

for($i=0; $i<count($lll); ++$i)
{
echo $i." ". $lll[$i]->Name." ".count($lll)." ";
}

foreach($lll as $li) {
$pp=$li;
?>
<li><a href="x"><? echo $pp->Name ?></a><li>
<?
}


echo $lll->Capacity."<<".$lll->Capacity." ".$lll->get_Item(1)->Name." >>>>".$qqq->Count." ".$lll->Count;


Everything works as expected until the last line,
the access of $lll->Count (which is a List of Person where as $qqq is a List
of String), i get a error:
Unable to cast object of type 'System.Collections.Generic.List`1[MvcAppCustomViewEngine.Models.Person]' to type 'System.Collections.Generic.List`1[System.String]'.

this error specifically for the $lll->Count piece of code,
what is odd is it prints the $lll->Capacity, accesses the get_Item(1),
the List of String, it prints its $qqq->Count properly with out error.
I don't understand why $lll->Count is causing a

Unable to cast object of type 'System.Collections.Generic.List`1[MvcAppCustomViewEngine.Models.Person]' to type 'System.Collections.Generic.List`1[System.String]'.

And count($lll) is 1 which is wrong, but the foreach structure does work,
and processed the three Person records in the List.

-tl
tleslie
 
Posts: 32
Joined: August 3rd, 2012, 4:42 am

Re: Odd List error

Postby Jakub Misek » August 9th, 2012, 8:19 pm

Thanks for the test case. I've successfully reproduced the error, so we can fix it into upcoming release.

Just note: count() does not work with IList or IDictionary objects yet, so it returns always 1 instead of real Count. But we will probably implement that, since it is more intuitive.
Jakub Misek │ DEVSENSE s.r.o. | @misekjakubjakub@devsense.com
User avatar
Jakub Misek
 
Posts: 2092
Joined: January 4th, 2012, 2:42 pm
Location: Prague


Return to Phalanger project

Who is online

Users browsing this forum: No registered users and 11 guests

cron

User Control Panel

Login

Who is online

In total there are 11 users online :: 0 registered, 0 hidden and 11 guests (based on users active over the past 5 minutes)
Most users ever online was 297 on March 29th, 2024, 7:06 am

Users browsing this forum: No registered users and 11 guests