Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
ef0949c
Copy sources from Versions.props to NuGet.config (#7191)
Jul 11, 2019
0c9ccae
Only check distinct errors (#7140)
forki Jul 11, 2019
598db3e
Use 1-based column numbers in tests (#7141)
forki Jul 11, 2019
fe0426a
Merge pull request #7197 from dotnet/merges/master-to-release/dev16.3
KevinRansom Jul 11, 2019
bf1055c
Update dependencies from https://github.com/dotnet/arcade build 20190…
dotnet-maestro[bot] Jul 11, 2019
13596c4
Merge pull request #7201 from dotnet/merges/master-to-release/dev16.3
KevinRansom Jul 12, 2019
da432e1
Better record and value formatting in tools (#7021)
cartermp Jul 12, 2019
660a545
fix portable PDBs for anon records (#7099)
dsyme Jul 12, 2019
9dc9d0e
fix portable PDBs for anon records (#7099)
dsyme Jul 12, 2019
60c915a
Moving ElseBranchHasWrongTypeTests over to NUnit (#7104)
forki Jul 12, 2019
869c2bb
Port tests for missing else branch to NUnit (#7209)
forki Jul 12, 2019
c80a0cb
Merge pull request #7208 from KevinRansom/cherrypickfix
KevinRansom Jul 12, 2019
2fabdaa
Merge pull request #7213 from dotnet/merges/master-to-release/dev16.3
brettfo Jul 12, 2019
59bfc83
Update dependencies from https://github.com/dotnet/arcade build 20190…
dotnet-maestro[bot] Jul 12, 2019
8ab272a
Update dependencies from https://github.com/dotnet/arcade build 20190…
Jul 13, 2019
1ad5657
Merge pull request #7222 from dotnet/merges/master-to-release/dev16.3
KevinRansom Jul 13, 2019
b7d5efd
Merge branch 'release/dev16.3' into merges/release/fsharp47-to-releas…
KevinRansom Jul 13, 2019
7780cab
Fix Supplementary Character / Surrogate Pair info (no code changes) (…
srutzky Jul 13, 2019
30cce45
Merge pull request #7228 from dotnet/merges/master-to-release/dev16.3
KevinRansom Jul 14, 2019
0abf39c
Merge pull request #7223 from dotnet/merges/release/fsharp47-to-relea…
KevinRansom Jul 14, 2019
f9a8e2a
Update IlxGen.fs (#7227)
TIHan Jul 14, 2019
c79a8ab
Merge pull request #7225 from dotnet/darc-master-1d1b7b40-d7f9-4b9d-9…
KevinRansom Jul 14, 2019
ec8a424
Check for exit code in compiler tests (#7211)
forki Jul 14, 2019
c4dba1f
Moving AccessOfTypeAbbreviationTests over to NUnit (#7226)
sergey-tihon Jul 14, 2019
f720c73
Merge pull request #7230 from dotnet/merges/master-to-release/dev16.3
KevinRansom Jul 14, 2019
75cef56
Moving ConstructorTests over to NUnit (#7236)
sergey-tihon Jul 15, 2019
c7cd220
[master] Update dependencies from dotnet/arcade (#7233)
dotnet-maestro[bot] Jul 15, 2019
0f24b3e
Update dependencies from https://github.com/dotnet/arcade build 20190…
dotnet-maestro[bot] Jul 16, 2019
863ec25
Moving UpcastDowncastTests over to NUnit (#7229)
sergey-tihon Jul 16, 2019
c8bac72
Update dependencies from https://github.com/dotnet/arcade build 20190…
dotnet-maestro[bot] Jul 17, 2019
6980587
Move ErrorMessages/NameResolution Tests to NUnit (#7237)
kMutagene Jul 17, 2019
4cf7b5b
Moving WarnExpressionTests over to NUnit (#7232)
sergey-tihon Jul 17, 2019
2f270f2
Merge pull request #7241 from dotnet/merges/master-to-release/dev16.3
KevinRansom Jul 17, 2019
650805b
move some error and warning tests to NUnit (#7244)
smcl Jul 17, 2019
375fd7c
Update dependencies from https://github.com/dotnet/arcade build 20190…
Jul 18, 2019
8d74566
Merge pull request #7253 from dotnet/darc-master-648345c2-b59c-4cd2-9…
KevinRansom Jul 19, 2019
c423de9
Move UnitGenericAbstractType To Nunit (#7257)
falfaddaghi Jul 19, 2019
4151eb2
Update dependencies from https://github.com/dotnet/arcade build 20190…
dotnet-maestro[bot] Jul 19, 2019
bdb2b79
Moving TypeMismatchTests over to NUnit (#7250)
sergey-tihon Jul 19, 2019
b0e5926
publish pdbs in FSharp.Core.nupkg (#7255)
brettfo Jul 19, 2019
3e7b66d
Enable hash algorithm selection (#7252)
KevinRansom Jul 20, 2019
c70ead8
Update dependencies from https://github.com/dotnet/arcade build 20190…
dotnet-maestro[bot] Jul 20, 2019
ff7b8ff
Improve netcore reference selection (#7263)
KevinRansom Jul 22, 2019
d53a38c
Moving Libraries Control tests to NUnit (#7234)
thinkbeforecoding Jul 22, 2019
5efa8a7
Member constraints and PrimitiveConstraints (#7210)
forki Jul 22, 2019
a7c68c3
Update dependencies from https://github.com/dotnet/arcade build 20190…
dotnet-maestro[bot] Jul 23, 2019
a67156b
Merge branch 'master' into merges/release/dev16.2-to-master
brettfo Jul 24, 2019
0bd851b
Merge pull request #7272 from dotnet/merges/release/dev16.2-to-master
Jul 25, 2019
37970b4
fixes issue #6832 (#7259)
KevinRansom Jul 25, 2019
d979174
Color nameof as intrinsic (#7273)
cartermp Jul 25, 2019
8e843ae
[master] Update dependencies from dotnet/arcade (#7269)
dotnet-maestro[bot] Jul 26, 2019
b3811d2
Merge pull request #7279 from dotnet/merges/release/fsharp47-to-relea…
Jul 26, 2019
ce483c0
Update dependencies from https://github.com/dotnet/arcade build 20190…
dotnet-maestro[bot] Jul 26, 2019
969a9c4
Fix test assert (#7283)
KevinRansom Jul 26, 2019
2304ea4
merge
KevinRansom Jul 26, 2019
c03755f
disablewarningtests
KevinRansom Jul 27, 2019
d488458
Merge pull request #7266 from dotnet/merges/master-to-release/dev16.3
Jul 27, 2019
cc60ed6
code cleanup prior to optional interop improvements (#7276)
dsyme Jul 27, 2019
e72ded1
Update dependencies from https://github.com/dotnet/arcade build 20190…
dotnet-maestro[bot] Jul 27, 2019
bdb229c
Moving ClassesTests over to NUnit (#7264)
sergey-tihon Jul 27, 2019
8370ef6
Move Basic Constants to NUnit (#7262)
falfaddaghi Jul 27, 2019
3ce8eb1
Moved Don't Suggest Tests over to NUnit (#7288)
sergey-tihon Jul 29, 2019
868b76a
[master] Update dependencies from dotnet/arcade (#7287)
dotnet-maestro[bot] Jul 29, 2019
9c1a0d1
Fix langversion with multiple projects (#7293)
KevinRansom Jul 30, 2019
8edf449
Merge remote-tracking branch 'upstream/master' into merges/master-to-…
brettfo Jul 30, 2019
54f13f0
Merge pull request #7292 from dotnet/merges/master-to-release/dev16.3
Jul 30, 2019
897afd3
Merge pull request #7301 from KevinRansom/release/fsharp47
brettfo Jul 30, 2019
a80b135
Merge Dev16.3, resolve conflicts.
KevinRansom Jul 30, 2019
282cd3d
Resolve merge issues, and take care of Test Framework incompatabilities
KevinRansom Jul 31, 2019
bd1becc
Tweak tests
KevinRansom Jul 31, 2019
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
Prev Previous commit
Next Next commit
Member constraints and PrimitiveConstraints (dotnet#7210)
  • Loading branch information
forki authored and KevinRansom committed Jul 22, 2019
commit 5efa8a7ba0bd4e3d62515f14d0b48c8a0edd5c58
18 changes: 15 additions & 3 deletions tests/fsharp/Compiler/CompilerAssert.fs
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,15 @@ let main argv = 0"""

Assert.IsEmpty(typeCheckResults.Errors, sprintf "Type Check errors: %A" typeCheckResults.Errors)

let TypeCheckWithErrors (source: string) expectedTypeErrors =
let TypeCheckWithErrorsAndOptions options (source: string) expectedTypeErrors =
lock gate <| fun () ->
let parseResults, fileAnswer = checker.ParseAndCheckFileInProject("test.fs", 0, SourceText.ofString source, defaultProjectOptions) |> Async.RunSynchronously
let parseResults, fileAnswer =
checker.ParseAndCheckFileInProject(
"test.fs",
0,
SourceText.ofString source,
{ defaultProjectOptions with OtherOptions = Array.append options defaultProjectOptions.OtherOptions})
|> Async.RunSynchronously

Assert.IsEmpty(parseResults.Errors, sprintf "Parse errors: %A" parseResults.Errors)

Expand All @@ -198,8 +204,14 @@ let main argv = 0"""
Assert.AreEqual(expectedErrorMsg, info.Message, "expectedErrorMsg")
)

let TypeCheckWithErrors (source: string) expectedTypeErrors =
TypeCheckWithErrorsAndOptions [||] source expectedTypeErrors

let TypeCheckSingleErrorWithOptions options (source: string) (expectedServerity: FSharpErrorSeverity) (expectedErrorNumber: int) (expectedErrorRange: int * int * int * int) (expectedErrorMsg: string) =
TypeCheckWithErrorsAndOptions options source [| expectedServerity, expectedErrorNumber, expectedErrorRange, expectedErrorMsg |]

let TypeCheckSingleError (source: string) (expectedServerity: FSharpErrorSeverity) (expectedErrorNumber: int) (expectedErrorRange: int * int * int * int) (expectedErrorMsg: string) =
TypeCheckWithErrors (source: string) [| expectedServerity, expectedErrorNumber, expectedErrorRange, expectedErrorMsg |]
TypeCheckWithErrors source [| expectedServerity, expectedErrorNumber, expectedErrorRange, expectedErrorMsg |]

let CompileExe (source: string) =
compile true source (fun (errors, _) ->
Expand Down
45 changes: 45 additions & 0 deletions tests/fsharp/Compiler/ConstraintSolver/MemberConstraints.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.

namespace FSharp.Compiler.UnitTests

open NUnit.Framework
open FSharp.Compiler.SourceCodeServices

[<TestFixture>]
module MemberConstraints =

[<Test>]
let ``we can overload operators on a type and not add all the extra jazz such as inlining and the ^ operator.``() =
CompilerAssert.CompileExeAndRun
"""
type Foo(x : int) =
member this.Val = x

static member (-->) ((src : Foo), (target : Foo)) = new Foo(src.Val + target.Val)
static member (-->) ((src : Foo), (target : int)) = new Foo(src.Val + target)

static member (+) ((src : Foo), (target : Foo)) = new Foo(src.Val + target.Val)
static member (+) ((src : Foo), (target : int)) = new Foo(src.Val + target)

let x = Foo(3) --> 4
let y = Foo(3) --> Foo(4)
let x2 = Foo(3) + 4
let y2 = Foo(3) + Foo(4)

if x.Val <> 7 then exit 1
if y.Val <> 7 then exit 1
if x2.Val <> 7 then exit 1
if y2.Val <> 7 then exit 1
"""

[<Test>]
let ``Invalid member constraint with ErrorRanges``() = // Regression test for FSharp1.0:2262
CompilerAssert.TypeCheckSingleErrorWithOptions
[| "--test:ErrorRanges" |]
"""
let inline length (x: ^a) : int = (^a : (member Length : int with get, set) (x, ()))
"""
FSharpErrorSeverity.Error
697
(2, 42, 2, 75)
"Invalid constraint"
109 changes: 109 additions & 0 deletions tests/fsharp/Compiler/ConstraintSolver/PrimitiveConstraints.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.

namespace FSharp.Compiler.UnitTests

open NUnit.Framework
open FSharp.Compiler.SourceCodeServices

[<TestFixture>]
module PrimitiveConstraints =

[<Test>]
let ``Test primitive : constraints``() =
CompilerAssert.CompileExeAndRun
"""
#light

type Foo(x : int) =
member this.Value = x
override this.ToString() = "Foo"

type Bar(x : int) =
inherit Foo(-1)
member this.Value2 = x
override this.ToString() = "Bar"

let test1 (x : Foo) = x.Value
let test2 (x : Bar) = (x.Value, x.Value2)

let f = new Foo(128)
let b = new Bar(256)

if test1 f <> 128 then exit 1
if test2 b <> (-1, 256) then exit 1
"""

[<Test>]
let ``Test primitive :> constraints``() =
CompilerAssert.CompileExeAndRun
"""
#light
type Foo(x : int) =
member this.Value = x
override this.ToString() = "Foo"

type Bar(x : int) =
inherit Foo(-1)
member this.Value2 = x
override this.ToString() = "Bar"

type Ram(x : int) =
inherit Foo(10)
member this.ValueA = x
override this.ToString() = "Ram"

let test (x : Foo) = (x.Value, x.ToString())

let f = new Foo(128)
let b = new Bar(256)
let r = new Ram(314)

if test f <> (128, "Foo") then exit 1
if test b <> (-1, "Bar") then exit 1
if test r <> (10, "Ram") then exit 1
"""

[<Test>]
let ``Test primitive : null constraint``() =
CompilerAssert.CompileExeAndRun
"""
let inline isNull<'a when 'a : null> (x : 'a) =
match x with
| null -> "is null"
| _ -> (x :> obj).ToString()

let runTest =
// Wrapping in try block to work around FSB 1989
try
if isNull null <> "is null" then exit 1
if isNull "F#" <> "F#" then exit 1
true
with _ -> exit 1

if runTest <> true then exit 1

exit 0
"""

[<Test>]
/// Title: Type checking oddity
///
/// This suggestion was resolved as by design,
/// so the test makes sure, we're emitting error message about 'not being a valid object construction expression'
let ``Invalid object constructor``() = // Regression test for FSharp1.0:4189
CompilerAssert.TypeCheckWithErrorsAndOptions
[| "--test:ErrorRanges" |]
"""
type ImmutableStack<'a> private(items: 'a list) =

member this.Push item = ImmutableStack(item::items)
member this.Pop = match items with | [] -> failwith "No elements in stack" | x::xs -> x,ImmutableStack(xs)

// Notice type annotation is commented out, which results in an error
new(col (*: seq<'a>*)) = ImmutableStack(List.ofSeq col)

"""
[| FSharpErrorSeverity.Error, 41, (4, 29, 4, 56), "A unique overload for method 'ImmutableStack`1' could not be determined based on type information prior to this program point. A type annotation may be needed. Candidates: new : col:'b -> ImmutableStack<'a>, private new : items:'a list -> ImmutableStack<'a>"
FSharpErrorSeverity.Error, 41, (5, 93, 5, 111), "A unique overload for method 'ImmutableStack`1' could not be determined based on type information prior to this program point. A type annotation may be needed. Candidates: new : col:'b -> ImmutableStack<'a>, private new : items:'a list -> ImmutableStack<'a>"
FSharpErrorSeverity.Error, 41, (8, 30, 8, 60), "A unique overload for method 'ImmutableStack`1' could not be determined based on type information prior to this program point. A type annotation may be needed. Candidates: new : col:'b -> ImmutableStack<'a> when 'b :> seq<'c>, private new : items:'a list -> ImmutableStack<'a>"
FSharpErrorSeverity.Error, 696, (8, 30, 8, 60), "This is not a valid object construction expression. Explicit object constructors must either call an alternate constructor or initialize all fields of the object and specify a call to a super class constructor." |]
2 changes: 2 additions & 0 deletions tests/fsharp/FSharpSuite.Tests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
<Compile Include="Compiler\ErrorMessages\ConstructorTests.fs" />
<Compile Include="Compiler\ErrorMessages\AccessOfTypeAbbreviationTests.fs" />
<Compile Include="Compiler\ErrorMessages\ElseBranchHasWrongTypeTests.fs" />
<Compile Include="Compiler\ConstraintSolver\PrimitiveConstraints.fs" />
<Compile Include="Compiler\ConstraintSolver\MemberConstraints.fs" />
<Compile Include="Compiler\ErrorMessages\MissingElseBranch.fs" />
<Compile Include="Compiler\ErrorMessages\UnitGenericAbstactType.fs" />
<Compile Include="Compiler\ErrorMessages\NameResolutionTests.fs" />
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
SOURCE=E_NoImplicitDowncast01.fs SCFLAGS="--test:ErrorRanges --flaterrors" # E_NoImplicitDowncast01.fs

SOURCE=PrimConstraint01.fs # PrimConstraint01.fs
SOURCE=PrimConstraint02.fs # PrimConstraint02.fs
SOURCE=PrimConstraint03.fs # PrimConstraint03.fs
SOURCE=E_PrimConstraint04.fs SCFLAGS="--test:ErrorRanges" # E_PrimConstraint04.fs

SOURCE=E_TypeFuncDeclaredExplicit01.fs # E_TypeFuncDeclaredExplicit01.fs

SOURCE=ValueRestriction01.fs # ValueRestriction01.fs
Expand All @@ -16,7 +11,4 @@
SOURCE=DelegateConstraint01.fs # DelegateConstraint01.fs
SOURCE=E_DelegateConstraint01.fs # E_DelegateConstraint01.fs

SOURCE=MemberConstraints01.fs # MemberConstraints01.fs
SOURCE=E_MemberConstraints01.fs SCFLAGS="--test:ErrorRanges" # E_MemberConstraints01.fs

SOURCE=ConstructorConstraint01.fs # ConstructorConstraint01.fs