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

Merged
merged 45 commits into from
Jan 14, 2025

Conversation

omarsy
Copy link
Member

@omarsy omarsy commented Sep 21, 2024

Related Issues:
Closes #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 61.01695% with 46 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
gnovm/pkg/gnolang/type_check.go 60.68% 37 Missing and 9 partials ⚠️

📢 Thoughts on this report? Let us know!

@omarsy omarsy force-pushed the fix/2628 branch 4 times, most recently from c9b02d2 to f49c088 Compare September 25, 2024 11:54
@github-actions github-actions bot added the 🧾 package/realm Tag used for new Realms or Packages. label Sep 25, 2024
@omarsy omarsy force-pushed the fix/2628 branch 2 times, most recently from 355d799 to e9a9be7 Compare September 26, 2024 10:31
@omarsy omarsy marked this pull request as ready for review October 18, 2024 20:52
@omarsy omarsy requested review from jaekwon, moul, piux2, thehowl, mvertes and a team as code owners 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
@omarsy omarsy changed the title WIP feat(gnovm): align Gno constant handling with Go specifications feat(gnovm): align Gno constant handling with Go specifications Oct 19, 2024
@Kouteki Kouteki added this to the 🚀 Mainnet launch milestone Oct 22, 2024
@omarsy omarsy requested a review from ltzmaxwell January 5, 2025 13:26
Copy link
Contributor

@ltzmaxwell ltzmaxwell left a comment

Choose a reason for hiding this comment

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

LGTM, approve this. @omarsy thank you for fixing this.

gnovm/pkg/gnolang/type_check.go Outdated Show resolved Hide resolved
@ltzmaxwell
Copy link
Contributor

cc: @thehowl to finalize this.

Copy link
Member

@thehowl thehowl left a comment

Choose a reason for hiding this comment

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

but the rest is good; some better documentation is appreciated but you can send it in another PR ;)

gnovm/pkg/gnolang/type_check.go Show resolved Hide resolved
@thehowl thehowl merged commit 3adb2ac into gnolang:master Jan 14, 2025
70 of 72 checks passed
@omarsy omarsy deleted the fix/2628 branch January 14, 2025 23:40
@Kouteki Kouteki removed the in focus Core team is prioritizing this work label Jan 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📦 🌐 tendermint v2 Issues or PRs tm2 related 📦 ⛰️ gno.land Issues or PRs gno.land package related 📦 🤖 gnovm Issues or PRs gnovm related 🧾 package/realm Tag used for new Realms or Packages.
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Constant Declaration with Slice Type Compiles Without Error
7 participants