@@ -300,7 +300,7 @@ type TyparRigidity =
300300[<Struct>]
301301type TyparFlags ( flags : int32 ) =
302302
303- new ( kind : TyparKind , rigidity : TyparRigidity , isFromError : bool , isCompGen : bool , staticReq : TyparStaticReq , dynamicReq : TyparDynamicReq , equalityDependsOn : bool , comparisonDependsOn : bool ) =
303+ new ( kind : TyparKind , rigidity : TyparRigidity , isFromError : bool , isCompGen : bool , staticReq : TyparStaticReq , dynamicReq : TyparDynamicReq , equalityDependsOn : bool , comparisonDependsOn : bool , supportsNullFlex : bool ) =
304304 TyparFlags(( if isFromError then 0b00000000000000010 else 0 ) |||
305305 ( if isCompGen then 0b00000000000000100 else 0 ) |||
306306 ( match staticReq with
@@ -321,7 +321,11 @@ type TyparFlags(flags: int32) =
321321 | TyparDynamicReq.No -> 0b00000000000000000
322322 | TyparDynamicReq.Yes -> 0b00000010000000000 ) |||
323323 ( if equalityDependsOn then
324- 0b00000100000000000 else 0 ))
324+ 0b00000100000000000 else 0 ) |||
325+ // 0b00001000100000000 is being checked by x.Kind, but never set in this version of the code
326+ // 0b00010000000000000 is taken by compat flex
327+ ( if supportsNullFlex then
328+ 0b00100000000000000 else 0 ))
325329
326330 /// Indicates if the type inference variable was generated after an error when type checking expressions or patterns
327331 member x.IsFromError = ( flags &&& 0b00000000000000010 ) <> 0x0
@@ -380,8 +384,20 @@ type TyparFlags(flags: int32) =
380384 else
381385 TyparFlags( flags &&& ~~~ 0b00010000000000000 )
382386
387+ /// Indicates that whether this type parameter is flexible for 'supports null' constraint, e.g. in the case of assignment to a mutable value
388+ member x.IsSupportsNullFlex =
389+ ( flags &&& 0b00100000000000000 ) <> 0x0
390+
391+ member x.WithSupportsNullFlex b =
392+ if b then
393+ TyparFlags( flags ||| 0b00100000000000000 )
394+ else
395+ TyparFlags( flags &&& ~~~ 0b00100000000000000 )
396+
397+
398+
383399 member x.WithStaticReq staticReq =
384- TyparFlags( x.Kind, x.Rigidity, x.IsFromError, x.IsCompilerGenerated, staticReq, x.DynamicReq, x.EqualityConditionalOn, x.ComparisonConditionalOn)
400+ TyparFlags( x.Kind, x.Rigidity, x.IsFromError, x.IsCompilerGenerated, staticReq, x.DynamicReq, x.EqualityConditionalOn, x.ComparisonConditionalOn, x.IsSupportsNullFlex )
385401
386402 /// Get the flags as included in the F# binary metadata. We pickle this as int64 to allow for future expansion
387403 member x.PickledBits = flags
@@ -2321,6 +2337,8 @@ type Typar =
23212337 /// Set whether this type parameter is a compat-flex type parameter (i.e. where "expr :> tp" only emits an optional warning)
23222338 member x.SetIsCompatFlex b = x.typar_ flags <- x.typar_ flags.WithCompatFlex b
23232339
2340+ member x.SetSupportsNullFlex b = x.typar_ flags <- x.typar_ flags.WithSupportsNullFlex b
2341+
23242342 /// Indicates whether a type variable can be instantiated by types or units-of-measure.
23252343 member x.Kind = x.typar_ flags.Kind
23262344
@@ -2425,12 +2443,12 @@ type Typar =
24252443 /// Sets the rigidity of a type variable
24262444 member x.SetRigidity b =
24272445 let flags = x.typar_ flags
2428- x.typar_ flags <- TyparFlags( flags.Kind, b, flags.IsFromError, flags.IsCompilerGenerated, flags.StaticReq, flags.DynamicReq, flags.EqualityConditionalOn, flags.ComparisonConditionalOn)
2446+ x.typar_ flags <- TyparFlags( flags.Kind, b, flags.IsFromError, flags.IsCompilerGenerated, flags.StaticReq, flags.DynamicReq, flags.EqualityConditionalOn, flags.ComparisonConditionalOn, flags.IsSupportsNullFlex )
24292447
24302448 /// Sets whether a type variable is compiler generated
24312449 member x.SetCompilerGenerated b =
24322450 let flags = x.typar_ flags
2433- x.typar_ flags <- TyparFlags( flags.Kind, flags.Rigidity, flags.IsFromError, b, flags.StaticReq, flags.DynamicReq, flags.EqualityConditionalOn, flags.ComparisonConditionalOn)
2451+ x.typar_ flags <- TyparFlags( flags.Kind, flags.Rigidity, flags.IsFromError, b, flags.StaticReq, flags.DynamicReq, flags.EqualityConditionalOn, flags.ComparisonConditionalOn, flags.IsSupportsNullFlex )
24342452
24352453 /// Sets whether a type variable has a static requirement
24362454 member x.SetStaticReq b =
@@ -2439,17 +2457,17 @@ type Typar =
24392457 /// Sets whether a type variable is required at runtime
24402458 member x.SetDynamicReq b =
24412459 let flags = x.typar_ flags
2442- x.typar_ flags <- TyparFlags( flags.Kind, flags.Rigidity, flags.IsFromError, flags.IsCompilerGenerated, flags.StaticReq, b, flags.EqualityConditionalOn, flags.ComparisonConditionalOn)
2460+ x.typar_ flags <- TyparFlags( flags.Kind, flags.Rigidity, flags.IsFromError, flags.IsCompilerGenerated, flags.StaticReq, b, flags.EqualityConditionalOn, flags.ComparisonConditionalOn, flags.IsSupportsNullFlex )
24432461
24442462 /// Sets whether the equality constraint of a type definition depends on this type variable
24452463 member x.SetEqualityDependsOn b =
24462464 let flags = x.typar_ flags
2447- x.typar_ flags <- TyparFlags( flags.Kind, flags.Rigidity, flags.IsFromError, flags.IsCompilerGenerated, flags.StaticReq, flags.DynamicReq, b, flags.ComparisonConditionalOn)
2465+ x.typar_ flags <- TyparFlags( flags.Kind, flags.Rigidity, flags.IsFromError, flags.IsCompilerGenerated, flags.StaticReq, flags.DynamicReq, b, flags.ComparisonConditionalOn, flags.IsSupportsNullFlex )
24482466
24492467 /// Sets whether the comparison constraint of a type definition depends on this type variable
24502468 member x.SetComparisonDependsOn b =
24512469 let flags = x.typar_ flags
2452- x.typar_ flags <- TyparFlags( flags.Kind, flags.Rigidity, flags.IsFromError, flags.IsCompilerGenerated, flags.StaticReq, flags.DynamicReq, flags.EqualityConditionalOn, b)
2470+ x.typar_ flags <- TyparFlags( flags.Kind, flags.Rigidity, flags.IsFromError, flags.IsCompilerGenerated, flags.StaticReq, flags.DynamicReq, flags.EqualityConditionalOn, b, flags.IsSupportsNullFlex )
24532471
24542472 [<DebuggerBrowsable( DebuggerBrowsableState.Never) >]
24552473 member x.DebugText = x.ToString()
@@ -6118,7 +6136,7 @@ type Construct() =
61186136 Typar.New
61196137 { typar_ id = id
61206138 typar_ stamp = newStamp()
6121- typar_ flags= TyparFlags( kind, rigid, isFromError, isCompGen, staticReq, dynamicReq, eqDep, compDep)
6139+ typar_ flags= TyparFlags( kind, rigid, isFromError, isCompGen, staticReq, dynamicReq, eqDep, compDep, false )
61226140 typar_ solution = None
61236141 typar_ astype = Unchecked.defaultof<_>
61246142 typar_ opt_ data =
0 commit comments