Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
felipensp committed Jun 14, 2023
1 parent bbd1027 commit c6065ce
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
7 changes: 7 additions & 0 deletions vlib/v/checker/tests/wrong_ref_type_as_concrete_err.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
vlib/v/checker/tests/wrong_ref_type_as_concrete_err.vv:9:39: error: cannot use &Type as generic concrete type, declare the function parameter as &T instead
7 |
8 | fn main() {
9 | mut dl := datatypes.DoublyLinkedList[&User]{}
| ^
10 | println(dl)
11 | }
11 changes: 11 additions & 0 deletions vlib/v/checker/tests/wrong_ref_type_as_concrete_err.vv
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import datatypes

[heap]
struct User {
name string
}

fn main() {
mut dl := datatypes.DoublyLinkedList[&User]{}
println(dl)
}
4 changes: 4 additions & 0 deletions vlib/v/parser/parse_type.v
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,10 @@ fn (mut p Parser) parse_generic_inst_type(name string) ast.Type {
mut is_instance := true
for p.tok.kind != .eof {
mut type_pos := p.tok.pos()
if p.tok.kind == .amp {
p.error_with_pos('cannot use &Type as generic concrete type, declare the function parameter as &T instead',
type_pos)
}
gt := p.parse_type()
type_pos = type_pos.extend(p.prev_tok.pos())
if gt.has_flag(.generic) {
Expand Down

0 comments on commit c6065ce

Please sign in to comment.