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

fix: untyped values use calling builtin function's type #1423

Merged
merged 6 commits into from
Jan 11, 2024

Conversation

deelawn
Copy link
Contributor

@deelawn deelawn commented Dec 7, 2023

Addresses #1085

The call to convConst should include the type in this case. This happens while processing a CallExpr and in this case the expression is a function call to the built function uint64. We have the expected type, so use when converting the constant to a typed value. If this type is still nil, then it will behave as it does currently.

However, the concrete type should only be supplied to convertConst if the call expression's type and the constant expression's type both have the same underlying unsigned type -- the base type of any value of these types were they to be evaluated as literals before being assigned a type.

Contributors' checklist...
  • Added new tests, or not needed, or not feasible
  • Provided an example (e.g. screenshot) to aid review or the PR is self-explanatory
  • Updated the official documentation or not needed
  • No breaking changes were made, or a BREAKING CHANGE: xxx message was included in the description
  • Added references to related issues and PRs
  • Provided any useful hints for running manual tests
  • Added new benchmarks to generated graphs, if any. More info here.

@deelawn deelawn requested review from jaekwon, moul and a team as code owners December 7, 2023 23:40
@github-actions github-actions bot added the 📦 🤖 gnovm Issues or PRs gnovm related label Dec 7, 2023
@deelawn deelawn marked this pull request as draft December 7, 2023 23:45
Copy link

codecov bot commented Dec 7, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (a338929) 56.31% compared to head (8e1ca79) 55.79%.
Report is 23 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1423      +/-   ##
==========================================
- Coverage   56.31%   55.79%   -0.53%     
==========================================
  Files         422      431       +9     
  Lines       65699    68649    +2950     
==========================================
+ Hits        37000    38303    +1303     
- Misses      25817    27381    +1564     
- Partials     2882     2965      +83     
Flag Coverage Δ
go-1.21.x ∅ <ø> (?)
misc ∅ <ø> (?)
misc-_test.genstd ∅ <ø> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@deelawn deelawn marked this pull request as ready for review December 8, 2023 01:19
Copy link
Contributor

@piux2 piux2 left a comment

Choose a reason for hiding this comment

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

The fix works well. There is a simpler alternative though. Please see the inline comments. WDYT?

gnovm/pkg/gnolang/preprocess.go Show resolved Hide resolved
@piux2
Copy link
Contributor

piux2 commented Jan 11, 2024

@deelawn awesome, LGTM

@deelawn deelawn merged commit 68dd403 into gnolang:master Jan 11, 2024
187 of 188 checks passed
@deelawn deelawn deleted the bug/untyped-int-conversion branch January 11, 2024 03:45
gfanton pushed a commit to moul/gno that referenced this pull request Jan 18, 2024
<!-- please provide a detailed description of the changes made in this
pull request. -->
Addresses gnolang#1085 

The call to `convConst` should include the type in this case. This
happens while processing a `CallExpr` and in this case the expression is
a function call to the built function `uint64`. We have the expected
type, so use when converting the constant to a typed value. If this type
is still nil, then it will behave as it does currently.

However, the concrete type should only be supplied to `convertConst` if
the call expression's type and the constant expression's type both have
the same underlying _unsigned type_ -- the base type of any value of
these types were they to be evaluated as literals before being assigned
a type.

<details><summary>Contributors' checklist...</summary>

- [x] Added new tests, or not needed, or not feasible
- [ ] Provided an example (e.g. screenshot) to aid review or the PR is
self-explanatory
- [ ] Updated the official documentation or not needed
- [ ] No breaking changes were made, or a `BREAKING CHANGE: xxx` message
was included in the description
- [x] Added references to related issues and PRs
- [ ] Provided any useful hints for running manual tests
- [ ] Added new benchmarks to [generated
graphs](https://gnoland.github.io/benchmarks), if any. More info
[here](https://github.com/gnolang/gno/blob/master/.benchmarks/README.md).
</details>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📦 🤖 gnovm Issues or PRs gnovm related
Projects
Status: No status
Archived in project
Development

Successfully merging this pull request may close these issues.

conversion to uint64 is bounded to int64 values (when passing as a literal)
3 participants