You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@thrift.apache.org by "Björn Bylander (Created JIRA)" <ji...@apache.org> on 2012/03/02 14:12:58 UTC

[jira] [Created] (THRIFT-1532) The type specifications in the generated Erlang code should include "undefined" where it's used as a default value

The type specifications in the generated Erlang code should include "undefined" where it's used as a default value
------------------------------------------------------------------------------------------------------------------

                 Key: THRIFT-1532
                 URL: https://issues.apache.org/jira/browse/THRIFT-1532
             Project: Thrift
          Issue Type: Improvement
          Components: Erlang - Compiler
    Affects Versions: 0.8
         Environment: Erlang/OTP R15B.
            Reporter: Björn Bylander
            Priority: Minor


The Erlang code generated by the compiler for, for example, an integer field of a struct sets a default value of 'undefined' but the type to just 'integer()' which doesn't include the default value. This makes Dialyzer complain if the field has not been initialized as it gets set to 'undefined' instead of an integer value.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

Re: [jira] [Commented] (THRIFT-1532) The type specifications in the generated Erlang code should include "undefined" where it's used as a default value

Posted by Marty Weiner <ma...@pinterest.com>.
unsubscribe

On Thu, Mar 22, 2012 at 1:42 AM, Hudson (Commented) (JIRA)
<ji...@apache.org>wrote:

>
>    [
> https://issues.apache.org/jira/browse/THRIFT-1532?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13235452#comment-13235452]
>
> Hudson commented on THRIFT-1532:
> --------------------------------
>
> Integrated in Thrift #428 (See [https://builds.apache.org/job/Thrift/428/
> ])
>    THRIFT-1532 - slightly better fix, take into account requiredness when
> adding default values (Revision 1303666)
>
>     Result = SUCCESS
> molinaro : http://svn.apache.org/viewvc/?view=rev&rev=1303666
> Files :
> * /thrift/trunk/compiler/cpp/src/generate/t_erl_generator.cc
> * /thrift/trunk/lib/erl/test/Thrift1475.thrift
>
>
> > The type specifications in the generated Erlang code should include
> "undefined" where it's used as a default value
> >
> ------------------------------------------------------------------------------------------------------------------
> >
> >                 Key: THRIFT-1532
> >                 URL: https://issues.apache.org/jira/browse/THRIFT-1532
> >             Project: Thrift
> >          Issue Type: Improvement
> >          Components: Erlang - Compiler
> >    Affects Versions: 0.8
> >         Environment: Erlang/OTP R15B.
> >            Reporter: Björn Bylander
> >            Assignee: Anthony Molinaro
> >            Priority: Minor
> >              Labels: compiler, dialyzer, erlang, specification, type
> >             Fix For: 0.9
> >
> >         Attachments: THRIFT-1532_t_erl_generator.cc.patch, agent.tar.gz
> >
> >   Original Estimate: 1h
> >  Remaining Estimate: 1h
> >
> > The Erlang code generated by the compiler for, for example, an integer
> field of a struct sets a default value of 'undefined' but the type to just
> 'integer()' which doesn't include the default value. This makes Dialyzer
> complain if the field has not been initialized as it gets set to
> 'undefined' instead of an integer value.
>
> --
> This message is automatically generated by JIRA.
> If you think it was sent incorrectly, please contact your JIRA
> administrators:
> https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
> For more information on JIRA, see: http://www.atlassian.com/software/jira
>
>
>

[jira] [Commented] (THRIFT-1532) The type specifications in the generated Erlang code should include "undefined" where it's used as a default value

Posted by "Anthony Molinaro (Commented) (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/THRIFT-1532?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13223500#comment-13223500 ] 

Anthony Molinaro commented on THRIFT-1532:
------------------------------------------

Actually see http://www.erlang.org/doc/reference_manual/typespec.html#id75102 undefined is automatically added to type declarations, so I think your error is something else.  Having a breaking test case is probably the best way for me to move forward, so if you have one please include it.
                
