How do I call a function through a member variable?

foo.bar(...) is always parsed as a method call, it never looks for fields. This avoids ambiguity, especially with traits. One can force it to be a field access by separating the call and the field access into two distinct expressions, for example,

let f = self.go;
f(n)

Or, better, just (self.go)(n).

Issue #2392 covers improving these diagnostics.

Leave a Comment