Skip to content

Mark Range.Zero as obsolete in favor of Range.range0 #18664

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

Merged
merged 3 commits into from
Jun 6, 2025
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
1 change: 1 addition & 0 deletions docs/release-notes/.FSharp.Compiler.Service/10.0.100.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@
* Scoped Nowarn: Add the #warnon compiler directive ([Language suggestion #278](https://github.com/fsharp/fslang-suggestions/issues/278), [RFC FS-1146 PR](https://github.com/fsharp/fslang-design/pull/782), [PR #18049](https://github.com/dotnet/fsharp/pull/18049) and [PR #18637](https://github.com/dotnet/fsharp/pull/18637))
* Simplify creation of `FSharpDiagnostics`. In a few cases, errors without ranges were assigned to the currently checked file, while in other cases they carried an empty range. The latter is now true in all cases. In a few cases, ranges at eof were corrected, while in others they were not. They are now always left uncorrected. This is a prerequisit for [#18553](https://github.com/dotnet/fsharp/issues/18553). ([PR #18610](https://github.com/dotnet/fsharp/pull/18610)).
* `SynExprRecordField` now includes a `range` field ([PR #18617](https://github.com/dotnet/fsharp/pull/18617))
* Mark `Range.Zero` as obsolete in favor of `Range.range0` ([PR #18664](https://github.com/dotnet/fsharp/pull/18664))
3 changes: 2 additions & 1 deletion src/Compiler/Checking/CheckIncrementalClasses.fs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ open FSharp.Compiler.NameResolution
open FSharp.Compiler.Syntax
open FSharp.Compiler.SyntaxTreeOps
open FSharp.Compiler.Text
open FSharp.Compiler.Text.Range
open FSharp.Compiler.Xml
open FSharp.Compiler.TcGlobals
open FSharp.Compiler.TypedTree
Expand Down Expand Up @@ -111,7 +112,7 @@ let TcStaticImplicitCtorInfo_Phase2A(cenv: cenv, env, tcref: TyconRef, m, copyOf
let prelimValReprInfo = TranslateSynValInfo cenv m (TcAttributes cenv env) valSynData
let prelimTyschemeG = GeneralizedType(copyOfTyconTypars, cctorTy)
let valReprInfo = InferGenericArityFromTyScheme prelimTyschemeG prelimValReprInfo
let cctorValScheme = ValScheme(id, prelimTyschemeG, Some valReprInfo, None, Some memberInfo, false, ValInline.Never, NormalVal, Some (SynAccess.Private Range.Zero), false, true, false, false)
let cctorValScheme = ValScheme(id, prelimTyschemeG, Some valReprInfo, None, Some memberInfo, false, ValInline.Never, NormalVal, Some (SynAccess.Private range0), false, true, false, false)

let cctorVal = MakeAndPublishVal cenv env (Parent tcref, false, ModuleOrMemberBinding, ValNotInRecScope, cctorValScheme, [(* no attributes*)], XmlDoc.Empty, None, false)
cctorArgs, cctorVal, cctorValScheme
Expand Down
6 changes: 3 additions & 3 deletions src/Compiler/Checking/Expressions/CheckExpressions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -811,10 +811,10 @@ let TcConst (cenv: cenv) (overallTy: TType) m env synConst =
Measure.Prod(tcMeasure ms1, tcMeasure ms2, m)
| SynMeasure.Divide(ms1, _, (SynMeasure.Seq (_ :: _ :: _, _) as ms2), m) ->
warning(Error(FSComp.SR.tcImplicitMeasureFollowingSlash(), m))
let factor1 = ms1 |> Option.defaultValue (SynMeasure.One Range.Zero)
let factor1 = ms1 |> Option.defaultValue (SynMeasure.One range0)
Measure.Prod(tcMeasure factor1, Measure.Inv (tcMeasure ms2), ms.Range)
| SynMeasure.Divide(measure1 = ms1; measure2 = ms2) ->
let factor1 = ms1 |> Option.defaultValue (SynMeasure.One Range.Zero)
let factor1 = ms1 |> Option.defaultValue (SynMeasure.One range0)
Measure.Prod(tcMeasure factor1, Measure.Inv (tcMeasure ms2), ms.Range)
| SynMeasure.Seq(mss, _) -> ProdMeasures (List.map tcMeasure mss)
| SynMeasure.Anon _ -> error(Error(FSComp.SR.tcUnexpectedMeasureAnon(), m))
Expand Down Expand Up @@ -2307,7 +2307,7 @@ module GeneralizationHelpers =
declaredTypars
|> List.map(fun typar -> typar.Range)

let m = declaredTyparsRange |> List.fold (fun r a -> unionRanges r a) range.Zero
let m = declaredTyparsRange |> List.fold (fun r a -> unionRanges r a) range0

errorR(Error(FSComp.SR.tcPropertyRequiresExplicitTypeParameters(), m))
| SynMemberKind.Constructor ->
Expand Down
4 changes: 2 additions & 2 deletions src/Compiler/Checking/import.fs
Original file line number Diff line number Diff line change
Expand Up @@ -565,10 +565,10 @@ let rec ImportProvidedType (env: ImportMap) (m: range) (* (tinst: TypeInst) *) (
| TType_app (tcref, [], _) when tcref.TypeOrMeasureKind = TyparKind.Measure -> Measure.Const(tcref, tcref.Range)
| TType_app (tcref, _, _) ->
errorR(Error(FSComp.SR.impInvalidMeasureArgument1(tcref.CompiledName, tp.Name), m))
Measure.One(tcref.Range)
Measure.One tcref.Range
| _ ->
errorR(Error(FSComp.SR.impInvalidMeasureArgument2(tp.Name), m))
Measure.One(Range.Zero)
Measure.One range0

TType_measure (conv genericArg)
else
Expand Down
6 changes: 2 additions & 4 deletions src/Compiler/CodeGen/IlxGenSupport.fs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ open System.Reflection
open Internal.Utilities.Library
open FSharp.Compiler.AbstractIL.IL
open FSharp.Compiler.TcGlobals
open FSharp.Compiler.Text.Range
open FSharp.Compiler.TypedTreeOps
open FSharp.Compiler.TypedTree

Expand Down Expand Up @@ -404,10 +405,7 @@ let rec GetNullnessFromTType (g: TcGlobals) ty =
else if isValueType then
// Generic value type: 0, followed by the representation of the type arguments in order including containing types
yield NullnessInfo.AmbivalentToNull
else if
IsUnionTypeWithNullAsTrueValue g tcref.Deref
|| TypeHasAllowNull tcref g FSharp.Compiler.Text.Range.Zero
then
else if IsUnionTypeWithNullAsTrueValue g tcref.Deref || TypeHasAllowNull tcref g range0 then
yield NullnessInfo.WithNull
else
// Reference type: the nullability (0, 1, or 2), followed by the representation of the type arguments in order including containing types
Expand Down
2 changes: 1 addition & 1 deletion src/Compiler/Driver/CompilerDiagnostics.fs
Original file line number Diff line number Diff line change
Expand Up @@ -889,7 +889,7 @@ type Exception with
|> List.map (fun (name, tTy) ->
tTy,
{
ArgReprInfo.Name = name |> Option.map (fun name -> Ident(name, range.Zero))
ArgReprInfo.Name = name |> Option.map (fun name -> Ident(name, range0))
ArgReprInfo.Attribs = []
ArgReprInfo.OtherRange = None
})
Expand Down
2 changes: 1 addition & 1 deletion src/Compiler/Service/FSharpCheckerResults.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3388,7 +3388,7 @@ type FSharpCheckFileResults
| None -> ()
| Some kwDescription ->
let kwText = kw |> TaggedText.tagKeyword |> wordL |> LayoutRender.toArray
yield ToolTipElement.Single(kwText, FSharpXmlDoc.FromXmlText(Xml.XmlDoc([| kwDescription |], range.Zero)))
yield ToolTipElement.Single(kwText, FSharpXmlDoc.FromXmlText(Xml.XmlDoc([| kwDescription |], range0)))
]

/// Resolve the names at the given location to give a data tip
Expand Down
3 changes: 2 additions & 1 deletion src/Compiler/Service/ServiceDeclarationLists.fs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ open FSharp.Compiler.Symbols.SymbolHelpers
open FSharp.Compiler.Syntax.PrettyNaming
open FSharp.Compiler.TcGlobals
open FSharp.Compiler.Text
open FSharp.Compiler.Text.Range
open FSharp.Compiler.Text.Layout
open FSharp.Compiler.Text.LayoutRender
open FSharp.Compiler.Text.TaggedText
Expand Down Expand Up @@ -100,7 +101,7 @@ module DeclarationListHelpers =
/// Generate the structured tooltip for a method info
let FormatOverloadsToList (infoReader: InfoReader) m denv (item: ItemWithInst) minfos symbol (width: int option) : ToolTipElement =
ToolTipFault |> Option.iter (fun msg ->
let exn = Error((0, msg), range.Zero)
let exn = Error((0, msg), range0)
let ph = PhasedDiagnostic.Create(exn, BuildPhase.TypeCheck)
simulateError ph)

Expand Down
10 changes: 5 additions & 5 deletions src/Compiler/Service/ServiceNavigation.fs
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,14 @@ type NavigationItems(declarations: NavigationTopLevelDeclaration[]) =

module NavigationImpl =
let unionRangesChecked r1 r2 =
if equals r1 range.Zero then r2
elif equals r2 range.Zero then r1
if equals r1 range0 then r2
elif equals r2 range0 then r1
else unionRanges r1 r2

let rangeOfDecls2 f decls =
match decls |> List.map (f >> (fun (d: NavigationItem) -> d.bodyRange)) with
| hd :: tl -> tl |> List.fold unionRangesChecked hd
| [] -> range.Zero
| [] -> range0

let rangeOfDecls = rangeOfDecls2 fst

Expand All @@ -118,7 +118,7 @@ module NavigationImpl =
match fldspec with
| SynUnionCaseKind.Fields(flds) ->
flds
|> List.fold (fun st (SynField(range = m)) -> unionRangesChecked m st) range.Zero
|> List.fold (fun st (SynField(range = m)) -> unionRangesChecked m st) range0
| SynUnionCaseKind.FullType(ty, _) -> ty.Range

let bodyRange mBody decls =
Expand Down Expand Up @@ -357,7 +357,7 @@ module NavigationImpl =
]
| _ -> []))

let m2 = members |> Seq.map fst |> Seq.fold unionRangesChecked range.Zero
let m2 = members |> Seq.map fst |> Seq.fold unionRangesChecked range0
let items = members |> List.collect snd
m2, items

Expand Down
2 changes: 1 addition & 1 deletion src/Compiler/Symbols/FSharpDiagnostic.fs
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ type FSharpDiagnostic(m: range, severity: FSharpDiagnosticSeverity, message: str
| _ -> diagnostic.FormatCore(flatErrors, suggestNames)

let errorNum = diagnostic.Number
let m = match diagnostic.Range with Some m -> m | None -> range.Zero
let m = match diagnostic.Range with Some m -> m | None -> range0
FSharpDiagnostic(m, severity, msg, diagnostic.Subcategory(), errorNum, "FS", extendedData)

static member NewlineifyErrorString(message) = NewlineifyErrorString(message)
Expand Down
2 changes: 1 addition & 1 deletion src/Compiler/Symbols/Symbols.fs
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,7 @@ type FSharpEntity(cenv: SymbolEnv, entity: EntityRef, tyargs: TType list) =

if entity.IsILEnumTycon then
let (TILObjectReprData(_scoref, _enc, tdef)) = entity.ILTyconInfo
let formalTypars = entity.Typars(range.Zero)
let formalTypars = entity.Typars range0
let formalTypeInst = generalizeTypars formalTypars
let ty = TType_app(entity, formalTypeInst, cenv.g.knownWithoutNull)
let formalTypeInfo = ILTypeInfo.FromType cenv.g ty
Expand Down
4 changes: 2 additions & 2 deletions src/Compiler/SyntaxTree/ParseHelpers.fs
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@ let adjustHatPrefixToTyparLookup mFull rightExpr =
let mkSynTypeTuple (elementTypes: SynTupleTypeSegment list) : SynType =
let range =
match elementTypes with
| [] -> Range.Zero
| [] -> range0
| head :: tail ->

(head.Range, tail)
Expand Down Expand Up @@ -889,7 +889,7 @@ let mkLocalBindings (mWhole, BindingSetPreAttrs(_, isRec, isUse, declsPreAttrs,
let mLetOrUse =
match decls with
| SynBinding(trivia = trivia) :: _ -> trivia.LeadingKeyword.Range
| _ -> Range.Zero
| _ -> range0

SynExpr.LetOrUse(
isRec,
Expand Down
14 changes: 6 additions & 8 deletions src/Compiler/SyntaxTree/SyntaxTrivia.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace FSharp.Compiler.SyntaxTrivia

open FSharp.Compiler.Text
open FSharp.Compiler.Text.Range

[<RequireQualifiedAccess; NoEquality; NoComparison>]
type IdentTrivia =
Expand Down Expand Up @@ -98,7 +99,7 @@ type SynExprLetOrUseTrivia =
static member Zero: SynExprLetOrUseTrivia =
{
InKeyword = None
LetOrUseKeyword = Range.Zero
LetOrUseKeyword = range0
}

[<NoEquality; NoComparison>]
Expand All @@ -110,7 +111,7 @@ type SynExprLetOrUseBangTrivia =

static member Zero: SynExprLetOrUseBangTrivia =
{
LetOrUseBangKeyword = Range.Zero
LetOrUseBangKeyword = range0
EqualsRange = None
}

Expand All @@ -134,18 +135,15 @@ type SynExprYieldOrReturnTrivia =
YieldOrReturnKeyword: range
}

static member Zero: SynExprYieldOrReturnTrivia = { YieldOrReturnKeyword = Range.Zero }
static member Zero: SynExprYieldOrReturnTrivia = { YieldOrReturnKeyword = range0 }

[<NoEquality; NoComparison>]
type SynExprYieldOrReturnFromTrivia =
{
YieldOrReturnFromKeyword: range
}

static member Zero: SynExprYieldOrReturnFromTrivia =
{
YieldOrReturnFromKeyword = Range.Zero
}
static member Zero: SynExprYieldOrReturnFromTrivia = { YieldOrReturnFromKeyword = range0 }

[<NoEquality; NoComparison>]
type SynExprDoBangTrivia = { DoBangKeyword: range }
Expand Down Expand Up @@ -288,7 +286,7 @@ type SynLeadingKeyword =
| MemberVal(m1, m2)
| OverrideVal(m1, m2)
| StaticMemberVal(m1, _, m2) -> Range.unionRanges m1 m2
| Synthetic -> Range.Zero
| Synthetic -> range0

[<NoEquality; NoComparison>]
type SynBindingTrivia =
Expand Down
2 changes: 1 addition & 1 deletion src/Compiler/SyntaxTree/XmlDoc.fs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ type PreXmlDoc =
if part1.IsEmpty then part2.Range
elif part2.IsEmpty then part1.Range
else unionRanges part1.Range part2.Range
| PreXmlDocEmpty -> Range.Zero
| PreXmlDocEmpty -> range0
| PreXmlDoc(pos, collector) -> collector.LinesRange pos

member x.IsEmpty =
Expand Down
4 changes: 2 additions & 2 deletions src/Compiler/TypedTree/TypedTreePickle.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2906,12 +2906,12 @@ and p_tycon_objmodel_kind x st =
| TFSharpEnum -> p_byte 4 st
| TFSharpUnion ->
if st.oglobals.compilingFSharpCore then
raise (Error(FSComp.SR.pickleFsharpCoreBackwardsCompatible ("union as FSharpTyconKind ", st.ofile), range.Zero))
raise (Error(FSComp.SR.pickleFsharpCoreBackwardsCompatible ("union as FSharpTyconKind ", st.ofile), range0))

p_byte 5 st
| TFSharpRecord ->
if st.oglobals.compilingFSharpCore then
raise (Error(FSComp.SR.pickleFsharpCoreBackwardsCompatible ("record as FSharpTyconKind ", st.ofile), range.Zero))
raise (Error(FSComp.SR.pickleFsharpCoreBackwardsCompatible ("record as FSharpTyconKind ", st.ofile), range0))

p_byte 6 st

Expand Down
1 change: 1 addition & 0 deletions src/Compiler/Utilities/range.fs
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ module FileIndex =
[<Struct; CustomEquality; NoComparison>]
[<System.Diagnostics.DebuggerDisplay("({StartLine},{StartColumn}-{EndLine},{EndColumn}) {ShortFileName} -> {DebugCode}")>]
type Range(code1: int64, code2: int64) =
[<Obsolete("Use Range.range0 instead")>]
static member Zero = range (0L, 0L)

new(fIdx, bl, bc, el, ec) =
Expand Down
2 changes: 2 additions & 0 deletions src/Compiler/Utilities/range.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// The Range and Pos types form part of the public API of FSharp.Compiler.Service
namespace FSharp.Compiler.Text

open System
open System.Collections.Generic

/// An index into a global tables of filenames
Expand Down Expand Up @@ -121,6 +122,7 @@ type Range =
member internal IsAdjacentTo: otherRange: Range -> bool

/// The range where all values are zero
[<Obsolete("Use Range.range0 instead")>]
static member Zero: range

/// Represents a range within a file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ module Codepage =
|> compile
|> shouldFail
|> withDiagnostics [
(Error 193, Line 0, Col 1, Line 0, Col 1, "No data is available for encoding 65535. For information on defining a custom encoding, see the documentation for the Encoding.RegisterProvider method.")
(Error 193, Line 1, Col 1, Line 1, Col 1, "No data is available for encoding 65535. For information on defining a custom encoding, see the documentation for the Encoding.RegisterProvider method.")
]

//# Boundary case
Expand Down
10 changes: 5 additions & 5 deletions tests/FSharp.Compiler.Service.Tests/RangeTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ open Xunit

[<Fact>]
let ``withStartEnd Test`` () =
let z = Range.Zero
let z = range0
let newStart = mkPos 2 4
let newEnd = mkPos 7 23
let r = withStartEnd newStart newEnd z
Expand All @@ -17,21 +17,21 @@ let ``withStartEnd Test`` () =

[<Fact>]
let ``withStart Test`` () =
let z = Range.Zero
let z = range0
let newStart = mkPos 2 4
let r = withStart newStart z
r.Start |> shouldEqual newStart

[<Fact>]
let ``withEnd Test`` () =
let z = Range.Zero
let z = range0
let newEnd = mkPos 2 4
let r = withEnd newEnd z
r.End |> shouldEqual newEnd

[<Fact>]
let ``shiftStart Test`` () =
let z = Range.Zero
let z = range0
let lineDelta = 10
let columnDelta = 20
let r = shiftStart lineDelta columnDelta z
Expand All @@ -40,7 +40,7 @@ let ``shiftStart Test`` () =

[<Fact>]
let ``shiftEnd Test`` () =
let z = Range.Zero
let z = range0
let lineDelta = 10
let columnDelta = 20
let r = shiftEnd lineDelta columnDelta z
Expand Down
3 changes: 2 additions & 1 deletion tests/FSharp.Compiler.Service.Tests/SourceTextTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

open System
open FSharp.Compiler.Text
open FSharp.Compiler.Text.Range
open Xunit

[<Fact>]
Expand Down Expand Up @@ -36,7 +37,7 @@ let ``Inconsistent return carriage return correct text`` () =
[<Fact>]
let ``Zero range should return empty string`` () =
let sourceText = SourceText.ofString "a"
let v = sourceText.GetSubTextFromRange Range.Zero
let v = sourceText.GetSubTextFromRange range0
Assert.Equal(String.Empty, v)

[<Fact>]
Expand Down
4 changes: 2 additions & 2 deletions tests/FSharp.Compiler.Service.Tests/TestDoubles.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module FSharp.Compiler.Service.Tests.TestDoubles

open System.IO
open FSharp.Compiler.Text
open FSharp.Compiler.Text.Range
open FSharp.Compiler.AbstractIL.ILBinaryReader
open FSharp.Compiler.CompilerConfig
open Internal.Utilities
Expand All @@ -20,4 +20,4 @@ let internal getArbitraryTcConfigBuilder() =
CopyFSharpCoreFlag.No,
(fun _ -> None),
None,
Range.Zero)
range0)
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
[IL]: Error [StackUnexpected]: : FSharp.Compiler.AbstractIL.IL::parseILVersion(string)][offset 0x0000000B][found Char] Unexpected type on the stack.
[IL]: Error [StackUnexpected]: : FSharp.Compiler.AbstractIL.IL::parseILVersion(string)][offset 0x00000021][found Char] Unexpected type on the stack.
[IL]: Error [StackUnexpected]: : <StartupCode$FSharp-Compiler-Service>.$FSharp.Compiler.DiagnosticsLogger::.cctor()][offset 0x000000CD][found Char] Unexpected type on the stack.
[IL]: Error [CallVirtOnValueType]: : FSharp.Compiler.Text.RangeModule+comparer@558::System.Collections.Generic.IEqualityComparer<FSharp.Compiler.Text.Range>.GetHashCode([FSharp.Compiler.Service]FSharp.Compiler.Text.Range)][offset 0x00000002] Callvirt on a value type method.
[IL]: Error [CallVirtOnValueType]: : FSharp.Compiler.Text.RangeModule+comparer@559::System.Collections.Generic.IEqualityComparer<FSharp.Compiler.Text.Range>.GetHashCode([FSharp.Compiler.Service]FSharp.Compiler.Text.Range)][offset 0x00000002] Callvirt on a value type method.
[IL]: Error [StackUnexpected]: : Internal.Utilities.PathMapModule::applyDir([FSharp.Compiler.Service]Internal.Utilities.PathMap, string)][offset 0x00000037][found Char] Unexpected type on the stack.
[IL]: Error [StackUnexpected]: : Internal.Utilities.PathMapModule::applyDir([FSharp.Compiler.Service]Internal.Utilities.PathMap, string)][offset 0x00000043][found Char] Unexpected type on the stack.
[IL]: Error [StackUnexpected]: : <StartupCode$FSharp-Compiler-Service>.$Internal.Utilities.XmlAdapters::.cctor()][offset 0x0000000A][found Char] Unexpected type on the stack.
Expand Down
Loading
Loading