JuliaLang/julia — pull request #5848 by ihnorton (2014-02-18 15:59:01+00:00)
Title: WIP: change getfield lowering and call overloaded version

Here is an attempt to implement getfield overloading, for #1974.

- [x] changed getfield lowering from quoted symbol to new type Field{:sym}
- [x] change the existing machinery to look inside the Field type for the symbol.
- [x] if a type *does not* have a field, then jl_f_get_field attempts to call an overloaded version.
- [ ] intercept missing field in codegen, check for overloaded version, and emit_call

@JeffBezanson, I suspect this is less general and somewhat inverted from the approach you [outlined](https://github.com/JuliaLang/julia/issues/1974#issuecomment-32226020). If so, I would appreciate any further clarification of how that would fit together (wanted to put in the effort to get familiar with the code before asking..). I finally got past the bootstrap crashes yesterday and now have some basic sense of how to debug inference.jl, so I wouldn't mind plugging away a bit more.

In any case, if this is way off, hopefully it can be considered as an invocation of [Stefan's algorithm](https://github.com/JuliaLang/julia/issues/1974#issuecomment-32216529) :)

```
julia> type Foo
x::Int
end
julia> b = Foo(1)
Foo(1)
julia> b.x
1
julia> getfield(n::Foo, ::Type{Field{:y}}) = println("called Foo.y")
getfield (generic function with 1 method)
julia> b.y
called Foo.y
```