-
Notifications
You must be signed in to change notification settings - Fork 375
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
fix: typed const conversion validation #3117
base: master
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #3117 +/- ##
==========================================
- Coverage 63.79% 63.65% -0.14%
==========================================
Files 549 549
Lines 78819 79068 +249
==========================================
+ Hits 50279 50333 +54
- Misses 25150 25326 +176
- Partials 3390 3409 +19
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
x := uint(tv.GetInt8()) | ||
tv.T = t | ||
tv.SetUint(x) | ||
case Uint8Kind: | ||
validate(Int8Kind, Uint8Kind, func() bool { return tv.GetInt8() >= 0 }) |
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.
When an int type value exceeding 255 comes in, it will exceed the range of uint8. I think overflow error should take precedence over convertable error - how do you think?
@@ -129,6 +129,136 @@ func TestBuiltinIdentifiersShadowing(t *testing.T) { | |||
} | |||
} | |||
|
|||
func TestConvertTo(t *testing.T) { |
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.
Nitpicking: this function should be located in values_conversions_tests.go
instead of gno_tests.go
.
@@ -796,6 +796,6 @@ func (m *Machine) doOpFuncLit() { | |||
func (m *Machine) doOpConvert() { | |||
xv := m.PopValue() | |||
t := m.PopValue().GetType() | |||
ConvertTo(m.Alloc, m.Store, xv, t) | |||
ConvertTo(m.Alloc, m.Store, xv, t, false) |
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.
Here, we don't know if xv
is a constant or not. Forcing false
for isConst
parameter here is incorrect for constant expressions. For example, the following sample should fail but it doesn't:
println(int(float64(1 + 0.5)))
During preprocessing, validates if typed constants are convertible.
Fixes issue
Typed constants are convertible only in a lossless way.
That means that we can convert floats to integers if the fractional part of the float is 0.