-
Notifications
You must be signed in to change notification settings - Fork 141
Incorrect treatment of java.lang.Boolean #43
Comments
You can map types as you want. It is only matter of type mappings. |
I think as I explain, that simply mapping java.lang.Boolean to bool? (even if it were possible), it would still cause a problem with the generated code because in the autounboxing positions, the bool? instance would still require accessing the Value property. As such, I think it is something that is dealt with in the code itself - although of course, I'm not an expert. But, hypothetically, if I wanted to deal with the above scenario via mappings, where would such mappings be defined (if in sharpen-all-options then there is no explicit mapping for java.lang.Boolean so I assume that this mapping is hardcoded somewere in sharpen itself)? As I'm doing some work with Sharpen at the moment, it would be good to have an informal chat away from the issues forum too. Feel free to message me. |
Yes and yes. The mapping from sharpen-all-options will override built-in mappings. So I think you can add two mappings:
|
Evaluating your boolean expression with myBool.booleanValue() can be mapped in C# simply by making sure that the final code looks something like this (I'm not sure thought, I'm thinking out loud) bool myMethod() { The only problem with this work around is that you have to not only evaluate the condition once of the nullable when invoking something() but you have to check a second time the boolean before making sure you can actually return some kind of value and be sure no code will break during the operation. |
If I have code
It is converted to:
Problem is that it converts Boolean and boolean as primitives, when the java code might depend upon a boolean being able to hold a null value.
A trivial but incorrect fix :
Obviously, this logic is complex so perhaps the answer is to require (and check) that the java code does not use the unbox feature and simply translate boolean to bool?, and within the java code and translate the booleanValue() method on Boolean to the Value property on the bool? instance.
Possible complete solution (depends upon autounboxing detection)::
The text was updated successfully, but these errors were encountered: