]> Cypherpunks repositories - gostls13.git/commitdiff
go/types, types2: remove unreachable func (minor cleanup)
authorRobert Griesemer <gri@golang.org>
Thu, 22 Feb 2024 19:00:31 +0000 (11:00 -0800)
committerGopher Robot <gobot@golang.org>
Thu, 22 Feb 2024 19:32:17 +0000 (19:32 +0000)
In some places we can't use unreachable() because it does
not terminate control flow and we need to resort to panic.
Be consistent and just use panic("unreachable") everywhere.
This also opens the door to reporting more specific panic
messages.

Mechanical change: s/unreachable()/panic("unreachable")/

Minor cleanup for better consistency.

Change-Id: I6b52af7c21dcfaa1ca19839d14040552db5d4cb4
Reviewed-on: https://go-review.googlesource.com/c/go/+/566135
Auto-Submit: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Robert Findley <rfindley@google.com>
38 files changed:
src/cmd/compile/internal/types2/builtins.go
src/cmd/compile/internal/types2/call.go
src/cmd/compile/internal/types2/check.go
src/cmd/compile/internal/types2/const.go
src/cmd/compile/internal/types2/decl.go
src/cmd/compile/internal/types2/errors.go
src/cmd/compile/internal/types2/expr.go
src/cmd/compile/internal/types2/gcsizes.go
src/cmd/compile/internal/types2/lookup.go
src/cmd/compile/internal/types2/operand.go
src/cmd/compile/internal/types2/predicates.go
src/cmd/compile/internal/types2/return.go
src/cmd/compile/internal/types2/selection.go
src/cmd/compile/internal/types2/signature.go
src/cmd/compile/internal/types2/sizes.go
src/cmd/compile/internal/types2/stmt.go
src/cmd/compile/internal/types2/subst.go
src/cmd/compile/internal/types2/typexpr.go
src/cmd/compile/internal/types2/universe.go
src/go/types/builtins.go
src/go/types/call.go
src/go/types/check.go
src/go/types/const.go
src/go/types/decl.go
src/go/types/errors.go
src/go/types/expr.go
src/go/types/gcsizes.go
src/go/types/lookup.go
src/go/types/operand.go
src/go/types/predicates.go
src/go/types/return.go
src/go/types/selection.go
src/go/types/signature.go
src/go/types/sizes.go
src/go/types/stmt.go
src/go/types/subst.go
src/go/types/typexpr.go
src/go/types/universe.go

index 79ed6ad640f0ef2144d9f424807afc5986d0866f..a87474ad6c1d31adadec4d95939287f53cb23ee7 100644 (file)
@@ -908,7 +908,7 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) (
                // trace is only available in test mode - no need to record signature
 
        default:
-               unreachable()
+               panic("unreachable")
        }
 
        assert(x.mode != invalid)
@@ -947,7 +947,7 @@ func hasVarSize(t Type, seen map[*Named]bool) (varSized bool) {
        case *Interface:
                return isTypeParam(t)
        case *Named, *Union:
-               unreachable()
+               panic("unreachable")
        }
        return false
 }
@@ -990,7 +990,7 @@ func (check *Checker) applyTypeFunc(f func(Type) Type, x *operand, id builtinId)
                case _Complex:
                        code = InvalidComplex
                default:
-                       unreachable()
+                       panic("unreachable")
                }
                check.softErrorf(x, code, "%s not supported as argument to %s for go1.18 (see go.dev/issue/50937)", x, predeclaredFuncs[id].name)
 
index 7e4cf8974ffcea56d636e81ba2696fc2589f0bfe..55400d436c2c753a1988c9b13c2aa409fbe0c35e 100644 (file)
@@ -757,7 +757,7 @@ func (check *Checker) selector(x *operand, e *syntax.SelectorExpr, def *TypeName
                                x.id = exp.id
                        default:
                                check.dump("%v: unexpected object %v", atPos(e.Sel), exp)
-                               unreachable()
+                               panic("unreachable")
                        }
                        x.expr = e
                        return
@@ -910,7 +910,7 @@ func (check *Checker) selector(x *operand, e *syntax.SelectorExpr, def *TypeName
                        check.addDeclDep(obj)
 
                default:
-                       unreachable()
+                       panic("unreachable")
                }
        }
 
index 058236708329df1a435c4923a329b9067f2513b6..8c2bac2850693c4047f04100e69c87d4d5171f8a 100644 (file)
@@ -513,7 +513,7 @@ func (check *Checker) recordUntyped() {
        for x, info := range check.untyped {
                if debug && isTyped(info.typ) {
                        check.dump("%v: %s (type %s) is typed", atPos(x), x, info.typ)
-                       unreachable()
+                       panic("unreachable")
                }
                check.recordTypeAndValue(x, info.mode, info.typ, info.val)
        }
@@ -578,7 +578,7 @@ func (check *Checker) recordBuiltinType(f syntax.Expr, sig *Signature) {
                case *syntax.ParenExpr:
                        f = p.X
                default:
-                       unreachable()
+                       panic("unreachable")
                }
        }
 }
index af27c727dd2e70d68a3ddbad2e9ee69875d0f7c9..5e5bc74ba34ed6081225e399b242ae106c309aed 100644 (file)
@@ -118,7 +118,7 @@ func representableConst(x constant.Value, check *Checker, typ *Basic, rounded *c
                        case Uint64:
                                return 0 <= x
                        default:
-                               unreachable()
+                               panic("unreachable")
                        }
                }
                // x does not fit into int64
@@ -159,7 +159,7 @@ func representableConst(x constant.Value, check *Checker, typ *Basic, rounded *c
                case UntypedFloat:
                        return true
                default:
-                       unreachable()
+                       panic("unreachable")
                }
 
        case isComplex(typ):
@@ -191,7 +191,7 @@ func representableConst(x constant.Value, check *Checker, typ *Basic, rounded *c
                case UntypedComplex:
                        return true
                default:
-                       unreachable()
+                       panic("unreachable")
                }
 
        case isString(typ):
index f3e3418f4fd5f9ba7fb0268b49a0836e17789787..4408a0b16810c41144cdd272687a4cb06afc86f0 100644 (file)
@@ -162,7 +162,7 @@ func (check *Checker) objDecl(obj Object, def *TypeName) {
                        }
 
                default:
-                       unreachable()
+                       panic("unreachable")
                }
                assert(obj.Type() != nil)
                return
@@ -171,7 +171,7 @@ func (check *Checker) objDecl(obj Object, def *TypeName) {
        d := check.objMap[obj]
        if d == nil {
                check.dump("%v: %s should have been declared", obj.Pos(), obj)
-               unreachable()
+               panic("unreachable")
        }
 
        // save/restore current environment and set up object environment
@@ -202,7 +202,7 @@ func (check *Checker) objDecl(obj Object, def *TypeName) {
                // functions may be recursive - no need to track dependencies
                check.funcDecl(obj, d)
        default:
-               unreachable()
+               panic("unreachable")
        }
 }
 
@@ -216,7 +216,7 @@ func (check *Checker) validCycle(obj Object) (valid bool) {
                isPkgObj := obj.Parent() == check.pkg.scope
                if isPkgObj != inObjMap {
                        check.dump("%v: inconsistent object map for %s (isPkgObj = %v, inObjMap = %v)", obj.Pos(), obj, isPkgObj, inObjMap)
-                       unreachable()
+                       panic("unreachable")
                }
        }
 
@@ -266,7 +266,7 @@ loop:
                case *Func:
                        // ignored for now
                default:
-                       unreachable()
+                       panic("unreachable")
                }
        }
 
index 4326ca67ef9d8ab8c29959f52d56217d662e8671..e7d8863c6f51d6b45f2684f83a38a6e7014a77ec 100644 (file)
@@ -28,10 +28,6 @@ func assert(p bool) {
        }
 }
 
-func unreachable() {
-       panic("unreachable")
-}
-
 // An error_ represents a type-checking error.
 // To report an error_, call Checker.report.
 type error_ struct {
index d7d60cc73cb6227e85228bc8caf9aeefb0334027..ca499a17a9f58b783f5cc48b572733e8a95d5b96 100644 (file)
@@ -268,7 +268,7 @@ func (check *Checker) updateExprType0(parent, x syntax.Expr, typ Type, final boo
                // upon assignment or use.
                if debug {
                        check.dump("%v: found old type(%s): %s (new: %s)", atPos(x), x, old.typ, typ)
-                       unreachable()
+                       panic("unreachable")
                }
                return
 
@@ -337,7 +337,7 @@ func (check *Checker) updateExprType0(parent, x syntax.Expr, typ Type, final boo
                }
 
        default:
-               unreachable()
+               panic("unreachable")
        }
 
        // If the new type is not final and still untyped, just
@@ -546,7 +546,7 @@ func (check *Checker) comparison(x, y *operand, op syntax.Operator, switchCase b
                }
 
        default:
-               unreachable()
+               panic("unreachable")
        }
 
        // comparison is ok
