Skip to content

Commit

Permalink
Moving ElseBranchHasWrongTypeTests over to NUnit
Browse files Browse the repository at this point in the history
  • Loading branch information
forki committed Jul 4, 2019
1 parent 274ffb1 commit 837b940
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/fsharp/TypeChecker.fs
Original file line number Diff line number Diff line change
Expand Up @@ -8604,7 +8604,7 @@ and Propagate cenv overallTy env tpenv (expr: ApplicableExpr) exprty delayed =
else
exprty

UnifyTypesAndRecover cenv env mExpr overallTy exprty
UnifyTypes cenv env mExpr overallTy exprty

| DelayedDot :: _
| DelayedSet _ :: _
Expand Down
36 changes: 36 additions & 0 deletions tests/fsharp/Compiler/ErrorMessages/ElseBranchHasWrongTypeTests.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.

namespace FSharp.Compiler.UnitTests

open NUnit.Framework

[<TestFixture>]
module ElseBranchHasWrongTypeTests =

[<Test>]
let ``Else branch is int while if branch is string``() =
CompilerAssert.TypeCheckSingleError
"""
let test = 100
let y =
if test > 10 then "test"
else 123
"""
1
(5, 9, 5, 12)
"All branches of an 'if' expression must return values of the same type as the first branch, which here is 'string'. This branch returns a value of type 'int'."


[<Test>]
let ``Else branch is a function that returns int while if branch is string``() =
CompilerAssert.TypeCheckSingleError
"""
let test = 100
let f x = test
let y =
if test > 10 then "test"
else f 10
"""
1
(6, 9, 6, 13)
"All branches of an 'if' expression must return values of the same type as the first branch, which here is 'string'. This branch returns a value of type 'int'."
1 change: 1 addition & 0 deletions tests/fsharp/FSharpSuite.Tests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
<Compile Include="TypeProviderTests.fs" />
<Compile Include="tests.fs" />
<Compile Include="Compiler\CompilerAssert.fs" />
<Compile Include="Compiler\ErrorMessages\ElseBranchHasWrongTypeTests.fs" />
<Compile Include="Compiler\ILHelpers.fs" />
<Compile Include="Compiler\SourceTextTests.fs" />
<Compile Include="Compiler\Language\AnonRecordTests.fs" />
Expand Down
9 changes: 0 additions & 9 deletions tests/fsharpqa/Source/Warnings/ElseBranchHasWrongType.fs

This file was deleted.

10 changes: 0 additions & 10 deletions tests/fsharpqa/Source/Warnings/ElseBranchHasWrongType2.fs

This file was deleted.

2 changes: 0 additions & 2 deletions tests/fsharpqa/Source/Warnings/env.lst
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@
SOURCE=SuggestDoubleBacktickIdentifiers.fs SCFLAGS="--vserrors" # SuggestDoubleBacktickIdentifiers.fs
SOURCE=SuggestDoubleBacktickUnions.fs SCFLAGS="--vserrors" # SuggestDoubleBacktickUnions.fs
SOURCE=GuardHasWrongType.fs # GuardHasWrongType.fs
SOURCE=ElseBranchHasWrongType.fs # ElseBranchHasWrongType.fs
SOURCE=ElseBranchHasWrongType2.fs # ElseBranchHasWrongType2.fs
SOURCE=ElseBranchHasWrongType3.fs # ElseBranchHasWrongType3.fs
SOURCE=ElseBranchHasWrongType4.fs # ElseBranchHasWrongType4.fs
SOURCE=NestedElseBranchHasWrongType.fs # NestedElseBranchHasWrongType.fs
Expand Down

0 comments on commit 837b940

Please sign in to comment.