compiler: support pointer dereferencing for structs

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
Evgenii Stratonikov 2020-08-02 14:56:47 +03:00
parent eb047b12a7
commit d54c60ded3
2 changed files with 22 additions and 0 deletions

View file

@ -610,6 +610,16 @@ func (c *codegen) Visit(node ast.Node) ast.Visitor {
c.emitLoadConst(c.typeAndValueOf(n))
return nil
case *ast.StarExpr:
_, ok := c.getStruct(c.typeOf(n.X))
if !ok {
c.prog.Err = errors.New("dereferencing is only supported on structs")
return nil
}
ast.Walk(c, n.X)
c.emitConvert(stackitem.StructT)
return nil
case *ast.Ident:
if tv := c.typeAndValueOf(n); tv.Value != nil {
c.emitLoadConst(tv)