eval: support arbitrary map types?
firelizzard18 opened this issue · comments
Adding something like this:
if mtyp, ok := expr.(*ast.MapType); ok {
keyTyp, err := bi.findTypeExpr(mtyp.Key)
if err != nil {
return nil, err
}
elemTyp, err := bi.findTypeExpr(mtyp.Value)
if err != nil {
return nil, err
}
typ := new(godwarf.MapType)
typ.KeyType = keyTyp
typ.ElemType = elemTyp
typ.Name = fmt.Sprintf("map[%v]%v", keyTyp, elemTyp)
typ.Type = typ
return typ, nil
}
to (*BinaryInfo).findTypeExpr
would allow evaluating arbitrary map types. I can't think of a scenario where this would matter, but it also seems a bit odd that evaluating a map[Key]Value
expression will fail if that specific type does not exist in the DWARF section.
Why would we do this? To have a better error when doing type assertions to map types? If there is a way to successfully use this constructed type (for example by using typecasts) it will be impossible to do anything with it because the Type field needs to be a StructType with an actual description of the hashtable's layout (the typ.Type = typ
line is wrong).
It was just something that I ran into while I was working on #3691. As I said, I can't think of a scenario where this would matter. I'm fine with closing this, unless you think it's worth the added complexity to return a better error; e.g. if findType
returns an error and the expression is a MapType, return "I can't make that map" or something instead of "I can't find that type".