Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,8 @@
<Compile Include="TypeChecks\Graph\GraphProcessingTests.fs" />
<Compile Include="TypeChecks\TyparNameTests.fs" />
<Compile Include="TypeChecks\CheckTypeTests.fs" />
<Compile Include="Miscellaneous\FsharpSuiteMigrated.fs" />
<Compile Include="TypeChecks\typeextensions.fs" />
<Compile Include="CompilerOptions\fsc\checked\checked.fs" />
<Compile Include="CompilerOptions\fsc\cliversion.fs" />
<Compile Include="CompilerOptions\fsc\codepage\codepage.fs" />
Expand Down Expand Up @@ -269,7 +271,7 @@
<Compile Include="Miscellaneous\ListLiterals.fs" />
<Compile Include="Miscellaneous\SemanticClassificationKeyBuilder.fs" />
<Compile Include="Miscellaneous\XmlDoc.fs" />
<Compile Include="Miscellaneous\FsharpSuiteMigrated.fs" />

<Compile Include="Miscellaneous\MigratedCoreTests.fs" />
<Compile Include="Miscellaneous\MigratedOverloadTests.fs" />
<Compile Include="Miscellaneous\MigratedTypeCheckTests.fs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
module TypeChecks.typeextensions
open System
open System.IO
open Xunit
open FSharp.Test
open FSharp.Test.Compiler
open FSharp.Compiler.IO
open NUnit.Framework
let private verifyFSXBaseline (cu) : unit =
match cu with
| FS fs ->
match fs.Baseline with
| None -> failwith "Baseline was not provided."
| Some bsl ->
let errorsExpectedBaseLine =
match bsl.FSBaseline.Content with
| Some b -> b.Replace("\r\n","\n")
| None -> String.Empty
let errorsActual =
match fs.Source with
| SourceCodeFileKind.Fsx _->
//let fsxScriptFile = FileInfo fs.Source.GetSourceFileName
//let dir = fsxScriptFile.Directory
//RunRealScriptWithOptionsAndReturnResult
//let cfg = testConfig fsxScriptFile.Directory.FullName
let version = ScriptHelpers.LangVersion.Preview
let _r = Miscellaneous.FsharpSuiteMigrated.ScriptRunner.runScriptFile version cu
//let result = TestFramework.fsi cfg "%s" cfg.fsi_flags []
//let fsxResult = CompilerAssert.RunRealScriptWithOptionsAndReturnResult [||] fsxScriptFile

//snd fsxResult |> sanitizeFsxOutput
"()"
| _ -> failwith $"not supposed to check %A{fs.Source}"

if errorsExpectedBaseLine <> errorsActual then
fs.CreateOutputDirectory()
createBaselineErrors bsl.FSBaseline errorsActual
elif FileSystem.FileExistsShim(bsl.FSBaseline.FilePath) then
FileSystem.FileDeleteShim(bsl.FSBaseline.FilePath)

Assert.AreEqual(errorsExpectedBaseLine, errorsActual, $"\nExpected:\n{errorsExpectedBaseLine}\nActual:\n{errorsActual}")
| _ -> failwith $"not supposed to check %A{cu}"

[<Fact>]
let ``issue.16034`` () =
let scriptPath = Path.Combine(
__SOURCE_DIRECTORY__
, "typeextensions"
, "issue.16034"
, "issue.16034.fsx"
)
RealFsxFromPath scriptPath
|> withBaseLine
|> verifyILBaseline
|> compileAndRun
|> verifyOutputWithDefaultBaseline

[<Fact>]
let ``issue.16034.check1`` () =

let scriptPath = Path.Combine(
__SOURCE_DIRECTORY__
, "typeextensions"
, "issue.16034"
, "issue.16034.check1.fsx"
)
RealFsxFromPath scriptPath
|> withBaseLine
|> verifyFSXBaseline

[<Fact>]
let ``issue.16034.check2`` () =
let scriptPath = Path.Combine(
__SOURCE_DIRECTORY__
, "typeextensions"
, "issue.16034"
, "issue.16034.check2.fsx"
)
RealFsxFromPath scriptPath
|> withBaseLine
|> verifyFSXBaseline


Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#load "issue.16034.fsx"
open Issue.``16034``
open Issue.``16034``.Extensions
t.indexed1(aa1="nok") <- 1 // error FS0073: internal error: The input must be non-negative. (Parameter 'n') (ArgumentException)
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@