> The type specifications in the generated Erlang code should include "undefined" where it's used as a default value
> ------------------------------------------------------------------------------------------------------------------
>
>                 Key: THRIFT-1532
>                 URL: https://issues.apache.org/jira/browse/THRIFT-1532
>             Project: Thrift
>          Issue Type: Improvement
>          Components: Erlang - Compiler
>    Affects Versions: 0.8
>         Environment: Erlang/OTP R15B.
>            Reporter: Björn Bylander
>            Assignee: Anthony Molinaro
>            Priority: Minor
>              Labels: compiler, dialyzer, erlang, specification, type
>         Attachments: THRIFT-1532_type_allows_undefined.patch
>
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> The Erlang code generated by the compiler for, for example, an integer field of a struct sets a default value of 'undefined' but the type to just 'integer()' which doesn't include the default value. This makes Dialyzer complain if the field has not been initialized as it gets set to 'undefined' instead of an integer value.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

[jira] [Commented] (THRIFT-1532) The type specifications in the generated Erlang code should include "undefined" where it's used as a default value

Posted by "Björn Bylander (Commented JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/THRIFT-1532?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13223591#comment-13223591 ] 

Björn Bylander commented on THRIFT-1532:
----------------------------------------

I've added agent.tar.gz. Unpack and then compile using "rebar compile". "dialyzer ebin" outputs the following:

agent_service.erl:34: Function 'GetSomeStruct'/0 has no local return
agent_service.erl:35: Record construction #someStruct{id::42} violates the declared type of field anI32::integer()
Unknown functions:
thrift_server:start_link/3
thrift_server:stop/1
done in 0m0.61s
done (warnings were emitted)


Removing the undefined default value from the "anI32" field in agent_types.hrl removes the Dialyzer error.

                
> The type specifications in the generated Erlang code should include "undefined" where it's used as a default value
> ------------------------------------------------------------------------------------------------------------------
>
>                 Key: THRIFT-1532
>                 URL: https://issues.apache.org/jira/browse/THRIFT-1532
>             Project: Thrift
>          Issue Type: Improvement
>          Components: Erlang - Compiler
>    Affects Versions: 0.8
>         Environment: Erlang/OTP R15B.
>            Reporter: Björn Bylander
>            Assignee: Anthony Molinaro
>            Priority: Minor
>              Labels: compiler, dialyzer, erlang, specification, type
>         Attachments: THRIFT-1532_type_allows_undefined.patch, agent.tar.gz
>
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> The Erlang code generated by the compiler for, for example, an integer field of a struct sets a default value of 'undefined' but the type to just 'integer()' which doesn't include the default value. This makes Dialyzer complain if the field has not been initialized as it gets set to 'undefined' instead of an integer value.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

[jira] [Updated] (THRIFT-1532) The type specifications in the generated Erlang code should include "undefined" where it's used as a default value

Posted by "Björn Bylander (Updated JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/THRIFT-1532?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Björn Bylander updated THRIFT-1532:
-----------------------------------

    Comment: was deleted

(was: Unpack and then compile using "rebar compile". "dialyzer ebin" outputs the following:

agent_service.erl:34: Function 'GetSomeStruct'/0 has no local return
agent_service.erl:35: Record construction #someStruct{id::42} violates the declared type of field anI32::integer()
Unknown functions:
  thrift_server:start_link/3
  thrift_server:stop/1
 done in 0m0.61s
done (warnings were emitted)
)
    
> The type specifications in the generated Erlang code should include "undefined" where it's used as a default value
> ------------------------------------------------------------------------------------------------------------------
>
>                 Key: THRIFT-1532
>                 URL: https://issues.apache.org/jira/browse/THRIFT-1532
>             Project: Thrift
>          Issue Type: Improvement
>          Components: Erlang - Compiler
>    Affects Versions: 0.8
>         Environment: Erlang/OTP R15B.
>            Reporter: Björn Bylander
>            Assignee: Anthony Molinaro
>            Priority: Minor
>              Labels: compiler, dialyzer, erlang, specification, type
>         Attachments: THRIFT-1532_type_allows_undefined.patch, agent.tar.gz
>
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> The Erlang code generated by the compiler for, for example, an integer field of a struct sets a default value of 'undefined' but the type to just 'integer()' which doesn't include the default value. This makes Dialyzer complain if the field has not been initialized as it gets set to 'undefined' instead of an integer value.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

