Ticket #158: numForBroke.patch
File numForBroke.patch, 4.4 KB (added by hopscc, 15 years ago) |
---|
-
Source/Cobra.Lang/Native.cs
520 520 return results; 521 521 } 522 522 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) { 525 526 if ((step > 0 && start > stop) || 526 527 (step < 0 && start < stop) || step == 0) 527 528 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>(); 529 530 for (int item = start; 530 531 (step > 0 && item < stop) || (step < 0 && item > stop); 531 532 item += step) … … 533 534 return results; 534 535 } 535 536 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) { 537 538 if ((step > 0 && start > stop) || 538 539 (step < 0 && start < stop) || step == 0) 539 540 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>(); 541 542 for (int item = start; 542 543 (step > 0 && item < stop) || (step < 0 && item > stop); 543 544 item += step) { 544 int value;545 TOut value; 545 546 if (forWhereGet(item, out value)) 546 547 results.Add(value); 547 548 } -
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 3 class 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
395 395 396 396 * Fixed: Non removal of intermediate file if -embed-run-time/ert specified and compilation fails. ticket:181 397 397 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