problem with invariant + struct
Posted: Sun Dec 14, 2008 7:09 am
The following code does not work.
I get the error (translated from Spanish): "use of possibly unassigned field __den in line 6".
This makes no sense to me, I'm not referring to __den at that line. I tried to inspect the intermediate .cs file but I cannot see the source of the problem.
Maybe invariants cannot be used in structs, but then the error message should be more informative. Besides, if I remove the constructor, the code seems to compile fine. But then I have no way to set the initialize the __den field, so the invariant exception will be thrown as soon as I try to do something with the object:
Regards,
Manuel
struct Rational
var __num as int
var __den as int
cue init(n as int, d as int) #[line 6]
__num, __den = 0, 1
invariant
__den <> 0
I get the error (translated from Spanish): "use of possibly unassigned field __den in line 6".
This makes no sense to me, I'm not referring to __den at that line. I tried to inspect the intermediate .cs file but I cannot see the source of the problem.
Maybe invariants cannot be used in structs, but then the error message should be more informative. Besides, if I remove the constructor, the code seems to compile fine. But then I have no way to set the initialize the __den field, so the invariant exception will be thrown as soon as I try to do something with the object:
struct Rational
var __num as int
var __den as int
invariant
__den <> 0
def toString as String is override
return '[__num]/[__den]'
def main is shared
r = Rational()
print r # Invariant exception!!
Regards,
Manuel