I have recently heard about Cobra and was delighted that there was a language with support for nilable and non-nilable types. However, it does not perform as I expected it to: I can write code that uses only non-nilable types, does not use any casts, compiles without warnings and still throws AssertException at runtime:
- Code: Select all
class Works
var _name as String
cue init
base.init
_name = "all fine here"
get name from var
class Oops
var _name as String
get name from var
cue init
base.init
class MainClass
def main
w = Works()
s1 as String = w.name
print s1
o = Oops()
s2 as String = o.name
print s2
I would expect the above code to fail at compile-time, the reason being that the String var _name was not assigned a non-nil value after its constructor terminated.
Any comments, explanations?
Kind regards,
blubb