From 7e46c1766dc412043c04abb868d66dd3807290f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Teichgr=C3=A4ber?= Date: Fri, 3 May 2019 15:41:00 +0200 Subject: [PATCH] compiler: fix comp. of func calls for func values of a defined type When compiling a piece of code where a function value is called, the compiler panics if the function value's type is a defined type, and not just a type literal (function signature): The type assertion (*types.Signature) fails, because the type of the func value is a *types.Named. This patch fixes this by using the type's underlying type, so that a types.Named is properly turned into its underlying types.Signature, before the type assertion takes place. It takes advantage of the property that all types have an underlying type (both are the same, if a type is not named). Fixes #320 --- compiler/compiler.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/compiler.go b/compiler/compiler.go index 33ad6308..b06085a8 100644 --- a/compiler/compiler.go +++ b/compiler/compiler.go @@ -1146,7 +1146,7 @@ func (c *Compiler) parseCall(frame *Frame, instr *ssa.CallCommon) (llvm.Value, e value := c.getValue(frame, instr.Value) // This is a func value, which cannot be called directly. We have to // extract the function pointer and context first from the func value. - funcPtr, context, err := c.decodeFuncValue(value, instr.Value.Type().(*types.Signature)) + funcPtr, context, err := c.decodeFuncValue(value, instr.Value.Type().Underlying().(*types.Signature)) if err != nil { return llvm.Value{}, err }