Wiki

Ticket #317: tkt-317-nilableArrayItems.patch

File tkt-317-nilableArrayItems.patch, 1.3 KB (added by hopscc, 11 years ago)
  • Source/CobraParser.cobra

     
    36043604        assert t 
    36053605 
    36063606        # TODO: the array and nilable check should probably be at the bottom of qualifiedType 
    3607  
     3607         
     3608        # Chk for nilable Type (for array element) e.g. TYPE?,   TYPE?[] 
     3609        if .optional('QUESTION') 
     3610            t = NilableTypeIdentifier(.last, t) 
     3611         
    36083612        # check for array 
    36093613        bracket = .optional('LBRACKET') 
    36103614        if bracket 
  • Tests/110-basics-two/800-arrays/300-nilable-array-item.cobra

     
     1# test array with nilable items - (semi-silent parse failure) 
     2# tkt 317  as float32?[] - array of nilable float32 
     3 
     4class NilArr 
     5    def main is shared 
     6        tNF as float32?[] = @[10.2f32, nil] 
     7        tNF = float32?[](10)    # expression works   
     8        tNF[0]= 32.1f32 
     9        tNF[2]=1.012f32 
     10        print tNF 
     11        .x(tNF) 
     12         
     13    def x(a as float32?[] ) is shared    
     14        print 'In x', a 
     15        assert a[0] == 32.1f32 
     16        assert a[2] == 1.012f32 
     17        assert a[1] == nil 
     18        assert a[9] == nil