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

WIP feat(gnovm): align Gno constant handling with Go specifications #2828

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

omarsy
Copy link
Contributor

@omarsy omarsy commented Sep 21, 2024

Related Issues:
#2628

This PR aims to align Gno's constant handling with the Go specification regarding constant expressions (see Go Specification on Constants).

  1. Primitive Type Requirement

    • Should Work:
      const t = 1
    • Should Return an Error:
      const t = []string{"1"}
      Error:
      (const (slice[("1" string)] []string)) (value of type []string) is not constant
      
  2. Function Calls Disallowed
    Only built-in functions should be allowed.

    • Should Work:
      const t = len("s")
    • Should Return an Error:
      func v() string {
          return ""
      }
      const t = v()
      Error:
      v<VPBlock(3,0)>() (value of type string) is not constant
      
  3. Constant Operands Requirement
    Constant expressions may contain only constant operands and are evaluated at compile time.

    • Should Work:
      const t = 1
      const v = t
    • Should Raise an Error:
      t := 1
      const v = t
      Error:
      t (variable of type int) is not constant
      
  4. Type Assertion Forbidden

    • This code:
      var i interface{} = 1
      const t, ok = i.(int)
    • Should Raise This Error:
      i.(int) (comma, ok expression of type int) is not constant
      
  5. Index Expression Forbidden

    • This code:
      var i = []string{}
      const t, ok = i[0]
    • Should Return This Error:
      i[0] (variable of type string) is not constant
      
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.

@github-actions github-actions bot added the 📦 🤖 gnovm Issues or PRs gnovm related label Sep 21, 2024
Copy link

codecov bot commented Sep 21, 2024

Codecov Report

Attention: Patch coverage is 68.60465% with 27 lines in your changes missing coverage. Please review.

Project coverage is 63.10%. Comparing base (f6bd2d3) to head (bb2d9fd).

Files with missing lines Patch % Lines
gnovm/pkg/gnolang/type_check.go 72.97% 20 Missing ⚠️
gnovm/pkg/gnolang/preprocess.go 41.66% 4 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2828      +/-   ##
==========================================
+ Coverage   63.08%   63.10%   +0.02%     
==========================================
  Files         563      563              
  Lines       79254    79340      +86     
==========================================
+ Hits        49998    50071      +73     
- Misses      25896    25899       +3     
- Partials     3360     3370      +10     
Flag Coverage Δ
contribs/gnodev 60.62% <ø> (ø)
contribs/gnofaucet 14.82% <ø> (ø)
gno.land 67.56% <ø> (ø)
gnovm 67.28% <68.60%> (+0.03%) ⬆️
misc/genstd 79.72% <ø> (ø)
misc/logos 19.95% <ø> (+0.50%) ⬆️
tm2 62.26% <ø> (+<0.01%) ⬆️

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.

@omarsy omarsy marked this pull request as ready for review October 18, 2024 20:52
@omarsy omarsy changed the title feat(gnovm): align Gno constant handling with Go specifications WIP feat(gnovm): align Gno constant handling with Go specifications Oct 18, 2024
@jefft0
Copy link
Contributor

jefft0 commented Oct 19, 2024

@omarsy , can you fix the lint-pr-title CI check?

@jefft0 jefft0 added the review/triage-pending PRs opened by external contributors that are waiting for the 1st review label Oct 19, 2024
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 🧾 package/realm Tag used for new Realms or Packages. review/triage-pending PRs opened by external contributors that are waiting for the 1st review
Projects
Status: No status
Status: Triage
Development

Successfully merging this pull request may close these issues.

2 participants