[jira] [Commented] (THRIFT-1532) The type specifications in the generated Erlang code should include "undefined" where it's used as a default value

Posted by "Anthony Molinaro (Commented) (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/THRIFT-1532?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13222483#comment-13222483 ] 

Anthony Molinaro commented on THRIFT-1532:
------------------------------------------

So I can't quite get dialyzer to cause errors on a generated file, do you happen to have a small .thrift file and test code which will fail.

Also, I have a feeling that the real fix it to get rid of '= undefined' in the struct definition.  You only need '=' when you have a default value and should leave off 'undefined'.
                
> The type specifications in the generated Erlang code should include "undefined" where it's used as a default value
> ------------------------------------------------------------------------------------------------------------------
>
>                 Key: THRIFT-1532
>                 URL: https://issues.apache.org/jira/browse/THRIFT-1532
>             Project: Thrift
>          Issue Type: Improvement
>          Components: Erlang - Compiler
>    Affects Versions: 0.8
>         Environment: Erlang/OTP R15B.
>            Reporter: Björn Bylander
>            Priority: Minor
>              Labels: compiler, dialyzer, erlang, specification, type
>         Attachments: THRIFT-1532_type_allows_undefined.patch
>
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> The Erlang code generated by the compiler for, for example, an integer field of a struct sets a default value of 'undefined' but the type to just 'integer()' which doesn't include the default value. This makes Dialyzer complain if the field has not been initialized as it gets set to 'undefined' instead of an integer value.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

[jira] [Commented] (THRIFT-1532) The type specifications in the generated Erlang code should include "undefined" where it's used as a default value

Posted by "Anthony Molinaro (Commented) (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/THRIFT-1532?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13235404#comment-13235404 ] 

Anthony Molinaro commented on THRIFT-1532:
------------------------------------------

Actually, made one more minor adjustment which I believe makes it even more correct.  Instead of having any complex type (ie, set, list, map, record), require a default value, I only add the defaults if it's a required field (as it should be perfectly correct to have an undefined optional or default field).

So this makes my example
{code}
struct StructB
{
  1: string x
}

struct StructA
{
  1: string a,
  2: binary b,
  3: optional string c,
  4: optional binary d,
  5: required string e,
  6: required binary f,
  7: string g = "foo",
  8: i32 h,
  9: optional i32 i,
  10: required i32 j,
  11: required i32 k = 5,
  12: double l,
  13: optional double m,
  14: required double n,
  15: double o = 3.14159,
  16: list<string> string_list,
  17: list<byte> byte_list = [1, 2, 3],
  18: required list<string> rsl,
  19: optional list<string> osl,
  20: set<string> string_set,
  21: required set<string> rss,
  22: optional set<string> oss,
  23: map<string, string> string_map,
  24: required map<string, string> rsm,
  25: optional map<string, string> osm,
  26: StructB structb
}
{code}
Now generate this
{code}
%% struct structB

-record(structB, {x :: string() | binary()}).

%% struct structA

