diff --git a/go.mod b/go.mod index a36aaa164..1d56ac36a 100644 --- a/go.mod +++ b/go.mod @@ -2,9 +2,9 @@ module golang.org/x/text go 1.24.0 -require golang.org/x/tools v0.36.0 // tagx:ignore +require golang.org/x/tools v0.37.0 // tagx:ignore require ( - golang.org/x/mod v0.27.0 // indirect; tagx:ignore + golang.org/x/mod v0.28.0 // indirect; tagx:ignore golang.org/x/sync v0.17.0 // indirect ) diff --git a/go.sum b/go.sum index d0c3f53e6..1fa55e6db 100644 --- a/go.sum +++ b/go.sum @@ -1,8 +1,8 @@ github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= -golang.org/x/mod v0.27.0 h1:kb+q2PyFnEADO2IEF935ehFUXlWiNjJWtRNgBLSfbxQ= -golang.org/x/mod v0.27.0/go.mod h1:rWI627Fq0DEoudcK+MBkNkCe0EetEaDSwJJkCcjpazc= +golang.org/x/mod v0.28.0 h1:gQBtGhjxykdjY9YhZpSlZIsbnaE2+PgjfLWUQTnoZ1U= +golang.org/x/mod v0.28.0/go.mod h1:yfB/L0NOf/kmEbXjzCPOx1iK1fRutOydrCMsqRhEBxI= golang.org/x/sync v0.17.0 h1:l60nONMj9l5drqw6jlhIELNv9I0A4OFgRsG9k2oT9Ug= golang.org/x/sync v0.17.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI= -golang.org/x/tools v0.36.0 h1:kWS0uv/zsvHEle1LbV5LE8QujrxB3wfQyxHfhOk0Qkg= -golang.org/x/tools v0.36.0/go.mod h1:WBDiHKJK8YgLHlcQPYQzNCkUxUypCaa5ZegCVutKm+s= +golang.org/x/tools v0.37.0 h1:DVSRzp7FwePZW356yEAChSdNcQo6Nsp+fex1SUW09lE= +golang.org/x/tools v0.37.0/go.mod h1:MBN5QPQtLMHVdvsbtarmTNukZDdgwdwlO5qGacAzF0w= diff --git a/message/pipeline/extract.go b/message/pipeline/extract.go index 23e58f021..7d8385d92 100644 --- a/message/pipeline/extract.go +++ b/message/pipeline/extract.go @@ -597,9 +597,13 @@ func (px packageExtracter) handleCall(call *ast.CallExpr) bool { key := []string{} if ident, ok := format.(*ast.Ident); ok { key = append(key, ident.Name) - if v, ok := ident.Obj.Decl.(*ast.ValueSpec); ok && v.Comment != nil { - // TODO: get comment above ValueSpec as well - comment = v.Comment.Text() + // Ident.Obj may be nil if the referenced declaration is in another + // file. + if ident.Obj != nil { + if v, ok := ident.Obj.Decl.(*ast.ValueSpec); ok && v.Comment != nil { + // TODO: get comment above ValueSpec as well + comment = v.Comment.Text() + } } } if c := px.getComment(call.Args[0]); c != "" { diff --git a/message/pipeline/testdata/test60555/catalog_gen.go b/message/pipeline/testdata/test60555/catalog_gen.go new file mode 100644 index 000000000..dce54afd5 --- /dev/null +++ b/message/pipeline/testdata/test60555/catalog_gen.go @@ -0,0 +1,38 @@ +// Code generated by running "go generate" in golang.org/x/text. DO NOT EDIT. + +package main + +import ( + "golang.org/x/text/language" + "golang.org/x/text/message" + "golang.org/x/text/message/catalog" +) + +type dictionary struct { + index []uint32 + data string +} + +func (d *dictionary) Lookup(key string) (data string, ok bool) { + p, ok := messageKeyToIndex[key] + if !ok { + return "", false + } + start, end := d.index[p], d.index[p+1] + if start == end { + return "", false + } + return d.data[start:end], true +} + +func init() { + dict := map[string]catalog.Dictionary{} + fallback := language.MustParse("en-US") + cat, err := catalog.NewFromMap(dict, catalog.Fallback(fallback)) + if err != nil { + panic(err) + } + message.DefaultCatalog = cat +} + +var messageKeyToIndex = map[string]int{} diff --git a/message/pipeline/testdata/test60555/extracted.gotext.json.want b/message/pipeline/testdata/test60555/extracted.gotext.json.want new file mode 100644 index 000000000..2abf7b7ad --- /dev/null +++ b/message/pipeline/testdata/test60555/extracted.gotext.json.want @@ -0,0 +1,15 @@ +{ + "language": "en-US", + "messages": [ + { + "id": [ + "testMessage", + "Test message" + ], + "key": "Test message", + "message": "Test message", + "translation": "", + "position": "testdata/test60555/main.go:17:10" + } + ] +} \ No newline at end of file diff --git a/message/pipeline/testdata/test60555/main.go b/message/pipeline/testdata/test60555/main.go new file mode 100644 index 000000000..69b7529c8 --- /dev/null +++ b/message/pipeline/testdata/test60555/main.go @@ -0,0 +1,18 @@ +// Copyright 2025 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import ( + "golang.org/x/text/language" + "golang.org/x/text/message" +) + +// Ensures that we can catch any regressions with nil dereferences +// from const declarations in other files within the same package. +// See issue https://golang.org/issues/60555 +func main() { + p := message.NewPrinter(language.English) + p.Printf(testMessage) +} diff --git a/message/pipeline/testdata/test60555/message.go b/message/pipeline/testdata/test60555/message.go new file mode 100644 index 000000000..ea2a98c1d --- /dev/null +++ b/message/pipeline/testdata/test60555/message.go @@ -0,0 +1,7 @@ +// Copyright 2025 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +const testMessage = "Test message" diff --git a/secure/precis/enforce_test.go b/secure/precis/enforce_test.go index 0ced110a9..d86a42f80 100644 --- a/secure/precis/enforce_test.go +++ b/secure/precis/enforce_test.go @@ -92,13 +92,6 @@ func TestTransformMallocs(t *testing.T) { } } -func min(a, b int) int { - if a < b { - return a - } - return b -} - // TestTransformerShortBuffers tests that the precis.Transformer implements the // spirit, not just the letter (the method signatures), of the // transform.Transformer interface. diff --git a/unicode/bidi/core.go b/unicode/bidi/core.go index 9d2ae547b..fb8273236 100644 --- a/unicode/bidi/core.go +++ b/unicode/bidi/core.go @@ -427,13 +427,6 @@ type isolatingRunSequence struct { func (i *isolatingRunSequence) Len() int { return len(i.indexes) } -func maxLevel(a, b level) level { - if a > b { - return a - } - return b -} - // Rule X10, second bullet: Determine the start-of-sequence (sos) and end-of-sequence (eos) types, // either L or R, for each isolating run sequence. func (p *paragraph) isolatingRunSequence(indexes []int) *isolatingRunSequence { @@ -474,8 +467,8 @@ func (p *paragraph) isolatingRunSequence(indexes []int) *isolatingRunSequence { indexes: indexes, types: types, level: level, - sos: typeForLevel(maxLevel(prevLevel, level)), - eos: typeForLevel(maxLevel(succLevel, level)), + sos: typeForLevel(max(prevLevel, level)), + eos: typeForLevel(max(succLevel, level)), } }