beanshell / beanshell

Beanshell scripting language
Apache License 2.0
815 stars 183 forks source link

Unary operator on boxed types doesn't seem to be working #762

Open nickl- opened 1 month ago

nickl- commented 1 month ago

We get an evaluation error trying to use unary operators on boxed type objects.

BeanShell 3.0.0-SNAPSHOT.5569
bsh % Integer i = new Integer(0);
--> $0 = 0I :Integer
bsh % ++i;
// Error: Evaluation Error: Unary operation "++" inappropriate for object : at Line: 2 : in file: <unknown file> : ;

bsh % --i;
// Error: Evaluation Error: Unary operation "--" inappropriate for object : at Line: 3 : in file: <unknown file> : ;

Which is possible in JAVA.

|  Welcome to JShell -- Version 11.0.22
|  For an introduction type: /help intro
jshell> Integer i = new Integer(0);
i ==> 0
jshell> --i;
$2 ==> -1
jshell> ++i;
$3 ==> 0