1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

parser: fix multiple embedded external module interface (#18531)

This commit is contained in:
yuyi 2023-06-24 02:23:24 +08:00 committed by GitHub
parent 1547a49fab
commit f3e1859ee8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 25 additions and 4 deletions

View File

@ -578,6 +578,7 @@ fn (mut p Parser) interface_decl() ast.InterfaceDecl {
mut is_mut := false
mut mut_pos := -1
for p.tok.kind != .rcbr && p.tok.kind != .eof {
// check embedded interface from internal module
if p.tok.kind == .name && p.tok.lit.len > 0 && p.tok.lit[0].is_capital()
&& (p.peek_tok.line_nr != p.tok.line_nr
|| p.peek_tok.kind !in [.name, .amp, .lsbr, .lpar]
@ -600,8 +601,7 @@ fn (mut p Parser) interface_decl() ast.InterfaceDecl {
}
continue
}
// Check embedded interface from external module
// check embedded interface from external module
if p.tok.kind == .name && p.peek_tok.kind == .dot {
if p.tok.lit !in p.imports {
p.error_with_pos('mod `${p.tok.lit}` not imported', p.tok.pos())
@ -624,6 +624,7 @@ fn (mut p Parser) interface_decl() ast.InterfaceDecl {
if p.tok.kind == .rcbr {
break
}
continue
}
if p.tok.kind == .key_mut {
@ -654,7 +655,6 @@ fn (mut p Parser) interface_decl() ast.InterfaceDecl {
p.error_with_pos('duplicate method `${name}`', method_start_pos)
return ast.InterfaceDecl{}
}
// field_names << name
args2, _, is_variadic := p.fn_args() // TODO merge ast.Param and ast.Arg to avoid this
mut args := [
ast.Param{
@ -688,7 +688,6 @@ fn (mut p Parser) interface_decl() ast.InterfaceDecl {
method.comments = mcomments
method.next_comments = mnext_comments
methods << method
// println('register method $name')
tmethod := ast.Fn{
name: name
params: args

View File

@ -0,0 +1,5 @@
module module_a
pub interface Writer {
write(name string) string
}

View File

@ -0,0 +1,5 @@
module module_b
pub interface Reader {
read(name string) string
}

View File

@ -0,0 +1,12 @@
import module_a
import module_b
pub interface MyInterface {
module_a.Writer
module_b.Reader
}
fn test_multiple_embed_external_interface() {
println('abc')
assert true
}