Wiki

Changeset 1264

Show
Ignore:
Timestamp:
02/07/08 13:16:52 (4 years ago)
Author:
chuck
Message:

Fixed: The results of a for-expression cannot be assigned back to the list variable to works on. Example: words = for word in words where word.trim.length

Location:
cobra/trunk
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • cobra/trunk/Source/CobraLang.cs

    r1229 r1264  
    603603    public delegate bool ForWhereGet<TIn, TOut>(TIn inValue, out TOut outValue); 
    604604 
    605     static public IList<TOut> For<TIn, TOut>(IList<TIn> list, ForGet<TIn, TOut> forGet) { 
     605    static public List<TOut> For<TIn, TOut>(IList<TIn> list, ForGet<TIn, TOut> forGet) { 
    606606        // TODO: if possible, it might be nice to get the generic type of the list coming in and then make a constructed type from it with TOut. 
    607607        List<TOut> results = new List<TOut>(list.Count); 
     
    611611    } 
    612612 
    613     static public IList<TOut> For<TIn, TOut>(IList<TIn> list, ForWhereGet<TIn, TOut> forWhereGet) { 
    614         IList<TOut> results = new List<TOut>(); 
     613    static public List<TOut> For<TIn, TOut>(IList<TIn> list, ForWhereGet<TIn, TOut> forWhereGet) { 
     614        List<TOut> results = new List<TOut>(); 
    615615        foreach (TIn item in list) { 
    616616            TOut value; 
  • cobra/trunk/Source/Expr.cobra

    r1262 r1264  
    830830                _whereExpr = TruthExpr(_whereExpr).bindAll to TruthExpr  # CC: axe cast when have "as same" 
    831831        _getExpr.bindImp 
    832         ilist = .compiler.libraryBox('System.Collections.Generic.IList<of>') 
     832        ilist = .compiler.libraryBox('System.Collections.Generic.List<of>') 
    833833        _type = ilist.constructedTypeFor([_getExpr.type to !]) 
    834834 
  • cobra/trunk/Tests/240-generics/100-use-generics-collections/610-for-expr-generic-list.cobra

    r1244 r1264  
    4242 
    4343        # where with a non bool-typed expression 
    44         stuff = 'aoeu   aoeu' 
     44        stuff = 'aoeu   asdf' 
    4545        words = for rawWord in stuff.split where rawWord.trim.length get rawWord.trim 
    46         assert words == ['aoeu', 'aoeu'] 
     46        assert words == ['aoeu', 'asdf'] 
     47        words = for word in words where word <> 'asdf'   # assign for expr back to source variable 
     48        assert words == ['aoeu']