Skip to content

Commit

Permalink
fix LanguagePrimitives.ErrorStrings messages depends on culture
Browse files Browse the repository at this point in the history
the SR.GetString use CultureInfo.CurrentUICulture, so need to be invoked at
runtime not bound when the module ErrorStrings is opened
  • Loading branch information
enricosada committed Jan 27, 2015
1 parent 58981ec commit 52a7252
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 34 deletions.
13 changes: 6 additions & 7 deletions src/fsharp/FSharp.Core/array.fs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ namespace Microsoft.FSharp.Collections
open Microsoft.FSharp.Core.Operators
open Microsoft.FSharp.Core.LanguagePrimitives.IntrinsicOperators
open Microsoft.FSharp.Core.SR
open Microsoft.FSharp.Core.LanguagePrimitives.ErrorStrings
#if FX_NO_ICLONEABLE
open Microsoft.FSharp.Core.ICloneableExtensions
#else
Expand Down Expand Up @@ -462,7 +461,7 @@ namespace Microsoft.FSharp.Collections
checkNonNull "array" array
let len = array.Length
if len = 0 then
invalidArg "array" InputArrayEmptyString
invalidArg "array" LanguagePrimitives.ErrorStrings.InputArrayEmptyString
else
let f = OptimizedClosures.FSharpFunc<_,_,_>.Adapt(f)
let mutable res = array.[0]
Expand All @@ -474,7 +473,7 @@ namespace Microsoft.FSharp.Collections
let reduceBack f (array : _[]) =
checkNonNull "array" array
let len = array.Length
if len = 0 then invalidArg "array" InputArrayEmptyString
if len = 0 then invalidArg "array" LanguagePrimitives.ErrorStrings.InputArrayEmptyString
else foldSubRight f array 0 (len - 2) array.[len - 1]

[<CompiledName("SortInPlaceWith")>]
Expand Down Expand Up @@ -575,7 +574,7 @@ namespace Microsoft.FSharp.Collections
[<CompiledName("Min")>]
let inline min (array:_[]) =
checkNonNull "array" array
if array.Length = 0 then invalidArg "array" InputArrayEmptyString
if array.Length = 0 then invalidArg "array" LanguagePrimitives.ErrorStrings.InputArrayEmptyString
let mutable acc = array.[0]
for i = 1 to array.Length - 1 do
let curr = array.[i]
Expand All @@ -586,7 +585,7 @@ namespace Microsoft.FSharp.Collections
[<CompiledName("MinBy")>]
let inline minBy f (array:_[]) =
checkNonNull "array" array
if array.Length = 0 then invalidArg "array" InputArrayEmptyString
if array.Length = 0 then invalidArg "array" LanguagePrimitives.ErrorStrings.InputArrayEmptyString
let mutable accv = array.[0]
let mutable acc = f accv
for i = 1 to array.Length - 1 do
Expand All @@ -600,7 +599,7 @@ namespace Microsoft.FSharp.Collections
[<CompiledName("Max")>]
let inline max (array:_[]) =
checkNonNull "array" array
if array.Length = 0 then invalidArg "array" InputArrayEmptyString
if array.Length = 0 then invalidArg "array" LanguagePrimitives.ErrorStrings.InputArrayEmptyString
let mutable acc = array.[0]
for i = 1 to array.Length - 1 do
let curr = array.[i]
Expand All @@ -611,7 +610,7 @@ namespace Microsoft.FSharp.Collections
[<CompiledName("MaxBy")>]
let inline maxBy f (array:_[]) =
checkNonNull "array" array
if array.Length = 0 then invalidArg "array" InputArrayEmptyString
if array.Length = 0 then invalidArg "array" LanguagePrimitives.ErrorStrings.InputArrayEmptyString
let mutable accv = array.[0]
let mutable acc = f accv
for i = 1 to array.Length - 1 do
Expand Down
5 changes: 2 additions & 3 deletions src/fsharp/FSharp.Core/local.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ namespace Microsoft.FSharp.Primitives.Basics

open Microsoft.FSharp.Core
open Microsoft.FSharp.Core.LanguagePrimitives.IntrinsicOperators
open Microsoft.FSharp.Core.LanguagePrimitives.ErrorStrings
open Microsoft.FSharp.Collections
open Microsoft.FSharp.Core.Operators
open System.Diagnostics.CodeAnalysis
Expand Down Expand Up @@ -242,7 +241,7 @@ module internal List =


