Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add conditional null guards to autogenerated code, so it can be used with any shipped FSharp.Core #17700

Merged
merged 2 commits into from
Sep 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/FSharp.Build/FSharpEmbedResourceText.fs
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,11 @@ open Printf
if isNull s then
System.Diagnostics.Debug.Assert(false, sprintf ""**RESOURCE ERROR**: Resource token %s does not exist!"" name)
#endif
#if BUILDING_WITH_LKG || NO_NULLCHECKING_LIB_SUPPORT
s
#else
Unchecked.nonNull s
#endif


static let mkFunctionValue (tys: System.Type[]) (impl:obj->obj) =
Expand All @@ -314,7 +318,11 @@ open Printf
// PERF: this technique is a bit slow (e.g. in simple cases, like 'sprintf ""%x""')
mkFunctionValue tys (fun inp -> impl rty inp)

#if BUILDING_WITH_LKG || NO_NULLCHECKING_LIB_SUPPORT
static let capture1 (fmt:string) i args ty (go: obj list -> System.Type -> int -> obj) : obj =
#else
static let capture1 (fmt:string) i args ty (go: objnull list -> System.Type -> int -> obj) : obj =
#endif
match fmt.[i] with
| '%' -> go args ty (i+1)
| 'd'
Expand All @@ -336,7 +344,11 @@ open Printf
if i >= len || (fmt.[i] = '%' && i+1 >= len) then
let b = new System.Text.StringBuilder()
b.AppendFormat(messageString, [| for x in List.rev args -> x |]) |> ignore
#if BUILDING_WITH_LKG || NO_NULLCHECKING_LIB_SUPPORT
box(b.ToString())
#else
box(b.ToString()) |> Unchecked.nonNull
#endif
// REVIEW: For these purposes, this should be a nop, but I'm leaving it
// in incase we ever decide to support labels for the error format string
// E.g., ""<name>%s<foo>%d""
Expand Down