Wiki

Ticket #163: infer-matchCollection-item.patch

File infer-matchCollection-item.patch, 2.8 KB (added by hopscc, 14 years ago)
  • Source/Boxes.cobra

     
    526526                if rt.isDescendantOf(.compiler.dictEnumeratorType) 
    527527                    return rt.memberForName('entry').resultType 
    528528                if rt.isDescendantOf(.compiler.enumeratorType) 
    529                     return rt.memberForName('current').resultType 
     529                    rtc = rt.memberForName('current').resultType 
     530                    if rtc.nonNil.name == 'Object'   
     531                        # Can we do better with indexer returnType? (e.g MatchCollection) 
     532                        idxr = .symbolForName(r'[]', true) 
     533                        if idxr 
     534                            rti = idxr.resultType 
     535                            if rti.nonNil.name <> 'Object'  
     536                                return rti  
     537                    return rtc   
    530538                else 
    531539                    throw FallThroughException({'rt': rt, 'this': this, 'getEnum': getEnum}) 
    532540        return nil 
  • Tests/300-type-inference/470-from-matchCollection.cobra

     
     1# test fix for Ticket 163 - failure infer returntype of re.matches, items of a MatchCollection 
     2use System.Text.RegularExpressions 
     3 
     4class TestReMatch 
     5 
     6    def main is shared 
     7        str = '@param folly' # some string 
     8        rePtn = r'^\s*@param\s+(.*)$' 
     9        m = Regex.match(str, rePtn)  
     10        if m.success 
     11            assert m.captures[0].value == str 
     12            #print 'Success: capture=[m.groups[1].captures[0]]' 
     13            assert m.groups[1].captures[0].value == 'folly' 
     14             
     15        str = '@param polly\n@param wally\n@param doodle alladay' # some string 
     16         
     17        expectCaptures = ['polly', 'wally', 'doodle alladay'] 
     18        groupsZero = System.Collections.ArrayList(str.split(c'\n')) 
     19 
     20        # This only used to compile if explicitly type var as below 
     21        #for match as Match in Regex.matches(str, rePtn, RegexOptions.Multiline) 
     22         
     23        for match in Regex.matches(str, rePtn, RegexOptions.Multiline) 
     24            assert match.groups[1].captures[0].value == expectCaptures[0] 
     25            gl = [groupsZero[0], expectCaptures[0]] 
     26            for g in match.groups 
     27                #print g.value 
     28                assert g.value == gl[0] # also wuz fail here 
     29                gl.removeAt(0) 
     30            groupsZero.removeAt(0) 
     31            expectCaptures.removeAt(0) 
  • Developer/IntermediateReleaseNotes.text

     
    455455* Fixed: Missing error checks for `out` and `inout` being used on an indexer or property. 
    456456 
    457457* Fixed: `someEnum is nil` causes a run-time exception. 
     458 
     459* Fixed: Failure to infer types related to System.Text.RegularExpressions (MatchColection and GroupCollections items): ticket 163