cmd/compile: remove types.Type.SetBroken

And use base.Fatalf in code that use t.SetBroke(true) instead.

Updates #51691

Change-Id: I9f3613379dd82d0dd069cdf7b61cbb281810e2e3
Reviewed-on: https://go-review.googlesource.com/c/go/+/394574
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
This commit is contained in:
Cuong Manh Le 2022-03-22 20:43:43 +07:00
parent 7e0a1d340f
commit 515135f4c3
3 changed files with 8 additions and 33 deletions

View file

@ -404,31 +404,16 @@ func typecheck(n ir.Node, top int) (res ir.Node) {
// this code a bit, especially the final case.
switch {
case top&(ctxStmt|ctxExpr) == ctxExpr && !isExpr && n.Op() != ir.OTYPE && !isMulti:
base.Errorf("%v used as value", n)
n.SetDiag(true)
if t != nil {
n.SetType(nil)
}
base.Fatalf("%v used as value", n)
case top&ctxType == 0 && n.Op() == ir.OTYPE && t != nil:
base.Errorf("type %v is not an expression", n.Type())
n.SetDiag(true)
base.Fatalf("type %v is not an expression", n.Type())
case top&(ctxStmt|ctxExpr) == ctxStmt && !isStmt && t != nil:
base.Errorf("%v evaluated but not used", n)
n.SetDiag(true)
n.SetType(nil)
base.Fatalf("%v evaluated but not used", n)
case top&(ctxType|ctxExpr) == ctxType && n.Op() != ir.OTYPE && n.Op() != ir.ONONAME && (t != nil || n.Op() == ir.ONAME):
base.Errorf("%v is not a type", n)
if t != nil {
if n.Op() == ir.ONAME {
t.SetBroke(true)
} else {
n.SetType(nil)
}
}
base.Fatalf("%v is not a type", n)
}
base.Pos = lno

View file

@ -132,15 +132,7 @@ func expandiface(t *Type) {
if AllowsGoVersion(t.Pkg(), 1, 18) {
continue
}
base.ErrorfAt(m.Pos, "interface contains embedded non-interface, non-union %v", m.Type)
m.SetBroke(true)
t.SetBroke(true)
// Add to fields so that error messages
// include the broken embedded type when
// printing t.
// TODO(mdempsky): Revisit this.
methods = append(methods, m)
continue
base.FatalfAt(m.Pos, "interface contains embedded non-interface, non-union %v", m.Type)
}
// Embedded interface: duplicate all methods
@ -268,7 +260,6 @@ func CalcSize(t *Type) {
}
if CalcSizeDisabled {
t.SetBroke(true)
base.Fatalf("width not calculated: %v", t)
}

View file

@ -229,7 +229,6 @@ func (t *Type) IsShape() bool { return t.flags&typeIsShape != 0 }
func (t *Type) HasShape() bool { return t.flags&typeHasShape != 0 }
func (t *Type) SetNotInHeap(b bool) { t.flags.set(typeNotInHeap, b) }
func (t *Type) SetBroke(b bool) { base.Assertf(!b, "SetBroke") }
func (t *Type) SetNoalg(b bool) { t.flags.set(typeNoalg, b) }
func (t *Type) SetDeferwidth(b bool) { t.flags.set(typeDeferwidth, b) }
func (t *Type) SetRecur(b bool) { t.flags.set(typeRecur, b) }
@ -796,7 +795,7 @@ func NewField(pos src.XPos, sym *Sym, typ *Type) *Field {
Offset: BADWIDTH,
}
if typ == nil {
f.SetBroke(true)
base.Fatalf("typ is nil")
}
return f
}
@ -1855,7 +1854,7 @@ func NewInterface(pkg *Pkg, methods []*Field, implicit bool) *Type {
}
}
if anyBroke(methods) {
t.SetBroke(true)
base.Fatalf("type contain broken method: %v", methods)
}
t.extra.(*Interface).pkg = pkg
t.extra.(*Interface).implicit = implicit
@ -1996,7 +1995,7 @@ func NewStruct(pkg *Pkg, fields []*Field) *Type {
t := newType(TSTRUCT)
t.SetFields(fields)
if anyBroke(fields) {
t.SetBroke(true)
base.Fatalf("struct contains broken field: %v", fields)
}
t.extra.(*Struct).pkg = pkg
if fieldsHasTParam(fields) {