-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathassertions.go
More file actions
37 lines (27 loc) · 821 Bytes
/
assertions.go
File metadata and controls
37 lines (27 loc) · 821 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers
// SPDX-License-Identifier: Apache-2.0
package codescan
import (
"fmt"
"go/types"
)
type Error string
func (e Error) Error() string {
return string(e)
}
const (
ErrInternal Error = "internal error due to a bug or a mishandling of go types AST. This usually indicates a bug in the scanner"
)
// code assertions to be explicit about the various expectations when entering a function
func mustNotBeABuiltinType(o *types.TypeName) {
if o.Pkg() != nil {
return
}
panic(fmt.Errorf("type %q expected not to be a builtin: %w", o.Name(), ErrInternal))
}
func mustHaveRightHandSide(a *types.Alias) {
if a.Rhs() != nil {
return
}
panic(fmt.Errorf("type alias %q expected to declare a right-hand-side: %w", a.Obj().Name(), ErrInternal))
}