[
https://issues.apache.org/jira/browse/THRIFT-4334?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Brian Forbis updated THRIFT-4334:
---------------------------------
Description:
Improper indentation is used when defaulting an attribute in a struct to
another struct or hash:
See the following example thrift
{code}
namespace perl ThriftTest
struct Header {
1: map<string, string> foobar = {"foo": "bar"}
}
struct Struct {
1: Header header = {"foobar": {"baz": "bat"}}
2: string foo
}
{code}
Header constructor: _This uses improper indentation when specifying the hash
keys to use in the initialization of foobar, but the indentation is returned to
the correct level afterwards_
{code}
package ThriftTest::Header;
use base qw(Class::Accessor);
ThriftTest::Header->mk_accessors( qw( foobar ) );
sub new {
my $classname = shift;
my $self = {};
my $vals = shift || {};
$self->{foobar} = {
"foo" => "bar",
};
if (UNIVERSAL::isa($vals,'HASH')) {
if (defined $vals->{foobar}) {
$self->{foobar} = $vals->{foobar};
}
}
return bless ($self, $classname);
}
{code}
Struct constructor: _This uses improper indentation when specifying the hash
keys to use in the initialization of ThriftTest::Header, but the indentation is
NOT returned to the correct level afterwards_
{code}
package ThriftTest::Struct;
use base qw(Class::Accessor);
ThriftTest::Struct->mk_accessors( qw( header foo ) );
sub new {
my $classname = shift;
my $self = {};
my $vals = shift || {};
$self->{header} = undef;
$self->{foo} = undef;
$self->{header} = new ThriftTest::Header({
"foobar" => {
"baz" => "bat",
},
});
if (UNIVERSAL::isa($vals,'HASH')) {
if (defined $vals->{header}) {
$self->{header} = $vals->{header};
}
if (defined $vals->{foo}) {
$self->{foo} = $vals->{foo};
}
}
return bless ($self, $classname);
}
{code}
Since this indentation bug is additive, every struct in the file that default
instantiates a struct in its constructor will offset the indentation to the
right by one level.
The cause of this bug looks to be in *t_perl_generator::render_const_value()*,
which does not *indent()* the keys set in the sub-object constructors. It also
does not set *indent_down()* at the end of instantiating the object.
was:
Improper indentation is used when defaulting an attribute in a struct to
another struct or hash:
See the following example thrift
{code}
namespace perl ThriftTest
struct Header {
1: map<string, string> foobar = {"foo": "bar"}
}
struct Struct {
1: Header header = {"foobar": {"baz": "bat"}}
2: string foo
}
{code}
Header constructor: _This uses improper indentation when specifying the hash
keys to use in the initialization of foobar, but the indentation is returned to
the correct level afterwards_
{code}
package ThriftTest::Header;
use base qw(Class::Accessor);
ThriftTest::Header->mk_accessors( qw( foobar ) );
sub new {
my $classname = shift;
my $self = {};
my $vals = shift || {};
$self->{foobar} = {
"foo" => "bar",
};
if (UNIVERSAL::isa($vals,'HASH')) {
if (defined $vals->{foobar}) {
$self->{foobar} = $vals->{foobar};
}
}
return bless ($self, $classname);
}
{code}
Struct constructor: _This uses improper indentation when specifying the hash
keys to use in the initialization of ThriftTest::Header, but the indentation is
NOT returned to the correct level afterwards_
{code}
package ThriftTest::Struct;
use base qw(Class::Accessor);
ThriftTest::Struct->mk_accessors( qw( header foo ) );
sub new {
my $classname = shift;
my $self = {};
my $vals = shift || {};
$self->{header} = undef;
$self->{foo} = undef;
$self->{header} = new ThriftTest::Header({
"foobar" => {
"baz" => "bat",
},
});
if (UNIVERSAL::isa($vals,'HASH')) {
if (defined $vals->{header}) {
$self->{header} = $vals->{header};
}
if (defined $vals->{foo}) {
$self->{foo} = $vals->{foo};
}
}
return bless ($self, $classname);
}
{code}
Since this indentation bug is additive, every struct in the file that default
instantiates a struct in its constructor will offset the indentation to the
right by one level.
The cause of this bug looks to be in *t_perl_generator::render_const_value()*,
which does not indent the keys set in the sub-object constructors. It also does
not set indent_down() at the end of instantiating the object.
> Perl indentation incorrect when defaulting field attribute to a struct
> ----------------------------------------------------------------------
>
> Key: THRIFT-4334
> URL: https://issues.apache.org/jira/browse/THRIFT-4334
> Project: Thrift
> Issue Type: Bug
> Components: Perl - Compiler
> Affects Versions: 0.10.0
> Reporter: Brian Forbis
> Priority: Trivial
>
> Improper indentation is used when defaulting an attribute in a struct to
> another struct or hash:
> See the following example thrift
> {code}
> namespace perl ThriftTest
> struct Header {
> 1: map<string, string> foobar = {"foo": "bar"}
> }
> struct Struct {
> 1: Header header = {"foobar": {"baz": "bat"}}
> 2: string foo
> }
> {code}
> Header constructor: _This uses improper indentation when specifying the hash
> keys to use in the initialization of foobar, but the indentation is returned
> to the correct level afterwards_
> {code}
> package ThriftTest::Header;
> use base qw(Class::Accessor);
> ThriftTest::Header->mk_accessors( qw( foobar ) );
> sub new {
> my $classname = shift;
> my $self = {};
> my $vals = shift || {};
> $self->{foobar} = {
> "foo" => "bar",
> };
> if (UNIVERSAL::isa($vals,'HASH')) {
> if (defined $vals->{foobar}) {
> $self->{foobar} = $vals->{foobar};
> }
> }
> return bless ($self, $classname);
> }
> {code}
> Struct constructor: _This uses improper indentation when specifying the hash
> keys to use in the initialization of ThriftTest::Header, but the indentation
> is NOT returned to the correct level afterwards_
> {code}
> package ThriftTest::Struct;
> use base qw(Class::Accessor);
> ThriftTest::Struct->mk_accessors( qw( header foo ) );
> sub new {
> my $classname = shift;
> my $self = {};
> my $vals = shift || {};
> $self->{header} = undef;
> $self->{foo} = undef;
> $self->{header} = new ThriftTest::Header({
> "foobar" => {
> "baz" => "bat",
> },
> });
> if (UNIVERSAL::isa($vals,'HASH')) {
> if (defined $vals->{header}) {
> $self->{header} = $vals->{header};
> }
> if (defined $vals->{foo}) {
> $self->{foo} = $vals->{foo};
> }
> }
> return bless ($self, $classname);
> }
> {code}
> Since this indentation bug is additive, every struct in the file that default
> instantiates a struct in its constructor will offset the indentation to the
> right by one level.
> The cause of this bug looks to be in
> *t_perl_generator::render_const_value()*, which does not *indent()* the keys
> set in the sub-object constructors. It also does not set *indent_down()* at
> the end of instantiating the object.
--
This message was sent by Atlassian JIRA
(v6.4.14#64029)