I have found some scripts where comparisons that use floats and OLECOLOR directly fail. For example:
``` If Light005.State Then ' State is a float V_R4 End If
If Light005.Colorfull Then ' Colorfull is an OLECOLOR VT_UI4 End If ```
This is because `stack_pop_bool` does not handle `VT_R4` and `VT_UI4` and returns `E_NOTIMPL`.
This adds additional types to `stack_pop_bool` similar to `VARIANT_Coerce`.
From: Jason Millard jsm174@gmail.com
--- dlls/vbscript/interp.c | 24 ++++++++++++++++++++++++ dlls/vbscript/tests/lang.vbs | 8 ++++++++ 2 files changed, 32 insertions(+)
diff --git a/dlls/vbscript/interp.c b/dlls/vbscript/interp.c index eb1dcab5f01..7b1284ebf29 100644 --- a/dlls/vbscript/interp.c +++ b/dlls/vbscript/interp.c @@ -432,12 +432,36 @@ static int stack_pop_bool(exec_ctx_t *ctx, BOOL *b) case VT_EMPTY: *b = FALSE; break; + case VT_I1: + *b = V_I1(val.v); + break; case VT_I2: *b = V_I2(val.v); break; case VT_I4: *b = V_I4(val.v); break; + case VT_UI1: + *b = V_UI1(val.v); + break; + case VT_UI2: + *b = V_UI2(val.v); + break; + case VT_UI4: + *b = V_UI4(val.v); + break; + case VT_I8: + *b = V_I8(val.v); + break; + case VT_UI8: + *b = V_UI8(val.v); + break; + case VT_R4: + *b = V_R4(val.v); + break; + case VT_R8: + *b = V_R8(val.v); + break; case VT_BSTR: hres = VarBoolFromStr(V_BSTR(val.v), ctx->script->lcid, 0, &vb); if(FAILED(hres)) diff --git a/dlls/vbscript/tests/lang.vbs b/dlls/vbscript/tests/lang.vbs index 77e132133b0..37612beac92 100644 --- a/dlls/vbscript/tests/lang.vbs +++ b/dlls/vbscript/tests/lang.vbs @@ -412,6 +412,14 @@ else end if Call ok(x = 1, "if ""0"" else not executed")
+y = 1.2 +if y then + x = true +else + x = false +end if +Call ok(x, "if y not evaluated as true") + x = 0 if "-1" then x = 1
You probably don't need all these types to be explicitly support, it's either I4 or R4, right? New test covers only float case, it should be updated for every type you add.
OLECOLOR was coming in as UI4 in my debugger.
Why wouldn't you want to cover the same cases as `VARIANT_Coerce`? Couldn't there be a getter in an IDispatch that returns the other types?
I'll add the other types, just wasn't sure how to do them in vbscript.
I see. Maybe we could simply use VariantChangeTypeEx(), I guess this was inlined for potential performance reasons. I'd wait for @jacek to comment.
I think that it should generally behave the same as `CBool()`, so yes, it would be better to use `VariantChangeTypeEx()`. For an example of tests, see existing `CBool` tests, there are some VT_DISPATCH tests. We could also use `CByte` for VT_UI1 tests.
Great. Thank you. I will rework this MR accordingly.
I submitted !3132 that changes type to VT_BOOL and removes duplication.