Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gen: Fix bug for typedefed defaults #324

Merged
merged 1 commit into from
Aug 26, 2017
Merged

gen: Fix bug for typedefed defaults #324

merged 1 commit into from
Aug 26, 2017

Conversation

abhinav
Copy link
Contributor

@abhinav abhinav commented Aug 25, 2017

We have a bug where if a field with a default value is a typedef of a
primitive type, the generated code will be equivalent to,

type Timestamp int64

var value *Timestamp = ptr.Int64(42)

This will fail because you cannot assign a *int64 to a *Timestamp.

This commit fixes this issue by generating a _Timestamp_ptr function
similar to one generated for other types.

We have a bug where if a field with a default value is a typedef of a
primitive type, the generated code will be equivalent to,

    type Timestamp int64

    var value *Timestamp = ptr.Int64(42)

This will fail because you cannot assign a `*int64` to a `*Timestamp`.

This commit fixes this issue by generating a `_Timestamp_ptr` function
similar to one generated for other types.
@@ -18,6 +18,10 @@ struct Event {
2: optional Timestamp time // optional typedef
}

struct DefaultPrimitiveTypedef {
1: optional State state = "hello"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would previously generated code that wouldn't compile

Copy link
Contributor

@HelloGrayson HelloGrayson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup.

@akshayjshah
Copy link

lgtm

@abhinav abhinav merged commit 45d4a33 into dev Aug 26, 2017
@abhinav abhinav deleted the typedef-default-fix branch August 26, 2017 23:10
abhinav added a commit that referenced this pull request Aug 28, 2017
The majority use case for accessing values of optional primitives is to
dereference it as-is or use the default/zero value if not.

This modifies code generation to include accessor functions for optional
primitive fields which return non-pointer versions of those fields.

So instead of,

    var foo string
    if s.Foo != nil {
        foo = *s.Foo
    }
    doSomething(foo)

Users can do,

    doSomething(s.GetFoo())

This should also ease migration for users coming from Apache Thrift.

Resolves #295

Depends on #324
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants