checker: check redefine global 'main' function (#13803)
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')
|
||||||
|
|
|
@ -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 }
|
||||||
|
| ~~~~
|
|
@ -0,0 +1 @@
|
||||||
|
__global main = fn () int { return 22 }
|
Loading…
Reference in New Issue