@@ -3800,10 +3800,9 @@ private SemanticType CheckIifeLambdaCall(FunctionCall call, LambdaExpression lam
38003800 } ;
38013801
38023802 // 4. Check lambda with expected type context
3803- var saved = _expectedType ;
3804- _expectedType = expectedFuncType ;
3805- var lambdaType = CheckExpression ( call . Function ) ;
3806- _expectedType = saved ;
3803+ SemanticType lambdaType ;
3804+ using ( EnterStore ( StorePosition . ArgumentPositional , expectedFuncType , call . Function ) )
3805+ lambdaType = CheckExpression ( call . Function ) ;
38073806
38083807 // 5. Return the inferred return type
38093808 return lambdaType is FunctionType ft ? ft . ReturnType : SemanticType . Unknown ;
@@ -4079,7 +4078,6 @@ private SemanticType CheckUnionCaseConstruction(
40794078 {
40804079 for ( int argIdx = 0 ; argIdx < call . Arguments . Length ; argIdx ++ )
40814080 {
4082- var previousExpectedType = _expectedType ;
40834081 var previousParameterTypedArgument = _parameterTypedArgument ;
40844082
40854083 // Cleared up front, so the arms below can only ever set it TOGETHER with the
@@ -4107,7 +4105,6 @@ private SemanticType CheckUnionCaseConstruction(
41074105 else
41084106 argTypes . Add ( SemanticType . Unknown ) ;
41094107 }
4110- _expectedType = previousExpectedType ;
41114108 _parameterTypedArgument = previousParameterTypedArgument ;
41124109 continue ;
41134110 }
@@ -4119,24 +4116,27 @@ private SemanticType CheckUnionCaseConstruction(
41194116 && earlyFuncSymbol != null && argIdx + earlyParamOffset < earlyFuncSymbol . Parameters . Count )
41204117 {
41214118 var paramType = earlyFuncSymbol . Parameters [ argIdx + earlyParamOffset ] . Type ;
4122- _expectedType = paramType is UnknownType ? null : paramType ;
4123- _parameterTypedArgument = ParameterTypedArgumentOf ( paramType , call . Arguments [ argIdx ] ) ;
4119+ using ( EnterStore ( StorePosition . ArgumentPositional , paramType , call . Arguments [ argIdx ] ) )
4120+ argTypes . Add ( CheckExpression ( call . Arguments [ argIdx ] ) ) ;
41244121 }
41254122 else if ( ! noCandidateExpectation
41264123 && calleeFunctionType != null && argIdx < calleeFunctionType . ParameterTypes . Count )
41274124 {
41284125 var paramType = calleeFunctionType . ParameterTypes [ argIdx ] ;
4129- _expectedType = paramType is UnknownType ? null : paramType ;
4130- _parameterTypedArgument = ParameterTypedArgumentOf ( paramType , call . Arguments [ argIdx ] ) ;
4126+ using ( EnterStore ( StorePosition . ArgumentPositional , paramType , call . Arguments [ argIdx ] ) )
4127+ argTypes . Add ( CheckExpression ( call . Arguments [ argIdx ] ) ) ;
41314128 }
41324129 else if ( noCandidateExpectation )
41334130 {
41344131 // The ENCLOSING context's expectation is not this argument's parameter type
41354132 // either, and leaving it in place would type the literal from it.
4136- _expectedType = null ;
4133+ using ( ClearExpectation ( call . Arguments [ argIdx ] ) )
4134+ argTypes . Add ( CheckExpression ( call . Arguments [ argIdx ] ) ) ;
4135+ }
4136+ else
4137+ {
4138+ argTypes . Add ( CheckExpression ( call . Arguments [ argIdx ] ) ) ;
41374139 }
4138- argTypes . Add ( CheckExpression ( call . Arguments [ argIdx ] ) ) ;
4139- _expectedType = previousExpectedType ;
41404140 _parameterTypedArgument = previousParameterTypedArgument ;
41414141 }
41424142 }
@@ -4158,24 +4158,27 @@ private SemanticType CheckUnionCaseConstruction(
41584158 span : kwarg . Span ?? kwarg . Value . Span ) ;
41594159 }
41604160
4161- var previousExpectedType = _expectedType ;
41624161 var previousParameterTypedArgument = _parameterTypedArgument ;
41634162 _parameterTypedArgument = null ;
4164- if ( calleeDenotesOverloadSet && TakesContextualCollectionType ( kwarg . Value ) )
4163+ IDisposable ? kwScope = null ;
4164+ try
41654165 {
4166- _expectedType = null ;
4167- }
4168- else if ( earlyFuncSymbol != null )
4169- {
4170- var param = FindKeywordParameter ( earlyFuncSymbol . Parameters , kwarg . Name ) ;
4171- if ( param != null )
4166+ if ( calleeDenotesOverloadSet && TakesContextualCollectionType ( kwarg . Value ) )
41724167 {
4173- _expectedType = param . Type is UnknownType ? null : param . Type ;
4174- _parameterTypedArgument = ParameterTypedArgumentOf ( param . Type , kwarg . Value ) ;
4168+ kwScope = ClearExpectation ( kwarg . Value ) ;
41754169 }
4170+ else if ( earlyFuncSymbol != null )
4171+ {
4172+ var param = FindKeywordParameter ( earlyFuncSymbol . Parameters , kwarg . Name ) ;
4173+ if ( param != null )
4174+ kwScope = EnterStore ( StorePosition . ArgumentKeyword , param . Type , kwarg . Value , keywordName : kwarg . Name ) ;
4175+ }
4176+ kwargTypes [ kwarg . Name ] = CheckExpression ( kwarg . Value ) ;
4177+ }
4178+ finally
4179+ {
4180+ kwScope ? . Dispose ( ) ;
41764181 }
4177- kwargTypes [ kwarg . Name ] = CheckExpression ( kwarg . Value ) ;
4178- _expectedType = previousExpectedType ;
41794182 _parameterTypedArgument = previousParameterTypedArgument ;
41804183 }
41814184
@@ -4229,26 +4232,28 @@ private bool TryCheckMapLambdaArguments(FunctionCall call, Expression callee, Li
42294232 // that CheckLambda ignores (it maps only up to the lambda's own arity).
42304233 var elementTypes = new List < SemanticType > ( ) ;
42314234 var iterableTypes = new List < SemanticType > ( ) ;
4232- var previousExpectedType = _expectedType ;
4233- _expectedType = null ;
4234- for ( int i = 1 ; i < call . Arguments . Length ; i ++ )
4235+ using ( ClearExpectation ( null ) )
42354236 {
4236- var argType = CheckExpression ( call . Arguments [ i ] ) ;
4237- iterableTypes . Add ( argType ) ;
4238- var elem = _typeInference . InferIterableElementType ( argType ) ;
4239- elementTypes . Add ( elem ?? SemanticType . Unknown ) ;
4237+ for ( int i = 1 ; i < call . Arguments . Length ; i ++ )
4238+ {
4239+ var argType = CheckExpression ( call . Arguments [ i ] ) ;
4240+ iterableTypes . Add ( argType ) ;
4241+ var elem = _typeInference . InferIterableElementType ( argType ) ;
4242+ elementTypes . Add ( elem ?? SemanticType . Unknown ) ;
4243+ }
42404244 }
42414245
42424246 // Feed the synthesized expected function type into the lambda so CheckLambda types its
42434247 // parameters from the element types (lambdas/CheckLambda already consume a FunctionType
42444248 // _expectedType). The return type is left Unknown; the body determines it.
4245- _expectedType = new FunctionType
4249+ var expectedMapFuncType = new FunctionType
42464250 {
42474251 ParameterTypes = elementTypes ,
42484252 ReturnType = SemanticType . Unknown
42494253 } ;
4250- var lambdaType = CheckExpression ( call . Arguments [ 0 ] ) ;
4251- _expectedType = previousExpectedType ;
4254+ SemanticType lambdaType ;
4255+ using ( EnterStore ( StorePosition . ArgumentPositional , expectedMapFuncType , call . Arguments [ 0 ] ) )
4256+ lambdaType = CheckExpression ( call . Arguments [ 0 ] ) ;
42524257
42534258 // Reassemble positional argTypes in source order: [lambda, iter1, iter2, ...].
42544259 argTypes . Add ( lambdaType ) ;
0 commit comments