Skip to content

Commit

Permalink
[dev.unified] cmd/compile/internal/typecheck: replace unreachable cod…
Browse files Browse the repository at this point in the history
…e with assert

Since the removal of -G=0 mode, IR is always well-typed. And in
well-typed IR, convlit will always returns expressions having real
types (i.e., not untyped).

Change-Id: I1ac99a88c94777829852519347a716d19af7948c
Reviewed-on: https://go-review.googlesource.com/c/go/+/413363
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
  • Loading branch information
mdempsky committed Jun 23, 2022
1 parent 20e1d5a commit c70e93f
Showing 1 changed file with 4 additions and 14 deletions.
18 changes: 4 additions & 14 deletions src/cmd/compile/internal/typecheck/subr.go
Expand Up @@ -301,24 +301,14 @@ func assignconvfn(n ir.Node, t *types.Type, context func() string) ir.Node {

n = convlit1(n, t, false, context)
if n.Type() == nil {
return n
base.Fatalf("cannot assign %v to %v", n, t)
}
if n.Type().IsUntyped() {
base.Fatalf("%L has untyped type", n)
}
if t.Kind() == types.TBLANK {
return n
}

// Convert ideal bool from comparison to plain bool
// if the next step is non-bool (like interface{}).
if n.Type() == types.UntypedBool && !t.IsBoolean() {
if n.Op() == ir.ONAME || n.Op() == ir.OLITERAL {
r := ir.NewConvExpr(base.Pos, ir.OCONVNOP, nil, n)
r.SetType(types.Types[types.TBOOL])
r.SetTypecheck(1)
r.SetImplicit(true)
n = r
}
}

if types.Identical(n.Type(), t) {
return n
}
Expand Down

0 comments on commit c70e93f

Please sign in to comment.