Skip to content

Commit d7ce94d

Browse files
authored
Merge pull request #9304 from dotnet/merges/master-to-release/dev16.7
Merge master to release/dev16.7
2 parents e488275 + 432d19f commit d7ce94d

16 files changed

Lines changed: 169 additions & 117 deletions

File tree

src/fsharp/AccessibilityLogic.fs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -208,12 +208,13 @@ and IsTypeInstAccessible g amap m ad tinst =
208208
/// Indicate if a provided member is accessible
209209
let IsProvidedMemberAccessible (amap:Import.ImportMap) m ad ty access =
210210
let g = amap.g
211-
let isTyAccessible = IsTypeAccessible g amap m ad ty
212-
if not isTyAccessible then false
211+
if IsTypeAccessible g amap m ad ty then
212+
match tryTcrefOfAppTy g ty with
213+
| ValueNone -> true
214+
| ValueSome tcrefOfViewedItem ->
215+
IsILMemberAccessible g amap m tcrefOfViewedItem ad access
213216
else
214-
not (isAppTy g ty) ||
215-
let tcrefOfViewedItem = tcrefOfAppTy g ty
216-
IsILMemberAccessible g amap m tcrefOfViewedItem ad access
217+
false
217218

218219
/// Compute the accessibility of a provided member
219220
let ComputeILAccess isPublic isFamily isFamilyOrAssembly isFamilyAndAssembly =

src/fsharp/LowerCallsAndSeqs.fs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,11 @@ let ConvertSequenceExprToObject g amap overallExpr =
542542
// printfn "FAILED - not worth compiling an unrecognized immediate yield! %s " (stringOfRange m)
543543
None
544544
else
545-
let tyConfirmsToSeq g ty = isAppTy g ty && tyconRefEq g (tcrefOfAppTy g ty) g.tcref_System_Collections_Generic_IEnumerable
545+
let tyConfirmsToSeq g ty =
546+
match tryTcrefOfAppTy g ty with
547+
| ValueSome tcref ->
548+
tyconRefEq g tcref g.tcref_System_Collections_Generic_IEnumerable
549+
| _ -> false
546550
match SearchEntireHierarchyOfType (tyConfirmsToSeq g) g amap m (tyOfExpr g arbitrarySeqExpr) with
547551
| None ->
548552
// printfn "FAILED - yield! did not yield a sequence! %s" (stringOfRange m)

