For those who are interested, this is diagnosed at run time because the closure here names a global variable rather than capturing a local variable.
var u = User()
u.setName("Kanga") { u.name = "haha" }
It's an unfortunate distinction between top-level code and code within a function body. To diagnose this statically, the compiler would need to analyze all closure bodies even though they don't mutably capture anything. It's possible to do this, but I'd much rather just not have top-level variable declarations treated like globals--that will always be a source of confusion where the compiler behavior is significantly different.