GNOME Bugzilla – Bug 779955
Property setters not executed if new value matches current value
Last modified: 2017-03-12 21:40:42 UTC
This is a regression from bug #631267. In vala master, property setters are not executed if the new value of the property matches the current value. This is harmless if properties are just wrappers around private fields, but it breaks badly if properties try to do anything more complicated. For example, consider this property in sudoku-view.vala: public int value { get { return game.board [row, col]; } set { if (is_fixed) { string text = "%d".printf (game.board [row, col]); layout = create_pango_layout (text); layout.set_font_description (style.font_desc); if (game.mode == GameMode.PLAY) return; } if (value == 0) { string text = ""; layout = create_pango_layout (text); layout.set_font_description (style.font_desc); if (game.board [row, col] != 0) game.remove (row, col); if (game.mode == GameMode.PLAY) return; } if (value == game.board [row, col]) { string text = "%d".printf (value); layout = create_pango_layout (text); layout.set_font_description (style.font_desc); return; } game.insert (row, col, value); } } With vala 0.34.6, the generated function begins with the following (correct) code (debug #lines removed for readability): void sudoku_cell_view_set_value (SudokuCellView* self, gint value) { gboolean _tmp0_ = FALSE; gboolean _tmp1_ = FALSE; gint _tmp16_ = 0; gint _tmp34_ = 0; SudokuGame* _tmp35_ = NULL; SudokuBoard* _tmp36_ = NULL; gint _tmp37_ = 0; gint _tmp38_ = 0; gint _tmp39_ = 0; SudokuGame* _tmp48_ = NULL; gint _tmp49_ = 0; gint _tmp50_ = 0; gint _tmp51_ = 0; g_return_if_fail (self != NULL); _tmp0_ = sudoku_cell_view_get_is_fixed (self); _tmp1_ = _tmp0_; if (_tmp1_) { With 0.35.7.21-9a8b1, the generated function begins with the following (incorrect) code: void sudoku_cell_view_set_value (SudokuCellView* self, gint value) { g_return_if_fail (self != NULL); if (sudoku_cell_view_get_value (self) != value) { gboolean _tmp0_; gboolean _tmp1_; gint _tmp16_; gint _tmp34_; SudokuGame* _tmp35_; SudokuBoard* _tmp36_; gint _tmp37_; gint _tmp38_; gint _tmp39_; SudokuGame* _tmp48_; gint _tmp49_; gint _tmp50_; gint _tmp51_; _tmp0_ = sudoku_cell_view_get_is_fixed (self); _tmp1_ = _tmp0_; if (_tmp1_) { The problem is the Vala code expects the property setter to be executed always, but this no longer occurs. I think the new check at the top of the function should only be used to set some boolean that could then be used later on to decide whether to emit g_object_notify().
Created attachment 347774 [details] [review] codegen: Property equality check can't be applied to non-automatic-bodies This is check was introduced with 64b9bfc1bc0abfed45ad07a8ebaef8a5f167f848
Attachment 347774 [details] pushed as 04489bc - codegen: Property equality check can't be applied to non-automatic-bodies