thanos
thanos copied to clipboard
Add special casing for `has_key?`
Currently has_key?
gets treated like any other method, which means that this Ruby:
if h.has_key?(:foo)
puts "has key foo"
end
gets compiled to this Go:
var hasKey bool
if _, ok := h["foo"]; ok {
hasKey = true
}
if hasKey {
fmt.Println("has key foo")
}
which is less than ideal, since the idiomatic key presence test would be simply
if _, ok := h["foo"]; ok {
fmt.Println("has key foo")
}
Instead, the TransformAST
func for has_key?
should return a ast.BadExpr
and rely on special handling by method name in the compiler.