We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 9e3e02d commit d364167Copy full SHA for d364167
1 file changed
doc/docs.md
@@ -1913,6 +1913,13 @@ println(u_name) // John
1913
1914
You can check the current type of a sum type using `is` and its negated form `!is`.
1915
1916
+Note that the variable's declared type stays the sum type itself. In the example
1917
+below, `x` has the static type `Alphabet`, even though the value it holds is an
1918
+`Abc`. Inside an `is` check (or a `match` branch) the compiler automatically
1919
+*smart casts* `x` to the matched variant, so within that block `x` has the static
1920
+type `Abc` and you can access its fields directly and safely, without writing an
1921
+explicit `as` cast.
1922
+
1923
You can do it either in an `if`:
1924
1925
```v cgen
0 commit comments