-
Notifications
You must be signed in to change notification settings - Fork 33
tuple: ordinal field #578
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
tuple: ordinal field #578
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -1560,6 +1560,9 @@ func (p *CodeBuilder) refMember(typ types.Type, name string, argVal ast.Expr, sr | |||||||||||||
|
|
||||||||||||||
| func (p *CodeBuilder) fieldRef(x ast.Expr, o *types.Struct, name string, src ast.Node, visited map[*types.Struct]none) bool { | ||||||||||||||
| var embed []*types.Var | ||||||||||||||
| if c := name[0]; c >= '0' && c <= '9' { // tuple: ordinal field | ||||||||||||||
| name = "X_" + name | ||||||||||||||
| } | ||||||||||||||
| for i, n := 0, o.NumFields(); i < n; i++ { | ||||||||||||||
| fld := o.Field(i) | ||||||||||||||
| if fld.Name() == name { | ||||||||||||||
|
|
@@ -1923,6 +1926,9 @@ func (p *CodeBuilder) btiMethod( | |||||||||||||
|
|
||||||||||||||
| func (p *CodeBuilder) normalField( | ||||||||||||||
| o *types.Struct, name string, arg *Element, src ast.Node) MemberKind { | ||||||||||||||
| if c := name[0]; c >= '0' && c <= '9' { // tuple: ordinal field | ||||||||||||||
| name = "X_" + name | ||||||||||||||
| } | ||||||||||||||
|
Comment on lines
+1929
to
+1931
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to the other location, accessing
Suggested change
|
||||||||||||||
| for i, n := 0, o.NumFields(); i < n; i++ { | ||||||||||||||
| fld := o.Field(i) | ||||||||||||||
| v := fld.Name() | ||||||||||||||
|
|
||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -202,6 +202,9 @@ func (p *CodeBuilder) tryUnpackTuple(lhs int) int { | |||||||||||||
| // It checks both the original fields and the virtual fields (e.g. tuple | ||||||||||||||
| // fields). | ||||||||||||||
| func (p *CodeBuilder) LookupField(t *types.Struct, name string) int { | ||||||||||||||
| if c := name[0]; c >= '0' && c <= '9' { // tuple: ordinal field | ||||||||||||||
| name = "X_" + name | ||||||||||||||
| } | ||||||||||||||
|
Comment on lines
+205
to
+207
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Accessing
Suggested change
|
||||||||||||||
| for i, n := 0, t.NumFields(); i < n; i++ { | ||||||||||||||
| if fld := t.Field(i); fld.Name() == name { | ||||||||||||||
| return i | ||||||||||||||
|
|
||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Accessing
name[0]without first checking ifnameis empty will cause a panic if an empty string is provided as the field name. It's safer to add a length check to prevent this potential runtime error.