提交 49faa92c 编写于 作者: K Kevin Ransom (msft) 提交者: GitHub

Merge branch 'master' into indexer

......@@ -31,6 +31,7 @@ This is for those who contributed language features, compiler improvements, or i
- [Gustavo Leon](https://github.com/gmpl)
- [Steffen Forkmann](https://github.com/forki)
- [Libo Zeng](https://github.com/liboz)
- [Rikki Gibson](https://github.com/RikkiGibson)
**SRTP Improvements**
......@@ -85,6 +86,11 @@ This is for those who contributed Visual Studio IDE features and platform suppor
* Separate color themes for light and dark mode - [Jakub Majocha](https://github.com/majocha)
* Semantic highlighting - [Vasily Kirichenko](https://github.com/vasily-kirichenko) and [Jared Hester](github.com/cloudroutine)
* ReSharper-like ordering in Completion lists - [Vasily Kirichenko](https://github.com/vasily-kirichenko)
* Collapse to Definition - [Vasily Kirichenko](https://github.com/vasily-kirichenko)
* Support for Editor Settings - [Jakub Majocha](https://github.com/majocha)
* Localized Go to Definition Status Bar - [Saul Rennison](https://github.com/saul)
* R#-like completion for items in unopened namespaces - [Vasily Kirichenko](https://github.com/vasily-kirichenko)
* Wrap XML docs - [Jakub Majocha](https://github.com/majocha)
**Project System**
......@@ -106,6 +112,8 @@ This is for those who contributed Visual Studio IDE features and platform suppor
* Add open Statement Analyzer and Codefix - [Vasily Kirichenko](https://github.com/vasily-kirichenko)
* Simplify Name Analyzer and Codefix - [Vasily Kirichenko](https://github.com/vasily-kirichenko)
* Gray Out Unused Values - [Vasily Kirichenko](https://github.com/vasily-kirichenko)
* Unused Declarations Analyzer and Codefix - [Vasily Kirichenko](https://github.com/vasily-kirichenko)
* Add reference to \<assembly\> analyzer and codefix - [Saul Rennison](https://github.com/saul)
### .NET Core Support
......@@ -123,4 +131,4 @@ Infrastructure isn't the sexiest stuff in the world, but it's absolutely necessa
* [Zp Babbi](https://github.com/zpbappi)
* [Gauthier Segay](https://github.com/smoothdeveloper)
* [Jared Hester](github.com/cloudroutine)
* [Cameron Taggert](https://github.com/ctaggart)
\ No newline at end of file
* [Cameron Taggert](https://github.com/ctaggart)
......@@ -625,14 +625,11 @@ let OutputPhasedErrorR (os:StringBuilder) (err:PhasedDiagnostic) =
os.Append(ConstraintSolverMissingConstraintE().Format (NicePrint.stringOfTyparConstraint denv (tpr,tpc))) |> ignore
if m.StartLine <> m2.StartLine then
os.Append(SeeAlsoE().Format (stringOfRange m)) |> ignore
| ConstraintSolverTypesNotInEqualityRelation(denv,(TType_measure _ as t1),(TType_measure _ as t2),m,m2,contextInfo) ->
| ConstraintSolverTypesNotInEqualityRelation(denv,(TType_measure _ as t1),(TType_measure _ as t2),m,m2,_) ->
// REVIEW: consider if we need to show _cxs (the type parameter constraints)
let t1, t2, _cxs = NicePrint.minimalStringsOfTwoTypes denv t1 t2
match contextInfo with
| ContextInfo.OmittedElseBranch range when range = m -> os.Append(FSComp.SR.missingElseBranch(t2)) |> ignore
| ContextInfo.ElseBranchResult range when range = m -> os.Append(FSComp.SR.elseBranchHasWrongType(t1,t2)) |> ignore
| _ -> os.Append(ConstraintSolverTypesNotInEqualityRelation1E().Format t1 t2 ) |> ignore
os.Append(ConstraintSolverTypesNotInEqualityRelation1E().Format t1 t2 ) |> ignore
if m.StartLine <> m2.StartLine then
os.Append(SeeAlsoE().Format (stringOfRange m)) |> ignore
......@@ -641,6 +638,12 @@ let OutputPhasedErrorR (os:StringBuilder) (err:PhasedDiagnostic) =
let t1, t2, _cxs = NicePrint.minimalStringsOfTwoTypes denv t1 t2
match contextInfo with
| ContextInfo.IfExpression range when range = m -> os.Append(FSComp.SR.ifExpression(t1,t2)) |> ignore
| ContextInfo.CollectionElement (isArray,range) when range = m ->
if isArray then
os.Append(FSComp.SR.arrayElementHasWrongType(t1,t2)) |> ignore
else
os.Append(FSComp.SR.listElementHasWrongType(t1,t2)) |> ignore
| ContextInfo.OmittedElseBranch range when range = m -> os.Append(FSComp.SR.missingElseBranch(t2)) |> ignore
| ContextInfo.ElseBranchResult range when range = m -> os.Append(FSComp.SR.elseBranchHasWrongType(t1,t2)) |> ignore
| _ -> os.Append(ConstraintSolverTypesNotInEqualityRelation2E().Format t1 t2) |> ignore
......@@ -666,6 +669,12 @@ let OutputPhasedErrorR (os:StringBuilder) (err:PhasedDiagnostic) =
&& typeEquiv g t2 t2' ->
let t1,t2,tpcs = NicePrint.minimalStringsOfTwoTypes denv t1 t2
match contextInfo with
| ContextInfo.IfExpression range when range = m -> os.Append(FSComp.SR.ifExpression(t1,t2)) |> ignore
| ContextInfo.CollectionElement (isArray,range) when range = m ->
if isArray then
os.Append(FSComp.SR.arrayElementHasWrongType(t1,t2)) |> ignore
else
os.Append(FSComp.SR.listElementHasWrongType(t1,t2)) |> ignore
| ContextInfo.OmittedElseBranch range when range = m -> os.Append(FSComp.SR.missingElseBranch(t2)) |> ignore
| ContextInfo.ElseBranchResult range when range = m -> os.Append(FSComp.SR.elseBranchHasWrongType(t1,t2)) |> ignore
| ContextInfo.TupleInRecordFields ->
......
......@@ -117,6 +117,8 @@ let FreshenMethInfo m (minfo:MethInfo) =
type ContextInfo =
/// No context was given.
| NoContext
/// The type equation comes from an IF expression.
| IfExpression of range
/// The type equation comes from an omitted else branch.
| OmittedElseBranch of range
/// The type equation comes from a type check of the result of an else branch.
......@@ -125,6 +127,8 @@ type ContextInfo =
| RecordFields
/// The type equation comes from the verification of a tuple in record fields.
| TupleInRecordFields
/// The type equation comes from a list or array constructor
| CollectionElement of bool * range
/// The type equation comes from a return in a computation expression.
| ReturnInComputationExpression
/// The type equation comes from a yield in a computation expression.
......
......@@ -52,6 +52,8 @@ val FreshenMethInfo : range -> MethInfo -> TType list
type ContextInfo =
/// No context was given.
| NoContext
/// The type equation comes from an IF expression.
| IfExpression of range
/// The type equation comes from an omitted else branch.
| OmittedElseBranch of range
/// The type equation comes from a type check of the result of an else branch.
......@@ -60,6 +62,8 @@ type ContextInfo =
| RecordFields
/// The type equation comes from the verification of a tuple in record fields.
| TupleInRecordFields
/// The type equation comes from a list or array constructor
| CollectionElement of bool * range
/// The type equation comes from a return in a computation expression.
| ReturnInComputationExpression
/// The type equation comes from a yield in a computation expression.
......
......@@ -17,8 +17,11 @@ undefinedNameTypeParameter,"The type parameter %s is not defined."
undefinedNamePatternDiscriminator,"The pattern discriminator '%s' is not defined."
replaceWithSuggestion,"Replace with '%s'"
addIndexerDot,"Add . for indexer access."
listElementHasWrongType,"All elements of a list constructor expression must have the same type. This expression was expected to have type '%s', but here has type '%s'."
arrayElementHasWrongType,"All elements of an array constructor expression must have the same type. This expression was expected to have type '%s', but here has type '%s'."
missingElseBranch,"The 'if' expression is missing an 'else' branch. The 'then' branch has type '%s'. Because 'if' is an expression, and not a statement, add an 'else' branch which returns a value of the same type."
elseBranchHasWrongType,"All branches of an 'if' expression must return the same type. This expression was expected to have type '%s' but here has type '%s'."
ifExpression,"The 'if' expression needs to have type '%s' to satisfy context type requirements. It currently has type '%s'."
elseBranchHasWrongType,"All branches of an 'if' expression must return the same type. This expression was expected to have type '%s', but here has type '%s'."
commaInsteadOfSemicolonInRecord,"A ';' is used to separate field values in records. Consider replacing ',' with ';'."
derefInsteadOfNot,"The '!' operator is used to dereference a ref cell. Consider using 'not expr' here."
buildUnexpectedTypeArgs,"The non-generic type '%s' does not expect any type arguments, but here is given %d type argument(s)"
......
......@@ -51,14 +51,14 @@ WARNING: DO NOT MODIFY this file unless you are knowledgeable about MSBuild and
<FSharpCoreImplicitPackageVersion>4.2.*</FSharpCoreImplicitPackageVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(DisableImplcitSystemValueTupleReference)' != 'true' ">
<PropertyGroup Condition=" '$(DisableImplicitSystemValueTupleReference)' != 'true' ">
<_FrameworkNeedsValueTupleReference Condition=" $(TargetFramework.StartsWith(netcoreapp1.)) or $(TargetFramework.StartsWith(netstandard1.)) ">true</_FrameworkNeedsValueTupleReference>
<_FrameworkNeedsValueTupleReference Condition=" '$(TargetFramework)' == 'net40' or '$(TargetFramework)' == 'net45' or '$(TargetFramework)' == 'net46' or '$(TargetFramework)' == 'net461' or '$(TargetFramework)' == 'net462' or '$(TargetFramework)' == 'net47' ">true</_FrameworkNeedsValueTupleReference>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.ValueTuple" Version="4.*" Condition=" '$(DisableImplcitSystemValueTupleReference)' != 'true' and '$(_FrameworkNeedsValueTupleReference)' == 'true' "></PackageReference>
<PackageReference Include="FSharp.Core" Version="$(FSharpCoreImplicitPackageVersion)" Condition=" '$(DisableImplcitSystemValueTupleReference)' != 'true' "></PackageReference>
<PackageReference Include="System.ValueTuple" Version="4.*" Condition=" '$(DisableImplicitSystemValueTupleReference)' != 'true' and '$(_FrameworkNeedsValueTupleReference)' == 'true' "></PackageReference>
<PackageReference Include="FSharp.Core" Version="$(FSharpCoreImplicitPackageVersion)" Condition=" '$(DisableImplicitFSharpCoreReference)' != 'true' "></PackageReference>
</ItemGroup>
</Project>
......@@ -5716,7 +5716,15 @@ and TcExprUndelayed cenv overallTy env tpenv (expr: SynExpr) =
// Always allow subsumption if a nominal type is known prior to type checking any arguments
let flex = not (isTyparTy cenv.g argty)
let args',tpenv = List.mapFold (TcExprFlex cenv flex argty env) tpenv args
let first = ref true
let getInitEnv m =
if !first then
first := false
env
else
{ env with eContextInfo = ContextInfo.CollectionElement (isArray,m) }
let args',tpenv = List.mapFold (fun tpenv (x:SynExpr) -> TcExprFlex cenv flex argty (getInitEnv x.Range) tpenv x) tpenv args
let expr =
if isArray then Expr.Op(TOp.Array, [argty],args',m)
......@@ -5873,12 +5881,19 @@ and TcExprUndelayed cenv overallTy env tpenv (expr: SynExpr) =
| SynExpr.IfThenElse (e1,e2,e3opt,spIfToThen,isRecovery,mIfToThen,m) ->
let e1',tpenv = TcExprThatCantBeCtorBody cenv cenv.g.bool_ty env tpenv e1
let e2',tpenv =
let env =
match env.eContextInfo with
| ContextInfo.ElseBranchResult _ -> { env with eContextInfo = ContextInfo.ElseBranchResult e2.Range }
| _ ->
match e3opt with
| None -> { env with eContextInfo = ContextInfo.OmittedElseBranch e2.Range }
| _ -> { env with eContextInfo = ContextInfo.IfExpression e2.Range }
if not isRecovery && Option.isNone e3opt then
let env = { env with eContextInfo = ContextInfo.OmittedElseBranch e2.Range}
UnifyTypes cenv env m cenv.g.unit_ty overallTy
TcExprThatCanBeCtorBody cenv overallTy env tpenv e2
else
TcExprThatCanBeCtorBody cenv overallTy env tpenv e2
TcExprThatCanBeCtorBody cenv overallTy env tpenv e2
let e3',sp2,tpenv =
match e3opt with
| None ->
......@@ -5887,6 +5902,7 @@ and TcExprUndelayed cenv overallTy env tpenv (expr: SynExpr) =
let env = { env with eContextInfo = ContextInfo.ElseBranchResult e3.Range }
let e3',tpenv = TcExprThatCanBeCtorBody cenv overallTy env tpenv e3
e3',SequencePointAtTarget,tpenv
primMkCond spIfToThen SequencePointAtTarget sp2 m overallTy e1' e2' e3', tpenv
// This is for internal use in the libraries only
......
......@@ -69,35 +69,17 @@ neg20.fs(53,38,53,39): typecheck error FS0001: This expression was expected to h
but here has type
'int'
neg20.fs(60,26,60,33): typecheck error FS0001: This expression was expected to have type
'B'
but here has type
'A'
neg20.fs(60,26,60,33): typecheck error FS0001: All elements of a list constructor expression must have the same type. This expression was expected to have type 'B', but here has type 'A'.
neg20.fs(61,27,61,35): typecheck error FS0001: This expression was expected to have type
'B1'
but here has type
'B2'
neg20.fs(61,27,61,35): typecheck error FS0001: All elements of a list constructor expression must have the same type. This expression was expected to have type 'B1', but here has type 'B2'.
neg20.fs(62,26,62,33): typecheck error FS0001: This expression was expected to have type
'C'
but here has type
'B'
neg20.fs(62,26,62,33): typecheck error FS0001: All elements of a list constructor expression must have the same type. This expression was expected to have type 'C', but here has type 'B'.
neg20.fs(66,25,66,32): typecheck error FS0001: This expression was expected to have type
'A'
but here has type
'B'
neg20.fs(66,25,66,32): typecheck error FS0001: All elements of a list constructor expression must have the same type. This expression was expected to have type 'A', but here has type 'B'.
neg20.fs(67,27,67,34): typecheck error FS0001: This expression was expected to have type
'B'
but here has type
'C'
neg20.fs(67,27,67,34): typecheck error FS0001: All elements of a list constructor expression must have the same type. This expression was expected to have type 'B', but here has type 'C'.
neg20.fs(70,31,70,38): typecheck error FS0001: This expression was expected to have type
'B'
but here has type
'C'
neg20.fs(70,31,70,38): typecheck error FS0001: All elements of a list constructor expression must have the same type. This expression was expected to have type 'B', but here has type 'C'.
neg20.fs(71,34,71,42): typecheck error FS0001: Type mismatch. Expecting a
'A list'
......@@ -128,7 +110,7 @@ but given a
'B list'
The type 'A' does not match the type 'B'
neg20.fs(83,47,83,54): typecheck error FS0001: All branches of an 'if' expression must return the same type. This expression was expected to have type 'B' but here has type 'C'.
neg20.fs(83,47,83,54): typecheck error FS0001: All branches of an 'if' expression must return the same type. This expression was expected to have type 'B', but here has type 'C'.
neg20.fs(87,54,87,61): typecheck error FS0001: This expression was expected to have type
'B'
......@@ -150,10 +132,7 @@ neg20.fs(97,26,97,33): typecheck error FS0001: This expression was expected to h
but here has type
'B'
neg20.fs(99,26,99,33): typecheck error FS0001: This expression was expected to have type
'B'
but here has type
'A'
neg20.fs(99,26,99,33): typecheck error FS0001: All elements of a list constructor expression must have the same type. This expression was expected to have type 'B', but here has type 'A'.
neg20.fs(108,12,108,16): typecheck error FS0001: Type mismatch. Expecting a
'B * B -> 'a'
......
......@@ -17,23 +17,11 @@ but given a
'float<s ^ 4>'
The unit of measure 's ^ 3' does not match the unit of measure 's ^ 4'
neg21.fs(19,59,19,67): typecheck error FS0001: Type mismatch. Expecting a
'area'
but given a
'float<m ^ 3>'
The unit of measure 'sqrm' does not match the unit of measure 'm ^ 3'
neg21.fs(19,59,19,67): typecheck error FS0001: The unit of measure 'sqrm' does not match the unit of measure 'm ^ 3'
neg21.fs(20,36,20,44): typecheck error FS0001: Type mismatch. Expecting a
'area'
but given a
'float<m ^ 3>'
The unit of measure 'sqrm' does not match the unit of measure 'm ^ 3'
neg21.fs(20,36,20,44): typecheck error FS0001: The unit of measure 'sqrm' does not match the unit of measure 'm ^ 3'
neg21.fs(21,53,21,59): typecheck error FS0001: Type mismatch. Expecting a
'float<s ^ 2>'
but given a
'float<m>'
The unit of measure 's ^ 2' does not match the unit of measure 'm'
neg21.fs(21,53,21,59): typecheck error FS0001: The unit of measure 's ^ 2' does not match the unit of measure 'm'
neg21.fs(22,17,22,21): typecheck error FS0001: The unit of measure 's ^ 4' does not match the unit of measure 'sqrm'
......
// #Warnings
//<Expects status="Error" id="FS0001">The 'if' expression needs to have type 'bool'</Expects>
let x = 1
let y : bool =
if x = 2 then "A"
else "B"
exit 0
\ No newline at end of file
// #Warnings
//<Expects status="Error" span="(7,10)" id="FS0001">All branches of an 'if' expression must return the same type. This expression was expected to have type 'string' but here has type 'int'.</Expects>
//<Expects status="Error" span="(7,10)" id="FS0001">All branches of an 'if' expression must return the same type. This expression was expected to have type 'string', but here has type 'int'.</Expects>
let test = 100
let y =
......
// #Warnings
//<Expects status="Error" id="FS0001">All branches of an 'if' expression must return the same type. This expression was expected to have type 'string' but here has type 'int'.</Expects>
//<Expects status="Error" id="FS0001">All branches of an 'if' expression must return the same type. This expression was expected to have type 'string', but here has type 'int'.</Expects>
let test = 100
let f x = test
......
// #Warnings
//<Expects status="Error" id="FS0001">All branches of an 'if' expression must return the same type.</Expects>
let x = 1
if x = 1 then true
else
if x = 2 then "A"
else "B"
exit 0
\ No newline at end of file
......@@ -45,6 +45,8 @@
SOURCE=SuggestDoubleBacktickUnions.fs SCFLAGS="--vserrors" # SuggestDoubleBacktickUnions.fs
SOURCE=ElseBranchHasWrongType.fs # ElseBranchHasWrongType.fs
SOURCE=ElseBranchHasWrongType2.fs # ElseBranchHasWrongType2.fs
SOURCE=NestedElseBranchHasWrongType.fs # NestedElseBranchHasWrongType.fs
SOURCE=ElseBranchHasWrongContextType.fs # ElseBranchHasWrongContextType.fs
SOURCE=ElseBranchContextDoesntPropagateInAppl.fs # ElseBranchContextDoesntPropagateInAppl.fs
SOURCE=ElseBranchContextDoesntPropagateInAppl2.fs # ElseBranchContextDoesntPropagateInAppl2.fs
SOURCE=ElseBranchContextDoesntPropagateInForLoop.fs # ElseBranchContextDoesntPropagateInForLoop.fs
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册