From dda9c1cc6e10b554c4eaa8325a2ff9f2cae19626 Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Sun, 21 Oct 2018 01:33:40 +0200 Subject: [PATCH] ir: fix interface call edge case A function on a type that is put in an interface must not be assumed to not need a context pointer when it isn't directly put in a function pointer, because the interface call side won't know this and pass an extra parameter with that extra function pointer. This is usually not a problem but WebAssembly has strict checks on function signatures so this resulted in an error when running src/examples/test/test.go. --- ir/passes.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ir/passes.go b/ir/passes.go index 9955658f..46133a10 100644 --- a/ir/passes.go +++ b/ir/passes.go @@ -416,6 +416,12 @@ func (p *Program) AllInterfaces() []*Interface { func (p *Program) FunctionNeedsContext(f *Function) bool { if !f.addressTaken { + if f.Signature.Recv() != nil { + _, hasInterfaceConversion := p.TypeNum(f.Signature.Recv().Type()) + if hasInterfaceConversion && p.SignatureNeedsContext(f.Signature) { + return true + } + } return false } return p.SignatureNeedsContext(f.Signature)