]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: refactoring mixing untyped type logic
authorCuong Manh Le <cuong.manhle.vn@gmail.com>
Fri, 18 Sep 2020 06:57:04 +0000 (13:57 +0700)
committerCuong Manh Le <cuong.manhle.vn@gmail.com>
Fri, 18 Sep 2020 07:56:50 +0000 (07:56 +0000)
defaultlit2 and typecheck use the same logic for getting mixing untyped
type, so move that logic to a function.

This is a followup of CL 255217.

Passes toolstash-check.

Change-Id: Ic0eadb7ed27a2f0f72e2d28fd5438500bf4c79e0
Reviewed-on: https://go-review.googlesource.com/c/go/+/255897
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
src/cmd/compile/internal/gc/const.go
src/cmd/compile/internal/gc/typecheck.go

index 399d0148bb056e454b594f4d8012e1c7fbc1e1c8..c0ed8192d9ce92720df0007dc5d4852c4f8261ee 100644 (file)
@@ -1072,12 +1072,7 @@ func defaultlit2(l *Node, r *Node, force bool) (*Node, *Node) {
                return l, r
        }
 
-       nn := l
-       if ctype(r.Type) > ctype(l.Type) {
-               nn = r
-       }
-
-       t := defaultType(nn.Type)
+       t := defaultType(mixUntyped(l.Type, r.Type))
        l = convlit(l, t)
        r = convlit(r, t)
        return l, r
@@ -1102,6 +1097,14 @@ func ctype(t *types.Type) Ctype {
        panic("unreachable")
 }
 
+func mixUntyped(t1, t2 *types.Type) *types.Type {
+       t := t1
+       if ctype(t2) > ctype(t1) {
+               t = t2
+       }
+       return t
+}
+
 func defaultType(t *types.Type) *types.Type {
        if !t.IsUntyped() || t.Etype == TNIL {
                return t
index 2654177c25bab3096dbec2889e7d66715e31de83..12c99bf48f80cc83c97838894fb1151cb2cb5250 100644 (file)
@@ -717,18 +717,7 @@ func typecheck1(n *Node, top int) (res *Node) {
                }
 
                if t.Etype == TIDEAL {
-                       switch {
-                       case l.Type == types.Idealcomplex || r.Type == types.Idealcomplex:
-                               t = types.Idealcomplex
-                       case l.Type == types.Idealfloat || r.Type == types.Idealfloat:
-                               t = types.Idealfloat
-                       case l.Type == types.Idealrune || r.Type == types.Idealrune:
-                               t = types.Idealrune
-                       case l.Type == types.Idealint || r.Type == types.Idealint:
-                               t = types.Idealint
-                       default:
-                               Fatalf("bad untyped type: %v", t)
-                       }
+                       t = mixUntyped(l.Type, r.Type)
                }
                if dt := defaultType(t); !okfor[op][dt.Etype] {
                        yyerror("invalid operation: %v (operator %v not defined on %v)", n, op, t)