Skip to content

Commit 2c06b5c

Browse files
committed
update tests
1 parent 31c5eb2 commit 2c06b5c

File tree

3 files changed

+163
-6
lines changed

3 files changed

+163
-6
lines changed

src/Compiler/pars.fsy

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4442,8 +4442,9 @@ declExpr:
44424442
match $3 with
44434443
| None -> $2
44444444
| Some(_, SynReturnInfo((ty, _), m)) ->
4445+
let m = unionRanges $2.Range m
44454446
parseState.LexBuffer.CheckLanguageFeatureAndRecover LanguageFeature.AllowTypedLetOrUseBang m
4446-
SynExpr.Typed($2, ty, unionRanges $2.Range m)
4447+
SynExpr.Typed($2, ty, m)
44474448
SynExpr.YieldOrReturn(($1, not $1), expr, (unionRanges (rhs parseState 1) expr.Range), trivia) }
44484449

44494450
| YIELD recover
@@ -4459,6 +4460,7 @@ declExpr:
44594460
| YIELD_BANG declExpr COLON typ
44604461
{ let trivia: SynExprYieldOrReturnFromTrivia = { YieldOrReturnFromKeyword = rhs parseState 1 }
44614462
let typedExpr = SynExpr.Typed($2, $4, unionRanges $2.Range $4.Range)
4463+
parseState.LexBuffer.CheckLanguageFeatureAndRecover LanguageFeature.AllowTypedLetOrUseBang typedExpr.Range
44624464
SynExpr.YieldOrReturnFrom(($1, not $1), typedExpr, (unionRanges (rhs parseState 1) $2.Range), trivia) }
44634465

44644466
| YIELD_BANG declExpr opt_topReturnTypeWithTypeConstraints
@@ -4467,8 +4469,9 @@ declExpr:
44674469
match $3 with
44684470
| None -> $2
44694471
| Some(_, SynReturnInfo((ty, _), m)) ->
4470-
parseState.LexBuffer.CheckLanguageFeatureAndRecover LanguageFeature.AllowTypedLetOrUseBang m
4471-
SynExpr.Typed($2, ty, unionRanges $2.Range m)
4472+
let m = unionRanges $2.Range m
4473+
parseState.LexBuffer.CheckLanguageFeatureAndRecover LanguageFeature.AllowTypedLetOrUseBang m
4474+
SynExpr.Typed($2, ty, m)
44724475
SynExpr.YieldOrReturnFrom(($1, not $1), expr, (unionRanges (rhs parseState 1) $2.Range), trivia) }
44734476

44744477
| BINDER headBindingPattern EQUALS typedSequentialExprBlock IN opt_OBLOCKSEP moreBinders typedSequentialExprBlock %prec expr_let

tests/FSharp.Compiler.ComponentTests/Language/ComputationExpressionTests.fs

Lines changed: 67 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.
1+
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.
22

33
namespace Language
44

@@ -24,7 +24,7 @@ let x = lb {1; 2;}
2424
|> ignore
2525

2626
[<Fact>]
27-
let ``Allow CE return and type annotations to play well together without needing parentheses``() =
27+
let ``Version 9.0: Allow CE return and type annotations don't play well together needing parentheses``() =
2828
FSharp """
2929
module ComputationExpressionTests
3030
open System
@@ -53,12 +53,45 @@ let f3 () =
5353
return (new MyType() : IDisposable)
5454
}
5555
"""
56+
|> withLangVersion90
5657
|> typecheck
5758
|> shouldFail
5859
|> withDiagnostics [
5960
(Error 3350, Line 11, Col 16, Line 11, Col 42, "Feature 'Allow let! and use! type annotations without requiring parentheses' is not available in F# 9.0. Please use language version 'PREVIEW' or greater.")
6061
]
6162

