From b879ccdc3e63a1b55dab90ea843f34563fe6988b Mon Sep 17 00:00:00 2001 From: Zackery Spytz Date: Fri, 18 Jan 2019 23:42:59 -0700 Subject: [PATCH] [OCaml] Fix the handling of bools in overloaded functions Use the SWIG_TYPECHECK_BOOL precedence level instead of SWIG_TYPECHECK_INTEGER when checking for bools. Add a runtime test in the form of overload_bool_runme.ml. --- Examples/test-suite/ocaml/overload_bool_runme.ml | 15 +++++++++++++++ Lib/ocaml/typecheck.i | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 Examples/test-suite/ocaml/overload_bool_runme.ml diff --git a/Examples/test-suite/ocaml/overload_bool_runme.ml b/Examples/test-suite/ocaml/overload_bool_runme.ml new file mode 100644 index 000000000..ce0ce9e40 --- /dev/null +++ b/Examples/test-suite/ocaml/overload_bool_runme.ml @@ -0,0 +1,15 @@ +open Swig +open Overload_bool + +let _ = + assert (_overloaded '(true) as string = "bool"); + assert (_overloaded '(false) as string = "bool"); + assert (_overloaded '(0) as string = "int"); + assert (_overloaded '(1) as string = "int"); + assert (_overloaded '(2) as string = "int"); + assert (_overloaded '("1234") as string = "string"); + assert (_boolfunction '(true) as string = "true"); + assert (_boolfunction '(false) as string = "false"); + assert (_intfunction '(true) as string = "int"); + assert (_intfunction '(false) as string = "int"); +;; diff --git a/Lib/ocaml/typecheck.i b/Lib/ocaml/typecheck.i index a13e1552e..9d95e2717 100644 --- a/Lib/ocaml/typecheck.i +++ b/Lib/ocaml/typecheck.i @@ -78,7 +78,7 @@ } } -%typecheck(SWIG_TYPECHECK_INTEGER) bool, oc_bool, BOOL, const bool &, const oc_bool &, const BOOL & { +%typecheck(SWIG_TYPECHECK_BOOL) bool, oc_bool, const bool &, const oc_bool & { if( !Is_block($input) ) $1 = 0; else { switch( SWIG_Tag_val($input) ) {