From 33598ca00508bcf8ef56708d646f95a6a5a78ecc Mon Sep 17 00:00:00 2001 From: Steven Gay Date: Mon, 15 Jan 2024 03:24:50 +1100 Subject: [PATCH] docs: add field shadowing comment (#20521) --- doc/docs.md | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/doc/docs.md b/doc/docs.md index bfc754b9dd..99aa3bbbcb 100644 --- a/doc/docs.md +++ b/doc/docs.md @@ -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 @@ -7308,4 +7325,4 @@ Assignment Operators += -= *= /= %= &= |= ^= >>= <<= >>>= -``` +``` \ No newline at end of file