63+
[<Fact>]
64+
let ``Version 9.0: Allow CE return! and type annotations don't to play well together needing parentheses``() =
65+
FSharp """
66+
module ComputationExpressionTests
67+
68+
type ResultBuilder() =
69+
member _.Return(x) = Ok x
70+
member _.ReturnFrom(x) = x
71+
member _.Bind(m, f) =
72+
match m with
73+
| Ok a -> f a
74+
| Error e -> Error e
75+
76+
let result = ResultBuilder()
77+
78+
let f() =
79+
result {
80+
return! Ok 1 : Result<int, string>
81+
}
82+
83+
let f1() =
84+
result {
85+
return! (Ok 1 : Result<int, string>)
86+
}
87+
"""
88+
|> withLangVersion90
89+
|> typecheck
90+
|> shouldFail
91+
|> withDiagnostics [
92+
(Error 3350, Line 16, Col 17, Line 16, Col 43, "Feature 'Allow let! and use! type annotations without requiring parentheses' is not available in F# 9.0. Please use language version 'PREVIEW' or greater.")
93+
]
94+
6295
[<Fact>]
6396
let ``Preview: Allow CE return and type annotations to play well together without needing parentheses``() =
6497
FSharp """
@@ -91,7 +124,38 @@ let f3 () =
91124
"""
92125
|> withLangVersionPreview
93126
|> asExe
94-
|> withOptions ["--nowarn:988"]
127+
|> ignoreWarnings
128+
|> compileAndRun
129+
|> shouldSucceed
130+
131+
[<Fact>]
132+
let ``Preview: Allow CE return! and type annotations to play well together without needing parentheses``() =
133+
FSharp """
134+
module ComputationExpressionTests
135+
136+
type ResultBuilder() =
137+
member _.Return(x) = Ok x
138+
member _.ReturnFrom(x) = x
139+
member _.Bind(m, f) =
140+
match m with
141+
| Ok a -> f a
142+
| Error e -> Error e
143+
144+
let result = ResultBuilder()
145+
146+
let f() =
147+
result {
148+
return! Ok 1 : Result<int, string>
149+
}
150+
151+
let f1() =
152+
result {
153+
return! (Ok 1 : Result<int, string>)
154+
}
155+
"""
156+
|> withLangVersionPreview
157+
|> asExe
158+
|> ignoreWarnings
95159
|> compileAndRun
96160
|> shouldSucceed
97161

tests/FSharp.Compiler.ComponentTests/Language/SequenceExpressions/SequenceExpressionTests.fs

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,4 +644,94 @@ let c = [ { 1;10 } ]
644644
|> withOptions [ "--nowarn:0020" ]
645645
|> withLangVersionPreview
646646
|> typecheck
647+
|> shouldSucceed
648+
649+
[<Fact>]
650+
let ``Version 9.0: Allow SE yield and type annotations don't play well together needing parentheses``() =
651+
FSharp """
652+
module SequenceExpressionTests
653+
open System
654+
655+
let f() =
656+
seq {
657+
yield 1 : int
658+
}
659+
660+
let f1() =
661+
seq {
662+
yield (1 : int)
663+
}
664+
"""
665+
|> withLangVersion90
666+
|> typecheck
667+
|> shouldFail
668+
|> withDiagnostics [
669+
(Error 3350, Line 7, Col 15, Line 7, Col 22, "Feature 'Allow let! and use! type annotations without requiring parentheses' is not available in F# 9.0. Please use language version 'PREVIEW' or greater.")
670+
]
671+
672+
[<Fact>]
673+
let ``Preview: Allow SE yield and type annotations to play well together without needing parentheses``() =
674+
FSharp """
675+
module SequenceExpressionTests
676+
open System
677+
678+
let f() =
679+
seq {
680+
yield 1 : int
681+
}
682+
683+
let f1() =
684+
seq {
685+
yield (1 : int)
686+
}
687+
"""
688+
|> withLangVersionPreview
689+
|> asExe
690+
|> ignoreWarnings
691+
|> compileAndRun
692+
|> shouldSucceed
693+
694+
[<Fact>]
695+
let ``Version 9.0: Allow SE yield! and type annotations don't play well together needing parentheses``() =
696+
FSharp """
697+
module SequenceExpressionTests
698+
open System
699+
700+
let f() =
701+
seq {
702+
yield! [1;2] : int list
703+
}
704+
705+
let f1() =
706+
seq {
707+
yield! ([1;2] : int list)
708+
}
709+
"""
710+
|> withLangVersion90
711+
|> typecheck
712+
|> shouldFail
713+
|> withDiagnostics [
714+
(Error 3350, Line 7, Col 16, Line 7, Col 32, "Feature 'Allow let! and use! type annotations without requiring parentheses' is not available in F# 9.0. Please use language version 'PREVIEW' or greater.")
715+
]
716+
717+
[<Fact>]
718+
let ``Preview: Allow SE yield! and type annotations to play well together without needing parentheses``() =
719+
FSharp """
720+
module SequenceExpressionTests
721+
open System
722+
723+
let f() =
724+
seq {
725+
yield! [1;2] : int list
726+
}
727+
728+
let f1() =
729+
seq {
730+
yield! ([1;2] : int list)
731+
}
732+
"""
733+
|> withLangVersionPreview
734+
|> asExe
735+
|> ignoreWarnings
736+
|> compileAndRun
647737
|> shouldSucceed

0 commit comments

Comments
 (0)