@@ -1042,7 +1042,7 @@ func (check *Checker) exprInternal(T *target, x *operand, e syntax.Expr, hint Ty
 
        switch e := e.(type) {
        case nil:
-               unreachable()
+               panic("unreachable")
 
        case *syntax.BadExpr:
                goto Error // error was reported before
@@ -1654,7 +1654,7 @@ func (check *Checker) exclude(x *operand, modeset uint) {
                        msg = "%s is not an expression"
                        code = NotAnExpr
                default:
-                       unreachable()
+                       panic("unreachable")
                }
                check.errorf(x, code, msg, x)
                x.mode = invalid
index d204d9feef028975cc45036eacea939cac87c9fb..15f3e006425ade842f3139fda9c2de6f9023cdca 100644 (file)
@@ -56,7 +56,7 @@ func (s *gcSizes) Alignof(T Type) (result int64) {
                        return s.WordSize
                }
        case *TypeParam, *Union:
-               unreachable()
+               panic("unreachable")
        }
        a := s.Sizeof(T) // may be 0 or negative
        // spec: "For a variable x of any type: unsafe.Alignof(x) is at least 1."
@@ -154,7 +154,7 @@ func (s *gcSizes) Sizeof(T Type) int64 {
                assert(!isTypeParam(T))
                return s.WordSize * 2
        case *TypeParam, *Union:
-               unreachable()
+               panic("unreachable")
        }
        return s.WordSize // catch-all
 }
index 5aa8091a5c2bd617ab6274de4204f4b40f9894ff..3583a48407c6eb6b2a86b9364dc91b51a81ffc6f 100644 (file)
@@ -472,7 +472,7 @@ func (check *Checker) missingMethod(V, T Type, static bool, equivalent func(x, y
                case field:
                        *cause = check.sprintf("(%s.%s is a field, not a method)", V, m.Name())
                default:
-                       unreachable()
+                       panic("unreachable")
                }
        }
 
index 193231794f9b37808e105a408c3fabfbc37569ed..15ec86fb5eca33c5d5c972ab3591bfc6e503df99 100644 (file)
@@ -226,7 +226,7 @@ func (x *operand) setConst(k syntax.LitKind, lit string) {
        case syntax.StringLit:
                kind = UntypedString
        default:
-               unreachable()
+               panic("unreachable")
        }
 
        val := makeFromLiteral(lit, k)
index bb2b53a9425bd7732c9e14d434a6349c4a0ff0a1..938f8dcf8b78bbfa92350cc139f9e7e3e2271c0d 100644 (file)
@@ -477,7 +477,7 @@ func (c *comparer) identical(x, y Type, p *ifacePair) bool {
                // avoid a crash in case of nil type
 
        default:
-               unreachable()
+               panic("unreachable")
        }
 
        return false
