Skip to content

Commit

Permalink
THRIFT-5826 binary constants create uncompilable Delphi code
Browse files Browse the repository at this point in the history
Client: Delphi
Patch: Jens Geyer
  • Loading branch information
Jens-G committed Oct 20, 2024
1 parent ca2ea95 commit 4d0addf
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
21 changes: 16 additions & 5 deletions compiler/cpp/src/thrift/generate/t_delphi_generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1237,7 +1237,14 @@ bool t_delphi_generator::const_needs_var(t_type* type) {
}

t_base_type::t_base tbase = ((t_base_type*)truetype)->get_base();
return (tbase == t_base_type::TYPE_UUID);
switch (tbase) {
case t_base_type::TYPE_UUID:
return true;
case t_base_type::TYPE_STRING:
return truetype->is_binary();
default:
return false;
}
}

void t_delphi_generator::print_const_prop(std::ostream& out,
Expand Down Expand Up @@ -1267,9 +1274,9 @@ void t_delphi_generator::print_const_value(std::ostream& vars,

if (truetype->is_base_type()) {
t_base_type::t_base tbase = ((t_base_type*)truetype)->get_base();
if(tbase == t_base_type::TYPE_UUID) { // already done otherwise
string v2 = render_const_value( vars, out, name, type, value, false);
indent_impl(out) << name << " := " << v2 << ";" << '\n';
if(const_needs_var(type)) {
string the_value = render_const_value( vars, out, name, type, value, false);
indent_impl(out) << name << " := " << the_value << ";" << '\n';
}
} else if (truetype->is_enum()) {
indent_impl(out) << name << " := " << type_name(type) << "." << value->get_identifier_name()
Expand Down Expand Up @@ -1321,7 +1328,11 @@ string t_delphi_generator::render_const_value(ostream& vars,
t_base_type::t_base tbase = ((t_base_type*)truetype)->get_base();
switch (tbase) {
case t_base_type::TYPE_STRING:
render << "'" << get_escaped_string(value) << "'";
if (truetype->is_binary()) {
render << "TEncoding.UTF8.GetBytes('" << get_escaped_string(value) << "')";
} else {
render << "'" << get_escaped_string(value) << "'";
}
break;
case t_base_type::TYPE_UUID:
if(guidAsLiteral) {
Expand Down
17 changes: 8 additions & 9 deletions lib/delphi/test/codegen/run-Pascal-Codegen-Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,16 @@ $FAIL_THRIFT = @(
"Include.thrift") # subdir includes don't work here

# expected to fail at Delphi Compiler
$FAIL_DELPHI = @()
$FAIL_DELPHI = @(
"Thrift5320.thrift" # this conflicts with Delphi scopes, but it's a bad practice testcase anyway
)

# unexpected but known bugs (TODO: fix them)
$KNOWN_BUGS = @( "ConstOptionalField.thrift"
, "IgnoreInitialismsTest.thrift"
, "JavaTypes.thrift"
, "JavaDefinitionOrderB.thrift"
, "JavaDeepCopyTest.thrift"
, "NameConflictTest.thrift"
, "Thrift5320.thrift" # this conflicts with Delphi scopes, but it's a bad practice testcase anyway
)
$KNOWN_BUGS = @(
"IgnoreInitialismsTest.thrift",
"JavaDefinitionOrderB.thrift",
"NameConflictTest.thrift"
)



Expand Down

0 comments on commit 4d0addf

Please sign in to comment.