Skip to content

Commit

Permalink
add more test and refine check
Browse files Browse the repository at this point in the history
  • Loading branch information
Delta456 committed Oct 2, 2024
1 parent 7325d4f commit 956102d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
4 changes: 2 additions & 2 deletions vlib/v/checker/checker.v
Original file line number Diff line number Diff line change
Expand Up @@ -3193,8 +3193,8 @@ fn (mut c Checker) cast_expr(mut node ast.CastExpr) ast.Type {

type_str := c.table.type_to_str(to_type)
type_rm_ptr := type_str.replace('&', '')
if type_rm_ptr.len == 1 && type_rm_ptr.starts_with_capital()
&& !c.expected_type.has_flag(.generic) {
if !c.expected_type.has_flag(.generic) && type_rm_ptr.len == 1
&& type_rm_ptr.starts_with_capital() {
c.error('unknown type `${to_sym.name}`', node.pos)
}

Expand Down
13 changes: 13 additions & 0 deletions vlib/v/checker/tests/cast_expr_T_type_err.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
vlib/v/checker/tests/cast_expr_T_type_err.vv:4:9: error: unknown type `A`
2 |
3 | fn main() {
4 | _ = A(0)
| ~~~~
5 | _ = &A(0)
6 | }
vlib/v/checker/tests/cast_expr_T_type_err.vv:5:9: error: unknown type `A`
3 | fn main() {
4 | _ = A(0)
5 | _ = &A(0)
| ~~~~~
6 | }
6 changes: 6 additions & 0 deletions vlib/v/checker/tests/cast_expr_T_type_err.vv
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module main

fn main() {
_ = A(0)
_ = &A(0)
}

0 comments on commit 956102d

Please sign in to comment.