index 01988b012e1356c0210e4f9a24246a98457063c3..4e9988755cbeff72406b56d8eb2537a69a22897e 100644 (file)
@@ -16,7 +16,7 @@ import (
 func (check *Checker) isTerminating(s syntax.Stmt, label string) bool {
        switch s := s.(type) {
        default:
-               unreachable()
+               panic("unreachable")
 
        case *syntax.DeclStmt, *syntax.EmptyStmt, *syntax.SendStmt,
                *syntax.AssignStmt, *syntax.CallStmt:
@@ -108,7 +108,7 @@ func (check *Checker) isTerminatingSwitch(body []*syntax.CaseClause, label strin
 func hasBreak(s syntax.Stmt, label string, implicit bool) bool {
        switch s := s.(type) {
        default:
-               unreachable()
+               panic("unreachable")
 
        case *syntax.DeclStmt, *syntax.EmptyStmt, *syntax.ExprStmt,
                *syntax.SendStmt, *syntax.AssignStmt, *syntax.CallStmt,
index dfbf3a0191c1e457f6434c9dc519b68cada06687..2d882b2ee4470ad8f71af5e28947dab6c80dc60f 100644 (file)
@@ -163,7 +163,7 @@ func SelectionString(s *Selection, qf Qualifier) string {
        case MethodExpr:
                k = "method expr "
        default:
-               unreachable()
+               panic("unreachable")
        }
        var buf bytes.Buffer
        buf.WriteString(k)
index 18a64ec1a0a9d3943d28ecca17916e26fa50c840..72b57bc8429860fb941836d79c9daf3b1c332fee 100644 (file)
@@ -247,7 +247,7 @@ func (check *Checker) funcType(sig *Signature, recvPar *syntax.Field, tparams []
                                case *TypeParam:
                                        // The underlying type of a receiver base type cannot be a
                                        // type parameter: "type T[P any] P" is not a valid declaration.
-                                       unreachable()
+                                       panic("unreachable")
                                }
                                if cause != "" {
                                        check.errorf(recv, InvalidRecv, "invalid receiver type %s (%s)", rtyp, cause)
index 486c05c61c7490bd495f25ced951b450d7129afd..7d20c97010caccb5db29a7e50458a1f720befe62 100644 (file)
@@ -94,7 +94,7 @@ func (s *StdSizes) Alignof(T Type) (result int64) {
                        return s.WordSize
                }
        case *TypeParam, *Union:
-               unreachable()
+               panic("unreachable")
        }
        a := s.Sizeof(T) // may be 0 or negative
        // spec: "For a variable x of any type: unsafe.Alignof(x) is at least 1."
@@ -221,7 +221,7 @@ func (s *StdSizes) Sizeof(T Type) int64 {
                assert(!isTypeParam(T))
                return s.WordSize * 2
        case *TypeParam, *Union:
-               unreachable()
+               panic("unreachable")
        }
        return s.WordSize // catch-all
 }
index 272636ff39f8f8fb8d0604046a7da5c16d0c0b8b..0ec5829ee4bb56f28cdfba2483d820ac7b2ba473 100644 (file)
@@ -186,7 +186,7 @@ func (check *Checker) suspendedCall(keyword string, call syntax.Expr) {
        case statement:
                return
        default:
-               unreachable()
+               panic("unreachable")
        }
        check.errorf(&x, code, "%s %s %s", keyword, msg, &x)
 }
index 1ad73c41ce1f08df4e91adf5d864880d703a7211..fa636a1e1ef19608e3427f051212204be0d636f3 100644 (file)
@@ -283,7 +283,7 @@ func (subst *subster) typ(typ Type) Type {
                return subst.smap.lookup(t)
 
        default:
-               unreachable()
+               panic("unreachable")
        }
 
        return typ
index d131306a142c6921002ee1e4ffc15c93ac40b622..be7c306a8d8ee5d7e47b5b2d413b4d7373192deb 100644 (file)
@@ -139,7 +139,7 @@ func (check *Checker) ident(x *operand, e *syntax.Name, def *TypeName, wantType
                x.mode = nilvalue
 
        default:
-               unreachable()
+               panic("unreachable")
        }
 
        x.typ = typ
index c8be81b9ebe708889b8a594ca225695dcf5f0544..8e1e4a2bb78c6a032129fa3d8bfe86d33a3ca42d 100644 (file)
@@ -279,7 +279,7 @@ func def(obj Object) {
                case *Builtin:
                        obj.pkg = Unsafe
                default:
-                       unreachable()
+                       panic("unreachable")
                }
        }
        if scope.Insert(obj) != nil {
index 040b24f5ccb58062ea041206b20672655bbc7180..6519fa302ab34c33e775adeb27f06d411491d8ab 100644 (file)
@@ -910,7 +910,7 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
                // trace is only available in test mode - no need to record signature
 
        default:
-               unreachable()
+               panic("unreachable")
        }
 
        assert(x.mode != invalid)
@@ -949,7 +949,7 @@ func hasVarSize(t Type, seen map[*Named]bool) (varSized bool) {
        case *Interface:
                return isTypeParam(t)
        case *Named, *Union:
-               unreachable()
+               panic("unreachable")
        }
        return false
 }
@@ -992,7 +992,7 @@ func (check *Checker) applyTypeFunc(f func(Type) Type, x *operand, id builtinId)
                case _Complex:
                        code = InvalidComplex
                default:
-                       unreachable()
+                       panic("unreachable")
                }
                check.softErrorf(x, code, "%s not supported as argument to %s for go1.18 (see go.dev/issue/50937)", x, predeclaredFuncs[id].name)
 
index dcd833d23c03c609b9eefe3e06f34d9682deeb1d..b7775f6c6b84ab546e9612f48c9c148e2fd69ffe 100644 (file)
@@ -758,7 +758,7 @@ func (check *Checker) selector(x *operand, e *ast.SelectorExpr, def *TypeName, w
                                x.id = exp.id
                        default:
                                check.dump("%v: unexpected object %v", e.Sel.Pos(), exp)
-                               unreachable()
+                               panic("unreachable")
                        }
                        x.expr = e
                        return
@@ -957,7 +957,7 @@ func (check *Checker) selector(x *operand, e *ast.SelectorExpr, def *TypeName, w
                        check.addDeclDep(obj)
 
                default:
-                       unreachable()
+                       panic("unreachable")
                }
        }
 
