Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
felipensp committed Nov 2, 2023
1 parent 705eea8 commit 7fde202
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions vlib/v/checker/assign.v
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,9 @@ fn (mut c Checker) assign_stmt(mut node ast.AssignStmt) {
}
}
}
if left_type.has_flag(.option) && right is ast.UnsafeExpr {
c.error('cannot assign `nil` to option value', right.pos())
}
}
else {
if mut left is ast.IndexExpr {
Expand Down
4 changes: 4 additions & 0 deletions vlib/v/checker/struct.v
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,10 @@ fn (mut c Checker) struct_decl(mut node ast.StructDecl) {
c.warn('unnecessary default value of `none`: struct fields are zeroed by default',
field.default_expr.pos)
}
if field.typ.has_flag(.option) && field.default_expr.is_nil() {
c.error('cannot assign `nil` to option value',
field.default_expr.pos())
}
continue
}
if field.typ in ast.unsigned_integer_type_idxs {
Expand Down

0 comments on commit 7fde202

Please sign in to comment.