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

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

Draft
wants to merge 1 commit 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

All modified and coverable lines are covered by tests ✅

Project coverage is 60.88%. Comparing base (5503cca) to head (78ec19f).
Report is 9 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2828      +/-   ##
==========================================
+ Coverage   60.83%   60.88%   +0.05%     
==========================================
  Files         563      563              
  Lines       75193    75235      +42     
==========================================
+ Hits        45743    45809      +66     
+ Misses      26076    26060      -16     
+ Partials     3374     3366       -8     
Flag Coverage Δ
contribs/gnodev 61.46% <ø> (ø)
contribs/gnofaucet 14.46% <ø> (ø)
misc/genstd 80.54% <ø> (ø)
misc/logos 20.23% <ø> (ø)
tm2 62.08% <ø> (+0.19%) ⬆️

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.

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
Status: Triage
Development

Successfully merging this pull request may close these issues.

1 participant