index 1e2ca59392d5e05037fb95f7da30159526d4db5b..be992215d1ea5d741207ef01708eae10f55c5837 100644 (file)
@@ -518,7 +518,7 @@ func (check *Checker) recordUntyped() {
        for x, info := range check.untyped {
                if debug && isTyped(info.typ) {
                        check.dump("%v: %s (type %s) is typed", x.Pos(), x, info.typ)
-                       unreachable()
+                       panic("unreachable")
                }
                check.recordTypeAndValue(x, info.mode, info.typ, info.val)
        }
@@ -554,7 +554,7 @@ func (check *Checker) recordBuiltinType(f ast.Expr, sig *Signature) {
                case *ast.ParenExpr:
                        f = p.X
                default:
-                       unreachable()
+                       panic("unreachable")
                }
        }
 }
index bffea146a0c7cb9bb331c11a694a659e675d2f3b..4956d128834934f3bdd8964601f59fea804dc6e7 100644 (file)
@@ -119,7 +119,7 @@ func representableConst(x constant.Value, check *Checker, typ *Basic, rounded *c
                        case Uint64:
                                return 0 <= x
                        default:
-                               unreachable()
+                               panic("unreachable")
                        }
                }
                // x does not fit into int64
@@ -160,7 +160,7 @@ func representableConst(x constant.Value, check *Checker, typ *Basic, rounded *c
                case UntypedFloat:
                        return true
                default:
-                       unreachable()
+                       panic("unreachable")
                }
 
        case isComplex(typ):
@@ -192,7 +192,7 @@ func representableConst(x constant.Value, check *Checker, typ *Basic, rounded *c
                case UntypedComplex:
                        return true
                default:
-                       unreachable()
+                       panic("unreachable")
                }
 
        case isString(typ):
index 9f8c44ab502e1822bb6b0f44a4435b16598e8a44..3994d1650f6289aad0da88de06dc4f0cc5027491 100644 (file)
@@ -160,7 +160,7 @@ func (check *Checker) objDecl(obj Object, def *TypeName) {
                        }
 
                default:
-                       unreachable()
+                       panic("unreachable")
                }
                assert(obj.Type() != nil)
                return
@@ -169,7 +169,7 @@ func (check *Checker) objDecl(obj Object, def *TypeName) {
        d := check.objMap[obj]
        if d == nil {
                check.dump("%v: %s should have been declared", obj.Pos(), obj)
-               unreachable()
+               panic("unreachable")
        }
 
        // save/restore current environment and set up object environment
@@ -200,7 +200,7 @@ func (check *Checker) objDecl(obj Object, def *TypeName) {
                // functions may be recursive - no need to track dependencies
                check.funcDecl(obj, d)
        default:
-               unreachable()
+               panic("unreachable")
        }
 }
 
@@ -214,7 +214,7 @@ func (check *Checker) validCycle(obj Object) (valid bool) {
                isPkgObj := obj.Parent() == check.pkg.scope
                if isPkgObj != inObjMap {
                        check.dump("%v: inconsistent object map for %s (isPkgObj = %v, inObjMap = %v)", obj.Pos(), obj, isPkgObj, inObjMap)
-                       unreachable()
+                       panic("unreachable")
                }
        }
 
@@ -264,7 +264,7 @@ loop:
                case *Func:
                        // ignored for now
                default:
