Skip to content

default value issue #9

@SteveBaker

Description

@SteveBaker

With this proto file:

 package Test;

 message MyTest {
        enum MyTestEnum {
                ZERO = 0 ;
                ONE  = 1 ;
        }
        optional MyTestEnum value = 2 [default = ZERO];
 }

...I get this JS output:

 "use strict";
 /** @suppress {duplicate}*/var Test;
 if (typeof(Test)=="undefined") {Test = {};}

 Test.MyTest = PROTO.Message("Test.MyTest",{
        MyTestEnum: PROTO.Enum("Test.MyTest.MyTestEnum",{
                ZERO :0,
                ONE :1  }),
        value: {
                options: {default_value:Test.MyTest.MyTestEnum.ZERO},
                multiplicity: PROTO.optional,
                type: function(){return Test.MyTest.MyTestEnum;},
                id: 2
        }});

...which produces (in Firefox):

 TypeError: Test.MyTest is undefined

...and in Chrome:

 Uncaught TypeError: Cannot read property 'MyTestEnum' of undefined 

...in both cases, the offending line is:

                  options: {default_value:Test.MyTest.MyTestEnum.ZERO},

...changing the default value from the enum "ZERO" to a literal value of "0" fixes the problem.

This .proto file works fine in at least three other protobuf systems - so I presume that it's legal.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions