@@ -148,6 +148,9 @@ func (f *File) InternedPath() intern.ID {
148148// google/protobuf/descriptor.proto, which is given special treatment in
149149// the language.
150150func (f * File ) IsDescriptorProto () bool {
151+ if f == nil {
152+ return false
153+ }
151154 return f .InternedPath () == f .session .builtins .DescriptorFile
152155}
153156
@@ -176,15 +179,23 @@ func (f *File) InternedPackage() intern.ID {
176179
177180// Imports returns an indexer over the imports declared in this file.
178181func (f * File ) Imports () seq.Indexer [Import ] {
179- return f .imports .Directs ()
182+ var imp imports
183+ if f != nil {
184+ imp = f .imports
185+ }
186+ return imp .Directs ()
180187}
181188
182189// TransitiveImports returns an indexer over the transitive imports for this
183190// file.
184191//
185192// This function does not report whether those imports are weak or not.
186193func (f * File ) TransitiveImports () seq.Indexer [Import ] {
187- return f .imports .Transitive ()
194+ var imp imports
195+ if f != nil {
196+ imp = f .imports
197+ }
198+ return imp .Transitive ()
188199}
189200
190201// ImportFor returns import metadata for a given file, if this file imports it.
@@ -199,8 +210,12 @@ func (f *File) ImportFor(that *File) Import {
199210
200211// Types returns the top level types of this file.
201212func (f * File ) Types () seq.Indexer [Type ] {
213+ var types []id.ID [Type ]
214+ if f != nil {
215+ types = f .types [:f .topLevelTypesEnd ]
216+ }
202217 return seq .NewFixedSlice (
203- f . types [: f . topLevelTypesEnd ] ,
218+ types ,
204219 func (_ int , p id.ID [Type ]) Type {
205220 return id .Wrap (f , p )
206221 },
@@ -209,8 +224,12 @@ func (f *File) Types() seq.Indexer[Type] {
209224
210225// AllTypes returns all types defined in this file.
211226func (f * File ) AllTypes () seq.Indexer [Type ] {
227+ var types []id.ID [Type ]
228+ if f != nil {
229+ types = f .types
230+ }
212231 return seq .NewFixedSlice (
213- f . types ,
232+ types ,
214233 func (_ int , p id.ID [Type ]) Type {
215234 return id .Wrap (f , p )
216235 },
@@ -220,8 +239,12 @@ func (f *File) AllTypes() seq.Indexer[Type] {
220239// Extensions returns the top level extensions defined in this file (i.e.,
221240// the contents of any top-level `extends` blocks).
222241func (f * File ) Extensions () seq.Indexer [Member ] {
242+ var slice []id.ID [Member ]
243+ if f != nil {
244+ slice = f .extns [:f .topLevelExtnsEnd ]
245+ }
223246 return seq .NewFixedSlice (
224- f . extns [: f . topLevelExtnsEnd ] ,
247+ slice ,
225248 func (_ int , p id.ID [Member ]) Member {
226249 return id .Wrap (f , p )
227250 },
@@ -230,8 +253,12 @@ func (f *File) Extensions() seq.Indexer[Member] {
230253
231254// AllExtensions returns all extensions defined in this file.
232255func (f * File ) AllExtensions () seq.Indexer [Member ] {
256+ var extns []id.ID [Member ]
257+ if f != nil {
258+ extns = f .extns
259+ }
233260 return seq .NewFixedSlice (
234- f . extns ,
261+ extns ,
235262 func (_ int , p id.ID [Member ]) Member {
236263 return id .Wrap (f , p )
237264 },
@@ -240,8 +267,12 @@ func (f *File) AllExtensions() seq.Indexer[Member] {
240267
241268// Extends returns the top level extend blocks in this file.
242269func (f * File ) Extends () seq.Indexer [Extend ] {
270+ var slice []id.ID [Extend ]
271+ if f != nil {
272+ slice = f .extends [:f .topLevelExtendsEnd ]
273+ }
243274 return seq .NewFixedSlice (
244- f . extends [: f . topLevelExtendsEnd ] ,
275+ slice ,
245276 func (_ int , p id.ID [Extend ]) Extend {
246277 return id .Wrap (f , p )
247278 },
@@ -250,8 +281,12 @@ func (f *File) Extends() seq.Indexer[Extend] {
250281
251282// AllExtends returns all extend blocks in this file.
252283func (f * File ) AllExtends () seq.Indexer [Extend ] {
284+ var extends []id.ID [Extend ]
285+ if f != nil {
286+ extends = f .extends
287+ }
253288 return seq .NewFixedSlice (
254- f . extends ,
289+ extends ,
255290 func (_ int , p id.ID [Extend ]) Extend {
256291 return id .Wrap (f , p )
257292 },
@@ -261,17 +296,25 @@ func (f *File) AllExtends() seq.Indexer[Extend] {
261296// AllMembers returns all fields defined in this file, including extensions
262297// and enum values.
263298func (f * File ) AllMembers () iter.Seq [Member ] {
299+ var raw iter.Seq [* rawMember ]
300+ if f != nil {
301+ raw = f .arenas .members .Values ()
302+ }
264303 i := 0
265- return iterx .Map (f . arenas . members . Values () , func (raw * rawMember ) Member {
304+ return iterx .Map (raw , func (raw * rawMember ) Member {
266305 i ++
267306 return id .WrapRaw (f , id.ID [Member ](i ), raw )
268307 })
269308}
270309
271310// Services returns all services defined in this file.
272311func (f * File ) Services () seq.Indexer [Service ] {
312+ var services []id.ID [Service ]
313+ if f != nil {
314+ services = f .services
315+ }
273316 return seq .NewFixedSlice (
274- f . services ,
317+ services ,
275318 func (_ int , p id.ID [Service ]) Service {
276319 return id .Wrap (f , p )
277320 },
@@ -280,11 +323,18 @@ func (f *File) Services() seq.Indexer[Service] {
280323
281324// Options returns the top level options applied to this file.
282325func (f * File ) Options () MessageValue {
283- return id .Wrap (f , f .options ).AsMessage ()
326+ var options id.ID [Value ]
327+ if f != nil {
328+ options = f .options
329+ }
330+ return id .Wrap (f , options ).AsMessage ()
284331}
285332
286333// FeatureSet returns the Editions features associated with this file.
287334func (f * File ) FeatureSet () FeatureSet {
335+ if f == nil {
336+ return FeatureSet {}
337+ }
288338 return id .Wrap (f , f .features )
289339}
290340
@@ -308,8 +358,12 @@ func (f *File) Deprecated() Value {
308358// imported by the file. The symbols are returned in an arbitrary but fixed
309359// order.
310360func (f * File ) Symbols () seq.Indexer [Symbol ] {
361+ var symbols []Ref [Symbol ]
362+ if f != nil {
363+ symbols = f .imported
364+ }
311365 return seq .NewFixedSlice (
312- f . imported ,
366+ symbols ,
313367 func (_ int , r Ref [Symbol ]) Symbol {
314368 return GetRef (f , r )
315369 },
0 commit comments