-                       unreachable()
+                       panic("unreachable")
                }
        }
 
index 0345cf78443de8629b1ff213b1c93de116be0205..0e4b8a8c44aa3402c81376c4a2cbff0e4de20cb2 100644 (file)
@@ -29,10 +29,6 @@ func assert(p bool) {
        }
 }
 
-func unreachable() {
-       panic("unreachable")
-}
-
 // An error_ represents a type-checking error.
 // To report an error_, call Checker.report.
 type error_ struct {
index 927cb50d40c3cab4d8e6e5b7acf532b5cb47ad05..626dd0e775cd5eef374e1599dc0fc493441abf5a 100644 (file)
@@ -255,7 +255,7 @@ func (check *Checker) updateExprType0(parent, x ast.Expr, typ Type, final bool)
                // upon assignment or use.
                if debug {
                        check.dump("%v: found old type(%s): %s (new: %s)", x.Pos(), x, old.typ, typ)
-                       unreachable()
+                       panic("unreachable")
                }
                return
 
@@ -301,7 +301,7 @@ func (check *Checker) updateExprType0(parent, x ast.Expr, typ Type, final bool)
                }
 
        default:
-               unreachable()
+               panic("unreachable")
        }
 
        // If the new type is not final and still untyped, just
@@ -524,7 +524,7 @@ func (check *Checker) comparison(x, y *operand, op token.Token, switchCase bool)
                }
 
        default:
-               unreachable()
+               panic("unreachable")
        }
 
        // comparison is ok
@@ -1601,7 +1601,7 @@ func (check *Checker) exclude(x *operand, modeset uint) {
                        msg = "%s is not an expression"
                        code = NotAnExpr
                default:
-                       unreachable()
+                       panic("unreachable")
                }
                check.errorf(x, code, msg, x)
                x.mode = invalid
index 4329cc22e82f3db527a6877a738ea398fef2a9a6..99ab95fb9004d5473aab93a248c5257e0e4d10b7 100644 (file)
@@ -58,7 +58,7 @@ func (s *gcSizes) Alignof(T Type) (result int64) {
                        return s.WordSize
                }
        case *TypeParam, *Union:
-               unreachable()
+               panic("unreachable")
        }
        a := s.Sizeof(T) // may be 0 or negative
        // spec: "For a variable x of any type: unsafe.Alignof(x) is at least 1."
@@ -156,7 +156,7 @@ func (s *gcSizes) Sizeof(T Type) int64 {
                assert(!isTypeParam(T))
                return s.WordSize * 2
        case *TypeParam, *Union:
-               unreachable()
+               panic("unreachable")
        }
        return s.WordSize // catch-all
 }
index 436a7afbaad5a99092cdea9ffb946f2f2a0e9c91..68bfd885dcaa16c93e3428a7efe46ac09ff3d63f 100644 (file)
@@ -474,7 +474,7 @@ func (check *Checker) missingMethod(V, T Type, static bool, equivalent func(x, y
                case field:
                        *cause = check.sprintf("(%s.%s is a field, not a method)", V, m.Name())
                default:
-                       unreachable()
+                       panic("unreachable")
                }
        }
 
index e922ca5cc3cbeaf574519ed09238e96f97308a5c..883ee62394cd663ba9f8c825326bbef715c16c3f 100644 (file)
@@ -229,7 +229,7 @@ func (x *operand) setConst(k token.Token, lit string) {
        case token.STRING:
                kind = UntypedString
        default:
-               unreachable()
+               panic("unreachable")
        }
 
        val := makeFromLiteral(lit, k)
index 677dff01a0d50ac5f1871ef3fd0685cd197b69ac..e1a32143f1bfd49cf5147d0a7a18d919579f59ac 100644 (file)
@@ -479,7 +479,7 @@ func (c *comparer) identical(x, y Type, p *ifacePair) bool {
                // avoid a crash in case of nil type
 
        default:
-               unreachable()
+               panic("unreachable")
        }
 
        return false
