[ 
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}
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.

  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}
> 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)

Reply via email to