let init count f =
if count < 0 then invalidArg "count" InputMustBeNonNegativeString
if count < 0 then invalidArg "count" LanguagePrimitives.ErrorStrings.InputMustBeNonNegativeString
if count = 0 then []
else
let res = freshConsNoTail (f 0)
Expand Down Expand Up @@ -560,7 +559,7 @@ module internal Array =
(# "newarr !0" type ('T) count : 'T array #)

let inline init (count:int) (f: int -> 'T) =
if count < 0 then invalidArg "count" InputMustBeNonNegativeString
if count < 0 then invalidArg "count" LanguagePrimitives.ErrorStrings.InputMustBeNonNegativeString
let arr = (zeroCreateUnchecked count : 'T array)
for i = 0 to count - 1 do
arr.[i] <- f i
Expand Down
14 changes: 7 additions & 7 deletions src/fsharp/FSharp.Core/prim-types.fs
Original file line number Diff line number Diff line change
Expand Up @@ -646,17 +646,17 @@ namespace Microsoft.FSharp.Core

module LanguagePrimitives =


module (* internal *) ErrorStrings =
[<Sealed>]
type (* internal *) ErrorStrings =
// inline functions cannot call GetString, so we must make these bits public
let AddressOpNotFirstClassString = SR.GetString(SR.addressOpNotFirstClass)
let NoNegateMinValueString = SR.GetString(SR.noNegateMinValue)
static member AddressOpNotFirstClassString with get () = SR.GetString(SR.addressOpNotFirstClass)
static member NoNegateMinValueString with get () = SR.GetString(SR.noNegateMinValue)
// needs to be public to be visible from inline function 'average' and others
let InputSequenceEmptyString = SR.GetString(SR.inputSequenceEmpty)
static member InputSequenceEmptyString with get () = SR.GetString(SR.inputSequenceEmpty)
// needs to be public to be visible from inline function 'average' and others
let InputArrayEmptyString = SR.GetString(SR.arrayWasEmpty)
static member InputArrayEmptyString with get () = SR.GetString(SR.arrayWasEmpty)
// needs to be public to be visible from inline function 'average' and others
let InputMustBeNonNegativeString = SR.GetString(SR.inputMustBeNonNegative)
static member InputMustBeNonNegativeString with get () = SR.GetString(SR.inputMustBeNonNegative)

[<CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1034:NestedTypesShouldNotBeVisible")>] // nested module OK
module IntrinsicOperators =
Expand Down
13 changes: 7 additions & 6 deletions src/fsharp/FSharp.Core/prim-types.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -983,22 +983,23 @@ namespace Microsoft.FSharp.Core
val inline DivideByInt< ^T > : x:^T -> y:int -> ^T when ^T : (static member DivideByInt : ^T * int -> ^T)

/// <summary>For internal use only</summary>
module (* internal *) ErrorStrings =
[<Sealed>]
type (* internal *) ErrorStrings =

[<CompilerMessage("This value is for use by compiled F# code and should not be used directly", 1204, IsHidden=true)>]
val InputSequenceEmptyString : string
static member InputSequenceEmptyString : string with get

[<CompilerMessage("This value is for use by compiled F# code and should not be used directly", 1204, IsHidden=true)>]
val InputArrayEmptyString : string
static member InputArrayEmptyString : string with get

[<CompilerMessage("This value is for use by compiled F# code and should not be used directly", 1204, IsHidden=true)>]
val AddressOpNotFirstClassString : string
static member AddressOpNotFirstClassString : string with get

[<CompilerMessage("This value is for use by compiled F# code and should not be used directly", 1204, IsHidden=true)>]
val NoNegateMinValueString : string
static member NoNegateMinValueString : string with get

[<CompilerMessage("This value is for use by compiled F# code and should not be used directly", 1204, IsHidden=true)>]
val InputMustBeNonNegativeString : string
static member InputMustBeNonNegativeString : string with get


//-------------------------------------------------------------------------
Expand Down
21 changes: 10 additions & 11 deletions src/fsharp/FSharp.Core/seq.fs
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,6 @@ namespace Microsoft.FSharp.Collections
open System.Collections.Generic
open Microsoft.FSharp.Core
open Microsoft.FSharp.Core.LanguagePrimitives.IntrinsicOperators
open Microsoft.FSharp.Core.LanguagePrimitives.ErrorStrings
open Microsoft.FSharp.Core.Operators
open Microsoft.FSharp.Core.CompilerServices
open Microsoft.FSharp.Control
Expand Down Expand Up @@ -1047,7 +1046,7 @@ namespace Microsoft.FSharp.Collections
let reduce f (source : seq<'T>) =
checkNonNull "source" source
use e = source.GetEnumerator()
if not (e.MoveNext()) then invalidArg "source" InputSequenceEmptyString;
if not (e.MoveNext()) then invalidArg "source" LanguagePrimitives.ErrorStrings.InputSequenceEmptyString;
let f = OptimizedClosures.FSharpFunc<_,_,_>.Adapt(f)
let mutable state = e.Current
while e.MoveNext() do
Expand Down Expand Up @@ -1375,7 +1374,7 @@ namespace Microsoft.FSharp.Collections
acc <- Checked.(+) acc e.Current
count <- count + 1
if count = 0 then
invalidArg "source" InputSequenceEmptyString
invalidArg "source" LanguagePrimitives.ErrorStrings.InputSequenceEmptyString
LanguagePrimitives.DivideByInt< (^a) > acc count

[<CompiledName("AverageBy")>]
Expand All @@ -1388,15 +1387,15 @@ namespace Microsoft.FSharp.Collections
acc <- Checked.(+) acc (f e.Current)
count <- count + 1
if count = 0 then
invalidArg "source" InputSequenceEmptyString;
invalidArg "source" LanguagePrimitives.ErrorStrings.InputSequenceEmptyString;
LanguagePrimitives.DivideByInt< (^U) > acc count

[<CompiledName("Min")>]
let inline min (source: seq<_>) =
checkNonNull "source" source
use e = source.GetEnumerator()
if not (e.MoveNext()) then
invalidArg "source" InputSequenceEmptyString;
invalidArg "source" LanguagePrimitives.ErrorStrings.InputSequenceEmptyString;
let mutable acc = e.Current
while e.MoveNext() do
let curr = e.Current
Expand All @@ -1409,7 +1408,7 @@ namespace Microsoft.FSharp.Collections
checkNonNull "source" source
use e = source.GetEnumerator()
if not (e.MoveNext()) then
invalidArg "source" InputSequenceEmptyString;
invalidArg "source" LanguagePrimitives.ErrorStrings.InputSequenceEmptyString;
let first = e.Current
let mutable acc = f first
let mutable accv = first
Expand Down Expand Up @@ -1443,7 +1442,7 @@ namespace Microsoft.FSharp.Collections
checkNonNull "source" source
use e = source.GetEnumerator()
if not (e.MoveNext()) then
invalidArg "source" InputSequenceEmptyString;
invalidArg "source" LanguagePrimitives.ErrorStrings.InputSequenceEmptyString;
let mutable acc = e.Current
while e.MoveNext() do
let curr = e.Current
Expand All @@ -1456,7 +1455,7 @@ namespace Microsoft.FSharp.Collections
checkNonNull "source" source
use e = source.GetEnumerator()
if not (e.MoveNext()) then
invalidArg "source" InputSequenceEmptyString;
invalidArg "source" LanguagePrimitives.ErrorStrings.InputSequenceEmptyString;
let first = e.Current
let mutable acc = f first
let mutable accv = first
Expand Down Expand Up @@ -1546,7 +1545,7 @@ namespace Microsoft.FSharp.Collections
checkNonNull "source" source
use e = source.GetEnumerator()
if (e.MoveNext()) then e.Current
else invalidArg "source" InputSequenceEmptyString
else invalidArg "source" LanguagePrimitives.ErrorStrings.InputSequenceEmptyString

[<CompiledName("Last")>]
let last (source : seq<_>) =
Expand All @@ -1557,7 +1556,7 @@ namespace Microsoft.FSharp.Collections
while (e.MoveNext()) do res <- e.Current
res
else
invalidArg "source" InputSequenceEmptyString
invalidArg "source" LanguagePrimitives.ErrorStrings.InputSequenceEmptyString


[<CompiledName("ExactlyOne")>]
Expand All @@ -1571,4 +1570,4 @@ namespace Microsoft.FSharp.Collections
else
v
else
invalidArg "source" InputSequenceEmptyString
invalidArg "source" LanguagePrimitives.ErrorStrings.InputSequenceEmptyString

0 comments on commit 52a7252

Please sign in to comment.