index 95318e90025450b684098c1a956dc44488f51a06..91bd95b6e0b049158fff0fc30f02940251cfd081 100644 (file)
@@ -17,7 +17,7 @@ import (
 func (check *Checker) isTerminating(s ast.Stmt, label string) bool {
        switch s := s.(type) {
        default:
-               unreachable()
+               panic("unreachable")
 
        case *ast.BadStmt, *ast.DeclStmt, *ast.EmptyStmt, *ast.SendStmt,
                *ast.IncDecStmt, *ast.AssignStmt, *ast.GoStmt, *ast.DeferStmt,
@@ -110,7 +110,7 @@ func (check *Checker) isTerminatingSwitch(body *ast.BlockStmt, label string) boo
 func hasBreak(s ast.Stmt, label string, implicit bool) bool {
        switch s := s.(type) {
        default:
-               unreachable()
+               panic("unreachable")
 
        case *ast.BadStmt, *ast.DeclStmt, *ast.EmptyStmt, *ast.ExprStmt,
                *ast.SendStmt, *ast.IncDecStmt, *ast.AssignStmt, *ast.GoStmt,
index 50d340c738afbbf000d343bbeeba4bf8633841b7..18d3204fb152ac947f8b34ee2af031b93599f8ba 100644 (file)
@@ -165,7 +165,7 @@ func SelectionString(s *Selection, qf Qualifier) string {
        case MethodExpr:
                k = "method expr "
        default:
-               unreachable()
+               panic("unreachable")
        }
        var buf bytes.Buffer
        buf.WriteString(k)
index cad42cb942430a40851929822b90634265fdf2ed..8d26a8776d6f932685598e20a083f4900428cf81 100644 (file)
@@ -251,7 +251,7 @@ func (check *Checker) funcType(sig *Signature, recvPar *ast.FieldList, ftyp *ast
                                case *TypeParam:
                                        // The underlying type of a receiver base type cannot be a
                                        // type parameter: "type T[P any] P" is not a valid declaration.
-                                       unreachable()
+                                       panic("unreachable")
                                }
                                if cause != "" {
                                        check.errorf(recv, InvalidRecv, "invalid receiver type %s (%s)", rtyp, cause)
index 12a21401e24301808672f999065d5a6a284e98a0..b7a2bea0e87e54bf9153f46bb081b58a1526631e 100644 (file)
@@ -96,7 +96,7 @@ func (s *StdSizes) Alignof(T Type) (result int64) {
                        return s.WordSize
                }
        case *TypeParam, *Union:
-               unreachable()
+               panic("unreachable")
        }
        a := s.Sizeof(T) // may be 0 or negative
        // spec: "For a variable x of any type: unsafe.Alignof(x) is at least 1."
@@ -223,7 +223,7 @@ func (s *StdSizes) Sizeof(T Type) int64 {
                assert(!isTypeParam(T))
                return s.WordSize * 2
        case *TypeParam, *Union:
-               unreachable()
+               panic("unreachable")
        }
        return s.WordSize // catch-all
 }
index f16e288ffc085a9683da8d9b9dde817a01aa7845..ca528368b5fe9b657d0b137a26c722ae7982f9de 100644 (file)
@@ -183,7 +183,7 @@ func (check *Checker) suspendedCall(keyword string, call *ast.CallExpr) {
        case statement:
                return
        default:
-               unreachable()
+               panic("unreachable")
        }
        check.errorf(&x, code, "%s %s %s", keyword, msg, &x)
 }
index 178f71728358940b2a774bbdfcfcee84251aea87..00796ac92483261f0b7cdf56c5ec380a6103d564 100644 (file)
@@ -285,7 +285,7 @@ func (subst *subster) typ(typ Type) Type {
                return subst.smap.lookup(t)
 
        default:
-               unreachable()
+               panic("unreachable")
        }
 
        return typ
index afb94b90261a498f20e50809dd21918cb0c2ae41..7179a2466c60a9f428dc69d0b34b446bf41984ca 100644 (file)
@@ -140,7 +140,7 @@ func (check *Checker) ident(x *operand, e *ast.Ident, def *TypeName, wantType bo
                x.mode = value
 
        default:
-               unreachable()
+               panic("unreachable")
        }
 
        x.typ = typ
index bde0293527f2681e09d592f1092aa3d36b9b756d..8154d29053b09b0ba5a0a7ed881fa535bdbc6299 100644 (file)
@@ -281,7 +281,7 @@ func def(obj Object) {
                case *Builtin:
                        obj.pkg = Unsafe
                default:
-                       unreachable()
+                       panic("unreachable")
                }
        }
        if scope.Insert(obj) != nil {