3354,tcNotAFunctionButIndexerNamedIndexingNotYetEnabled,"This value supports indexing, e.g. '%s.[index]'. The syntax '%s[index]' requires /langversion:preview. See https://aka.ms/fsharp-index-notation."
3354,tcNotAFunctionButIndexerIndexingNotYetEnabled,"This expression supports indexing, e.g. 'expr.[index]'. The syntax 'expr[index]' requires /langversion:preview. See https://aka.ms/fsharp-index-notation."
""".field public static literal float64 bytesInMegabyte = float64(1048576.1000000001)"""
""".field public static literal float64 bytesInKilobyte = float64(1024.10009765625)"""
""".field public static literal float32 secondsInDayPlusThree = float32(86403.102)"""
""".field public static literal char chars = char(0x0062)"""
]
[<Fact>]
let``Logical operations on booleans are evaluated at compile time``()=
FSharp"""
module LiteralArithmetic
let [<Literal>] flag = true
let [<Literal>] flippedFlag = not flag
let [<Literal>] simple1 = flippedFlag || false
let [<Literal>] simple2 = true && not true
let [<Literal>] complex1 = false || (flag && not flippedFlag)
let [<Literal>] complex2 = false || (flag && flippedFlag)
let [<Literal>] complex3 = true || (flag && not flippedFlag)
"""
|>withLangVersionPreview
|>compile
|>shouldSucceed
|>verifyIL[
""".field public static literal bool flag = bool(true)"""
""".field public static literal bool flippedFlag = bool(false)"""
""".field public static literal bool simple1 = bool(false)"""
""".field public static literal bool simple2 = bool(false)"""
""".field public static literal bool complex1 = bool(true)"""
""".field public static literal bool complex2 = bool(false)"""
""".field public static literal bool complex3 = bool(true)"""
]
[<Fact>]
let``Arithmetic can be used for constructing enum literals``()=
FSharp"""
module LiteralArithmetic
type E =
| A = 1
| B = 2
let [<Literal>] x = enum<E> (1 + 1)
"""
|>withLangVersionPreview
|>compile
|>shouldSucceed
|>verifyIL[
""".field public static literal valuetype LiteralArithmetic/E x = int32(0x00000002)"""
]
[<Fact>]
let``Arithmetic can be used for constructing literals in attributes``()=
FSharp"""
module LiteralArithmetic
open System.Runtime.CompilerServices
// 256 = AggressiveInlining
[<MethodImpl(enum -(-1 <<< 8))>]
let x () =
3
"""
|>withLangVersionPreview
|>compile
|>shouldSucceed
|>verifyIL[
""".method public static int32 x() cil managed aggressiveinlining"""
]
[<Fact>]
let``Compilation fails when addition in literal overflows``()=
FSharp"""
module LiteralArithmetic
let [<Literal>] x = System.Int32.MaxValue + 1
"""
|>withLangVersionPreview
|>compile
|>shouldFail
|>withResult{
Error=Error3177
Range={StartLine=4
StartColumn=21
EndLine=4
EndColumn=46}
Message="This literal expression or attribute argument results in an arithmetic overflow."
}
[<Fact>]
let``Compilation fails when using decimal arithmetic in literal``()=
FSharp"""
module LiteralArithmetic
let [<Literal>] x = 1m + 1m
"""
|>withLangVersionPreview
|>compile
|>shouldFail
|>withResults[
{Error=Error267
Range={StartLine=4
StartColumn=21
EndLine=4
EndColumn=23}
Message="This is not a valid constant expression or custom attribute value"}
{Error=Error267
Range={StartLine=4
StartColumn=26
EndLine=4
EndColumn=28}
Message="This is not a valid constant expression or custom attribute value"}
{Error=Error267
Range={StartLine=4
StartColumn=21
EndLine=4
EndColumn=28}
Message="This is not a valid constant expression or custom attribute value"}
]
[<Fact>]
let``Compilation fails when using arithmetic with a non-literal in literal``()=
FSharp"""
module LiteralArithmetic
let [<Literal>] x = 1 + System.DateTime.Now.Hour
"""
|>withLangVersionPreview
|>compile
|>shouldFail
|>withResults[
#if!NETCOREAPP
{Error=Warning52
Range={StartLine=4
StartColumn=25
EndLine=4
EndColumn=49}
Message="The value has been copied to ensure the original is not mutated by this operation or because the copy is implicit when returning a struct from a member and another member is then accessed"}
#endif
{Error=Error267
Range={StartLine=4
StartColumn=25
EndLine=4
EndColumn=49}
Message="This is not a valid constant expression or custom attribute value"}
{Error=Error267
Range={StartLine=4
StartColumn=21
EndLine=4
EndColumn=49}
Message="This is not a valid constant expression or custom attribute value"}