Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

eval: support arbitrary map types? #3690

Open
firelizzard18 opened this issue Apr 2, 2024 · 2 comments
Open

eval: support arbitrary map types? #3690

firelizzard18 opened this issue Apr 2, 2024 · 2 comments

Comments

@firelizzard18
Copy link

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.

@aarzilli
Copy link
Member

aarzilli commented Apr 2, 2024

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).

@firelizzard18
Copy link
Author

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".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants