[Vala] throw not checking throw type correctly



Alright, I know this is invalid code, but it compiles with warnings, and
seg faults when run. The problem is that the vala compiler did not
identify the invalid code and call it an error.


---< start error.vala >---
using GLib;
int main (string[] args)
{
  try
  {
    stdout.printf("Ok, got here\n");
    throw 1;
    stdout.printf("Ok, but not here\n");
  }
  catch (Error ex)
  {
    stdout.printf("Ex: %s\n",ex.message);
  }
  return 0;
}
---< end error.vala >---

$ valac error.vala 
error.vala:11.5-11.40: warning: unreachable code detected
    stdout.printf("Ok, but not here\n");
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error.c: In function ‘_main’:
error.c:21: warning: assignment makes pointer from integer without a
cast
Compilation succeeded - 1 warning(s)

$ ./error 
Ok, got here
Segmentation fault

$ valac --version
Vala 0.5.2


looking at the C output it is obvious why it is segfaulting.

---< start clip >---
  GError* _tmp0;
  fprintf (stdout, "Ok, got here\n");
  _tmp0 = NULL;
  inner_error = (_tmp0 = 1, (_tmp0 == NULL ? ((gpointer) (_tmp0)) : g_error_copy (_tmp0)));
---< end clip >---


the C compiler warned about the bogus _tmp0 = 1.

Should not valac have considered "throw 1;" an error?

~Dwight





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