mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
parser: detect wrong usage of Option as concrete type (#18334)
This commit is contained in:
parent
0fc33c6fa3
commit
4e21b2ab4e
5
vlib/v/checker/tests/option_concrete_type_err.out
Normal file
5
vlib/v/checker/tests/option_concrete_type_err.out
Normal file
@ -0,0 +1,5 @@
|
||||
vlib/v/checker/tests/option_concrete_type_err.vv:5:8: error: cannot use Option type name as concrete type
|
||||
3 | }
|
||||
4 |
|
||||
5 | r := f[?int]()
|
||||
| ^
|
5
vlib/v/checker/tests/option_concrete_type_err.vv
Normal file
5
vlib/v/checker/tests/option_concrete_type_err.vv
Normal file
@ -0,0 +1,5 @@
|
||||
fn f[T]() T {
|
||||
return none
|
||||
}
|
||||
|
||||
r := f[?int]()
|
@ -485,7 +485,10 @@ fn (mut p Parser) expr_with_left(left ast.Expr, precedence int, is_stmt_ident bo
|
||||
} else if left !is ast.IntegerLiteral && p.tok.kind in [.lsbr, .nilsbr]
|
||||
&& (p.tok.line_nr == p.prev_tok.line_nr || (p.prev_tok.kind == .string
|
||||
&& p.tok.line_nr == p.prev_tok.line_nr + p.prev_tok.lit.count('\n'))) {
|
||||
if p.tok.kind == .nilsbr {
|
||||
if p.peek_tok.kind == .question && p.peek_token(2).kind == .name {
|
||||
p.next()
|
||||
p.error_with_pos('cannot use Option type name as concrete type', p.tok.pos())
|
||||
} else if p.tok.kind == .nilsbr {
|
||||
node = p.index_expr(node, true)
|
||||
} else {
|
||||
node = p.index_expr(node, false)
|
||||
|
Loading…
Reference in New Issue
Block a user