-
Notifications
You must be signed in to change notification settings - Fork 4
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
Add simple conversions #3
Conversation
right = &ast.CallExpr{ | ||
Fun: leftType, | ||
Args: []ast.Expr{right}, | ||
} |
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.
This basically fudges the right in this:
left = right
to be
left = leftType(right)
@@ -54,7 +55,8 @@ type StringSlice []string | |||
type WorkloadSlice []*Workload | |||
|
|||
type Workload struct { | |||
ID string | |||
ID string | |||
Value int |
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.
While I was here, I also edited the e2e to have an example of int-to-int32 conversion which does require a user provided function since it could be lossy.
// Only allow this for basic and named. | ||
|
||
switch typeDecode.(type) { | ||
case *types.Basic, *types.Named: |
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.
Basic: stuff like string
or int
Named: stuff like Label
in type Label string
return false | ||
} | ||
|
||
if types.ConvertibleTo(typ, typeDecode) && types.ConvertibleTo(typeDecode, typ) { |
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.
typeDecode
is the most underlying type for typ
.
- For pointers this is the type of the ultimate memory location
- For named types, it is the type of the real underlying type
This check only lets this special code execute if BOTH the left and right are convertible to their underlying type (which in effect selects type LEFT RIGHT
types).
return false | ||
} | ||
|
||
if types.Identical(typ, typeDecode) { |
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.
for example typ=string
will have typeDecode=string
too and string
is convertible to string
but we don't want that to trigger the special code.
f52aef2
to
d879198
Compare
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.
This all looks good to me - I'm not very familiar with this code yet though.
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.
🚀 Thank you @rboyer!! this will remove a bunch of annotations in Consul.
This should handle
type Label string
automatic conversions to/from each other.