File tree Expand file tree Collapse file tree 1 file changed +4
-4
lines changed
Expand file tree Collapse file tree 1 file changed +4
-4
lines changed Original file line number Diff line number Diff line change @@ -229,9 +229,6 @@ let writeSpecToFile (generatorState: GeneratorState) (spec: ParserSpec) (compile
229229
230230 writer.WriteLine " #nowarn \" 1182\" // the generated code often has unused variable 'parseState'"
231231
232- writer.WriteLine
233- " #nowarn \" 3261\" // the generated code would need to properly annotate nulls, e.g. changing System.Object to `obj|null`"
234-
235232 for s in generatorState.opens do
236233 writer.WriteLine " open %s " s
237234 writer.WriteLineInterface " open %s " s
@@ -371,7 +368,10 @@ let writeSpecToFile (generatorState: GeneratorState) (spec: ParserSpec) (compile
371368 | None -> " " )
372369 ( match typ with
373370 | Some _ -> " Microsoft.FSharp.Core.Operators.box _fsyacc_x"
374- | None -> " (null : System.Object)" )
371+ // We can't use null here because if all tokens are untyped, the function will be generic.
372+ // We used to use (null : obj) but that leads to warnings when nullable reference types are enabled.
373+ // box null does the right thing regardless of NRT and gets optimized to a single ldnull.
374+ | None -> " Microsoft.FSharp.Core.Operators.box null" )
375375
376376 for key, _ in spec.Types |> Seq.countBy fst |> Seq.filter ( fun ( _ , n ) -> n > 1 ) do
377377 failwithf " %s is given multiple %%t ype declarations" key
You can’t perform that action at this time.
0 commit comments