[
https://issues.apache.org/jira/browse/THRIFT-4334?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16178324#comment-16178324
]
ASF GitHub Bot commented on THRIFT-4334:
----------------------------------------
GitHub user bforbis opened a pull request:
https://github.com/apache/thrift/pull/1373
THRIFT-4334: Fix perl indentation for default attribute values
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/bforbis/thrift THRIFT-4334-perl-indentation
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/thrift/pull/1373.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #1373
----
commit acb7b85b1639f4c7455772c37a33b6c437d0a7cd
Author: Brian Forbis <[email protected]>
Date: 2017-09-23T05:06:08Z
THRIFT-4334: Fix perl indentation for default attribute values of array /
hashes / objects
----
> 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}
> struct Object {
> 1: map<string, string> hashWithDefault = {"foo": "bar"}
> 2: list<string> arrayWithDefault = ["foo", "bar", "baz"]
> }
> struct OtherObject {
> 1: Object objectWithDefault = {"hashWithDefault": {"baz": "bat"},
> "arrayWithDefault": ["a", "b", "c"]}
> 2: string primitiveStringType
> }
> {code}
> Object constructor: _This uses improper indentation when specifying the hash
> keys to use in the initialization of hashWithDefault and arrayWithDefault,
> but the indentation is returned to the correct level afterwards_
> {code}
> package Object;
> use base qw(Class::Accessor);
> Object->mk_accessors( qw( hashWithDefault arrayWithDefault ) );
> sub new {
> my $classname = shift;
> my $self = {};
> my $vals = shift || {};
> $self->{hashWithDefault} = {
> "foo" => "bar",
> };
> $self->{arrayWithDefault} = [
> "foo",
> "bar",
> "baz",
> ];
> if (UNIVERSAL::isa($vals,'HASH')) {
> if (defined $vals->{hashWithDefault}) {
> $self->{hashWithDefault} = $vals->{hashWithDefault};
> }
> if (defined $vals->{arrayWithDefault}) {
> $self->{arrayWithDefault} = $vals->{arrayWithDefault};
> }
> }
> return bless ($self, $classname);
> }
> {code}
> OtherObject constructor: _This uses improper indentation when specifying the
> hash keys to use in the initialization of Object, but the indentation is NOT
> returned to the correct level afterwards_
> {code}
> package OtherObject;
> use base qw(Class::Accessor);
> OtherObject->mk_accessors( qw( objectWithDefault primitiveStringType ) );
> sub new {
> my $classname = shift;
> my $self = {};
> my $vals = shift || {};
> $self->{objectWithDefault} = undef;
> $self->{primitiveStringType} = undef;
> $self->{objectWithDefault} = new Object({
> "hashWithDefault" => {
> "baz" => "bat",
> },
> "arrayWithDefault" => [
> "a",
> "b",
> "c",
> ],
> });
> if (UNIVERSAL::isa($vals,'HASH')) {
> if (defined $vals->{objectWithDefault}) {
> $self->{objectWithDefault} = $vals->{objectWithDefault};
> }
> if (defined $vals->{primitiveStringType}) {
> $self->{primitiveStringType} = $vals->{primitiveStringType};
> }
> }
> 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)