[Vala] Trap for the unwary or incorrect code?



Hi gentlemen,

If I have the following code, or similar:
void main (string[] args) {
  uint ui = 2;
  int i = -3;
  if (i < ui) {
    stdout.printf("Comparison works\n");
  }
}

No output is produced.  Given Vala is generally very good at warning about
type mismatches, or correctly doing an implicit cast, I find this rather
strange.  Yes, I should not be comparing a negative value against an
unsigned value, but logically the comparison should produce the expected
output, I would have thought?  Also, I note that I can assign a value of -2
to ui without any complaint.

In general, as type inference can make the type of a variable unclear to
the casual viewer, and the declaration of a variable may be in a different
file, this permissiveness is a potential source of error, I think.

Regards,

Andrew Lees.


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]