Ticket #117: non-nilable-coalesce.patch
File non-nilable-coalesce.patch, 3.2 KB (added by hopscc, 15 years ago) |
---|
-
Source/BinaryOpExpr.cobra
950 950 if _left.type is ptt or _right.type is ptt 951 951 # x ? y ...where either is typed as passthrough 952 952 _type = ptt 953 else if not _left.type inherits NilableType 954 .throwError('The left hand type of "?" is not nilable (it\'s "[_left.type.name]") so the expression will always evaluate to the left hand side.') 953 955 else if _left.type inherits NilableType and not _right.type inherits NilableType 954 956 # x ? y ...where x can be nil, but y cannot 955 957 _type = _left.type.nonNil # TODO: should be greatest common denominator between the two … … 999 1001 1000 1002 def _bindImp 1001 1003 base._bindImp 1002 # TODO: error check that the left hand type is nilable? 1004 if not _left.type inherits NilableType 1005 .throwError('The left hand type of "?=" is not nilable (it\'s "[_left.type.name]") so the expression will always evaluate to the left hand side.') 1003 1006 # TODO: error check that the right hand type is not nilable? 1004 1007 _type = _right.type 1005 1008 -
Tests/820-errors/200-expressions/134-non-nilable-coalesce.cobra
1 # errors on nil coalesce if lhs non-nilable 2 class Nilable 3 def main is shared 4 a = 0 5 6 b = a ? 99 # .error. The left hand type of "?" is not nilable 7 assert b == 0 8 a = 10 9 b = a ? 99 # .error. The left hand type of "?" is not nilable 10 assert b == 10 11 12 a ?= 47 # .error. The left hand type of "?=" is not nilable 13 assert b == 10 14 15 s = 'yy' 16 assert s ? 'xxx' == 'yy' # .error. The left hand type of "?" is not nilable 17 18 s ?= 'xxx' # .error. The left hand type of "?=" is not nilable 19 assert s == 'yy' 20 21 -
Tests/240-generics/200-nilables/801-qu-op.cobra
14 14 return _name ? .getType.name # used to be a bug 15 15 16 16 def foo 17 s = (Test('foo') ? Test()).name 17 t as Test? = Test('foo') 18 s = (t ? Test()).name 18 19 assert s=='foo' 20 19 21 assert (Test().nilableProperty ? 'aoeu') == 'aoeu' 22 23 # augmented assign ?= 24 t1 as Test? = Test('foo') 25 t1 ?= Test() 26 s = t1.name 27 assert s=='foo' 20 28 21 29 get nilableProperty as String? 22 30 return nil -
Developer/IntermediateReleaseNotes.text
392 392 * Fixed: Cobra gives an inscrutable error message for numeric for-loops that have incompatible numeric types. ticket:165 393 393 394 394 * Fixed: Improper codegen for static constructors. ticket:169 395 396 * Fixed: Operators ? and ?= give error if lhs expression is not nilable ticket:117