Skip to content

checker: check error of implementing other module private interface (fix #19620) - #19688

Merged
spytheman merged 2 commits into
vlang:masterfrom
yuyi98:check_private_interface
Oct 29, 2023
Merged

spytheman merged 2 commits into
vlang:masterfrom
yuyi98:check_private_interface

Conversation

@yuyi98

@yuyi98 yuyi98 commented Oct 28, 2023

Copy link
Copy Markdown
Member

This PR check error of implementing other module private interface (fix #19620).

  • Check error of implementing other module private interface.
  • Add test.
// sub module
module baz

interface Foo {
	a int
}

pub fn print_foo(f Foo) {
	println(f.a)
}
module main
import baz

fn main() {
	b := Bar{10}
	baz.print_foo(b) // prints 10
}

struct Bar {
	a int
}

PS D:\Test\v\tt1> v run .    
tt1.v:6:16: error: `Bar` cannot implement private interface `baz.Foo` of other module
    4 | fn main() {
    5 |     b := Bar{10}
    6 |     baz.print_foo(b) // prints 10
      |                   ^
    7 | }
    8 |

Comment thread vlib/v/checker/checker.v

@spytheman spytheman left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Excellent work.

@spytheman
spytheman merged commit 7681a0b into vlang:master Oct 29, 2023
@yuyi98
yuyi98 deleted the check_private_interface branch October 29, 2023 12:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Structs in other modules should not be able to implement private interfaces

2 participants