Bugfix :: Fix 'Type inference problem too complicated' for SRTP with "T:null and T:struct" dummy constraint #18345
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Fixes #18288.
The problem occured when inferring types and the solution contained a method defined like
_: 'T when 'T: null and 'T: struct.This problem is fixed.
I have also added consistency checks for pairs of typar constraints that are invalid - will wait in the issue comments for @gusty to see if reporting an error for this combination will break an essential trick without providing alternative.
I also realized that combination of
delegateandcomparisonconstraints is invalid as well, but was misusing a wrong error message -> it gets a new error message now.With all the logic around typarTy and checks for their constraints having the following form:
isTyparTy g ty && (destTyparTy g ty).Constraints |> List.exists (function | TyparConstraint...._ -> true | _ -> false),the code got convoluted with this boilerplate.
I extracted this logic into helper functions and applied them where they made sense: