doc: mention module shadowing (#7051)
parent
5b6eb7b2c9
commit
4f540e6ac3
14
doc/docs.md
14
doc/docs.md
|
@ -297,11 +297,12 @@ In development mode the compiler will warn you that you haven't used the variabl
|
||||||
In production mode (enabled by passing the `-prod` flag to v – `v -prod foo.v`)
|
In production mode (enabled by passing the `-prod` flag to v – `v -prod foo.v`)
|
||||||
it will not compile at all (like in Go).
|
it will not compile at all (like in Go).
|
||||||
|
|
||||||
|
<!-- this should be `failcompile`, but it compiles -->
|
||||||
```v
|
```v
|
||||||
fn main() {
|
fn main() {
|
||||||
a := 10
|
a := 10
|
||||||
if true {
|
if true {
|
||||||
a := 20 // error: shadowed variable
|
a := 20 // error: redefinition of `a`
|
||||||
}
|
}
|
||||||
// warning: unused variable `a`
|
// warning: unused variable `a`
|
||||||
}
|
}
|
||||||
|
@ -310,6 +311,17 @@ fn main() {
|
||||||
Unlike most languages, variable shadowing is not allowed. Declaring a variable with a name
|
Unlike most languages, variable shadowing is not allowed. Declaring a variable with a name
|
||||||
that is already used in a parent scope will cause a compilation error.
|
that is already used in a parent scope will cause a compilation error.
|
||||||
|
|
||||||
|
You can shadow imported modules though, as it is very useful in some situations:
|
||||||
|
```v ignore
|
||||||
|
import ui
|
||||||
|
import gg
|
||||||
|
|
||||||
|
fn draw(ctx &gg.Context) {
|
||||||
|
gg := ctx.parent.get_ui().gg
|
||||||
|
gg.draw_rect(...)
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
## Types
|
## Types
|
||||||
|
|
||||||
### Primitive types
|
### Primitive types
|
||||||
|
|
|
@ -24,14 +24,14 @@ The code is available <a href='https://github.com/vlang/v/tree/master/tutorials/
|
||||||
|
|
||||||
```
|
```
|
||||||
wget https://github.com/vlang/v/releases/latest/download/linux.zip
|
wget https://github.com/vlang/v/releases/latest/download/linux.zip
|
||||||
unzip linux.zip
|
unzip v_linux.zip
|
||||||
cd v
|
cd v
|
||||||
sudo ./v symlink
|
sudo ./v symlink
|
||||||
```
|
```
|
||||||
|
|
||||||
Now V should be globally available on your system.
|
Now V should be globally available on your system.
|
||||||
|
|
||||||
> On macOS use `macos.zip`, on Windows - `windows.zip`.
|
> On macOS use `v_macos.zip`, on Windows - `v_windows.zip`.
|
||||||
If you use a BSD system, Solaris, Android, or simply want to install V
|
If you use a BSD system, Solaris, Android, or simply want to install V
|
||||||
from source, follow the simple instructions here:
|
from source, follow the simple instructions here:
|
||||||
https://github.com/vlang/v#installing-v-from-source
|
https://github.com/vlang/v#installing-v-from-source
|
||||||
|
|
Loading…
Reference in New Issue