@@ -271,8 +271,13 @@ func (c *compilerContext) getTypeMethodSet(typ types.Type) llvm.Value {
271271// getInterfaceMethodSet returns a global variable with the method set of the
272272// given named interface type. This method set is used by the interface lowering
273273// pass.
274- func (c * compilerContext ) getInterfaceMethodSet (typ * types.Named ) llvm.Value {
275- global := c .mod .NamedGlobal (typ .String () + "$interface" )
274+ func (c * compilerContext ) getInterfaceMethodSet (typ types.Type ) llvm.Value {
275+ name := typ .String ()
276+ if _ , ok := typ .(* types.Named ); ! ok {
277+ // Anonymous interface.
278+ name = "reflect/types.interface:" + name
279+ }
280+ global := c .mod .NamedGlobal (name + "$interface" )
276281 zero := llvm .ConstInt (c .ctx .Int32Type (), 0 , false )
277282 if ! global .IsNil () {
278283 // method set already exist, return it
@@ -287,7 +292,7 @@ func (c *compilerContext) getInterfaceMethodSet(typ *types.Named) llvm.Value {
287292 }
288293
289294 value := llvm .ConstArray (c .i8ptrType , methods )
290- global = llvm .AddGlobal (c .mod , value .Type (), typ . String () + "$interface" )
295+ global = llvm .AddGlobal (c .mod , value .Type (), name + "$interface" )
291296 global .SetInitializer (value )
292297 global .SetGlobalConstant (true )
293298 global .SetLinkage (llvm .PrivateLinkage )
@@ -329,7 +334,7 @@ func (b *builder) createTypeAssert(expr *ssa.TypeAssert) llvm.Value {
329334 // the main Go compiler, where the runtime checks whether the type
330335 // implements each method of the interface. See:
331336 // https://research.swtch.com/interfaces
332- methodSet := b .getInterfaceMethodSet (expr .AssertedType .( * types. Named ) )
337+ methodSet := b .getInterfaceMethodSet (expr .AssertedType )
333338 commaOk = b .createRuntimeCall ("interfaceImplements" , []llvm.Value {actualTypeNum , methodSet }, "" )
334339
335340 } else {
@@ -402,7 +407,7 @@ func (b *builder) getInvokeCall(instr *ssa.CallCommon) (llvm.Value, []llvm.Value
402407 typecode := b .CreateExtractValue (itf , 0 , "invoke.typecode" )
403408 values := []llvm.Value {
404409 typecode ,
405- b .getInterfaceMethodSet (instr .Value .Type ().( * types. Named ) ),
410+ b .getInterfaceMethodSet (instr .Value .Type ()),
406411 b .getMethodSignature (instr .Method ),
407412 }
408413 fn := b .createRuntimeCall ("interfaceMethod" , values , "invoke.func" )
0 commit comments