Skip to content

Commit

Permalink
Merge pull request #256 from ConsenSys/fix-bug-compile-visibility
Browse files Browse the repository at this point in the history
fix: fixes #255 variable visibility inheritance regression
  • Loading branch information
gbotrel committed Feb 13, 2022
2 parents 89505d2 + 550d184 commit 9b9e3b5
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
5 changes: 5 additions & 0 deletions frontend/schema/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,11 @@ func parse(r []Field, input interface{}, target reflect.Type, parentFullName, pa
return r, fmt.Errorf("conflicting visibility. %s (%s) has a parent with different visibility attribute", getFullName(parentGoName, name, nameTag), visibility.String())
}

// inherit parent visibility
if visibility == Unset {
visibility = parentVisibility
}

fValue := tValue.FieldByIndex(f.Index)

if fValue.CanAddr() && fValue.Addr().CanInterface() {
Expand Down
45 changes: 45 additions & 0 deletions frontend/schema/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,51 @@ func TestSchemaCorrectness(t *testing.T) {
assert.Equal(expectedBuf.String(), instanceBuf.String())
}

type circuitInherit1 struct {
X variable `gnark:"x"`
Y struct {
U, V variable
} `gnark:",public"`
}

type circuitInherit2 struct {
X struct {
A variable `gnark:"x,secret"`
}
Y struct {
U variable `gnark:",public"`
V struct {
Z variable
W variable
}
} `gnark:",public"`
}

func TestSchemaInherit(t *testing.T) {
assert := require.New(t)

{
var c circuitInherit1

s, err := Parse(&c, tVariable, nil)
assert.NoError(err)

assert.Equal(2, s.NbPublic)
assert.Equal(1, s.NbSecret)
}

{
var c circuitInherit2

s, err := Parse(&c, tVariable, nil)
assert.NoError(err)

assert.Equal(3, s.NbPublic)
assert.Equal(1, s.NbSecret)
}

}

var tVariable reflect.Type

func init() {
Expand Down

0 comments on commit 9b9e3b5

Please sign in to comment.