Ticket #4: assert-assign.patch
File assert-assign.patch, 4.5 KB (added by hopscc, 16 years ago) |
---|
-
Source/Compiler.cobra
1141 1141 def warning(cw as CobraWarning) 1142 1142 require not cw.isError 1143 1143 _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 1145 1152 shared 1146 1153 var _unknownSuggestions = { 1147 1154 # literals … … 1207 1214 _errors.add(message) 1208 1215 else 1209 1216 _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 1211 1233 ## 1212 1234 ## Generating and compiling C# 1213 1235 ## -
Source/Node.cobra
54 54 else 55 55 return '[type]: ' + .message 56 56 57 def augmentMessage(augment as String) 58 _message = _message + augment 59 57 60 def toString as String is override 58 61 return '[.getType.name]: [.consoleString]' 59 62 -
Source/CobraParser.cobra
40 40 41 41 def warning(we as CobraWarning) 42 42 43 44 43 interface IErrorRecorder 45 44 46 45 def recordError(error as SourceException) … … 1775 1774 def assertStmt as Stmt 1776 1775 token = .expect('ASSERT') 1777 1776 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 '='") 1778 1779 info = if(.optional('COMMA'), .expression, nil) 1779 1780 return AssertStmt(token, expr, info) 1780 1781 1782 1781 1783 def branchStmt as Stmt 1782 1784 token = .expect('BRANCH') 1783 1785 e = .expression -
Source/Statements.cobra
188 188 def _bindImp 189 189 base._bindImp 190 190 _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") 191 195 if _info 192 196 _info.bindImp 193 197 -
Tests/820-errors/300-statements/400-assert-assign.cobra
1 # .error. assert condition is an assignment 2 class Test 3 4 def main 5 is shared 6 7 a = 23+1 8 assert a=24 -
Tests/800-warnings/400-assert-true.cobra
1 class AssertTrue 2 3 def main is shared 4 a= 'MyString' 5 assert a #.warning. This assertion is always true -
Developer/IntermediateReleaseNotes.text
35 35 * Fixed: Cannot implement a method whose signature is matched by an extension method of a base class. 36 36 37 37 * 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)