mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: check redefine global 'main' function (#13803)
This commit is contained in:
parent
894080b844
commit
0337882240
@ -2097,6 +2097,10 @@ fn (mut c Checker) global_decl(mut node ast.GlobalDecl) {
|
|||||||
c.error('unknown type `$sym.name`', field.typ_pos)
|
c.error('unknown type `$sym.name`', field.typ_pos)
|
||||||
}
|
}
|
||||||
if field.has_expr {
|
if field.has_expr {
|
||||||
|
if field.expr is ast.AnonFn && field.name == 'main' {
|
||||||
|
c.error('the `main` function is the program entry point, cannot redefine it',
|
||||||
|
field.pos)
|
||||||
|
}
|
||||||
field.typ = c.expr(field.expr)
|
field.typ = c.expr(field.expr)
|
||||||
mut v := c.file.global_scope.find_global(field.name) or {
|
mut v := c.file.global_scope.find_global(field.name) or {
|
||||||
panic('internal compiler error - could not find global in scope')
|
panic('internal compiler error - could not find global in scope')
|
||||||
|
3
vlib/v/checker/tests/globals/redefine_main.out
Normal file
3
vlib/v/checker/tests/globals/redefine_main.out
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
vlib/v/checker/tests/globals/redefine_main.vv:1:10: error: the `main` function is the program entry point, cannot redefine it
|
||||||
|
1 | __global main = fn () int { return 22 }
|
||||||
|
| ~~~~
|
1
vlib/v/checker/tests/globals/redefine_main.vv
Normal file
1
vlib/v/checker/tests/globals/redefine_main.vv
Normal file
@ -0,0 +1 @@
|
|||||||
|
__global main = fn () int { return 22 }
|
Loading…
x
Reference in New Issue
Block a user