Re: [Vala] Problem with switch statment



Hi,

Thanks Jürg for your response.

I found a simple solution to avoid this warnings.
Rather than using a "return", I use a bool and at the end of the procedure, I return the bool.

Do you think this is a good solution?

def private on_button_press(sender : TreeView, eb : Gdk.EventButton) : bool
       column : Gtk.TreeViewColumn
       cell_x, cell_y : int
       path : Gtk.TreePath
       thereturn : bool = false
       x : int
       x = (int)eb.x
       y : int
       y = (int)eb.y
       selection : Gtk.TreeSelection = treeview.get_selection()
treeview.get_path_at_pos(x, y, out path, out column, out cell_x, out cell_y)
       if(!(selection.count_selected_rows()>0))
           selection.select_path(path)
       case eb.button
           when 1
               if(selection.count_selected_rows()<=1)
                   thereturn = false
               else
                   if selection.path_is_selected(path)
if (((eb.state & Gdk.ModifierType.SHIFT_MASK) == Gdk.ModifierType.SHIFT_MASK) and((eb.state & Gdk.ModifierType.CONTROL_MASK) == Gdk.ModifierType.CONTROL_MASK))
                           selection.unselect_path(path)
else if(!(((eb.state & Gdk.ModifierType.SHIFT_MASK) == Gdk.ModifierType.SHIFT_MASK) and ((eb.state & Gdk.ModifierType.CONTROL_MASK) == Gdk.ModifierType.CONTROL_MASK)))
                           thereturn = true
                       thereturn = true
                  thereturn = false
           when 2
               print("button 2 clicked\n")
           when 3
if (((eb.state & Gdk.ModifierType.SHIFT_MASK) == Gdk.ModifierType.SHIFT_MASK) and((eb.state & Gdk.ModifierType.CONTROL_MASK) == Gdk.ModifierType.CONTROL_MASK))
                   thereturn = false
               else
                   selectioncount : int
                   selectioncount = selection.count_selected_rows()
                   if (selectioncount<=1)
                       selection.unselect_all()
                       selection.select_path(path)
                if use_popup_menu is true
                    show_treeview_popup(eb.time)
                    thereturn = true
       return thereturn

Nicolas

I assume the reason for this is that the Genie parser just always
appends a break statement even if you have, for example, a return
statement right at the end of the block. So, from the control flow
analyzer, that inserted break statement may be unreachable.

This will need an exception in the flow analyzer for generated
statements or something like that.

Jürg








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