Skip to content

Field functions after embedded structs are not visible #840

Closed

Description

@antonmedv

@diegommm looks like something to broken with the way nature iterates embedded structs and fields as methods.

type Env struct {
	EmbeddedEnv
	Func func() int
}

type EmbeddedEnv struct{}

In this case Func will be not accessible.

Activity

  1. antonmedv commented on Sep 18, 2025

    @antonmedv
    MemberAuthor

    I added the falling test. Please, take a look.

    func TestEnvFieldMethods(t *testing.T) {
    program, err := expr.Compile(`Func(0)`, expr.Env(&Env{}))
    require.NoError(t, err)
    env := &Env{}
    env.Func = func() int {
    return 42
    }
    out, err := expr.Run(program, Env{})
    require.NoError(t, err)
    require.Equal(t, 42, out)
    }
    type Env struct {
    EmbeddedEnv
    Func func() int
    }
    type EmbeddedEnv struct{}

  2. diegommm commented on Sep 20, 2025

    @diegommm
    Contributor

    Will take a look.

  3. added a commit that references this issue on Sep 21, 2025
    787cc4e
  4. diegommm commented on Sep 21, 2025

    @diegommm
    Contributor

    Created a fix in #843

  5. added a commit that references this issue on Sep 21, 2025
    7dbd409
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions