Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions src/absil/illib.fs
Original file line number Diff line number Diff line change
Expand Up @@ -716,8 +716,8 @@ type LazyWithContext<'T,'ctxt> =
funcOrException = box f;
findOriginalException = findOriginalException }
static member NotLazy(x:'T) : LazyWithContext<'T,'ctxt> =
{ value = x;
funcOrException = null;
{ value = x
funcOrException = null
findOriginalException = id }
member x.IsDelayed = (match x.funcOrException with null -> false | :? LazyWithContextFailure -> false | _ -> true)
member x.IsForced = (match x.funcOrException with null -> true | _ -> false)
Expand Down
15 changes: 7 additions & 8 deletions src/absil/ilwritepdb.fs
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,9 @@ let writePortablePdbInfo (fixupSPs:bool) showTimes fpdb (info:PdbData) =
let _spCounts, _allSps = fixupOverlappingSequencePoints fixupSPs showTimes info.Methods
let externalRowCounts = getRowCounts info.TableRowCounts
let docs =
if info.Documents = null then
Array.empty<PdbDocumentData>
else
info.Documents
match info.Documents with
| null -> Array.empty<PdbDocumentData>
| _ -> info.Documents

let metadata = MetadataBuilder()
let serializeDocumentName (name:string) =
Expand Down Expand Up @@ -251,9 +250,9 @@ let writePortablePdbInfo (fixupSPs:bool) showTimes fpdb (info:PdbData) =
info.Methods |> Array.iteri (fun _i minfo ->
let docHandle, sequencePointBlob =
let sps =
if minfo.SequencePoints = null then
Array.empty<PdbSequencePoint>
else
match minfo.SequencePoints with
| null -> Array.empty<PdbSequencePoint>
| _ ->
match minfo.Range with
| None -> Array.empty<PdbSequencePoint>
| Some (_,_) -> minfo.SequencePoints
Expand All @@ -266,7 +265,7 @@ let writePortablePdbInfo (fixupSPs:bool) showTimes fpdb (info:PdbData) =
| false, _ -> Unchecked.defaultof<DocumentHandle>
| true, f -> f

// Return a document that the entire method body is declared within.
// Return a document that the entire method body is declared within.
// If part of the method body is in another document returns nil handle.
let tryGetSingleDocumentIndex =
let mutable singleDocumentIndex = 0
Expand Down
2 changes: 1 addition & 1 deletion src/fsharp/ErrorLogger.fs
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ let NewlineifyErrorString (message:string) = message.Replace(stringThatIsAProxyF
/// NOTE: newlines are recognized and replaced with stringThatIsAProxyForANewlineInFlatErrors (ASCII 29, the 'group separator'),
/// which is decoded by the IDE with 'NewlineifyErrorString' back into newlines, so that multi-line errors can be displayed in QuickInfo
let NormalizeErrorString (text : string) =
if text = null then nullArg "text"
if isNull text then nullArg "text"
let text = text.Trim()

let buf = System.Text.StringBuilder()
Expand Down
4 changes: 2 additions & 2 deletions src/fsharp/FSharp.Core/control.fs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ namespace System.Threading

member this.Equals(ctr:CancellationTokenRegistration) =
match this.source with
| null -> ctr.source = null
| null -> isNull ctr.source
| _ -> this.source.Equals(ctr.source) && this.id = ctr.id

override this.Equals(o:obj) =
Expand Down Expand Up @@ -91,7 +91,7 @@ namespace System.Threading

member this.Equals(ct:CancellationToken) =
match this.source with
| null -> ct.source = null
| null -> isNull ct.source
| _ -> this.source.Equals(ct.source)

override this.Equals(o:obj) =
Expand Down
2 changes: 1 addition & 1 deletion src/fsharp/FSharp.Core/math/z.fs
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ namespace System.Numerics
| _ -> invalidArg "x" "signs should be +/- 1 or 0"

static member Parse(text:string) =
if text = null then raise (new ArgumentNullException("text"))
if isNull text then raise (new ArgumentNullException("text"))
let text = text.Trim()
let len = text.Length
if len = 0 then raise (new System.FormatException(SR.GetString(SR.badFormatString)))
Expand Down
2 changes: 1 addition & 1 deletion src/fsharp/FSharp.Core/prim-types.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4128,7 +4128,7 @@ namespace Microsoft.FSharp.Core
#if FX_NO_CHAR_PARSE
// replace System.Char.Parse
let inline charParse (s: string) =
if s = null then raise (System.ArgumentNullException())
if isNull s then raise (System.ArgumentNullException())
elif s.Length = 1 then s.[0]
else raise (System.FormatException "String must be exactly one character long.")
#endif
Expand Down
39 changes: 31 additions & 8 deletions src/fsharp/FSharp.Core/printf.fs
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,10 @@ module internal PrintfImpl =
let invariantCulture = System.Globalization.CultureInfo.InvariantCulture

let inline boolToString v = if v then "true" else "false"
let inline stringToSafeString v = if v = null then "" else v
let inline stringToSafeString v =
match v with
| null -> ""
| _ -> v

[<Literal>]
let DefaultPrecision = 6
Expand Down Expand Up @@ -1001,25 +1004,30 @@ module internal PrintfImpl =
type private PrintfBuilder<'S, 'Re, 'Res>() =

let mutable count = 0

let verifyMethodInfoWasTaken (_mi : System.Reflection.MemberInfo) =
#if DEBUG
if _mi = null then
let verifyMethodInfoWasTaken (mi : System.Reflection.MemberInfo) =
if isNull mi then
ignore (System.Diagnostics.Debugger.Launch())
#else
()
#endif

let buildSpecialChained(spec : FormatSpecifier, argTys : Type[], prefix : string, tail : obj, retTy) =
if spec.TypeChar = 'a' then
let mi = typeof<Specializations<'S, 'Re, 'Res>>.GetMethod("LittleAChained", NonPublicStatics)
#if DEBUG
verifyMethodInfoWasTaken mi
#else
#endif

let mi = mi.MakeGenericMethod([| argTys.[1]; retTy |])
let args = [| box prefix; tail |]
mi.Invoke(null, args)
elif spec.TypeChar = 't' then
let mi = typeof<Specializations<'S, 'Re, 'Res>>.GetMethod("TChained", NonPublicStatics)
#if DEBUG
verifyMethodInfoWasTaken mi
#else
#endif
let mi = mi.MakeGenericMethod([| retTy |])
let args = [| box prefix; tail |]
mi.Invoke(null, args)
Expand All @@ -1031,9 +1039,10 @@ module internal PrintfImpl =
let prefix = if spec.TypeChar = '%' then "PercentStarChained" else "StarChained"
let name = prefix + (string n)
typeof<Specializations<'S, 'Re, 'Res>>.GetMethod(name, NonPublicStatics)

#if DEBUG
verifyMethodInfoWasTaken mi

#else
#endif
let argTypes, args =
if spec.TypeChar = '%' then
[| retTy |], [| box prefix; tail |]
Expand All @@ -1048,13 +1057,19 @@ module internal PrintfImpl =
let buildSpecialFinal(spec : FormatSpecifier, argTys : Type[], prefix : string, suffix : string) =
if spec.TypeChar = 'a' then
let mi = typeof<Specializations<'S, 'Re, 'Res>>.GetMethod("LittleAFinal", NonPublicStatics)
#if DEBUG
verifyMethodInfoWasTaken mi
#else
#endif
let mi = mi.MakeGenericMethod(argTys.[1] : Type)
let args = [| box prefix; box suffix |]
mi.Invoke(null, args)
elif spec.TypeChar = 't' then
let mi = typeof<Specializations<'S, 'Re, 'Res>>.GetMethod("TFinal", NonPublicStatics)
#if DEBUG
verifyMethodInfoWasTaken mi
#else
#endif
let args = [| box prefix; box suffix |]
mi.Invoke(null, args)
else
Expand All @@ -1065,8 +1080,10 @@ module internal PrintfImpl =
let prefix = if spec.TypeChar = '%' then "PercentStarFinal" else "StarFinal"
let name = prefix + (string n)
typeof<Specializations<'S, 'Re, 'Res>>.GetMethod(name, NonPublicStatics)
#if DEBUG
verifyMethodInfoWasTaken mi
#else
#endif

let mi, args =
if spec.TypeChar = '%' then
Expand All @@ -1081,13 +1098,19 @@ module internal PrintfImpl =

let buildPlainFinal(args : obj[], argTypes : Type[]) =
let mi = typeof<Specializations<'S, 'Re, 'Res>>.GetMethod("Final" + (argTypes.Length.ToString()), NonPublicStatics)
#if DEBUG
verifyMethodInfoWasTaken mi
#else
#endif
let mi = mi.MakeGenericMethod(argTypes)
mi.Invoke(null, args)

let buildPlainChained(args : obj[], argTypes : Type[]) =
let mi = typeof<Specializations<'S, 'Re, 'Res>>.GetMethod("Chained" + ((argTypes.Length - 1).ToString()), NonPublicStatics)
#if DEBUG
verifyMethodInfoWasTaken mi
#else
#endif
let mi = mi.MakeGenericMethod(argTypes)
mi.Invoke(null, args)

Expand Down
2 changes: 1 addition & 1 deletion src/fsharp/FSharp.Core/quotations.fs
Original file line number Diff line number Diff line change
Expand Up @@ -931,7 +931,7 @@ module Patterns =
| Some methInfo -> methInfo

let bindMethodHelper (parentT: Type, nm,marity,argtys,rty) =
if parentT = null then invalidArg "parentT" (SR.GetString(SR.QparentCannotBeNull))
if isNull parentT then invalidArg "parentT" (SR.GetString(SR.QparentCannotBeNull))
if marity = 0 then
let tyargTs = if parentT.IsGenericType then parentT.GetGenericArguments() else [| |]
let argTs = Array.ofList (List.map (instFormal tyargTs) argtys)
Expand Down
6 changes: 3 additions & 3 deletions src/fsharp/TypeChecker.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5162,7 +5162,7 @@ and TcPat warnOnUpper cenv env topValInfo vFlags (tpenv,names,takenNames) ty pat
| _ ->
error(Error(FSComp.SR.tcUnionCaseFieldCannotBeUsedMoreThanOnce(id.idText), id.idRange))
for i = 0 to nargtys - 1 do
if box result.[i] = null then
if isNull (box result.[i]) then
result.[i] <- SynPat.Wild(m.MakeSynthetic())

let args = List.ofArray result
Expand Down Expand Up @@ -8299,7 +8299,7 @@ and TcItemThen cenv overallTy env tpenv (item,mItem,rest,afterOverloadResolution
for (_, id, arg) in namedCallerArgs do
match argNames |> List.tryFindIndex (fun id2 -> id.idText = id2.idText) with
| Some i ->
if box fittedArgs.[i] = null then
if isNull(box fittedArgs.[i]) then
fittedArgs.[i] <- arg
let argContainerOpt = match item with
| Item.UnionCase(uci,_) -> Some(ArgumentContainer.UnionCase(uci))
Expand All @@ -8325,7 +8325,7 @@ and TcItemThen cenv overallTy env tpenv (item,mItem,rest,afterOverloadResolution
| _ -> false

if isSpecialCaseForBackwardCompatibility then
assert (box fittedArgs.[currentIndex] = null)
assert (isNull(box fittedArgs.[currentIndex]))
fittedArgs.[currentIndex] <- List.item currentIndex args // grab original argument, not item from the list of named parametere
currentIndex <- currentIndex + 1
else
Expand Down
38 changes: 20 additions & 18 deletions src/fsharp/infos.fs
Original file line number Diff line number Diff line change
Expand Up @@ -561,24 +561,26 @@ type ParamData =
type ILFieldInit with
/// Compute the ILFieldInit for the given provided constant value for a provided enum type.
static member FromProvidedObj m (v:obj) =
if v = null then ILFieldInit.Null else
let objTy = v.GetType()
let v = if objTy.IsEnum then objTy.GetField("value__").GetValue(v) else v
match v with
| :? single as i -> ILFieldInit.Single i
| :? double as i -> ILFieldInit.Double i
| :? bool as i -> ILFieldInit.Bool i
| :? char as i -> ILFieldInit.Char (uint16 i)
| :? string as i -> ILFieldInit.String i
| :? sbyte as i -> ILFieldInit.Int8 i
| :? byte as i -> ILFieldInit.UInt8 i
| :? int16 as i -> ILFieldInit.Int16 i
| :? uint16 as i -> ILFieldInit.UInt16 i
| :? int as i -> ILFieldInit.Int32 i
| :? uint32 as i -> ILFieldInit.UInt32 i
| :? int64 as i -> ILFieldInit.Int64 i
| :? uint64 as i -> ILFieldInit.UInt64 i
| _ -> error(Error(FSComp.SR.infosInvalidProvidedLiteralValue(try v.ToString() with _ -> "?"),m))
match v with
| null -> ILFieldInit.Null
| _ ->
let objTy = v.GetType()
let v = if objTy.IsEnum then objTy.GetField("value__").GetValue(v) else v
match v with
| :? single as i -> ILFieldInit.Single i
| :? double as i -> ILFieldInit.Double i
| :? bool as i -> ILFieldInit.Bool i
| :? char as i -> ILFieldInit.Char (uint16 i)
| :? string as i -> ILFieldInit.String i
| :? sbyte as i -> ILFieldInit.Int8 i
| :? byte as i -> ILFieldInit.UInt8 i
| :? int16 as i -> ILFieldInit.Int16 i
| :? uint16 as i -> ILFieldInit.UInt16 i
| :? int as i -> ILFieldInit.Int32 i
| :? uint32 as i -> ILFieldInit.UInt32 i
| :? int64 as i -> ILFieldInit.Int64 i
| :? uint64 as i -> ILFieldInit.UInt64 i
| _ -> error(Error(FSComp.SR.infosInvalidProvidedLiteralValue(try v.ToString() with _ -> "?"),m))


/// Compute the OptionalArgInfo for a provided parameter.
Expand Down
2 changes: 1 addition & 1 deletion src/fsharp/vs/ServiceDeclarations.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1243,7 +1243,7 @@ type FSharpDeclarationListItem(name, glyph:int, info) =

// The dataTipSpinWaitTime limits how long we block the UI thread while a tooltip pops up next to a selected item in an IntelliSense completion list.
// This time appears to be somewhat amortized by the time it takes the VS completion UI to actually bring up the tooltip after selecting an item in the first place.
if task = null then
if isNull task then
// kick off the actual (non-cooperative) work
task <- System.Threading.Tasks.Task.Factory.StartNew(fun() ->
let text = decl.DescriptionTextAsync |> Async.RunSynchronously
Expand Down
11 changes: 6 additions & 5 deletions src/utils/CompilerLocationUtils.fs
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,13 @@ module internal FSharpEnvironment =
Option.ofString
(try
let key = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32)
if key = null then null
else
match key with
| null -> null
| _ ->
let sub = key.OpenSubKey(subKey)
if sub = null then null
else
downcast (sub.GetValue(null, null))
match sub with
| null -> null
| _ -> downcast (sub.GetValue(null, null))
with e->
System.Diagnostics.Debug.Assert(false, sprintf "Failed in Get32BitRegistryStringValueViaDotNet: %s" (e.ToString()))
null)
Expand Down
9 changes: 6 additions & 3 deletions src/utils/sformat.fs
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,7 @@ namespace Microsoft.FSharp.Text.StructuredFormat
| res ->
let attr = (res.[0] :?> StructuredFormatDisplayAttribute)
let txt = attr.Value
if txt = null || txt.Length <= 1 then
if isNull txt || txt.Length <= 1 then
None
else
let messageRegexPattern = @"^(?<pre>.*?)(?<!\\){(?<prop>.*?)(?<!\\)}(?<post>.*)$"
Expand Down Expand Up @@ -1169,8 +1169,11 @@ namespace Microsoft.FSharp.Text.StructuredFormat
| :? unativeint as d -> d.ToString() + "un"
| :? bool as b -> (if b then "true" else "false")
| :? char as c -> "\'" + formatChar true c + "\'"
| _ -> try let text = obj.ToString()
if text = null then "" else text
| _ -> try
let text = obj.ToString()
match text with
| null -> ""
| _ -> text
with e ->
// If a .ToString() call throws an exception, catch it and use the message as the result.
// This may be informative, e.g. division by zero etc...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ type internal FSharpLanguageServiceBackgroundRequests
// Called before a Goto Definition to wait a moment to synchonize the parse
member fls.TrySynchronizeParseFileInformation(view: IVsTextView, source: ISource, millisecondsTimeout:int) =

if (lastParseFileRequest = null || lastParseFileRequest.Timestamp <> source.ChangeCount) then
if isNull lastParseFileRequest || lastParseFileRequest.Timestamp <> source.ChangeCount then
let req = fls.TriggerParseFile(view, source)

if req <> null && (req.IsSynchronous || req.Result <> null) then
Expand Down
4 changes: 2 additions & 2 deletions vsintegration/src/FSharp.LanguageService/FSharpSource.fs
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ type internal FSharpSource(service:LanguageService, textLines, colorizer, vsFile
member source.HandleCompletionResponse(req) =
match req with
| null -> source.ResetFSharpIntelliSenseToAppearAdornment()
| _ when req.View = null || req.ResultIntellisenseInfo = null -> source.ResetFSharpIntelliSenseToAppearAdornment()
| _ when isNull req.View || isNull req.ResultIntellisenseInfo -> source.ResetFSharpIntelliSenseToAppearAdornment()
| _ when (req.Timestamp <> source.ChangeCount) -> source.ResetFSharpIntelliSenseToAppearAdornment()
| _ ->
source.HandleResponseHelper(req)
Expand All @@ -448,7 +448,7 @@ type internal FSharpSource(service:LanguageService, textLines, colorizer, vsFile
async {
let! decls = req.ResultIntellisenseInfo.GetDeclarations(req.Snapshot, req.Line, req.Col, reason)
do! Async.SwitchToContext UIThread.TheSynchronizationContext
if (decls = null || decls.IsEmpty()) && req.Timestamp <> req.ResultTimestamp then
if (isNull decls || decls.IsEmpty()) && req.Timestamp <> req.ResultTimestamp then
// Second chance intellisense: we didn't get any result and the basis typecheck was stale. We need to retrigger the completion.
source.Completion(req.View, req.TokenInfo, req.Reason, RequireFreshResults.Yes)
else
Expand Down
Loading