Summary: Impossible to run a struct invariant using assert(s)
           Product: D
           Version: 1.041
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD

--- Comment #0 from Leandro Lucarella <> 2009-12-05 08:24:54 
PST ---
This fails to compile (with -unittest):

struct S {
    invariant() { assert (false); }
    unittest { S s; assert (s); }

With this error message:
  inv.d(3): Error: expression s of type S does not have a boolean value

With both DMD 1 and 2 (tested with DMD 1.041 and DMD 2.037. Changing struct to
class compiles fine (and dumps a core if you run it, of course ;).

Thes specs are not clear on this in both D1 and D2. Invariant is only mentioned
in structs, but I guess it's more likely to think that the description of class
invariant apply to structs too, so I guess this should be supported in both D1
and D2.

If it's a change to big to make it in D1, I think the specs should be updated
to clarify the differences between struct and class invariants. In D2 I don't
see why the language should not be updated to support this, since there is no
other way to trigger an invariant check (and, for example, invariant is not
executed when a struct is constructed or when using alias this, I think).

Configure issuemail:
------- You are receiving this mail because: -------

Reply via email to