mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: allow x := unsafe { nil }
This commit is contained in:
parent
dc79f1392b
commit
a68d03ac59
@ -191,7 +191,7 @@ pub fn (mut b Builder) ensure_cap(n int) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
new_data := vcalloc(n * b.element_size)
|
new_data := vcalloc(n * b.element_size)
|
||||||
if b.data != voidptr(0) {
|
if b.data != unsafe { nil } {
|
||||||
unsafe { vmemcpy(new_data, b.data, b.len * b.element_size) }
|
unsafe { vmemcpy(new_data, b.data, b.len * b.element_size) }
|
||||||
// TODO: the old data may be leaked when no GC is used (ref-counting?)
|
// TODO: the old data may be leaked when no GC is used (ref-counting?)
|
||||||
if b.flags.has(.noslices) {
|
if b.flags.has(.noslices) {
|
||||||
@ -212,7 +212,7 @@ pub fn (mut b Builder) free() {
|
|||||||
if b.data != 0 {
|
if b.data != 0 {
|
||||||
unsafe { free(b.data) }
|
unsafe { free(b.data) }
|
||||||
unsafe {
|
unsafe {
|
||||||
b.data = voidptr(0)
|
b.data = nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -206,35 +206,35 @@ pub struct Config {
|
|||||||
|
|
||||||
[inline]
|
[inline]
|
||||||
fn (ctx &Context) init() {
|
fn (ctx &Context) init() {
|
||||||
if ctx.cfg.init_fn != voidptr(0) {
|
if ctx.cfg.init_fn != unsafe { nil } {
|
||||||
ctx.cfg.init_fn(ctx.cfg.user_data)
|
ctx.cfg.init_fn(ctx.cfg.user_data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[inline]
|
[inline]
|
||||||
fn (ctx &Context) frame() {
|
fn (ctx &Context) frame() {
|
||||||
if ctx.cfg.frame_fn != voidptr(0) {
|
if ctx.cfg.frame_fn != unsafe { nil } {
|
||||||
ctx.cfg.frame_fn(ctx.cfg.user_data)
|
ctx.cfg.frame_fn(ctx.cfg.user_data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[inline]
|
[inline]
|
||||||
fn (ctx &Context) cleanup() {
|
fn (ctx &Context) cleanup() {
|
||||||
if ctx.cfg.cleanup_fn != voidptr(0) {
|
if ctx.cfg.cleanup_fn != unsafe { nil } {
|
||||||
ctx.cfg.cleanup_fn(ctx.cfg.user_data)
|
ctx.cfg.cleanup_fn(ctx.cfg.user_data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[inline]
|
[inline]
|
||||||
fn (ctx &Context) fail(error string) {
|
fn (ctx &Context) fail(error string) {
|
||||||
if ctx.cfg.fail_fn != voidptr(0) {
|
if ctx.cfg.fail_fn != unsafe { nil } {
|
||||||
ctx.cfg.fail_fn(error)
|
ctx.cfg.fail_fn(error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[inline]
|
[inline]
|
||||||
fn (ctx &Context) event(event &Event) {
|
fn (ctx &Context) event(event &Event) {
|
||||||
if ctx.cfg.event_fn != voidptr(0) {
|
if ctx.cfg.event_fn != unsafe { nil } {
|
||||||
ctx.cfg.event_fn(event, ctx.cfg.user_data)
|
ctx.cfg.event_fn(event, ctx.cfg.user_data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -812,7 +812,7 @@ pub fn (mut t Table) register_builtin_type_symbols() {
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
t.register_sym(kind: .interface_, name: 'IError', cname: 'IError', mod: 'builtin')
|
t.register_sym(kind: .interface_, name: 'IError', cname: 'IError', mod: 'builtin')
|
||||||
t.register_sym(kind: .voidptr, name: 'nil', cname: 'nil', mod: 'builtin')
|
t.register_sym(kind: .voidptr, name: 'nil', cname: 'voidptr', mod: 'builtin')
|
||||||
}
|
}
|
||||||
|
|
||||||
[inline]
|
[inline]
|
||||||
|
@ -222,7 +222,8 @@ pub fn (mut c Checker) assign_stmt(mut node ast.AssignStmt) {
|
|||||||
}
|
}
|
||||||
if right is ast.Nil {
|
if right is ast.Nil {
|
||||||
// `x := unsafe { nil }` is allowed
|
// `x := unsafe { nil }` is allowed
|
||||||
c.error('use of untyped nil in assignment', right.pos())
|
c.error('use of untyped nil in assignment (use `unsafe`)',
|
||||||
|
right.pos())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mut ident_var_info := left.info as ast.IdentVar
|
mut ident_var_info := left.info as ast.IdentVar
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
vlib/v/checker/tests/nil.vv:3:18: error: use of untyped nil in assignment
|
vlib/v/checker/tests/nil.vv:3:18: error: use of untyped nil in assignment (use `unsafe`)
|
||||||
1 | fn main() {
|
1 | fn main() {
|
||||||
2 | unsafe {
|
2 | unsafe {
|
||||||
3 | value := nil
|
3 | value := nil
|
||||||
|
Loading…
x
Reference in New Issue
Block a user