[iagno] Compile with --experimental-non-null.



commit d51d43cca7c1b84ed3df60d157330f6376007c6d
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Thu Feb 7 04:34:36 2019 +0100

    Compile with --experimental-non-null.

 src/computer-player.vala | 33 +++++++++++-------
 src/game-view.vala       | 68 +++++++++++++++++++++++--------------
 src/game-window.vala     | 45 +++++++++++++++----------
 src/game.vala            | 14 +++++---
 src/iagno.vala           | 87 +++++++++++++++++++++++++++++++-----------------
 src/meson.build          |  3 +-
 src/themes-dialog.vala   | 24 +++++++++----
 7 files changed, 176 insertions(+), 98 deletions(-)
---
diff --git a/src/computer-player.vala b/src/computer-player.vala
index 8d8cc06..5a3a4b0 100644
--- a/src/computer-player.vala
+++ b/src/computer-player.vala
@@ -194,11 +194,14 @@ public class ComputerPlayer : Object
         get_possible_moves_sorted (g, ref moves);
 
         /* Try each move using alpha-beta pruning to optimise finding the best branch */
-        foreach (var move in moves)
+        foreach (PossibleMove? move in moves)
         {
-            if (g.place_tile (move.x, move.y, true) == 0)
+            if (move == null)
+                assert_not_reached ();
+
+            if (g.place_tile (((!) move).x, ((!) move).y, true) == 0)
             {
-                critical ("Computer marked move (depth %d, %d,%d, %d flips) as valid, but is invalid when 
checking.\n%s", depth, move.x, move.y, move.n_tiles, g.to_string ());
+                critical ("Computer marked move (depth %d, %d,%d, %d flips) as valid, but is invalid when 
checking.\n%s", depth, ((!) move).x, ((!) move).y, ((!) move).n_tiles, g.to_string ());
                 assert_not_reached ();
             }
 
@@ -206,8 +209,8 @@ public class ComputerPlayer : Object
             if (a_new > a)
             {
                 a = a_new;
-                x = move.x;
-                y = move.y;
+                x = ((!) move).x;
+                y = ((!) move).y;
             }
 
             g.undo ();
@@ -236,11 +239,14 @@ public class ComputerPlayer : Object
             get_possible_moves_sorted (g, ref moves);
 
             /* Try each move using alpha-beta pruning to optimise finding the best branch */
-            foreach (var move in moves)
+            foreach (PossibleMove? move in moves)
             {
-                if (g.place_tile (move.x, move.y) == 0)
+                if (move == null)
+                    assert_not_reached ();
+
+                if (g.place_tile (((!) move).x, ((!) move).y) == 0)
                 {
-                    critical ("Computer marked move (depth %d, %d,%d, %d flips) as valid, but is invalid 
when checking.\n%s", depth, move.x, move.y, move.n_tiles, g.to_string ());
+                    critical ("Computer marked move (depth %d, %d,%d, %d flips) as valid, but is invalid 
when checking.\n%s", depth, ((!) move).x, ((!) move).y, ((!) move).n_tiles, g.to_string ());
                     assert_not_reached ();
                 }
 
@@ -287,7 +293,9 @@ public class ComputerPlayer : Object
 
     private static int compare_move (PossibleMove? a, PossibleMove? b)
     {
-        return b.n_tiles - a.n_tiles;
+        if (a == null || b == null)
+            assert_not_reached ();
+        return ((!) b).n_tiles - ((!) a).n_tiles;
     }
 
     /*\
@@ -372,16 +380,17 @@ public class ComputerPlayer : Object
 
     private static void random_select (Game g, out int move_x, out int move_y)
     {
-        List<int> moves = null;
+        List<int> moves = new List<int> ();
         for (var x = 0; x < g.size; x++)
             for (var y = 0; y < g.size; y++)
                 if (g.can_place (x, y, g.current_color))
                     moves.append (x * g.size + y);
 
-        if (moves == null)
+        int length = (int) moves.length ();
+        if (length == 0)
             assert_not_reached ();
 
-        var i = Random.int_range (0, (int) moves.length ());
+        var i = Random.int_range (0, length);
         var xy = moves.nth_data (i);
         move_x = xy / g.size;
         move_y = xy % g.size;
diff --git a/src/game-view.vala b/src/game-view.vala
index f0fbd47..3ec3aec 100644
--- a/src/game-view.vala
+++ b/src/game-view.vala
@@ -99,23 +99,31 @@ public class GameView : Gtk.DrawingArea
     /* Used for a delay between the last move and flipping the pieces */
     private bool flip_final_result_now = false;
 
-    private Game? _game = null;
-    public Game? game
+    private bool game_is_set = false;
+    private Game _game;
+    public Game game
     {
-        get { return _game; }
+        get
+        {
+            if (!game_is_set)
+                assert_not_reached ();
+            return _game;
+        }
         set
         {
-            if (_game != null)
+            Game? test = value;
+            if (test == null)
+                assert_not_reached ();
+
+            if (game_is_set)
                 SignalHandler.disconnect_by_func (_game, null, this);
             _game = value;
-            pixmaps = new int[game.size,game.size];
-            if (_game != null)
-            {
-                _game.square_changed.connect (square_changed_cb);
-                for (int x = 0; x < game.size; x++)
-                    for (int y = 0; y < game.size; y++)
-                        pixmaps[x, y] = get_pixmap (_game.get_owner (x, y));
-            }
+            game_is_set = true;
+            pixmaps = new int [_game.size, _game.size];
+            for (int x = 0; x < _game.size; x++)
+                for (int y = 0; y < _game.size; y++)
+                    pixmaps[x, y] = get_pixmap (_game.get_owner (x, y));
+            _game.square_changed.connect (square_changed_cb);
 
             show_highlight = false;
             highlight_x = 3;    // TODO default on 3 3 / 4 4 (on 8×8 board) when dark and
@@ -132,13 +140,13 @@ public class GameView : Gtk.DrawingArea
         get { return _theme; }
         set {
             var key = new KeyFile ();
-            if (value == "default")
+            if (value == null || (!) value == "default")
                 set_default_theme (ref key);
             else
                 try
                 {
                     string key_path = Path.build_filename (DATA_DIRECTORY, "themes", "key");
-                    string filepath = Path.build_filename (key_path, value);
+                    string filepath = Path.build_filename (key_path, (!) value);
                     if (Path.get_dirname (filepath) != key_path)
                         throw new FileError.FAILED ("Theme file is not in the \"key\" directory.");
 
@@ -164,12 +172,12 @@ public class GameView : Gtk.DrawingArea
 
     private void set_default_theme (ref KeyFile key)
     {
-        var defaults = Gtk.Settings.get_default ();
+        Gtk.Settings? defaults = Gtk.Settings.get_default ();
 
         string filename;
-        if ("HighContrast" in defaults.gtk_theme_name)
+        if (defaults != null && "HighContrast" in ((!) defaults).gtk_theme_name)
             filename = "high_contrast.theme";
-        else if (defaults.gtk_application_prefer_dark_theme == true)
+        else if (defaults != null && ((!) defaults).gtk_application_prefer_dark_theme == true)
             filename = "adwaita.theme";
         else
             filename = "classic.theme";
@@ -234,6 +242,7 @@ public class GameView : Gtk.DrawingArea
     }
 
     private void calculate ()
+        requires (game_is_set)
     {
         int size = int.min (get_allocated_width (), get_allocated_height ());
         paving_size = (size - 2 * border_width + spacing_width) / game.size;
@@ -244,7 +253,7 @@ public class GameView : Gtk.DrawingArea
 
     public override bool draw (Cairo.Context cr)
     {
-        if (game == null)
+        if (!game_is_set)
             return false;
 
         calculate ();
@@ -312,8 +321,8 @@ public class GameView : Gtk.DrawingArea
 
                 var matrix = Cairo.Matrix.identity ();
                 matrix.translate (texture_x - tile_x, texture_y - tile_y);
-                tiles_pattern.set_matrix (matrix);
-                cr.set_source (tiles_pattern);
+                ((!) tiles_pattern).set_matrix (matrix);
+                cr.set_source ((!) tiles_pattern);
                 cr.rectangle (tile_x, tile_y, tile_size, tile_size);
                 cr.fill ();
             }
@@ -386,6 +395,7 @@ public class GameView : Gtk.DrawingArea
     }
 
     private void update_square (int x, int y)
+        requires (game_is_set)
     {
         int pixmap = get_pixmap (game.get_owner (x, y));
 
@@ -454,6 +464,7 @@ public class GameView : Gtk.DrawingArea
     }
 
     private bool animate_cb ()
+        requires (game_is_set)
     {
         bool animating = false;
 
@@ -493,6 +504,9 @@ public class GameView : Gtk.DrawingArea
 
     public override bool button_press_event (Gdk.EventButton event)
     {
+        if (!game_is_set)
+            return false;
+
         if (event.button == Gdk.BUTTON_PRIMARY || event.button == Gdk.BUTTON_SECONDARY)
         {
             int x = (int) (event.x - board_x) / paving_size;
@@ -512,7 +526,10 @@ public class GameView : Gtk.DrawingArea
 
     public override bool key_press_event (Gdk.EventKey event)
     {
-        string key = Gdk.keyval_name (event.keyval);
+        if (!game_is_set)
+            return false;
+
+        string key = (!) (Gdk.keyval_name (event.keyval) ?? "");
 
         if (show_highlight && (key == "space" || key == "Return" || key == "KP_Enter"))
         {
@@ -646,15 +663,15 @@ public class GameView : Gtk.DrawingArea
 
             /* draw dark piece */
             matrix.translate (height / 2.0, 0);
-            scoreboard_tiles_pattern.set_matrix (matrix);
-            cr.set_source (scoreboard_tiles_pattern);
+            ((!) scoreboard_tiles_pattern).set_matrix (matrix);
+            cr.set_source ((!) scoreboard_tiles_pattern);
             cr.rectangle (0, 0, height / 2.0, height / 2.0);
             cr.fill ();
 
             /* draw white piece */
             matrix.translate (3 * height, height);
-            scoreboard_tiles_pattern.set_matrix (matrix);
-            cr.set_source (scoreboard_tiles_pattern);
+            ((!) scoreboard_tiles_pattern).set_matrix (matrix);
+            cr.set_source ((!) scoreboard_tiles_pattern);
             cr.rectangle (0, height / 2.0, height / 2.0, height / 2.0);
             cr.fill ();
         // }
@@ -679,6 +696,7 @@ public class GameView : Gtk.DrawingArea
     }
 
     public void update_scoreboard ()
+        requires (game_is_set)
     {
         current_player_number = (game.current_color == Player.DARK) ? 0 : 1;
         scoreboard.queue_draw ();  // TODO queue_draw_area (…), or only refresh part of the DrawingArea, or 
both
diff --git a/src/game-window.vala b/src/game-window.vala
index 5703c77..36d461f 100644
--- a/src/game-window.vala
+++ b/src/game-window.vala
@@ -95,8 +95,10 @@ public class GameWindow : ApplicationWindow
         if (css_resource != null)
         {
             CssProvider css_provider = new CssProvider ();
-            css_provider.load_from_resource (css_resource);
-            StyleContext.add_provider_for_screen (Gdk.Screen.get_default (), css_provider, 
STYLE_PROVIDER_PRIORITY_APPLICATION);
+            css_provider.load_from_resource ((!) css_resource);
+            Gdk.Screen? gdk_screen = Gdk.Screen.get_default ();
+            if (gdk_screen != null) // else..?
+                StyleContext.add_provider_for_screen ((!) gdk_screen, css_provider, 
STYLE_PROVIDER_PRIORITY_APPLICATION);
         }
 
         view = _view;
@@ -128,16 +130,17 @@ public class GameWindow : ApplicationWindow
         if (GameWindowFlags.SHOW_START_BUTTON in flags)
         {
             /* Translators: when configuring a new game, label of the blue Start button (with a mnemonic 
that appears pressing Alt) */
-            start_game_button = new Button.with_mnemonic (_("_Start Game"));
-            start_game_button.width_request = 222;
-            start_game_button.height_request = 60;
-            start_game_button.halign = Align.CENTER;
-            start_game_button.set_action_name ("win.start-game");
+            Button _start_game_button = new Button.with_mnemonic (_("_Start Game"));
+            _start_game_button.width_request = 222;
+            _start_game_button.height_request = 60;
+            _start_game_button.halign = Align.CENTER;
+            _start_game_button.set_action_name ("win.start-game");
             /* Translators: when configuring a new game, tooltip text of the blue Start button */
-            // start_game_button.set_tooltip_text (_("Start a new game as configured"));
-            ((StyleContext) start_game_button.get_style_context ()).add_class ("suggested-action");
-            start_game_button.show ();
-            new_game_box.pack_end (start_game_button, false, false, 0);
+            // _start_game_button.set_tooltip_text (_("Start a new game as configured"));
+            ((StyleContext) _start_game_button.get_style_context ()).add_class ("suggested-action");
+            _start_game_button.show ();
+            new_game_box.pack_end (_start_game_button, false, false, 0);
+            start_game_button = _start_game_button;
         }
 
         game_box.pack_start (view, true, true, 0);
@@ -266,7 +269,7 @@ public class GameWindow : ApplicationWindow
         if (!game_finished && back_button.visible)
             back_button.grab_focus ();
         else if (start_game_button != null)
-            start_game_button.grab_focus ();
+            ((!) start_game_button).grab_focus ();
     }
 
     private void show_view ()
@@ -287,7 +290,8 @@ public class GameWindow : ApplicationWindow
 
     private void new_game_cb ()
     {
-        if (stack.get_visible_child_name () != "frame")
+        string? stack_child = stack.get_visible_child_name ();
+        if (stack_child == null || (!) stack_child != "frame")
             return;
 
         wait ();
@@ -303,7 +307,8 @@ public class GameWindow : ApplicationWindow
 
     private void start_game_cb ()
     {
-        if (stack.get_visible_child_name () != "start-box")
+        string? stack_child = stack.get_visible_child_name ();
+        if (stack_child == null || (!) stack_child != "start-box")
             return;
 
         game_finished = false;
@@ -320,7 +325,8 @@ public class GameWindow : ApplicationWindow
 
     private void back_cb ()
     {
-        if (stack.get_visible_child_name () != "start-box")
+        string? stack_child = stack.get_visible_child_name ();
+        if (stack_child == null || (!) stack_child != "start-box")
             return;
         // TODO change back headerbar subtitle?
         stack.set_transition_type (StackTransitionType.SLIDE_RIGHT);
@@ -336,7 +342,8 @@ public class GameWindow : ApplicationWindow
 
     private void undo_cb ()
     {
-        if (stack.get_visible_child_name () != "frame")
+        string? stack_child = stack.get_visible_child_name ();
+        if (stack_child == null || (!) stack_child != "frame")
             return;
 
         game_finished = false;
@@ -349,7 +356,8 @@ public class GameWindow : ApplicationWindow
 
     private void redo_cb ()
     {
-        if (stack.get_visible_child_name () != "frame")
+        string? stack_child = stack.get_visible_child_name ();
+        if (stack_child == null || (!) stack_child != "frame")
             return;
 
         if (new_game_button.is_focus)
@@ -360,7 +368,8 @@ public class GameWindow : ApplicationWindow
 
     private void hint_cb ()
     {
-        if (stack.get_visible_child_name () != "frame")
+        string? stack_child = stack.get_visible_child_name ();
+        if (stack_child == null || (!) stack_child != "frame")
             return;
         hint ();
     }
diff --git a/src/game.vala b/src/game.vala
index 0a4d235..4ffbaea 100644
--- a/src/game.vala
+++ b/src/game.vala
@@ -359,14 +359,20 @@ public class Game : Object
         history_index--;
 
         /* if not pass */
-        if (undo_stack[history_index] != null)
+        int? undo_item = undo_stack [history_index];
+        if (undo_item != null)
         {
             /* last log entry is the placed tile, previous are flipped tiles */
-            unset_tile (undo_stack[history_index], Player.NONE);
-            while (history_index > -1 && undo_stack[history_index] != null)
+            unset_tile ((!) undo_item, Player.NONE);
+            undo_item = undo_stack [history_index];
+            while (history_index > -1 && undo_item != null)
             {
                 n_opponent_tiles++;
-                unset_tile (undo_stack[history_index], enemy);
+                unset_tile ((!) undo_item, enemy);
+                if (history_index > -1)
+                    undo_item = undo_stack [history_index];
+                else
+                    undo_item = null;
             }
         }
 
diff --git a/src/iagno.vala b/src/iagno.vala
index 77b56d1..358234b 100644
--- a/src/iagno.vala
+++ b/src/iagno.vala
@@ -45,6 +45,8 @@ public class Iagno : Gtk.Application
     private GameView view;
     private Label dark_score_label;
     private Label light_score_label;
+
+    private bool should_init_themes_dialog = true;
     private ThemesDialog themes_dialog;
 
     /* Computer player (if there is one) */
@@ -54,9 +56,10 @@ public class Iagno : Gtk.Application
     private Player player_one;
 
     /* The game being played */
-    private Game? game = null;
+    private Game game;
+    private bool game_is_set = false;
 
-    private const OptionEntry[] option_entries =
+    private const OptionEntry [] option_entries =
     {
         /* Translators: command-line option description, see 'iagno --help' */
         { "alternative-start", 0, 0, OptionArg.NONE, ref alternative_start, N_("Start with an alternative 
position"), null},
@@ -87,10 +90,10 @@ public class Iagno : Gtk.Application
 
         /* Translators: command-line option description, see 'iagno --help' */
         { "version", 'v', 0, OptionArg.NONE, null,                          N_("Print release version and 
exit"), null},
-        { null }
+        {}
     };
 
-    private const GLib.ActionEntry app_actions[] =
+    private const GLib.ActionEntry app_actions [] =
     {
         {"theme", theme_cb},
         {"help", help_cb},
@@ -98,7 +101,7 @@ public class Iagno : Gtk.Application
         {"quit", quit}
     };
 
-    public static int main (string[] args)
+    public static int main (string [] args)
     {
         Intl.setlocale (LocaleCategory.ALL, "");
         Intl.bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
@@ -158,28 +161,37 @@ public class Iagno : Gtk.Application
         settings = new GLib.Settings ("org.gnome.Reversi");
 
         if (sound != null)
-            settings.set_boolean ("sound", sound);
+            settings.set_boolean ("sound", (!) sound);
 
         bool start_now = (two_players == true) || (play_first != null);
         if (start_now)
             settings.set_int ("num-players", two_players ? 2 : 1);
 
         if (play_first != null)
-            settings.set_string ("color", play_first ? "dark" : "light");
+            settings.set_string ("color", ((!) play_first) ? "dark" : "light");
 
         // TODO start one-player game immediately, if two_players == false
-        if (level == "1" || level == "2" || level == "3")   // TODO add a localized text option?
-            settings.set_int ("computer-level", int.parse (level));
-        else if (level == "one")    /*  || level == "easy" */
-            settings.set_int ("computer-level", 1);
-        else if (level == "two")    /*  || level == "medium" */
-            settings.set_int ("computer-level", 2);
-        else if (level == "three")  /*  || level == "hard" */
-            settings.set_int ("computer-level", 3);
-        else if (level != null)
-            /* Translators: command-line error message, displayed for an incorrect level request; try 'iagno 
-l 5' */
-            stderr.printf ("%s\n", _("Level should be between 1 (easy) and 3 (hard). Settings unchanged."));
-        //  stderr.printf ("%s\n", _("Level should be 1 (easy), 2 (medium) or 3 (hard). Settings 
unchanged."));     // TODO better?
+        if (level != null)
+        {
+            // TODO add a localized text option?
+            switch ((!) level)
+            {
+                case "1":
+                case "one":     settings.set_int ("computer-level", 1); break;  // TODO "easy"
+
+                case "2":
+                case "two":     settings.set_int ("computer-level", 2); break;  // TODO "medium"
+
+                case "3":
+                case "three":   settings.set_int ("computer-level", 3); break;  // TODO "hard"
+
+                default:
+                    /* Translators: command-line error message, displayed for an incorrect level request; 
try 'iagno -l 5' */
+                    stderr.printf ("%s\n", _("Level should be between 1 (easy) and 3 (hard). Settings 
unchanged."));
+                //  stderr.printf ("%s\n", _("Level should be 1 (easy), 2 (medium) or 3 (hard). Settings 
unchanged.")); // TODO better?
+                    break;
+            }
+        }
 
         /* UI parts */
         Builder builder = new Builder.from_resource ("/org/gnome/Reversi/ui/iagno-screens.ui");
@@ -228,7 +240,7 @@ public class Iagno : Gtk.Application
 
         Box level_box = (Box) builder.get_object ("difficulty-box");
         Box color_box = (Box) builder.get_object ("color-box");
-        settings.changed["num-players"].connect (() => {
+        settings.changed ["num-players"].connect (() => {
             bool solo = settings.get_int ("num-players") == 1;
             level_box.sensitive = solo;
             color_box.sensitive = solo;
@@ -265,10 +277,11 @@ public class Iagno : Gtk.Application
     private void theme_cb ()
     {
         /* Don’t permit to open more than one dialog */
-        if (themes_dialog == null)
+        if (should_init_themes_dialog)
         {
             themes_dialog = new ThemesDialog (settings, view);
             themes_dialog.set_transient_for (window);
+            should_init_themes_dialog = false;
         }
         themes_dialog.present ();
     }
@@ -287,8 +300,8 @@ public class Iagno : Gtk.Application
 
     private void about_cb ()
     {
-        string[] authors = { "Ian Peters", "Robert Ancell", null };
-        string[] documenters = { "Tiffany Antopolski", null };
+        string [] authors = { "Ian Peters", "Robert Ancell" };
+        string [] documenters = { "Tiffany Antopolski" };
 
         show_about_dialog (window,
                            "name", PROGRAM_NAME,
@@ -315,9 +328,10 @@ public class Iagno : Gtk.Application
     \*/
 
     private void back_cb ()
+        requires (game_is_set)
     {
         if (game.current_color != player_one && computer != null && !game.is_complete)
-            computer.move_async.begin (SLOW_MOVE_DELAY);
+            ((!) computer).move_async.begin (SLOW_MOVE_DELAY);
         else if (game.is_complete)
             game_complete (false);
     }
@@ -325,18 +339,19 @@ public class Iagno : Gtk.Application
     private void wait_cb ()
     {
         if (computer != null)
-            computer.cancel_move ();
+            ((!) computer).cancel_move ();
     }
 
     private void start_game ()
     {
-        if (game != null)
+        if (game_is_set)
             SignalHandler.disconnect_by_func (game, null, this);
 
         if (computer != null)
-            computer.cancel_move ();
+            ((!) computer).cancel_move ();
 
         game = new Game (alternative_start, size);
+        game_is_set = true;
         game.turn_ended.connect (turn_ended_cb);
         view.game = game;
 
@@ -353,10 +368,11 @@ public class Iagno : Gtk.Application
         update_ui ();
 
         if (player_one != Player.DARK && computer != null)
-            computer.move_async.begin (MODERATE_MOVE_DELAY);     // TODO MODERATE_MOVE_DELAY = 1.0, but 
after the sliding animation…
+            ((!) computer).move_async.begin (MODERATE_MOVE_DELAY);     // TODO MODERATE_MOVE_DELAY = 1.0, 
but after the sliding animation…
     }
 
     private void update_ui ()
+        requires (game_is_set)
     {
         window.set_subtitle (null);
 
@@ -371,6 +387,7 @@ public class Iagno : Gtk.Application
     }
 
     private void undo_cb ()
+        requires (game_is_set)
     {
         if (computer == null)
         {
@@ -380,7 +397,7 @@ public class Iagno : Gtk.Application
         }
         else
         {
-            computer.cancel_move ();
+            ((!) computer).cancel_move ();
 
             /* Undo once if the human player just moved, otherwise undo both moves */
             if (game.current_color != player_one)
@@ -399,6 +416,7 @@ public class Iagno : Gtk.Application
     }
 
     private void turn_ended_cb ()
+        requires (game_is_set)
     {
         update_ui ();
         if (game.current_player_can_move)
@@ -410,6 +428,7 @@ public class Iagno : Gtk.Application
     }
 
     private void prepare_move ()
+        requires (game_is_set)
     {
         /* for the move that just ended */
         play_sound (Sound.FLIP);
@@ -421,10 +440,11 @@ public class Iagno : Gtk.Application
          * but not so long as to become boring.
          */
         if (game.current_color != player_one && computer != null)
-            computer.move_async.begin (fast_mode ? QUICK_MOVE_DELAY : SLOW_MOVE_DELAY);
+            ((!) computer).move_async.begin (fast_mode ? QUICK_MOVE_DELAY : SLOW_MOVE_DELAY);
     }
 
     private void pass ()
+        requires (game_is_set)
     {
         /* for the move that just ended */
         play_sound (Sound.FLIP);
@@ -444,6 +464,7 @@ public class Iagno : Gtk.Application
     }
 
     private void game_complete (bool play_gameover_sound = true)
+        requires (game_is_set)
     {
         window.finish_game ();
 
@@ -468,6 +489,7 @@ public class Iagno : Gtk.Application
     }
 
     private void player_move_cb (int x, int y)
+        requires (game_is_set)
     {
         /* Ignore if we are waiting for the AI to move or if game is finished */
         if ((game.current_color != player_one && computer != null) || !game.current_player_can_move)
@@ -512,6 +534,9 @@ public class Iagno : Gtk.Application
                                              Canberra.PROP_MEDIA_NAME, name,
                                              Canberra.PROP_MEDIA_FILENAME, path);
         if (r != 0)
-            warning ("Error playing %s: %s", path, Canberra.strerror (r));
+        {
+            string? error = Canberra.strerror (r);
+            warning ("Error playing %s: %s", path, error ?? "unknown error");
+        }
     }
 }
diff --git a/src/meson.build b/src/meson.build
index 8504a51..3632757 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -29,7 +29,8 @@ executable(meson.project_name(),
     ],
     vala_args: [
         '--target-glib', '2.44',
-        '--vapidir', join_paths(meson.current_source_dir(), 'vapi')
+        '--vapidir', join_paths(meson.current_source_dir(), 'vapi'),
+        '--enable-experimental-non-null'
     ],
     dependencies: [
         canberra_dependency,
diff --git a/src/themes-dialog.vala b/src/themes-dialog.vala
index 4e318c0..cec14e4 100644
--- a/src/themes-dialog.vala
+++ b/src/themes-dialog.vala
@@ -32,7 +32,13 @@ public class ThemesDialog : Dialog
 
     public ThemesDialog (GLib.Settings settings, GameView view)
     {
-        Object (use_header_bar: Gtk.Settings.get_default ().gtk_dialogs_use_header ? 1 : 0);
+        Gtk.Settings? gtk_settings = Gtk.Settings.get_default ();
+        int use_header_bar;
+        if (gtk_settings != null && !((!) gtk_settings).gtk_dialogs_use_header)
+            use_header_bar = 0;
+        else
+            use_header_bar = 1;
+        Object (use_header_bar: use_header_bar);
         this.view = view;
         delete_event.connect (do_not_close);
 
@@ -43,11 +49,11 @@ public class ThemesDialog : Dialog
             dir = Dir.open (Path.build_filename (DATA_DIRECTORY, "themes", "key"));
             while (true)
             {
-                string filename = dir.read_name ();
+                string? filename = dir.read_name ();
                 if (filename == null)
                     break;
 
-                string path = Path.build_filename (DATA_DIRECTORY, "themes", "key", filename);
+                string path = Path.build_filename (DATA_DIRECTORY, "themes", "key", (!) filename);
                 var key = new GLib.KeyFile ();
                 string name;
                 try
@@ -73,7 +79,7 @@ public class ThemesDialog : Dialog
                 var lbl = new Label (name);
                 lbl.visible = true;
                 lbl.xalign = 0;
-                var data = new Label (filename);
+                var data = new Label ((!) filename);
                 data.visible = false;
 
                 box.add (img);
@@ -82,14 +88,18 @@ public class ThemesDialog : Dialog
                 row.add (box);
                 listbox.add (row);
 
-                if (filename == settings.get_string ("theme"))
+                if ((!) filename == settings.get_string ("theme"))
                     listbox.select_row (row);
             }
             // FIXME bug on <ctrl>double-click
             listbox.row_selected.connect ((row) => {
-                    view.theme = ((Label) (((Box) row.get_child ()).get_children ().nth_data (2))).label;
+                    if (row == null)
+                        return; // assert_not_reached?
+
+                    string view_theme = ((Label) (((Box) ((!) row).get_child ()).get_children ().nth_data 
(2))).label;
+                    view.theme = view_theme;
                     // TODO BETTER view.theme may have fall back to "default"
-                    settings.set_string ("theme", view.theme);
+                    settings.set_string ("theme", view_theme);
                     queue_draw ();      // try to redraw because there’re sometimes bugs
                 });
         }


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