Skip to content

bug in handling of embedding plus interfaces with non-exported methods #1536

@gopherbot

Description

@gopherbot

by daveroundy:

====================
package hiding

type Public interface {
    private()
}

type PublicType struct{}
func (p *PublicType) private() {
    // This should do something private
}
====================
package main

import (
    "hiding"
)

type MyPublic struct {
    hiding.PublicType
}

func MakeMyPublic() hiding.Public {
    return &MyPublic{ hiding.PublicType{} }
}

func main() {
    MakeMyPublic()
}
====================

These compile fine, but die at runtime with:

bin/main 
panic: interface conversion: *main.MyPublic is not hiding.Public: missing method private

runtime.panic+0xa7 /mnt/home/droundy/src/go/src/pkg/runtime/proc.c:1023
    runtime.panic(0x410398, 0xf840014000)
itab+0xff /mnt/home/droundy/src/go/src/pkg/runtime/iface.c:125
    itab(0x410bf0, 0x410130, 0x100000000, 0x1, 0x0, ...)
runtime.convT2I+0x55 /mnt/home/droundy/src/go/src/pkg/runtime/iface.c:192
    runtime.convT2I(0x410130, 0x410bf0, 0xf840000000, 0x40bb5a)
main.MakeMyPublic+0x43 /tmp/bug-test/main.go:12
    main.MakeMyPublic(0x4279f8, 0x0)
main.main+0x1c /tmp/bug-test/main.go:16
    main.main()
runtime.mainstart+0xf /mnt/home/droundy/src/go/src/pkg/runtime/amd64/asm.s:77
    runtime.mainstart()
runtime.goexit /mnt/home/droundy/src/go/src/pkg/runtime/proc.c:149
    runtime.goexit()

This should either be a compile-time failure or should be fine at runtime.  I'd prefer
the latter.

Attachments:

  1. hiding.go (151 bytes)
  2. main.go (193 bytes)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions