File tree Expand file tree Collapse file tree 5 files changed +85
-3
lines changed Expand file tree Collapse file tree 5 files changed +85
-3
lines changed Original file line number Diff line number Diff line change @@ -597,9 +597,13 @@ func (px packageExtracter) handleCall(call *ast.CallExpr) bool {
597597 key := []string {}
598598 if ident , ok := format .(* ast.Ident ); ok {
599599 key = append (key , ident .Name )
600- if v , ok := ident .Obj .Decl .(* ast.ValueSpec ); ok && v .Comment != nil {
601- // TODO: get comment above ValueSpec as well
602- comment = v .Comment .Text ()
600+ // Ident.Obj may be nil if the referenced declaration is in another
601+ // file.
602+ if ident .Obj != nil {
603+ if v , ok := ident .Obj .Decl .(* ast.ValueSpec ); ok && v .Comment != nil {
604+ // TODO: get comment above ValueSpec as well
605+ comment = v .Comment .Text ()
606+ }
603607 }
604608 }
605609 if c := px .getComment (call .Args [0 ]); c != "" {
Original file line number Diff line number Diff line change 1+ {
2+ "language": "en-US",
3+ "messages": [
4+ {
5+ "id": [
6+ "testMessage",
7+ "Test message"
8+ ],
9+ "key": "Test message",
10+ "message": "Test message",
11+ "translation": "",
12+ "position": "testdata/test60555/main.go:17:10"
13+ }
14+ ]
15+ }
Original file line number Diff line number Diff line change 1+ // Copyright 2025 The Go Authors. All rights reserved.
2+ // Use of this source code is governed by a BSD-style
3+ // license that can be found in the LICENSE file.
4+
5+ package main
6+
7+ import (
8+ "golang.org/x/text/language"
9+ "golang.org/x/text/message"
10+ )
11+
12+ // Ensures that we can catch any regressions with nil dereferences
13+ // from const declarations in other files within the same package.
14+ // See issue https://golang.org/issues/60555
15+ func main () {
16+ p := message .NewPrinter (language .English )
17+ p .Printf (testMessage )
18+ }
Original file line number Diff line number Diff line change 1+ // Copyright 2025 The Go Authors. All rights reserved.
2+ // Use of this source code is governed by a BSD-style
3+ // license that can be found in the LICENSE file.
4+
5+ package main
6+
7+ const testMessage = "Test message"
You can’t perform that action at this time.
0 commit comments