Wiki

Ticket #158: numForBroke.patch

File numForBroke.patch, 4.4 KB (added by hopscc, 15 years ago)
  • Source/Cobra.Lang/Native.cs

     
    520520        return results; 
    521521    } 
    522522 
    523     /* Numeric forExpr */ 
    524     static public List<int> For<TIn, TOut>(int start, int stop, int step, ForGet<int, int> forGet) { 
     523 
     524    /* Numeric forExpr - ints in, any type returned */         
     525    static public List<TOut> For<TIn, TOut>(int start, int stop, int step, ForGet<int, TOut> forGet) { 
    525526        if ((step > 0 && start > stop) ||  
    526527            (step < 0 && start < stop) || step == 0) 
    527528                throw new IndexOutOfRangeException(string.Format("for expression will never terminate; start={0} stop={1} step={2}", start, stop, step)); 
    528         List<int> results = new List<int>(); 
     529        List<TOut> results = new List<TOut>(); 
    529530        for (int item = start;  
    530531            (step > 0 && item < stop) || (step < 0 && item > stop); 
    531532            item += step) 
     
    533534        return results; 
    534535    } 
    535536 
    536     static public List<int> For<TIn, TOut>(int start, int stop, int step, ForWhereGet<int, int> forWhereGet) { 
     537    static public List<TOut> For<TIn, TOut>(int start, int stop, int step, ForWhereGet<int, TOut> forWhereGet) { 
    537538        if ((step > 0 && start > stop) ||  
    538539            (step < 0 && start < stop) || step == 0) 
    539540                throw new IndexOutOfRangeException(string.Format("for expression will never terminate; start={0} stop={1} step={2}", start, stop, step)); 
    540         List<int> results = new List<int>(); 
     541        List<TOut> results = new List<TOut>(); 
    541542        for (int item = start; 
    542543            (step > 0 && item < stop) || (step < 0 && item > stop); 
    543544            item += step) { 
    544             int value; 
     545            TOut value; 
    545546            if (forWhereGet(item, out value)) 
    546547                results.Add(value); 
    547548        } 
  • Tests/110-basics-two/600-functional/122-for-expr-numeric-method.cobra

     
     1# test for compile failure for expr over numeric range calling method with non int param and return 
     2#  Numeric For broken ticket:158 
     3class NumFor 
     4 
     5    def main is shared 
     6        #n = [5,6] 
     7        n = 5 
     8        stuff = for i in n get i 
     9        #trace stuff 
     10        assert stuff.typeOf is List<of int> 
     11        assert stuff == [0, 1, 2, 3, 4] 
     12         
     13        # this worked originally 
     14        stuffI = for i in 1:n get .thingI(i) 
     15        #trace stuffI 
     16        assert stuffI.typeOf is List<of int> 
     17        assert stuffI == [1, 4, 9, 16] 
     18         
     19        # these didnt compile 
     20        stuffO = for i in 1:n get .thing(i) 
     21        #trace stuffO 
     22        assert stuffO.typeOf is List<of Object> 
     23        assert stuffO == [1, 4, 9, 16] 
     24         
     25        stuffS = for i in 1:n get .thingS(i) 
     26        #trace stuffS 
     27        assert stuffS.typeOf is List<of String> 
     28        assert stuffS == ['1', '4', '9', '16'] 
     29     
     30        stuffX = for i in 1:n get .thingX("[i]") 
     31        #trace stuffX 
     32        assert stuffX.typeOf is List<of String> 
     33        assert stuffX == [r'-1-', r'-2-', r'-3-', r'-4-'] 
     34     
     35        # this worked originally 
     36        b = for i in 3 : 6 where i>=4 get .thingI(i) 
     37        assert b.typeOf is List<of int> 
     38        assert b == [16, 25] 
     39 
     40        # these didnt 
     41        bO = for i in 3 : 6 where i>=4 get .thing(i) 
     42        assert bO.typeOf is List<of Object> 
     43        assert bO == [16, 25] 
     44         
     45        bS = for i in 3 : 6 where i>=4 get .thingS(i) 
     46        assert bS.typeOf is List<of String> 
     47        assert bS == ['16', '25'] 
     48     
     49        bX = for i in 3 : 6 where i>=4 get .thingX("[i]") 
     50        assert bX.typeOf is List<of String> 
     51        assert bX == ['-4-', '-5-'] 
     52         
     53         
     54    # this worked originally 
     55    def thingI(i as int) as int is shared 
     56        return i*i 
     57    # these didnt    
     58    def thing(i as int) as Object is shared 
     59        return i*i  
     60         
     61    def thingS(i as int) as String is shared 
     62        return '[i*i]'  
     63         
     64    def thingX(i as String) as String is shared 
     65        return '-[i]-'  
     66         
     67     
  • Developer/IntermediateReleaseNotes.text

     
    395395 
    396396* Fixed: Non removal of intermediate file if -embed-run-time/ert specified and compilation fails. ticket:181 
    397397 
    398 + * Fixed: to? should give warning if operation is redundant. ticket:76 
     398* Fixed: to? should give warning if operation is redundant. ticket:76 
     399 
     400* Fixed: numeric For expr broken: ticket:158