Re: [Vala] Problem with switch statment



Hi Jamie,
Thanks for your response.
My function work but i have this message when building:

treeview.gs:143.9-158.13: warning: unreachable code detected
Compilation succeeded - 1 warning(s)

This is the code:

       case eb.button
           when 1
               if(selection.count_selected_rows()<=1)
                   return 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)))
                           return true
                       return true
                  return false
           when 2
               print("button 2 clicked\n")
               break
           when 3
if (((eb.state & Gdk.ModifierType.SHIFT_MASK) == Gdk.ModifierType.SHIFT_MASK) and((eb.state & Gdk.ModifierType.CONTROL_MASK) == Gdk.ModifierType.CONTROL_MASK))
                   return 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)
                    return true
       if(!(selection.count_selected_rows()>0))
           selection.select_path(path)
       return false

The warning message come from the first line in "when 3", but it work correctly.
Do you know if the problem come from my code or the genie parser ?
Because the same code in vala does not return any warnings.

Another question i need to use a GLib.List, i know under vala, it's:

GLib.List<TreePath> mylist;

But how to use it with genie ?

Thanks in advance for your response,
Nicolas.

it works the same as vala except you dont need a break statement EG
in vala :
        switch (eb.button) {
            case 1:
                do_something ();
                break;
            case 2:
                do_something ();
                break;
            case 3:
                do_something ();
                break;
        }

is same as Genie

        case eb.button
            when 1
                do_something ();
            when 2
                do_something ();
            when 3
                do_something ();



if you want to combine options just use comma

case eb.button
           when 1,2,3
                do_something ();

this is same as vala

switch (eb.button) { case 1:
            case 2:
            case 3:
                do_something ();
                break;
    }

please use latest vala master and send me code file if problem persists

jamie








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