1
0
mirror of https://github.com/golang/go synced 2024-11-18 23:05:06 -07:00

go.tools/ssa/interp: make typeAssert robust against nil types

R=adonovan
CC=golang-dev
https://golang.org/cl/16180043
This commit is contained in:
Robert Griesemer 2013-10-23 13:45:49 -07:00
parent a1886cc6ef
commit c8f4d650c8

View File

@ -881,13 +881,12 @@ func unop(instr *ssa.UnOp, x value) value {
func typeAssert(i *interpreter, instr *ssa.TypeAssert, itf iface) value {
var v value
err := ""
if idst, ok := instr.AssertedType.Underlying().(*types.Interface); ok {
if itf.t == nil {
err = fmt.Sprintf("interface conversion: interface is nil, not %s", instr.AssertedType)
} else {
v = itf
err = checkInterface(i, idst, itf)
}
if itf.t == nil {
err = fmt.Sprintf("interface conversion: interface is nil, not %s", instr.AssertedType)
} else if idst, ok := instr.AssertedType.Underlying().(*types.Interface); ok {
v = itf
err = checkInterface(i, idst, itf)
} else if types.IsIdentical(itf.t, instr.AssertedType) {
v = copyVal(itf.v) // extract value