From: Cuong Manh Le Date: Fri, 18 Sep 2020 06:57:04 +0000 (+0700) Subject: cmd/compile: refactoring mixing untyped type logic X-Git-Tag: go1.16beta1~1000 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=06f7e655d1764f5ad57bc14f82326c181c37901c;p=gostls13.git cmd/compile: refactoring mixing untyped type logic 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 Run-TryBot: Cuong Manh Le TryBot-Result: Go Bot Reviewed-by: Matthew Dempsky --- diff --git a/src/cmd/compile/internal/gc/const.go b/src/cmd/compile/internal/gc/const.go index 399d0148bb..c0ed8192d9 100644 --- a/src/cmd/compile/internal/gc/const.go +++ b/src/cmd/compile/internal/gc/const.go @@ -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 diff --git a/src/cmd/compile/internal/gc/typecheck.go b/src/cmd/compile/internal/gc/typecheck.go index 2654177c25..12c99bf48f 100644 --- a/src/cmd/compile/internal/gc/typecheck.go +++ b/src/cmd/compile/internal/gc/typecheck.go @@ -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)