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
12 changes: 11 additions & 1 deletion tests/FSharp.TestHelpers/TestFramework.fs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ module Commands =
let csc exec cscExe flags srcFiles =
exec cscExe (sprintf "%s %s" flags (srcFiles |> Seq.ofList |> String.concat " "))

let vbc exec vbcExe flags srcFiles =
exec vbcExe (sprintf "%s %s" flags (srcFiles |> Seq.ofList |> String.concat " "))

let fsi exec fsiExe flags sources =
exec fsiExe (sprintf "%s %s" flags (sources |> Seq.ofList |> String.concat " "))

Expand Down Expand Up @@ -123,6 +126,8 @@ type TestConfig =
{ EnvironmentVariables : Map<string, string>
CSC : string
csc_flags : string
VBC : string
vbc_flags : string
BUILD_CONFIG : string
FSC : string
fsc_flags : string
Expand Down Expand Up @@ -183,11 +188,13 @@ let config configurationName envVars =
let artifactsBinPath = artifactsPath ++ "bin"
let coreClrRuntimePackageVersion = "3.0.0-preview-27318-01"
let csc_flags = "/nologo"
let vbc_flags = "/nologo"
let fsc_flags = "-r:System.Core.dll --nowarn:20 --define:COMPILED"
let fsi_flags = "-r:System.Core.dll --nowarn:20 --define:INTERACTIVE --maxerrors:1 --abortonerror"
let Is64BitOperatingSystem = WindowsPlatform.Is64BitOperatingSystem envVars
let architectureMoniker = if Is64BitOperatingSystem then "x64" else "x86"
let CSC = requireFile (packagesDir ++ "Microsoft.Net.Compilers" ++ "2.7.0" ++ "tools" ++ "csc.exe")
let VBC = requireFile (packagesDir ++ "Microsoft.Net.Compilers" ++ "2.7.0" ++ "tools" ++ "vbc.exe")
let ILDASM = requireFile (packagesDir ++ ("runtime.win-" + architectureMoniker + ".Microsoft.NETCore.ILDAsm") ++ coreClrRuntimePackageVersion ++ "runtimes" ++ ("win-" + architectureMoniker) ++ "native" ++ "ildasm.exe")
let ILASM = requireFile (packagesDir ++ ("runtime.win-" + architectureMoniker + ".Microsoft.NETCore.ILAsm") ++ coreClrRuntimePackageVersion ++ "runtimes" ++ ("win-" + architectureMoniker) ++ "native" ++ "ilasm.exe")
let coreclrdll = requireFile (packagesDir ++ ("runtime.win-" + architectureMoniker + ".Microsoft.NETCore.Runtime.CoreCLR") ++ coreClrRuntimePackageVersion ++ "runtimes" ++ ("win-" + architectureMoniker) ++ "native" ++ "coreclr.dll")
Expand Down Expand Up @@ -223,6 +230,7 @@ let config configurationName envVars =
ILDASM = ILDASM
ILASM = ILASM
PEVERIFY = PEVERIFY
VBC = VBC
CSC = CSC
BUILD_CONFIG = configurationName
FSC = FSC
Expand All @@ -235,7 +243,8 @@ let config configurationName envVars =
FSharpCompilerInteractiveSettings = FSharpCompilerInteractiveSettings
csc_flags = csc_flags
fsc_flags = fsc_flags
fsi_flags = fsi_flags
fsi_flags = fsi_flags
vbc_flags = vbc_flags
Directory=""
DotNetExe = dotNetExe
DefaultPlatform = defaultPlatform }
Expand Down Expand Up @@ -462,6 +471,7 @@ let fscBothToOut cfg out arg = Printf.ksprintf (Commands.fsc cfg.Directory (exec
let fscBothToOutExpectFail cfg out arg = Printf.ksprintf (Commands.fsc cfg.Directory (execBothToOutExpectFail cfg cfg.Directory out) cfg.DotNetExe cfg.FSC) arg
let fscAppendErrExpectFail cfg errPath arg = Printf.ksprintf (Commands.fsc cfg.Directory (execAppendErrExpectFail cfg errPath) cfg.DotNetExe cfg.FSC) arg
let csc cfg arg = Printf.ksprintf (Commands.csc (exec cfg) cfg.CSC) arg
let vbc cfg arg = Printf.ksprintf (Commands.vbc (exec cfg) cfg.VBC) arg
let ildasm cfg arg = Printf.ksprintf (Commands.ildasm (exec cfg) cfg.ILDASM) arg
let ilasm cfg arg = Printf.ksprintf (Commands.ilasm (exec cfg) cfg.ILASM) arg
let peverify cfg = Commands.peverify (exec cfg) cfg.PEVERIFY "/nologo"
Expand Down
20 changes: 20 additions & 0 deletions tests/fsharp/core/members/set-only-property/calls.bsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

calls.fsx(9,22,9,27): typecheck error FS0495: The object constructor 'Class' has no argument or settable return property 'Prop1'. The required signature is csharp.Class() : csharp.Class.

calls.fsx(10,26,10,31): typecheck error FS0495: The object constructor 'BasicClass' has no argument or settable return property 'Prop1'. The required signature is basic.BasicClass() : basic.BasicClass.

calls.fsx(13,21,13,26): typecheck error FS0495: The member or object constructor 'mkCs' has no argument or settable return property 'Prop1'. The required signature is static member Maker.mkCs : unit -> csharp.Class.

calls.fsx(14,21,14,26): typecheck error FS0495: The member or object constructor 'mkVb' has no argument or settable return property 'Prop1'. The required signature is static member Maker.mkVb : unit -> basic.BasicClass.

calls.fsx(18,30,18,31): typecheck error FS0629: Method 'set_Prop2' is not accessible from this code location

calls.fsx(19,34,19,35): typecheck error FS0629: Method 'set_Prop2' is not accessible from this code location

calls.fsx(20,24,20,29): typecheck error FS0495: The object constructor 'Class' has no argument or settable return property 'Prop2'. The required signature is new : unit -> fsharp.Class.

calls.fsx(22,29,22,30): typecheck error FS0629: Method 'set_Prop2' is not accessible from this code location

calls.fsx(23,29,23,30): typecheck error FS0629: Method 'set_Prop2' is not accessible from this code location

calls.fsx(24,23,24,28): typecheck error FS0495: The member or object constructor 'mkFs' has no argument or settable return property 'Prop2'. The required signature is static member Maker.mkFs : unit -> fsharp.Class.
24 changes: 24 additions & 0 deletions tests/fsharp/core/members/set-only-property/calls.fsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#r "cs.dll"
#r "vb.dll"
#r "fs.dll"
type Maker =
static member mkCs () = csharp.Class()
static member mkVb () = basic.BasicClass()
static member mkFs () = fsharp.Class()
// so long https://github.com/dotnet/fsharp/issues/8351 isn't fixed, Prop1 setters are failing
let a = csharp.Class(Prop1=1)
let b = basic.BasicClass(Prop1=1)
let c = fsharp.Class(Prop1=1) // this one works, inconsistent but correct.

let aa = Maker.mkCs(Prop1=1)
let bb = Maker.mkVb(Prop1=1)
let cc = Maker.mkFs(Prop1=1) // this one works, inconsistent but correct.

// those are expected to fail, albeit with inconsistent error messages / marked ranges
let aaa = csharp.Class(Prop2=1)
let bbb = basic.BasicClass(Prop2=1)
let ccc = fsharp.Class(Prop2=1)

let aaaa = Maker.mkCs(Prop2=1)
let bbbb = Maker.mkVb(Prop2=1)
let cccc = Maker.mkFs(Prop2=1)
8 changes: 8 additions & 0 deletions tests/fsharp/core/members/set-only-property/cs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace csharp
{
public class Class
{
public int Prop1 { set; private get; }
public int Prop2 { private set; get; }
}
}
8 changes: 8 additions & 0 deletions tests/fsharp/core/members/set-only-property/fs.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace fsharp
type Class () =
let mutable v = 0
member x.Prop1 with set(value) = v <- value
and private get () = v

member x.Prop2 with private set(value) = v <- value
and public get () = v
21 changes: 21 additions & 0 deletions tests/fsharp/core/members/set-only-property/vb.vb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
namespace basic
public class BasicClass
dim v as integer
public property Prop1 as integer
private get
return v
end get
set(value as integer)
v = value
end set
end property
public property Prop2 as integer
get
return v
end get
private set(value as integer)
v = value
end set
end property
end class
end namespace
10 changes: 10 additions & 0 deletions tests/fsharp/tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1813,6 +1813,16 @@ module CoreTests =
fsc cfg "%s -o:xmlverify.exe -g" cfg.fsc_flags ["xmlverify.fs"]

peverifyWithArgs cfg "/nologo" "xmlverify.exe"


[<Test>]
let ``property setter in method or constructor`` () =
let cfg = testConfig "core/members/set-only-property"
csc cfg @"%s /target:library /out:cs.dll" cfg.csc_flags ["cs.cs"]
vbc cfg @"%s /target:library /out:vb.dll" cfg.vbc_flags ["vb.vb"]
fsc cfg @"%s /target:library /out:fs.dll" cfg.fsc_flags ["fs.fs"]
singleNegTest cfg "calls"

#endif

module VersionTests =
Expand Down