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
Currently, the compiler does not allow declaring an extension function over maps:
extends fun testFun(self: map<Int,Int>) {
......
}
Hence, the compiler also rejects mutating functions having maps in their self argument:
extends mutates fun testFun(self: map<Int,Int>) {
......
}
Since maps are passed by value, programs like the following do not modify maps:
fun addEntry(m: map<Int,Int>) {
m.set(1, 10);
}
fun testFun() {
let m: map<Int,Int> = emptyMap();
addEntry(m); // After calling addEntry, m is NOT modified, because addEntry created a copy of m.
}
This means that if a user actually wants to modify a map in some function, the user needs to do workarounds like wrapping the map inside a struct and pass it to a mutating function:
Currently, the compiler does not allow declaring an extension function over maps:
Hence, the compiler also rejects mutating functions having maps in their
self
argument:Since maps are passed by value, programs like the following do
not
modify maps:This means that if a user actually wants to modify a map in some function, the user needs to do workarounds like wrapping the map inside a struct and pass it to a mutating function:
It should be possible to pass a map to an extension (and hence mutating) function directly.
The text was updated successfully, but these errors were encountered: