diff --git a/compiler/defcmp.pas b/compiler/defcmp.pas index b2a6269524..021e5ec1fe 100644 --- a/compiler/defcmp.pas +++ b/compiler/defcmp.pas @@ -1289,7 +1289,7 @@ implementation here } eq:=te_convert_l3; end - { java.lang.string -> unicodestring } + { unicodestring -> java.lang.string } else if (def_to=java_jlstring) and (is_wide_or_unicode_string(def_from) or (fromtreetype=stringconstn)) then @@ -1300,6 +1300,12 @@ implementation else eq:=te_convert_l2; end + else if (def_to=java_jlstring) and + is_anychar(def_from) then + begin + doconv:=tc_char_2_string; + eq:=te_convert_l2 + end else { specific to implicit pointer object types } if is_implicit_pointer_object_type(def_to) then diff --git a/compiler/jvm/njvmcnv.pas b/compiler/jvm/njvmcnv.pas index 8e85355896..3406242a5f 100644 --- a/compiler/jvm/njvmcnv.pas +++ b/compiler/jvm/njvmcnv.pas @@ -32,6 +32,7 @@ interface tjvmtypeconvnode = class(tcgtypeconvnode) function typecheck_dynarray_to_openarray: tnode; override; function typecheck_string_to_chararray: tnode; override; + function typecheck_char_to_string: tnode; override; function pass_1: tnode; override; function simplify(forinline: boolean): tnode; override; @@ -169,6 +170,21 @@ implementation end; + function tjvmtypeconvnode.typecheck_char_to_string: tnode; + begin + { make sure the generic code gets a stringdef } + if self.totypedef=java_jlstring then + begin + inserttypeconv(left,cunicodestringtype); + inserttypeconv(left,totypedef); + result:=left; + left:=nil; + exit; + end; + result:=inherited; + end; + + {***************************************************************************** FirstTypeConv *****************************************************************************} @@ -205,8 +221,9 @@ implementation exit; { string constants passed to java.lang.String must be converted to widestring } - if (left.nodetype=stringconstn) and - not(tstringconstnode(left).cst_type in [cst_unicodestring,cst_widestring]) and + if ((is_conststringnode(left) and + not(tstringconstnode(left).cst_type in [cst_unicodestring,cst_widestring])) or + is_constcharnode(left)) and (maybe_find_real_class_definition(resultdef,false)=java_jlstring) then inserttypeconv(left,cunicodestringtype); end;