You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
V version: V 0.2.4 359b674.66a67de OS: windows, Microsoft Windows 10 Enterprise v19042 64-bit
What did you do?
I updates a module of mine vlang-yaml to test it against the latest V version
What did you expect to see?
Run my test cases like v -stats test ., and using -stats to also see all the compiler warnings.
What did you see instead?
The error message is clear: Append ? like so x1.obj["national"]?. See below
What is wrong: Only when indexing a map with a sum type, you need to handle the option (error). If not a sum type, it is not necessary. That is inconsistent. Either the errors must be handle when indexing a map or not. My preference:
x := mymap["a"]
x := mymap["a"] or { mydefault }
x := mymap["a"] or { return error("..") }
step3_reader_test.v:58:15: warning: `or {}` block required when indexing a map with sum type value
56 | assert x2.ar[2] == YamlValue("New York Yankees")
57 | }
58 | x3 := x1.obj["national"]
| ~~~~~~~~~~~~
59 | assert x3 is YamlListValue
60 | if x3 is YamlListValue {
The text was updated successfully, but these errors were encountered:
Yep, this is one of the few exceptions. Allegedly this exception is there to make use of maps easier at the cost of pushing compile-time safety to run-time panic (i.e. also a kind of "safety").
But I don't like this strawman reasoning as we can easily propagate the error with ? (or in the future with ! which though has a different meaning as of now) as in x := mymap["a"]?["b"]?["c"]? which if required by compiler is just one character more than x := mymap["a"]["b"]["c"] and makes it explicit and safe before even executing the resulting app.
We shouldn't also forget about the case if it's an l-value. But that's an old discussion and V lang differs now in a way we could easily use ? or ! as noted above.
Feel free to push harder for this than I'm able to 😉!
V version: V 0.2.4 359b674.66a67de
OS: windows, Microsoft Windows 10 Enterprise v19042 64-bit
What did you do?
I updates a module of mine vlang-yaml to test it against the latest V version
What did you expect to see?
Run my test cases like
v -stats test .
, and using -stats to also see all the compiler warnings.What did you see instead?
The error message is clear: Append
?
like sox1.obj["national"]?
. See belowWhat is wrong: Only when indexing a map with a sum type, you need to handle the option (error). If not a sum type, it is not necessary. That is inconsistent. Either the errors must be handle when indexing a map or not. My preference:
The text was updated successfully, but these errors were encountered: