docs: add field shadowing comment (#20521)

This commit is contained in:
Steven Gay 2024-01-15 03:24:50 +11:00 committed by GitHub
parent acf75c71da
commit 33598ca005
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -480,7 +480,24 @@ fn main() {
}
}
```
While variable shadowing is not allowed, field shadowing is allowed.
```v
pub struct Dimension {
width int = -1
height int = -1
}
pub struct Test {
Dimension
width int = 100
// height int
}
fn main() {
test := Test{}
println('${test.width} ${test.height} ${test.Dimension.width}') // 100 -1 -1
}
```
## V Types
### Primitive types