Skip to content

Commit

Permalink
Let safe signals work with nullable parameters.
Browse files Browse the repository at this point in the history
  • Loading branch information
hugopl committed Jun 21, 2024
1 parent 12749f5 commit 77e8207
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
5 changes: 5 additions & 0 deletions spec/safe_signal_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,9 @@ describe "Save signals" do
GC.collect
obj_ref.value.should eq(nil)
end

it "validate nilable parameters" do
Gio::SimpleAction::ActivateSignal.new(GObject::Object.new, "").validate_params(::Union(GLib::Variant, ::Nil))

end
end
7 changes: 4 additions & 3 deletions src/generator/signal_gen.cr
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,11 @@ module Generator

arg = arg_strategy.arg
arg_type_info = arg.type_info
nullmark = " | Nil" if arg.nullable?

s << to_identifier(arg.name) << " : "
s << to_crystal_type(arg_type_info, include_namespace: true) << ".class" << nullmark << ','
s << to_identifier(arg.name) << " : ("
s << to_crystal_type(arg_type_info, include_namespace: true)
s << " | Nil" if arg.nullable?
s << ").class,"
end
end
end
Expand Down

0 comments on commit 77e8207

Please sign in to comment.