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

Support for variable and constant exports for packages in the compiler #1154

Closed
roman-khimov opened this issue Jul 7, 2020 · 1 comment · Fixed by #1240
Closed

Support for variable and constant exports for packages in the compiler #1154

roman-khimov opened this issue Jul 7, 2020 · 1 comment · Fixed by #1240
Labels
compiler Go smart contract compiler
Milestone

Comments

@roman-khimov
Copy link
Member

Given the following foo:

package foo

const Const = 42

// NewBar return an integer \o/
func NewBar() int {
        return 10
}

This test should work:

func TestImportConst(t *testing.T) {
       src := `
               package importconst

               import "github.com/nspcc-dev/neo-go/pkg/compiler/testdata/foo"

               func Main() int {
                       return foo.Const
               }
       `
       eval(t, src, big.NewInt(42))
}

But it doesn't and it also fails if we're to change foo to export a variable. It's a bit complicated to fix because traverseGlobals is assumed to be called once as it emits an INITSSLOT opcode and convertGlobals shouldn't ignore constants for subpackages. ast.SelectorExpr handling at line 808 of codegen.go also should be made aware of package-level constants and variables.

It's also somewhat related to #1150 as at the moment these variables/constants would end up in the same namespace.

@roman-khimov roman-khimov added the compiler Go smart contract compiler label Jul 7, 2020
@roman-khimov roman-khimov added this to the v0.91.0 milestone Jul 7, 2020
roman-khimov added a commit that referenced this issue Jul 7, 2020
Neo 3.0 has new updated and improved constants. A better (non-function-based)
fix requires #1154 to be solved.
@fyrchik
Copy link
Contributor

fyrchik commented Jul 27, 2020

Somewhat depends on #1228 , where Main func is no longer special.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler Go smart contract compiler
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants