-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Map key becomes "valid/existing" after value lookup #247
Comments
@luauser32167 This is the intended behavior, similar to that of |
This is a bit surprising... Basically it has the following semantics: m1 := map[int]str;
printf("%s\n", m1[69105]); // "" (empty string, because the default value is zero initialized)
mapsetdefault(m1, "leaves");
printf("%s\n", m1[69105]); // "leaves"
printf("%s\n", repr(m1)); // { } (no keys)
type Point = struct { x, y: int };
m2 := map[str]Point;
m2["origin"].x = 10; // sets the default value's 'x' field to 10 (because the key "origin" was not found)
printf("%s\n", repr(m2)); // { } (no keys)
m2["origin"] = Point{10, 20};
printf("%s\n", repr(m2)); // { "origin": Point{x: 10, y: 20} } (now has 1 key called "origin")
printf("%d\n", mapgetdefalut(m2).x); // the default value's 'x' field is still 10 |
@luauser32167 The following is even more surprising for me than having
Assigning Here is what C++ is doing: https://www.onlinegdb.com/_2_bEnIeRK. |
The text was updated successfully, but these errors were encountered: