Wiki

Ticket #4: assert-assign.patch

File assert-assign.patch, 4.5 KB (added by hopscc, 16 years ago)
  • Source/Compiler.cobra

     
    11411141    def warning(cw as CobraWarning) 
    11421142        require not cw.isError 
    11431143        _addMessage(cw) 
    1144  
     1144         
     1145    def augmentWarning(node as ISyntaxNode, lookFor as String, srch as String, augment as String) as bool 
     1146        require  
     1147            lookFor.length 
     1148            augment.length 
     1149        body 
     1150            return _augmentWarning(CobraWarning(node.token, lookFor), srch, augment) 
     1151         
    11451152    shared 
    11461153        var _unknownSuggestions = { 
    11471154        # literals 
     
    12071214            _errors.add(message) 
    12081215        else 
    12091216            _warnings.add(message) 
    1210  
     1217             
     1218    def _augmentWarning(message as SourceException, srch as String, augment as String) as bool 
     1219        key = if(message.hasSourceSite, '[message.fileName]:[message.lineNum]', '') 
     1220        if not _messagesPerSourceLine.containsKey(key) 
     1221            return false 
     1222             
     1223        lowerToMatch = message.message.toLower 
     1224        lowerSrch = if(srch.length > 0, srch.toLower, '') 
     1225        for se in _messagesPerSourceLine[key] 
     1226            lowerMsg = se.message.toLower 
     1227            if lowerMsg.contains(lowerToMatch)   # matched 
     1228                if srch.length == 0 or lowerMsg.contains(lowerSrch) 
     1229                    se.augmentMessage(augment) 
     1230                    return true 
     1231        return false 
     1232             
    12111233    ## 
    12121234    ## Generating and compiling C# 
    12131235    ## 
  • Source/Node.cobra

     
    5454        else 
    5555            return '[type]: ' + .message 
    5656 
     57    def augmentMessage(augment as String) 
     58        _message = _message + augment 
     59         
    5760    def toString as String is override 
    5861        return '[.getType.name]: [.consoleString]' 
    5962 
  • Source/CobraParser.cobra

     
    4040 
    4141    def warning(we as CobraWarning) 
    4242 
    43  
    4443interface IErrorRecorder 
    4544 
    4645    def recordError(error as SourceException) 
     
    17751774    def assertStmt as Stmt 
    17761775        token = .expect('ASSERT') 
    17771776        expr = .expression 
     1777        if expr inherits AbstractAssignExpr  # ++ [Inverse]CoalesceAssign expr? 
     1778            .throwError("Assert condition is an assignment. Since asserts may be suppressed these conditions should not have side effects. Perhaps you meant to do a comparison '==' instead of assignment '='") 
    17781779        info = if(.optional('COMMA'), .expression, nil) 
    17791780        return AssertStmt(token, expr, info) 
    17801781 
     1782 
    17811783    def branchStmt as Stmt 
    17821784        token = .expect('BRANCH') 
    17831785        e = .expression 
  • Source/Statements.cobra

     
    188188    def _bindImp 
    189189        base._bindImp 
    190190        _expr.bindImp 
     191        # Augment any warning about non nilable expr evaluate to true 
     192        .compiler.augmentWarning(this, "always evaluate to true because it is not nilable", _ 
     193            'You can remove the expression', _ 
     194            "This assertion is always true. You can remove the assertion or correct the condition") 
    191195        if _info 
    192196            _info.bindImp 
    193197 
  • Tests/820-errors/300-statements/400-assert-assign.cobra

     
     1# .error. assert condition is an assignment 
     2class Test 
     3 
     4    def main 
     5        is shared 
     6         
     7        a = 23+1 
     8        assert a=24  
  • Tests/800-warnings/400-assert-true.cobra

     
     1class AssertTrue 
     2 
     3    def main is shared 
     4        a= 'MyString' 
     5        assert a   #.warning. This assertion is always true 
  • Developer/IntermediateReleaseNotes.text

     
    3535* Fixed: Cannot implement a method whose signature is matched by an extension method of a base class. 
    3636 
    3737* Fixed: Method return types from generics in DLLs are always considered nilable even if the generic parameter was not (such as `bool`). 
     38 
     39*Fixed: Disallow assignment in an assert: ticket4 (hopscc)