Skip to content

new compiler: private struct fields of another module can be read #28827

Description

@davlgd

Describe the bug

The new compiler lets a module read a private field of a struct declared in another module. The old compiler rejects it, as expected.

Reproduction Steps

lib/lib.v:

module lib

pub struct Box {
mut:
	secret int
}

pub fn new_box() Box {
	return Box{
		secret: 42
	}
}

main.v:

import lib

fn main() {
	b := lib.new_box()
	println(b.secret)
}

v -new-compiler run main.v

Expected Behavior

The error the old compiler gives:

main.v:5:12: error: field `lib.Box.secret` is not public

Current Behavior

It compiles and prints 42.

V version

V 0.5.2 4af2cb4 (-new-compiler). The old compiler I compare with is what -old-compiler runs, the V 0.5.2 release (7647ce1).

Environment details (OS name and version, etc.)

macOS 26.6, arm64, Apple clang 21

Note

You can use the 👍 reaction to increase the issue's priority for developers.

Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.

Activity

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions