Skip to content
Discussion options

You must be logged in to vote

It is a very explicit error, which is happening because you have a := 10 before the function definitions. In script mode, all functions, structs, etc. must occur before the first "code" (which in this case is just declaring a variable.

Your example:

module main

a := 10

fn main_a() {

	a := 10
	println('Hello World!')
}

fn main_b() {
	a := 10

}

gives the following:

$ v run x.v
x.v:3:1: notice: script mode started here
    1 | module main
    2 | 
    3 | a := 10
      | ^
    4 | 
    5 | fn main_a() {
x.v:5:4: error: all definitions must occur before code in script mode
    3 | a := 10
    4 | 
    5 | fn main_a() {
      |    ~~~~~~
    6 | 
    7 |     a := 10
$

while just moving t…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@foliagetree23
Comment options

@JalonSolov
Comment options

Answer selected by foliagetree23
@foliagetree23
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants