Skip to content
Merged
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
7 changes: 4 additions & 3 deletions src/Compiler/Checking/CheckComputationExpressions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2182,10 +2182,11 @@ let TcSequenceExpression (cenv: cenv) env tpenv comp (overallTy: OverallTy) m =
Choice2Of2 expr, tpenv
else
let genResultTy = NewInferenceType g
UnifyTypes cenv env m genOuterTy (mkSeqTy cenv.g genResultTy)
let mExpr = expr.Range
UnifyTypes cenv env mExpr genOuterTy (mkSeqTy cenv.g genResultTy)
let exprTy = tyOfExpr cenv.g expr
AddCxTypeMustSubsumeType env.eContextInfo env.DisplayEnv cenv.css m NoTrace genResultTy exprTy
let resExpr = mkCallSeqSingleton cenv.g m genResultTy (mkCoerceExpr(expr, genResultTy, m, exprTy))
AddCxTypeMustSubsumeType env.eContextInfo env.DisplayEnv cenv.css mExpr NoTrace genResultTy exprTy
let resExpr = mkCallSeqSingleton cenv.g mExpr genResultTy (mkCoerceExpr(expr, genResultTy, mExpr, exprTy))
Choice1Of2 resExpr, tpenv
else
let stmt, tpenv = TcStmtThatCantBeCtorBody cenv env tpenv comp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,3 +293,45 @@ type Derived3() =
(Error 856, Line 8, Col 16, Line 8, Col 22, "This override takes a different number of arguments to the corresponding abstract member. The following abstract members were found:" + System.Environment.NewLine + " abstract Base.Member: int * string -> string")
(Error 856, Line 12, Col 16, Line 12, Col 22, "This override takes a different number of arguments to the corresponding abstract member. The following abstract members were found:" + System.Environment.NewLine + " abstract Base.Member: int * string -> string")
(Error 1, Line 16, Col 24, Line 16, Col 34, "This expression was expected to have type\n 'int' \nbut here has type\n 'string' ")]

[<Fact>]
let ``Elements in computed lists, arrays and sequences``() =
FSharp """
let f1 =
[|
if true then
1
"wrong"
|]

let f2: int list =
[
if true then
"a"
yield! [ 3; 4 ]
]

let f3 =
[
if true then
"a"
"b"
yield! [ 3; 4 ]
]

let f4 =
seq {
1L
let _ = ()
2.5
3L
}
"""
|> typecheck
|> shouldFail
|> withDiagnostics [
(Error 193, Line 6, Col 9, Line 6, Col 16, "Type constraint mismatch. The type \n 'string' \nis not compatible with type\n 'int' \n")
(Error 193, Line 12, Col 13, Line 12, Col 16, "Type constraint mismatch. The type \n 'string' \nis not compatible with type\n 'int' \n")
(Error 193, Line 21, Col 9, Line 21, Col 24, "Type constraint mismatch. The type \n 'int list' \nis not compatible with type\n 'string seq' \n")
(Error 193, Line 28, Col 9, Line 28, Col 12, "Type constraint mismatch. The type \n 'float' \nis not compatible with type\n 'int64' \n")
]
2 changes: 1 addition & 1 deletion tests/fsharp/typecheck/sigs/neg24.bsl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ neg24.fs(302,33,302,34): typecheck error FS0001: All elements of a list must be

neg24.fs(302,36,302,37): typecheck error FS0001: All elements of a list must be implicitly convertible to the type of the first element, which here is 'unit'. This element has type 'int'.

neg24.fs(304,9,305,34): typecheck error FS0193: Type constraint mismatch. The type
neg24.fs(305,24,305,25): typecheck error FS0193: Type constraint mismatch. The type
'int'
is not compatible with type
'unit'
Expand Down
2 changes: 1 addition & 1 deletion tests/fsharp/typecheck/sigs/version47/neg24.bsl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ neg24.fs(302,33,302,34): typecheck error FS0001: All elements of a list must be

neg24.fs(302,36,302,37): typecheck error FS0001: All elements of a list must be implicitly convertible to the type of the first element, which here is 'unit'. This element has type 'int'.

neg24.fs(304,9,305,34): typecheck error FS0193: Type constraint mismatch. The type
neg24.fs(305,24,305,25): typecheck error FS0193: Type constraint mismatch. The type
'int'
is not compatible with type
'unit'
Expand Down