Copyright (c) Microsoft Corporation. All Rights Reserved.

For help type #help;;

> [Loading /tests/FSharp.Compiler.ComponentTests/TypeChecks/typeextensions/issue.16034/issue.16034.fsx
Loading /tests/FSharp.Compiler.ComponentTests/TypeChecks/typeextensions/issue.16034/issue.16034.check2.fsx]
module FSI_0001.Issue.16034
val mutable i: int
type T =
new: unit -> T
member indexed1: a1: obj -> int with get
member indexed1: a1: obj -> int with set
module Extensions =
val mutable j: int
type T with
member indexed1: aa1: obj -> int with get
type T with
member indexed1: aa1: obj -> int with set
val t: T

module FSI_0001.Issue.16034.check2

error FS0073: internal error: The input must be non-negative. (Parameter 'n') (ArgumentException)
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#load "issue.16034.fsx"
open Issue.``16034``
open Issue.``16034``.Extensions
t.indexed1(a1="nok") <- 1 // error FS0073: internal error: The input must be non-negative. (Parameter 'n') (ArgumentException)
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@


Copyright (c) Microsoft Corporation. All Rights Reserved.

For help type #help;;

> [Loading /tests/FSharp.Compiler.ComponentTests/TypeChecks/typeextensions/issue.16034/issue.16034.fsx
Loading /tests/FSharp.Compiler.ComponentTests/TypeChecks/typeextensions/issue.16034/issue.16034.check2.fsx]
module FSI_0001.Issue.16034
val mutable i: int
type T =
new: unit -> T
member indexed1: a1: obj -> int with get
member indexed1: a1: obj -> int with set
module Extensions =
val mutable j: int
type T with
member indexed1: aa1: obj -> int with get
type T with
member indexed1: aa1: obj -> int with set
val t: T

module FSI_0001.Issue.16034.check2

error FS0073: internal error: The input must be non-negative. (Parameter 'n') (ArgumentException)
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
let mutable i = 0
type T() =
member x.indexed1
with get (a1: obj) =
i <- i + 1
printfn $"T().indexed1 %A{a1} !\t%03i{i}"
1
and set (a1: obj) (value: int) =
i <- i + 1
printfn $"T().indexed1 %A{a1} <- %i{value} !\t%03i{i}"

module Extensions =
let mutable j = 0
type T with
member x.indexed1
with get (aa1: obj) =
i <- i + 1
j <- j + 1
printfn $"type extensions aa1 %A{aa1} !\t%03i{i}\t%03i{j}"
1
and set (aa1: obj) (value: int) =
i <- i + 1
j <- j + 1
printfn $"type extension aa1 %A{aa1} <- %i{value}!\t%03i{i}\t%03i{j}"
let t = T()
t.indexed1 ["ok"] <- 1 // calls the intrinsic property
t.indexed1 ("ok") <- 2 // calls the intrinsic property
t.indexed1 "ok" <- 3 // calls the intrinsic property
t.indexed1 "ok" // calls the intrinsic property
t.get_indexed1 "ok" // calls the intrinsic property
t.set_indexed1 (a1="ok",value=1) // calls the intrinsic property

open Extensions

t.indexed1 "nok" // calls the intrinsic property?
t.indexed1 (a1="ok") // calls the intrinsic property
t.indexed1 (aa1="ok") // calls the type extension property
t.indexed1 ["nok"] <- 1 // calls the intrinsic property?
t.indexed1 ("nok") <- 2 // calls the intrinsic property?
t.indexed1 "nok" <- 3 // calls the intrinsic property?

t.get_indexed1 ("nok") // calls the intrinsic property?
t.get_indexed1 ["nok"] // calls the intrinsic property?
t.get_indexed1 "nok" // calls the intrinsic property?

t.set_indexed1 ("nok_015",1) // calls the intrinsic property?
t.set_indexed1 ("nok_016",value=2) // calls the intrinsic property?
t.set_indexed1 (a1="ok_017",value=1) // calls the intrinsic property
t.set_indexed1 (aa1="ok_018",value=1) // calls the type extension property
Loading