mirror of
https://github.com/golang/go
synced 2024-11-18 17:54:57 -07:00
go.tools/ssa: emit ChangeType when using method as function in f := T.meth.
Previously: typeOf(f).Signature.Recv == T Now: typeOf(f).Signature.Params.At(0) == T Added test. BUG=5781 R=gri CC=golang-dev https://golang.org/cl/10622043
This commit is contained in:
parent
b68a029040
commit
86b0a65b65
@ -735,7 +735,7 @@ func (b *builder) expr(fn *Function, e ast.Expr) Value {
|
||||
id := MakeId(e.Sel.Name, fn.Pkg.Types)
|
||||
typ := fn.Pkg.typeOf(e.X)
|
||||
if m := fn.Prog.MethodSet(typ)[id]; m != nil {
|
||||
return m
|
||||
return emitConv(fn, m, fn.Pkg.typeOf(e))
|
||||
}
|
||||
|
||||
// T must be an interface; return wrapper.
|
||||
|
@ -124,8 +124,7 @@ func isValuePreserving(ut_src, ut_dst types.Type) bool {
|
||||
return ok
|
||||
|
||||
case *types.Signature:
|
||||
// Conversion between f(T) function and (T) func f() method?
|
||||
// TODO(adonovan): is this sound? Discuss with gri.
|
||||
// Conversion from (T) func f() method to f(T) function?
|
||||
_, ok := ut_src.(*types.Signature)
|
||||
return ok
|
||||
}
|
||||
|
11
ssa/interp/testdata/boundmeth.go
vendored
11
ssa/interp/testdata/boundmeth.go
vendored
@ -79,10 +79,21 @@ func anonStruct() {
|
||||
assert(get() == 3)
|
||||
}
|
||||
|
||||
func typeCheck() {
|
||||
var i interface{}
|
||||
i = (*S).incr
|
||||
_ = i.(func(*S)) // type assertion: receiver type prepended to params
|
||||
|
||||
var s S
|
||||
i = s.incr
|
||||
_ = i.(func()) // type assertion: receiver type disappears
|
||||
}
|
||||
|
||||
func main() {
|
||||
valueReceiver()
|
||||
pointerReceiver()
|
||||
addressibleValuePointerReceiver()
|
||||
promotedReceiver()
|
||||
anonStruct()
|
||||
typeCheck()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user