From f0fb1bd41a149592beb489974d06993feb9abdc1 Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Sat, 24 Nov 2018 22:13:01 +0100 Subject: [PATCH] compiler: fix binops on named types in struct fields --- compiler/compiler.go | 4 ++-- testdata/binop.go | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/compiler/compiler.go b/compiler/compiler.go index 1a56c98c1..816f91d8e 100644 --- a/compiler/compiler.go +++ b/compiler/compiler.go @@ -2225,7 +2225,7 @@ func (c *Compiler) parseExpr(frame *Frame, expr ssa.Value) (llvm.Value, error) { if err != nil { return llvm.Value{}, err } - return c.parseBinOp(expr.Op, expr.X.Type().Underlying(), x, y) + return c.parseBinOp(expr.Op, expr.X.Type(), x, y) case *ssa.Call: // Passing the current task here to the subroutine. It is only used when // the subroutine is blocking. @@ -2711,7 +2711,7 @@ func (c *Compiler) parseExpr(frame *Frame, expr ssa.Value) (llvm.Value, error) { } func (c *Compiler) parseBinOp(op token.Token, typ types.Type, x, y llvm.Value) (llvm.Value, error) { - switch typ := typ.(type) { + switch typ := typ.Underlying().(type) { case *types.Basic: if typ.Info()&types.IsInteger != 0 { // Operations on integers diff --git a/testdata/binop.go b/testdata/binop.go index 64a339539..e98545f9a 100644 --- a/testdata/binop.go +++ b/testdata/binop.go @@ -58,8 +58,10 @@ var s2 = Struct2{"foo", 0.0, 5} var a1 = [2]int{1, 2} +type Int int + type Struct1 struct { - i int + i Int b bool }