@@ -590,8 +590,8 @@ let UnifyTupleTypeAndInferCharacteristics contextInfo (cenv: cenv) denv m knownT
590590 if isAnyTupleTy g knownTy then
591591 let tupInfo, ptys = destAnyTupleTy g knownTy
592592 let tupInfo = (if isExplicitStruct then tupInfoStruct else tupInfo)
593- let ptys =
594- if List.length ps = List.length ptys then ptys
593+ let ptys =
594+ if List.length ps = List.length ptys then ptys
595595 else NewInferenceTypes g ps
596596 tupInfo, ptys
597597 else
@@ -5288,11 +5288,16 @@ and TcExprThenDynamic (cenv: cenv) overallTy env tpenv isArg e1 mQmark e2 delaye
52885288
52895289 TcExprThen cenv overallTy env tpenv isArg appExpr delayed
52905290
5291- and TcExprsWithFlexes (cenv: cenv) env m tpenv flexes argTys args =
5292- if List.length args <> List.length argTys then error(Error(FSComp.SR.tcExpressionCountMisMatch((List.length argTys), (List.length args)), m))
5291+ and TcExprsWithFlexes (cenv: cenv) env m tpenv flexes ( argTys: TType list) ( args: SynExpr list) =
5292+ if args.Length <> argTys.Length then error(Error(FSComp.SR.tcExpressionCountMisMatch((argTys.Length ), (args.Length )), m))
52935293 (tpenv, List.zip3 flexes argTys args) ||> List.mapFold (fun tpenv (flex, ty, e) ->
52945294 TcExprFlex cenv flex false ty env tpenv e)
52955295
5296+ and TcExprsNoFlexes (cenv: cenv) env m tpenv (argTys: TType list) (args: SynExpr list) =
5297+ if args.Length <> argTys.Length then error(Error(FSComp.SR.tcExpressionCountMisMatch((argTys.Length), (args.Length)), m))
5298+ (tpenv, List.zip argTys args) ||> List.mapFold (fun tpenv (ty, e) ->
5299+ TcExprFlex2 cenv ty env false tpenv e)
5300+
52965301and CheckSuperInit (cenv: cenv) objTy m =
52975302 let g = cenv.g
52985303
@@ -5348,7 +5353,7 @@ and TcPropagatingExprLeafThenConvert (cenv: cenv) overallTy actualTy (env: TcEnv
53485353 UnifyTypes cenv env m overallTy.Commit actualTy
53495354 f ()
53505355
5351- /// Process a leaf construct, for cases where we propogate the overall type eagerly in
5356+ /// Process a leaf construct, for cases where we propagate the overall type eagerly in
53525357/// some cases. Then apply additional type-directed conversions.
53535358///
53545359/// However in some cases favour propagating characteristics of the overall type.
@@ -5360,7 +5365,7 @@ and TcPropagatingExprLeafThenConvert (cenv: cenv) overallTy actualTy (env: TcEnv
53605365/// - tuple (except if overallTy is a tuple type or a variable type that can become one)
53615366/// - anon record (except if overallTy is an anon record type or a variable type that can become one)
53625367/// - record (except if overallTy is requiresCtor || haveCtor or a record type or a variable type that can become one))
5363- and TcPossiblyPropogatingExprLeafThenConvert isPropagating (cenv: cenv) (overallTy: OverallTy) (env: TcEnv) m processExpr =
5368+ and TcPossiblyPropagatingExprLeafThenConvert isPropagating (cenv: cenv) (overallTy: OverallTy) (env: TcEnv) m processExpr =
53645369
53655370 let g = cenv.g
53665371
@@ -5538,7 +5543,7 @@ and TcExprUndelayed (cenv: cenv) (overallTy: OverallTy) env tpenv (synExpr: SynE
55385543
55395544 | SynExpr.AnonRecd (isStruct, withExprOpt, unsortedFieldExprs, mWholeExpr) ->
55405545 TcNonControlFlowExpr env <| fun env ->
5541- TcPossiblyPropogatingExprLeafThenConvert (fun ty -> isAnonRecdTy g ty || isTyparTy g ty) cenv overallTy env mWholeExpr (fun overallTy ->
5546+ TcPossiblyPropagatingExprLeafThenConvert (fun ty -> isAnonRecdTy g ty || isTyparTy g ty) cenv overallTy env mWholeExpr (fun overallTy ->
55425547 TcAnonRecdExpr cenv overallTy env tpenv (isStruct, withExprOpt, unsortedFieldExprs, mWholeExpr)
55435548 )
55445549
@@ -5799,13 +5804,27 @@ and TcExprLazy (cenv: cenv) overallTy env tpenv (synInnerExpr, m) =
57995804 let expr = mkLazyDelayed g m innerTy (mkUnitDelayLambda g m innerExpr)
58005805 expr, tpenv
58015806
5807+ and CheckTupleIsCorrectLength g (env: TcEnv) m tupleTy (args: 'a list) tcArgs =
5808+ if isAnyTupleTy g tupleTy then
5809+ let tupInfo, ptys = destAnyTupleTy g tupleTy
5810+
5811+ if args.Length <> ptys.Length then
5812+ let argTys = NewInferenceTypes g args
5813+ suppressErrorReporting (fun () -> tcArgs argTys)
5814+ let expectedTy = TType_tuple (tupInfo, argTys)
5815+
5816+ // We let error recovery handle this exception
5817+ error (ErrorFromAddingTypeEquation(g, env.DisplayEnv, tupleTy, expectedTy,
5818+ (ConstraintSolverTupleDiffLengths(env.DisplayEnv, ptys, argTys, m, m)), m))
5819+
58025820and TcExprTuple (cenv: cenv) overallTy env tpenv (isExplicitStruct, args, m) =
58035821 let g = cenv.g
5804- TcPossiblyPropogatingExprLeafThenConvert (fun ty -> isAnyTupleTy g ty || isTyparTy g ty) cenv overallTy env m (fun overallTy ->
5805- let tupInfo, argTys = UnifyTupleTypeAndInferCharacteristics env.eContextInfo cenv env.DisplayEnv m overallTy isExplicitStruct args
5822+ TcPossiblyPropagatingExprLeafThenConvert (fun ty -> isAnyTupleTy g ty || isTyparTy g ty) cenv overallTy env m (fun overallTy ->
58065823
5807- let flexes = argTys |> List.map (fun _ -> false)
5808- let argsR, tpenv = TcExprsWithFlexes cenv env m tpenv flexes argTys args
5824+ CheckTupleIsCorrectLength g env m overallTy args (fun argTys -> TcExprsNoFlexes cenv env m tpenv argTys args |> ignore)
5825+
5826+ let tupInfo, argTys = UnifyTupleTypeAndInferCharacteristics env.eContextInfo cenv env.DisplayEnv m overallTy isExplicitStruct args
5827+ let argsR, tpenv = TcExprsNoFlexes cenv env m tpenv argTys args
58095828 let expr = mkAnyTupled g m tupInfo argsR argTys
58105829 expr, tpenv
58115830 )
@@ -5882,7 +5901,7 @@ and TcExprRecord (cenv: cenv) overallTy env tpenv (inherits, withExprOpt, synRec
58825901 CallExprHasTypeSink cenv.tcSink (mWholeExpr, env.NameEnv, overallTy.Commit, env.AccessRights)
58835902 let requiresCtor = (GetCtorShapeCounter env = 1) // Get special expression forms for constructors
58845903 let haveCtor = Option.isSome inherits
5885- TcPossiblyPropogatingExprLeafThenConvert (fun ty -> requiresCtor || haveCtor || isRecdTy g ty || isTyparTy g ty) cenv overallTy env mWholeExpr (fun overallTy ->
5904+ TcPossiblyPropagatingExprLeafThenConvert (fun ty -> requiresCtor || haveCtor || isRecdTy g ty || isTyparTy g ty) cenv overallTy env mWholeExpr (fun overallTy ->
58865905 TcRecdExpr cenv overallTy env tpenv (inherits, withExprOpt, synRecdFields, mWholeExpr)
58875906 )
58885907
@@ -6085,8 +6104,7 @@ and TcExprILAssembly (cenv: cenv) overallTy env tpenv (ilInstrs, synTyArgs, synA
60856104 let argTys = NewInferenceTypes g synArgs
60866105 let tyargs, tpenv = TcTypes cenv NewTyparsOK CheckCxs ItemOccurence.UseInType WarnOnIWSAM.Yes env tpenv synTyArgs
60876106 // No subsumption at uses of IL assembly code
6088- let flexes = argTys |> List.map (fun _ -> false)
6089- let args, tpenv = TcExprsWithFlexes cenv env m tpenv flexes argTys synArgs
6107+ let args, tpenv = TcExprsNoFlexes cenv env m tpenv argTys synArgs
60906108 let retTys, tpenv = TcTypes cenv NewTyparsOK CheckCxs ItemOccurence.UseInType WarnOnIWSAM.Yes env tpenv synRetTys
60916109 let returnTy =
60926110 match retTys with
@@ -7151,8 +7169,7 @@ and TcInterpolatedStringExpr cenv (overallTy: OverallTy) env m tpenv (parts: Syn
71517169 mkCallNewFormat g m printerTy printerArgTy printerResidueTy printerResultTy printerTupleTy str, tpenv
71527170 else
71537171 // Type check the expressions filling the holes
7154- let flexes = argTys |> List.map (fun _ -> false)
7155- let fillExprs, tpenv = TcExprsWithFlexes cenv env m tpenv flexes argTys synFillExprs
7172+ let fillExprs, tpenv = TcExprsNoFlexes cenv env m tpenv argTys synFillExprs
71567173
71577174 let fillExprsBoxed = (argTys, fillExprs) ||> List.map2 (mkCallBox g m)
71587175
@@ -7178,8 +7195,7 @@ and TcInterpolatedStringExpr cenv (overallTy: OverallTy) env m tpenv (parts: Syn
71787195 | Choice2Of2 createFormattableStringMethod ->
71797196
71807197 // Type check the expressions filling the holes
7181- let flexes = argTys |> List.map (fun _ -> false)
7182- let fillExprs, tpenv = TcExprsWithFlexes cenv env m tpenv flexes argTys synFillExprs
7198+ let fillExprs, tpenv = TcExprsNoFlexes cenv env m tpenv argTys synFillExprs
71837199
71847200 let fillExprsBoxed = (argTys, fillExprs) ||> List.map2 (mkCallBox g m)
71857201
0 commit comments