Skip to content
Please note that GitHub no longer supports your web browser.

We recommend upgrading to the latest Google Chrome or Firefox.

Learn more
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

example in document not work in playground #3043

Open
bronze1man opened this issue Dec 11, 2019 · 3 comments
Open

example in document not work in playground #3043

bronze1man opened this issue Dec 11, 2019 · 3 comments
Assignees
Labels

Comments

@bronze1man
Copy link

@bronze1man bronze1man commented Dec 11, 2019

V version:
OS:
https://vlang.io/play
What did you do?

fn main() {
enum Color {
	red green blue
}

mut color := Color.red
// V knows that `color` is a `Color`. No need to use `color = Color.green` here.
color = .green
println(color) // "1"  TODO: print "green"? 

}

errorMessage:

unexpected token: `}`
    9| println(color) // "1"  TODO: print "green"? 
@vuhg

This comment has been minimized.

Copy link

@vuhg vuhg commented Dec 11, 2019

Following code works, the cause is enum Color that is declared in fn main

enum Color {
  red green blue
}

fn main() {
  mut color := Color.red
  // V knows that `color` is a `Color`. No need to use `color = Color.green` here.
  color = .green
  println(color) // "1"  TODO: print "green"? 
}
@bronze1man

This comment has been minimized.

Copy link
Author

@bronze1man bronze1man commented Dec 11, 2019

@vuhg so it is bad error message. I do not know why it is not working...

@M4SSD35TRUCT10N

This comment has been minimized.

Copy link
Contributor

@M4SSD35TRUCT10N M4SSD35TRUCT10N commented Dec 12, 2019

@medvednikov The above screened behavior seems a bit odd. It's not documented that enums have to be declared outside of functions. I tried some other stuff and declared some enums within a bunch of functions (this time not within main) and get a similar error. Although I did this (declaring them 'standalone') naturally and never thought about this, they are just some kinds of variables aren't they? So one should be able to do the above declaration style. That would limit their scope too - besides pub enum declaration.

I personally think it's a documentation issue to clarify the use of them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.