src/fsharp/MethodCalls.fs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -848,8 +848,8 @@ let MakeMethInfoCall amap m minfo minst args =
848848
let TryImportProvidedMethodBaseAsLibraryIntrinsic (amap: Import.ImportMap, m: range, mbase: Tainted<ProvidedMethodBase>) =
849849
let methodName = mbase.PUntaint((fun x -> x.Name), m)
850850
let declaringType = Import.ImportProvidedType amap m (mbase.PApply((fun x -> x.DeclaringType), m))
851-
if isAppTy amap.g declaringType then
852-
let declaringEntity = tcrefOfAppTy amap.g declaringType
851+
match tryTcrefOfAppTy amap.g declaringType with
852+
| ValueSome declaringEntity ->
853853
if not declaringEntity.IsLocalRef && ccuEq declaringEntity.nlr.Ccu amap.g.fslibCcu then
854854
match amap.g.knownIntrinsics.TryGetValue ((declaringEntity.LogicalName, methodName)) with
855855
| true, vref -> Some vref
@@ -861,7 +861,7 @@ let TryImportProvidedMethodBaseAsLibraryIntrinsic (amap: Import.ImportMap, m: ra
861861
| _ -> None
862862
else
863863
None
864-
else
864+
| _ ->
865865
None
866866
#endif
867867

src/fsharp/NameResolution.fs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2398,10 +2398,10 @@ let rec ResolveLongIdentInTypePrim (ncenv: NameResolver) nenv lookupKind (resInf
23982398
| _ -> ()
23992399

24002400
let errorTextF s =
2401-
if isAppTy g ty then
2402-
let tcref = tcrefOfAppTy g ty
2401+
match tryTcrefOfAppTy g ty with
2402+
| ValueSome tcref ->
24032403
FSComp.SR.undefinedNameFieldConstructorOrMemberWhenTypeIsKnown(tcref.DisplayNameWithStaticParametersAndTypars, s)
2404-
else
2404+
| _ ->
24052405
FSComp.SR.undefinedNameFieldConstructorOrMember(s)
24062406

24072407
raze (UndefinedName (depth, errorTextF, id, suggestMembers))

src/fsharp/TypeChecker.fs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17400,10 +17400,7 @@ and TcSignatureElements cenv parent endm env xml mutRecNSInfo defs =
1740017400
}
1740117401

1740217402
and TcSignatureElementsNonMutRec cenv parent typeNames endm env defs =
17403-
eventually {
17404-
17405-
return! Eventually.fold (TcSignatureElementNonMutRec cenv parent typeNames endm) env defs
17406-
}
17403+
Eventually.fold (TcSignatureElementNonMutRec cenv parent typeNames endm) env defs
1740717404

1740817405
and TcSignatureElementsMutRec cenv parent typeNames m mutRecNSInfo envInitial (defs: SynModuleSigDecl list) =
1740917406
eventually {
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.
2+
3+
namespace FSharp.Compiler.UnitTests
4+
5+
open NUnit.Framework
6+
7+
[<TestFixture>]
8+
module ``Array2D Tests`` =
9+
10+
[<Test>]
11+
let ``Iter should not throw on non-zero based 2D arrays``() =
12+
// Regression for FSHARP1.0: 5919
13+
// bug in array2D functions would cause iter to blow up
14+
15+
let a = Array2D.createBased 1 5 10 10 0.0
16+
let testDelegate = TestDelegate (fun _ -> a |> Array2D.iter (printf "%f"))
17+
18+
Assert.DoesNotThrow testDelegate
19+
20+
[<Test>]
21+
let ``Iteri should not throw on non-zero based 2D arrays``() =
22+
// Regression for FSHARP1.0: 5919
23+
// bug in array2D functions would cause iteri to blow up
24+
25+
let a = Array2D.createBased 1 5 10 10 0.0
26+
let testDelegate = TestDelegate (fun _ -> a |> Array2D.iteri (fun _ _ x -> printf "%f" x))
27+
28+
Assert.DoesNotThrow testDelegate
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.
2+
3+
namespace FSharp.Compiler.UnitTests
4+
5+
open NUnit.Framework
6+
7+
[<TestFixture>]
8+
module ``IEnumerable Tests`` =
9+
10+
// Regression test for FSHARP1.0:4726
11+
// Makes sure that the .Dispose() method, if available, in invoked on IEnumerable
12+
13+
let mutable dispose_called_in_E = 0 // we expect this to be incremented 3 times
14+
let mutable dispose_called_in_C = 0 // we expect this to be incremented once (=this is what the bug was about, i.e. .Dispose() was never invoked)
15+
16+
type E(_c:int) = class
17+
interface System.IDisposable with
18+
member __.Dispose () = dispose_called_in_E <- dispose_called_in_E + 1
19+
end
20+
21+
type C() = class
22+
let mutable i = 0
23+
interface System.Collections.IEnumerator with
24+
member __.Current with get () = new E(i) :> obj
25+
member __.MoveNext () =
26+
i <- i+1
27+
i<4
28+
member __.Reset () = i <- 0
29+
interface System.Collections.IEnumerable with
30+
member x.GetEnumerator () = x :> System.Collections.IEnumerator
31+
32+
interface System.IDisposable with
33+
member __.Dispose () = dispose_called_in_C <- dispose_called_in_C + 1
34+
end
35+
end
36+
37+
[<Test>]
38+
let ``Dispose``() =
39+
let _ = Seq.cast (new C()) |> Seq.map (fun x -> use o = x;
40+
o) |> Seq.length
41+
42+
Assert.areEqual 3 dispose_called_in_E
43+
Assert.areEqual 1 dispose_called_in_C
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.
2+
3+
namespace FSharp.Compiler.UnitTests
4+
5+
open NUnit.Framework
6+
open FSharp.Compiler.SourceCodeServices
7+
8+
[<TestFixture>]
9+
module ``List Tests`` =
10+
11+
[<Test>]
12+
let ``List hd should not exist``() =
13+
// Regression test for FSharp1.0:5641
14+
// Title: List.hd/tl --> List.head/tail
15+
16+
CompilerAssert.TypeCheckSingleError
17+
"""
18+
List.hd [1] |> ignore
19+
"""
20+
FSharpErrorSeverity.Error
21+
39
22+
(2, 6, 2, 8)
23+
"The value, constructor, namespace or type 'hd' is not defined."
24+
25+
26+
27+
[<Test>]
28+
let ``List tl should not exist``() =
29+
// Regression test for FSharp1.0:5641
30+
// Title: List.hd/tl --> List.head/tail
31+
32+
CompilerAssert.TypeCheckSingleError
33+
"""
34+
List.tl [1] |> ignore
35+
"""
36+
FSharpErrorSeverity.Error
37+
39
38+
(2, 6, 2, 8)
39+
"The value, constructor, namespace or type 'tl' is not defined."
40+
41+
[<Test>]
42+
let ``List head of empty list``() =
43+
let testDelegate = TestDelegate (fun _ -> (List.head [] |> ignore))
44+
45+
Assert.Throws<System.ArgumentException> testDelegate |> ignore
46+
47+
[<Test>]
48+
let ``List tail of empty list``() =
49+
let testDelegate = TestDelegate (fun _ -> (List.tail [] |> ignore))
50+
51+
Assert.Throws<System.ArgumentException> testDelegate |> ignore
52+
53+
[<Test>]
54+
let ``List head and tail``() =
55+
Assert.areEqual 1 (List.head [1 .. 10])
56+
Assert.areEqual "a" (List.head ["a"])
57+
Assert.areEqual [2 .. 10] (List.tail [1 .. 10])
58+
Assert.areEqual [] (List.tail [1])
59+
Assert.areEqual (List.head (List.tail ['a'; 'a'])) (List.head ['a'; 'a'])
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.
2+
3+
namespace FSharp.Compiler.UnitTests
4+
5+
open NUnit.Framework
6+
7+
[<TestFixture>]
8+
module ``Map Tests`` =
9+
10+
[<Test>]
11+
let ``Equality should be implemented on map``() =
12+
// Dev11:19569 - this used to throw an ArgumentException saying Object didn't implement IComparable
13+
14+
let m = Map.ofArray [| 1, obj() |]
15+
let testDelegate = TestDelegate (fun _ -> (m = m) |> ignore)
16+
17+
Assert.DoesNotThrow testDelegate

tests/fsharp/FSharpSuite.Tests.fsproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@
7878
<Compile Include="Compiler\Stress\LargeExprTests.fs" />
7979
<Compile Include="Compiler\Regressions\IndexerRegressionTests.fs" />
8080
<Compile Include="Compiler\Regressions\ForInDoMutableRegressionTest.fs" />
81+
<Compile Include="Compiler\Libraries\Core\Collections\IEnumerableTests.fs" />
82+
<Compile Include="Compiler\Libraries\Core\Collections\MapTests.fs" />
83+
<Compile Include="Compiler\Libraries\Core\Collections\CollectionTests.fs" />
84+
<Compile Include="Compiler\Libraries\Core\Collections\ListTests.fs" />
8185
<None Include="app.config" />
8286
<None Include="update.base.line.with.actuals.fsx" />
8387

0 commit comments

Comments
 (0)