CommandHelper

CommandHelper

46.5k Downloads

[Feature/bug] String variables can be used as integers if they are integers, but doubles can't.

LadyCailinBot opened this issue ยท 3 comments

commented

CMDHELPER-3103 - Reported by Pieter12345

@A = '2'; @A + 3; <-- works.
@A = '2.1'; @A + 3; <-- CastException: Expecting an integer, but received "2.1" instead.

Since integers are auto-casted, I think doubles should be too.

Note that this works: @A = '2.1'; double(@A) + 3;

commented

Comment by PseudoKnight

Just to note, @A = '2.1'; @A + 3.0; works fine because it detects a double and treats all values as doubles.

commented

Comment by PseudoKnight

This could be fixed if we changed ArgumentValidation.anyDoubles() from

if(c1 instanceof CDouble) {

to

if(c1 instanceof CDouble || c1 instanceof CString && c1.val().indexOf(".", 1) > -1) {

This won't affect any existing Java or mscript that I can think of, and it would allow arguments passed in by alias to be considered doubles even when they weren't casted -- more forgiving. I think this is appropriate since we're in ArgumentValidation here, which is usually used for this sort of thing. indexOf() is used here instead of full double evaluation since it's going to throw an exception later anyway if it's invalid. It would add small amount of overhead when not adding CDoubles. There might be something I haven't thought of, but I think this might be worth doing.

commented

Comment by LadyCailin

Fixed.