Skip to content

Commit

Permalink
Make the output of fsyacc compatible with nullable reference types.
Browse files Browse the repository at this point in the history
  • Loading branch information
teo-tsirpanis committed Dec 21, 2024
1 parent e8a4481 commit 48b945e
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/FsYacc.Core/fsyaccdriver.fs
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,6 @@ let writeSpecToFile (generatorState: GeneratorState) (spec: ParserSpec) (compile

writer.WriteLine "#nowarn \"1182\" // the generated code often has unused variable 'parseState'"

writer.WriteLine
"#nowarn \"3261\" // the generated code would need to properly annotate nulls, e.g. changing System.Object to `obj|null`"

for s in generatorState.opens do
writer.WriteLine "open %s" s
writer.WriteLineInterface "open %s" s
Expand Down Expand Up @@ -371,7 +368,10 @@ let writeSpecToFile (generatorState: GeneratorState) (spec: ParserSpec) (compile
| None -> "")
(match typ with
| Some _ -> "Microsoft.FSharp.Core.Operators.box _fsyacc_x"
| None -> "(null : System.Object)")
// We can't use null here because if all tokens are untyped, the function will be generic.
// We used to use (null : obj) but that leads to warnings when nullable reference types are enabled.
// box null does the right thing regardless of NRT and gets optimized to a single ldnull.
| None -> "Microsoft.FSharp.Core.Operators.box null")

for key, _ in spec.Types |> Seq.countBy fst |> Seq.filter (fun (_, n) -> n > 1) do
failwithf "%s is given multiple %%type declarations" key
Expand Down

0 comments on commit 48b945e

Please sign in to comment.