Skip to content

Commit

Permalink
use any instead of interface{}
Browse files Browse the repository at this point in the history
  • Loading branch information
jhump committed Oct 14, 2024
1 parent 7e91472 commit 8dd4ee6
Show file tree
Hide file tree
Showing 13 changed files with 51 additions and 51 deletions.
4 changes: 2 additions & 2 deletions ast/identifiers.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func NewIdentNode(val string, tok Token) *IdentNode {
}
}

func (n *IdentNode) Value() interface{} {
func (n *IdentNode) Value() any {
return n.AsIdentifier()
}

Expand Down Expand Up @@ -129,7 +129,7 @@ func NewCompoundIdentNode(leadingDot *RuneNode, components []*IdentNode, dots []
}
}

func (n *CompoundIdentNode) Value() interface{} {
func (n *CompoundIdentNode) Value() any {
return n.AsIdentifier()
}

Expand Down
2 changes: 1 addition & 1 deletion ast/no_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func (n *NoSourceNode) GetOutputType() Node {
return n
}

func (n *NoSourceNode) Value() interface{} {
func (n *NoSourceNode) Value() any {
return nil
}

Expand Down
4 changes: 2 additions & 2 deletions ast/ranges.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,15 +185,15 @@ func (n *RangeNode) RangeEnd() Node {
return n.StartVal
}

func (n *RangeNode) StartValue() interface{} {
func (n *RangeNode) StartValue() any {
return n.StartVal.Value()
}

func (n *RangeNode) StartValueAsInt32(minVal, maxVal int32) (int32, bool) {
return AsInt32(n.StartVal, minVal, maxVal)
}

func (n *RangeNode) EndValue() interface{} {
func (n *RangeNode) EndValue() any {
if n.EndVal == nil {
return nil
}
Expand Down
20 changes: 10 additions & 10 deletions ast/values.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type ValueNode interface {
// If the ValueNode is a NoSourceNode, indicating that there is no actual
// source code (and thus not AST information), then this method always
// returns nil.
Value() interface{}
Value() any
}

var _ ValueNode = (*IdentNode)(nil)
Expand Down Expand Up @@ -84,7 +84,7 @@ func NewStringLiteralNode(val string, tok Token) *StringLiteralNode {
}
}

func (n *StringLiteralNode) Value() interface{} {
func (n *StringLiteralNode) Value() any {
return n.AsString()
}

Expand Down Expand Up @@ -122,7 +122,7 @@ func NewCompoundLiteralStringNode(components ...*StringLiteralNode) *CompoundStr
}
}

func (n *CompoundStringLiteralNode) Value() interface{} {
func (n *CompoundStringLiteralNode) Value() any {
return n.AsString()
}

Expand Down Expand Up @@ -170,7 +170,7 @@ func NewUintLiteralNode(val uint64, tok Token) *UintLiteralNode {
}
}

func (n *UintLiteralNode) Value() interface{} {
func (n *UintLiteralNode) Value() any {
return n.Val
}

Expand Down Expand Up @@ -217,7 +217,7 @@ func NewNegativeIntLiteralNode(sign *RuneNode, i *UintLiteralNode) *NegativeIntL
}
}

func (n *NegativeIntLiteralNode) Value() interface{} {
func (n *NegativeIntLiteralNode) Value() any {
return n.Val
}

Expand Down Expand Up @@ -259,7 +259,7 @@ func NewFloatLiteralNode(val float64, tok Token) *FloatLiteralNode {
}
}

func (n *FloatLiteralNode) Value() interface{} {
func (n *FloatLiteralNode) Value() any {
return n.AsFloat()
}

Expand Down Expand Up @@ -291,7 +291,7 @@ func NewSpecialFloatLiteralNode(name *KeywordNode) *SpecialFloatLiteralNode {
}
}

func (n *SpecialFloatLiteralNode) Value() interface{} {
func (n *SpecialFloatLiteralNode) Value() any {
return n.AsFloat()
}

Expand Down Expand Up @@ -331,7 +331,7 @@ func NewSignedFloatLiteralNode(sign *RuneNode, f FloatValueNode) *SignedFloatLit
}
}

func (n *SignedFloatLiteralNode) Value() interface{} {
func (n *SignedFloatLiteralNode) Value() any {
return n.Val
}

Expand Down Expand Up @@ -400,7 +400,7 @@ func NewArrayLiteralNode(openBracket *RuneNode, vals []ValueNode, commas []*Rune
}
}

func (n *ArrayLiteralNode) Value() interface{} {
func (n *ArrayLiteralNode) Value() any {
return n.Elements
}

Expand Down Expand Up @@ -469,7 +469,7 @@ func NewMessageLiteralNode(openSym *RuneNode, vals []*MessageFieldNode, seps []*
}
}

func (n *MessageLiteralNode) Value() interface{} {
func (n *MessageLiteralNode) Value() any {
return n.Elements
}

Expand Down
2 changes: 1 addition & 1 deletion compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ type PanicError struct {
// The file that was being processed when the panic occurred
File string
// The value returned by recover()
Value interface{}
Value any
// A formatted stack trace
Stack string
}
Expand Down
2 changes: 1 addition & 1 deletion internal/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type hasOptionNode interface {
FileNode() ast.FileDeclNode // needed in order to query for NodeInfo
}

type errorHandler func(span ast.SourceSpan, format string, args ...interface{}) error
type errorHandler func(span ast.SourceSpan, format string, args ...any) error

func FindFirstOption(res hasOptionNode, handler errorHandler, scope string, opts []*descriptorpb.UninterpretedOption, name string) (int, error) {
return findOption(res, handler, scope, opts, name, false, true)
Expand Down
6 changes: 3 additions & 3 deletions linker/descriptors.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,8 @@ func (r *result) SourceLocations() protoreflect.SourceLocations {
return &r.srcLocations
}

func computeSourceLocIndex(locs []protoreflect.SourceLocation) map[interface{}]int {
index := map[interface{}]int{}
func computeSourceLocIndex(locs []protoreflect.SourceLocation) map[any]int {
index := map[any]int{}
for i, loc := range locs {
if loc.Next == 0 {
index[pathKey(loc.Path)] = i
Expand Down Expand Up @@ -368,7 +368,7 @@ type srcLocs struct {
protoreflect.SourceLocations
file *result
locs []protoreflect.SourceLocation
index map[interface{}]int
index map[any]int
}

func (s *srcLocs) Len() int {
Expand Down
2 changes: 1 addition & 1 deletion linker/pathkey.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (

var pathElementType = reflect.TypeOf(protoreflect.SourcePath{}).Elem()

func pathKey(p protoreflect.SourcePath) interface{} {
func pathKey(p protoreflect.SourcePath) any {
if p == nil {
// Reflection code below doesn't work with nil slices
return [0]int32{}
Expand Down
14 changes: 7 additions & 7 deletions options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func interpretOptions(lenient bool, file file, res linker.Resolver, handler *rep
return interp.index, nil
}

func (interp *interpreter) handleErrorf(span ast.SourceSpan, msg string, args ...interface{}) error {
func (interp *interpreter) handleErrorf(span ast.SourceSpan, msg string, args ...any) error {
if interp.lenienceEnabled {
interp.lenientErrReported = true
return nil
Expand Down Expand Up @@ -457,7 +457,7 @@ func (interp *interpreter) processDefaultOption(scope string, fqn string, fld *d
}

val := optNode.GetValue()
var v interface{}
var v any
if val.Value() == nil {
// no value in the AST, so we dig the value out of the uninterpreted option proto
v, err = interp.defaultValueFromProto(mc, fld, opt, val)
Expand Down Expand Up @@ -500,7 +500,7 @@ func (interp *interpreter) processDefaultOption(scope string, fqn string, fld *d
return found, nil
}

func (interp *interpreter) defaultValue(mc *internal.MessageContext, fld *descriptorpb.FieldDescriptorProto, val ast.ValueNode) (interface{}, error) {
func (interp *interpreter) defaultValue(mc *internal.MessageContext, fld *descriptorpb.FieldDescriptorProto, val ast.ValueNode) (any, error) {
if _, ok := val.(*ast.MessageLiteralNode); ok {
return -1, reporter.Errorf(interp.nodeInfo(val), "%vdefault value cannot be a message", mc)
}
Expand All @@ -518,7 +518,7 @@ func (interp *interpreter) defaultValue(mc *internal.MessageContext, fld *descri
return interp.scalarFieldValue(mc, fld.GetType(), val, false)
}

func (interp *interpreter) defaultValueFromProto(mc *internal.MessageContext, fld *descriptorpb.FieldDescriptorProto, opt *descriptorpb.UninterpretedOption, node ast.Node) (interface{}, error) {
func (interp *interpreter) defaultValueFromProto(mc *internal.MessageContext, fld *descriptorpb.FieldDescriptorProto, opt *descriptorpb.UninterpretedOption, node ast.Node) (any, error) {
if opt.AggregateValue != nil {
return -1, reporter.Errorf(interp.nodeInfo(node), "%vdefault value cannot be a message", mc)
}
Expand Down Expand Up @@ -1567,7 +1567,7 @@ func fieldName(fld protoreflect.FieldDescriptor) string {
return string(fld.Name())
}

func valueKind(val interface{}) string {
func valueKind(val any) string {
switch val := val.(type) {
case ast.Identifier:
return "identifier"
Expand Down Expand Up @@ -1746,7 +1746,7 @@ func (interp *interpreter) scalarFieldValue(
fldType descriptorpb.FieldDescriptorProto_Type,
val ast.ValueNode,
insideMsgLiteral bool,
) (interface{}, error) {
) (any, error) {
v := val.Value()
switch fldType {
case descriptorpb.FieldDescriptorProto_TYPE_BOOL:
Expand Down Expand Up @@ -1884,7 +1884,7 @@ func (interp *interpreter) scalarFieldValueFromProto(
fldType descriptorpb.FieldDescriptorProto_Type,
opt *descriptorpb.UninterpretedOption,
node ast.Node,
) (interface{}, error) {
) (any, error) {
switch fldType {
case descriptorpb.FieldDescriptorProto_TYPE_BOOL:
if opt.IdentifierValue != nil {
Expand Down
Loading

0 comments on commit 8dd4ee6

Please sign in to comment.