-record(structA, {a :: string() | binary(),
                  b :: string() | binary(),
                  c :: string() | binary(),
                  d :: string() | binary(),
                  e :: string() | binary(),
                  f :: string() | binary(),
                  g = "foo" :: string() | binary(),
                  h :: integer(),
                  i :: integer(),
                  j :: integer(),
                  k = 5 :: integer(),
                  l :: float(),
                  m :: float(),
                  n :: float(),
                  o = 3.14159 :: float(),
                  string_list :: list(),
                  byte_list = [1,2,3] :: list(),
                  rsl = [] :: list(),
                  osl :: list(),
                  string_set :: set(),
                  rss = sets:new() :: set(),
                  oss :: set(),
                  string_map :: dict(),
                  rsm = dict:new() :: dict(),
                  osm :: dict(),
                  structb :: #structB{}}).
{code}

Please try it out and let me know how it goes.

                
> The type specifications in the generated Erlang code should include "undefined" where it's used as a default value
> ------------------------------------------------------------------------------------------------------------------
>
>                 Key: THRIFT-1532
>                 URL: https://issues.apache.org/jira/browse/THRIFT-1532
>             Project: Thrift
>          Issue Type: Improvement
>          Components: Erlang - Compiler
>    Affects Versions: 0.8
>         Environment: Erlang/OTP R15B.
>            Reporter: Björn Bylander
>            Assignee: Anthony Molinaro
>            Priority: Minor
>              Labels: compiler, dialyzer, erlang, specification, type
>             Fix For: 0.9
>
>         Attachments: THRIFT-1532_t_erl_generator.cc.patch, agent.tar.gz
>
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> The Erlang code generated by the compiler for, for example, an integer field of a struct sets a default value of 'undefined' but the type to just 'integer()' which doesn't include the default value. This makes Dialyzer complain if the field has not been initialized as it gets set to 'undefined' instead of an integer value.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

[jira] [Commented] (THRIFT-1532) The type specifications in the generated Erlang code should include "undefined" where it's used as a default value

Posted by "Hudson (Commented) (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/THRIFT-1532?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13235410#comment-13235410 ] 

Hudson commented on THRIFT-1532:
--------------------------------

Integrated in Thrift #426 (See [https://builds.apache.org/job/Thrift/426/])
    THRIFT-1532/THRIFT-1475 - fix record generation for erlang (Revision 1303663)

     Result = SUCCESS
molinaro : http://svn.apache.org/viewvc/?view=rev&rev=1303663
Files : 
* /thrift/trunk/compiler/cpp/src/generate/t_erl_generator.cc
* /thrift/trunk/lib/erl/Makefile.am
* /thrift/trunk/lib/erl/test/Thrift1475.thrift

                
> The type specifications in the generated Erlang code should include "undefined" where it's used as a default value
> ------------------------------------------------------------------------------------------------------------------
>
>                 Key: THRIFT-1532
>                 URL: https://issues.apache.org/jira/browse/THRIFT-1532
>             Project: Thrift
>          Issue Type: Improvement
>          Components: Erlang - Compiler
>    Affects Versions: 0.8
>         Environment: Erlang/OTP R15B.
>            Reporter: Björn Bylander
>            Assignee: Anthony Molinaro
>            Priority: Minor
>              Labels: compiler, dialyzer, erlang, specification, type
>             Fix For: 0.9
>
>         Attachments: THRIFT-1532_t_erl_generator.cc.patch, agent.tar.gz
>
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> The Erlang code generated by the compiler for, for example, an integer field of a struct sets a default value of 'undefined' but the type to just 'integer()' which doesn't include the default value. This makes Dialyzer complain if the field has not been initialized as it gets set to 'undefined' instead of an integer value.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

[jira] [Commented] (THRIFT-1532) The type specifications in the generated Erlang code should include "undefined" where it's used as a default value

Posted by "Björn Bylander (Commented JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/THRIFT-1532?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13235472#comment-13235472 ] 

Björn Bylander commented on THRIFT-1532:
----------------------------------------

Thanks, your solutions works fine for me, I think it's a good solution.
                
> The type specifications in the generated Erlang code should include "undefined" where it's used as a default value
> ------------------------------------------------------------------------------------------------------------------
>
>                 Key: THRIFT-1532
>                 URL: https://issues.apache.org/jira/browse/THRIFT-1532
>             Project: Thrift
>          Issue Type: Improvement
>          Components: Erlang - Compiler
>    Affects Versions: 0.8
>         Environment: Erlang/OTP R15B.
>            Reporter: Björn Bylander
>            Assignee: Anthony Molinaro
>            Priority: Minor
>              Labels: compiler, dialyzer, erlang, specification, type
>             Fix For: 0.9
>
>         Attachments: THRIFT-1532_t_erl_generator.cc.patch, agent.tar.gz
>
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> The Erlang code generated by the compiler for, for example, an integer field of a struct sets a default value of 'undefined' but the type to just 'integer()' which doesn't include the default value. This makes Dialyzer complain if the field has not been initialized as it gets set to 'undefined' instead of an integer value.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

[jira] [Updated] (THRIFT-1532) The type specifications in the generated Erlang code should include "undefined" where it's used as a default value

Posted by "Björn Bylander (Updated JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/THRIFT-1532?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Björn Bylander updated THRIFT-1532:
-----------------------------------

    Attachment: THRIFT-1532_type_allows_undefined.patch

Fixes THRIFT-1532.
                
> The type specifications in the generated Erlang code should include "undefined" where it's used as a default value
> ------------------------------------------------------------------------------------------------------------------
>
>                 Key: THRIFT-1532
>                 URL: https://issues.apache.org/jira/browse/THRIFT-1532
>             Project: Thrift
>          Issue Type: Improvement
>          Components: Erlang - Compiler
>    Affects Versions: 0.8
>         Environment: Erlang/OTP R15B.
>            Reporter: Björn Bylander
>            Priority: Minor
>              Labels: compiler, dialyzer, erlang, specification, type
>         Attachments: THRIFT-1532_type_allows_undefined.patch
>
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> The Erlang code generated by the compiler for, for example, an integer field of a struct sets a default value of 'undefined' but the type to just 'integer()' which doesn't include the default value. This makes Dialyzer complain if the field has not been initialized as it gets set to 'undefined' instead of an integer value.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

[jira] [Updated] (THRIFT-1532) The type specifications in the generated Erlang code should include "undefined" where it's used as a default value

Posted by "Björn Bylander (Updated JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/THRIFT-1532?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Björn Bylander updated THRIFT-1532:
-----------------------------------

    Patch Info: Patch Available
    
> The type specifications in the generated Erlang code should include "undefined" where it's used as a default value
> ------------------------------------------------------------------------------------------------------------------
>
>                 Key: THRIFT-1532
>                 URL: https://issues.apache.org/jira/browse/THRIFT-1532
>             Project: Thrift
>          Issue Type: Improvement
>          Components: Erlang - Compiler
>    Affects Versions: 0.8
>         Environment: Erlang/OTP R15B.
>            Reporter: Björn Bylander
>            Priority: Minor
>              Labels: compiler, dialyzer, erlang, specification, type
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> The Erlang code generated by the compiler for, for example, an integer field of a struct sets a default value of 'undefined' but the type to just 'integer()' which doesn't include the default value. This makes Dialyzer complain if the field has not been initialized as it gets set to 'undefined' instead of an integer value.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

[jira] [Updated] (THRIFT-1532) The type specifications in the generated Erlang code should include "undefined" where it's used as a default value

Posted by "Björn Bylander (Updated JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/THRIFT-1532?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Björn Bylander updated THRIFT-1532:
-----------------------------------

    Attachment: THRIFT-1532_t_erl_generator.cc.patch

t_erl_generator should only render default values for compound types.
                
> The type specifications in the generated Erlang code should include "undefined" where it's used as a default value
> ------------------------------------------------------------------------------------------------------------------
>
>                 Key: THRIFT-1532
>                 URL: https://issues.apache.org/jira/browse/THRIFT-1532
>             Project: Thrift
>          Issue Type: Improvement
>          Components: Erlang - Compiler
>    Affects Versions: 0.8
>         Environment: Erlang/OTP R15B.
>            Reporter: Björn Bylander
>            Assignee: Anthony Molinaro
>            Priority: Minor
>              Labels: compiler, dialyzer, erlang, specification, type
>         Attachments: THRIFT-1532_t_erl_generator.cc.patch, THRIFT-1532_type_allows_undefined.patch, agent.tar.gz
>
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> The Erlang code generated by the compiler for, for example, an integer field of a struct sets a default value of 'undefined' but the type to just 'integer()' which doesn't include the default value. This makes Dialyzer complain if the field has not been initialized as it gets set to 'undefined' instead of an integer value.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

[jira] [Commented] (THRIFT-1532) The type specifications in the generated Erlang code should include "undefined" where it's used as a default value

Posted by "Hudson (Commented) (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/THRIFT-1532?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13235452#comment-13235452 ] 

Hudson commented on THRIFT-1532:
--------------------------------

Integrated in Thrift #428 (See [https://builds.apache.org/job/Thrift/428/])
    THRIFT-1532 - slightly better fix, take into account requiredness when adding default values (Revision 1303666)

     Result = SUCCESS
molinaro : http://svn.apache.org/viewvc/?view=rev&rev=1303666
Files : 
* /thrift/trunk/compiler/cpp/src/generate/t_erl_generator.cc
* /thrift/trunk/lib/erl/test/Thrift1475.thrift

                
> The type specifications in the generated Erlang code should include "undefined" where it's used as a default value
> ------------------------------------------------------------------------------------------------------------------
>
>                 Key: THRIFT-1532
>                 URL: https://issues.apache.org/jira/browse/THRIFT-1532
>             Project: Thrift
>          Issue Type: Improvement
>          Components: Erlang - Compiler
>    Affects Versions: 0.8
>         Environment: Erlang/OTP R15B.
>            Reporter: Björn Bylander
>            Assignee: Anthony Molinaro
>            Priority: Minor
>              Labels: compiler, dialyzer, erlang, specification, type
>             Fix For: 0.9
>
>         Attachments: THRIFT-1532_t_erl_generator.cc.patch, agent.tar.gz
>
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> The Erlang code generated by the compiler for, for example, an integer field of a struct sets a default value of 'undefined' but the type to just 'integer()' which doesn't include the default value. This makes Dialyzer complain if the field has not been initialized as it gets set to 'undefined' instead of an integer value.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

[jira] [Commented] (THRIFT-1532) The type specifications in the generated Erlang code should include "undefined" where it's used as a default value

Posted by "Björn Bylander (Commented JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/THRIFT-1532?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13222514#comment-13222514 ] 

Björn Bylander commented on THRIFT-1532:
----------------------------------------

I'll get back to you with an example .thrift file. Regarding using undefined as a default value: Yes, you could remove it as a default value but you still need to support it as a valid value at least for struct/record fields as any uninitialized fields are set to undefined by Erlang and it's really nice to allow undefined record fields.
                
> The type specifications in the generated Erlang code should include "undefined" where it's used as a default value
> ------------------------------------------------------------------------------------------------------------------
>
>                 Key: THRIFT-1532
>                 URL: https://issues.apache.org/jira/browse/THRIFT-1532
>             Project: Thrift
>          Issue Type: Improvement
>          Components: Erlang - Compiler
>    Affects Versions: 0.8
>         Environment: Erlang/OTP R15B.
>            Reporter: Björn Bylander
>            Assignee: Anthony Molinaro
>            Priority: Minor
>              Labels: compiler, dialyzer, erlang, specification, type
>         Attachments: THRIFT-1532_type_allows_undefined.patch
>
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> The Erlang code generated by the compiler for, for example, an integer field of a struct sets a default value of 'undefined' but the type to just 'integer()' which doesn't include the default value. This makes Dialyzer complain if the field has not been initialized as it gets set to 'undefined' instead of an integer value.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

[jira] [Commented] (THRIFT-1532) The type specifications in the generated Erlang code should include "undefined" where it's used as a default value

Posted by "Björn Bylander (Commented JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/THRIFT-1532?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13223506#comment-13223506 ] 

Björn Bylander commented on THRIFT-1532:
----------------------------------------

Huh, you're right. Based on that documentation it would seem that the problem is that undefined is used as a default value. I'll add an example soon.
                
> The type specifications in the generated Erlang code should include "undefined" where it's used as a default value
> ------------------------------------------------------------------------------------------------------------------
>
>                 Key: THRIFT-1532
>                 URL: https://issues.apache.org/jira/browse/THRIFT-1532
>             Project: Thrift
>          Issue Type: Improvement
>          Components: Erlang - Compiler
>    Affects Versions: 0.8
>         Environment: Erlang/OTP R15B.
>            Reporter: Björn Bylander
>            Assignee: Anthony Molinaro
>            Priority: Minor
>              Labels: compiler, dialyzer, erlang, specification, type
>         Attachments: THRIFT-1532_type_allows_undefined.patch
>
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> The Erlang code generated by the compiler for, for example, an integer field of a struct sets a default value of 'undefined' but the type to just 'integer()' which doesn't include the default value. This makes Dialyzer complain if the field has not been initialized as it gets set to 'undefined' instead of an integer value.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

[jira] [Updated] (THRIFT-1532) The type specifications in the generated Erlang code should include "undefined" where it's used as a default value

Posted by "Björn Bylander (Updated JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/THRIFT-1532?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Björn Bylander updated THRIFT-1532:
-----------------------------------

    Attachment: agent.tar.gz

Unpack and then compile using "rebar compile". "dialyzer ebin" outputs the following:

agent_service.erl:34: Function 'GetSomeStruct'/0 has no local return
agent_service.erl:35: Record construction #someStruct{id::42} violates the declared type of field anI32::integer()
Unknown functions:
  thrift_server:start_link/3
  thrift_server:stop/1
 done in 0m0.61s
done (warnings were emitted)

                
> The type specifications in the generated Erlang code should include "undefined" where it's used as a default value
> ------------------------------------------------------------------------------------------------------------------
>
>                 Key: THRIFT-1532
>                 URL: https://issues.apache.org/jira/browse/THRIFT-1532
>             Project: Thrift
>          Issue Type: Improvement
>          Components: Erlang - Compiler
>    Affects Versions: 0.8
>         Environment: Erlang/OTP R15B.
>            Reporter: Björn Bylander
>            Assignee: Anthony Molinaro
>            Priority: Minor
>              Labels: compiler, dialyzer, erlang, specification, type
>         Attachments: THRIFT-1532_type_allows_undefined.patch, agent.tar.gz
>
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> The Erlang code generated by the compiler for, for example, an integer field of a struct sets a default value of 'undefined' but the type to just 'integer()' which doesn't include the default value. This makes Dialyzer complain if the field has not been initialized as it gets set to 'undefined' instead of an integer value.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

[jira] [Assigned] (THRIFT-1532) The type specifications in the generated Erlang code should include "undefined" where it's used as a default value

Posted by "Anthony Molinaro (Assigned) (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/THRIFT-1532?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Anthony Molinaro reassigned THRIFT-1532:
----------------------------------------

    Assignee: Anthony Molinaro
    
> The type specifications in the generated Erlang code should include "undefined" where it's used as a default value
> ------------------------------------------------------------------------------------------------------------------
>
>                 Key: THRIFT-1532
>                 URL: https://issues.apache.org/jira/browse/THRIFT-1532
>             Project: Thrift
>          Issue Type: Improvement
>          Components: Erlang - Compiler
>    Affects Versions: 0.8
>         Environment: Erlang/OTP R15B.
>            Reporter: Björn Bylander
>            Assignee: Anthony Molinaro
>            Priority: Minor
>              Labels: compiler, dialyzer, erlang, specification, type
>         Attachments: THRIFT-1532_type_allows_undefined.patch
>
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> The Erlang code generated by the compiler for, for example, an integer field of a struct sets a default value of 'undefined' but the type to just 'integer()' which doesn't include the default value. This makes Dialyzer complain if the field has not been initialized as it gets set to 'undefined' instead of an integer value.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

[jira] [Resolved] (THRIFT-1532) The type specifications in the generated Erlang code should include "undefined" where it's used as a default value

Posted by "Anthony Molinaro (Resolved) (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/THRIFT-1532?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Anthony Molinaro resolved THRIFT-1532.
--------------------------------------

       Resolution: Fixed
    Fix Version/s: 0.9

Okay, so I used most of your patch, but modified as there were a few problems (mainly that default values went away with your patch).

I did not include this chunk
{code}
@@ -497,7 +499,7 @@
   } else if (type->is_enum()) {
     return "integer()";
   } else if (type->is_struct() || type->is_xception()) {
-    return "#" + uncapitalize(type->get_name()) + "{}";
+    return "#" + uncapitalize(type->get_name()) + "{} | undefined";
   } else if (type->is_map()) {
     return "dict()";
   } else if (type->is_set()) {
{code}
as I don't believe it's necessary as the docs state (http://www.erlang.org/doc/reference_manual/typespec.html#id75102) that it should be unnecessary to include undefined.

I also went ahead for string types and the have the type of 'string() | binary()' as that is technically what is allowed.

An example generation is for this
{code}
struct StructA
{
  1: string a,
  2: binary b,
  3: optional string c,
  4: optional binary d,
  5: required string e,
  6: required binary f,
  7: string g = "foo", 
  8: i32 h,       
  9: optional i32 i,
  10: required i32 j, 
  11: required i32 k = 5,
  12: double l,   
  13: optional double m,
  14: required double n,
  15: double o = 3.14159,
  16: list<string> string_list,
  17: list<byte> byte_list = [1, 2, 3],
  18: set<string> string_set, 
  19: map<string, string> string_map
}                 
{code}

It now generates
{code}
-record(structA, {a :: string() | binary(),
                  b :: string() | binary(),
                  c :: string() | binary(),
                  d :: string() | binary(),
                  e :: string() | binary(),
                  f :: string() | binary(),
                  g = "foo" :: string() | binary(),
                  h :: integer(),
                  i :: integer(),
                  j :: integer(),
                  k = 5 :: integer(),
                  l :: float(),
                  m :: float(),
                  n :: float(),
                  o = 3.14159 :: float(),
                  string_list = [] :: list(),
                  byte_list = [1,2,3] :: list(),
                  string_set = sets:new() :: set(),
                  string_map = dict:new() :: dict()}).
{code}

Which I feel is more correct.

Please try out SVN head and let me know if it works for you.  And if you feel I should include that chunk that I left out please include a thrift file which breaks and I can try it out.
                
> The type specifications in the generated Erlang code should include "undefined" where it's used as a default value
> ------------------------------------------------------------------------------------------------------------------
>
>                 Key: THRIFT-1532
>                 URL: https://issues.apache.org/jira/browse/THRIFT-1532
>             Project: Thrift
>          Issue Type: Improvement
>          Components: Erlang - Compiler
>    Affects Versions: 0.8
>         Environment: Erlang/OTP R15B.
>            Reporter: Björn Bylander
>            Assignee: Anthony Molinaro
>            Priority: Minor
>              Labels: compiler, dialyzer, erlang, specification, type
>             Fix For: 0.9
>
>         Attachments: THRIFT-1532_t_erl_generator.cc.patch, agent.tar.gz
>
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> The Erlang code generated by the compiler for, for example, an integer field of a struct sets a default value of 'undefined' but the type to just 'integer()' which doesn't include the default value. This makes Dialyzer complain if the field has not been initialized as it gets set to 'undefined' instead of an integer value.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

[jira] [Updated] (THRIFT-1532) The type specifications in the generated Erlang code should include "undefined" where it's used as a default value

Posted by "Björn Bylander (Updated JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/THRIFT-1532?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Björn Bylander updated THRIFT-1532:
-----------------------------------

    Attachment:     (was: THRIFT-1532_type_allows_undefined.patch)
    
> The type specifications in the generated Erlang code should include "undefined" where it's used as a default value
> ------------------------------------------------------------------------------------------------------------------
>
>                 Key: THRIFT-1532
>                 URL: https://issues.apache.org/jira/browse/THRIFT-1532
>             Project: Thrift
>          Issue Type: Improvement
>          Components: Erlang - Compiler
>    Affects Versions: 0.8
>         Environment: Erlang/OTP R15B.
>            Reporter: Björn Bylander
>            Assignee: Anthony Molinaro
>            Priority: Minor
>              Labels: compiler, dialyzer, erlang, specification, type
>         Attachments: THRIFT-1532_t_erl_generator.cc.patch, agent.tar.gz
>
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> The Erlang code generated by the compiler for, for example, an integer field of a struct sets a default value of 'undefined' but the type to just 'integer()' which doesn't include the default value. This makes Dialyzer complain if the field has not been initialized as it gets set to 'undefined' instead of an integer value.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira