thrift-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "James E. King, III (JIRA)" <j...@apache.org>
Subject [jira] [Closed] (THRIFT-4334) Perl indentation incorrect when defaulting field attribute to a struct
Date Thu, 14 Dec 2017 13:55:25 GMT

     [ https://issues.apache.org/jira/browse/THRIFT-4334?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

James E. King, III closed THRIFT-4334.
--------------------------------------

> 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
>            Assignee: James E. King, III
>            Priority: Trivial
>             Fix For: 0.11.0
>
>
> 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)

Mime
View raw message