From f1903f3c1f003377079c95b46efb8f62fc4f5bcd Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Thu, 30 Apr 2020 18:06:14 +0200 Subject: [PATCH] parser: fix imported interfaces --- vlib/v/checker/checker.v | 11 +++++++---- vlib/v/parser/struct.v | 2 +- vlib/v/tests/interface_test.v | 10 ++++++---- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index b3ca5f4ca6..8d18ddaded 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -50,7 +50,7 @@ pub fn new_checker(table &table.Table, pref &pref.Preferences) Checker { pub fn (mut c Checker) check(ast_file ast.File) { c.file = ast_file for i, ast_import in ast_file.imports { - for j in 0..i { + for j in 0 .. i { if ast_import.mod == ast_file.imports[j].mod { c.error('module name `$ast_import.mod` duplicate', ast_import.pos) } @@ -976,7 +976,7 @@ pub fn (mut c Checker) return_stmt(return_stmt mut ast.Return) { pub fn (mut c Checker) enum_decl(decl ast.EnumDecl) { for i, field in decl.fields { - for j in 0..i { + for j in 0 .. i { if field.name == decl.fields[j].name { c.error('field name `$field.name` duplicate', field.pos) } @@ -1439,7 +1439,9 @@ fn (mut c Checker) stmt(node ast.Stmt) { } fn (mut c Checker) stmts(stmts []ast.Stmt) { - mut unreachable := token.Position{line_nr: -1} + mut unreachable := token.Position{ + line_nr: -1 + } c.expected_type = table.void_type for stmt in stmts { if c.scope_returns { @@ -1877,7 +1879,8 @@ pub fn (mut c Checker) if_expr(node mut ast.IfExpr) table.Type { // p.warn('if expr ret $type_sym.name') t := c.expr(it.expr) if is_ternary && t != first_typ { - c.error('mismatched types `${c.table.type_to_str(first_typ)}` and `${c.table.type_to_str(t)}`', node.pos) + c.error('mismatched types `${c.table.type_to_str(first_typ)}` and `${c.table.type_to_str(t)}`', + node.pos) } node.typ = t return t diff --git a/vlib/v/parser/struct.v b/vlib/v/parser/struct.v index 16a06060fa..6732c4ca9c 100644 --- a/vlib/v/parser/struct.v +++ b/vlib/v/parser/struct.v @@ -257,7 +257,7 @@ fn (mut p Parser) interface_decl() ast.InterfaceDecl { p.next() } p.next() // `interface` - interface_name := p.check_name() + interface_name := p.prepend_mod(p.check_name()) // println('interface decl $interface_name') p.check(.lcbr) // Declare the type diff --git a/vlib/v/tests/interface_test.v b/vlib/v/tests/interface_test.v index e6f30015a2..24b340d951 100644 --- a/vlib/v/tests/interface_test.v +++ b/vlib/v/tests/interface_test.v @@ -1,3 +1,4 @@ + struct Dog { breed string } @@ -28,10 +29,6 @@ fn test_todo() { else{} } -interface Speaker { - name() string - speak() -} fn perform_speak(s Speaker) { s.speak() @@ -86,3 +83,8 @@ struct Foo { speakers []Speaker } +interface Speaker { + name() string + speak() +} +