Skip to content

Commit

Permalink
Avoid .OriginalDefinition for comparing class types.
Browse files Browse the repository at this point in the history
  • Loading branch information
danpere committed Nov 28, 2024
1 parent 41ef580 commit f2eea04
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,10 @@ static bool CastWillAlwaysFail(ITypeSymbol castFrom, ITypeSymbol castTo)
return false;
}

// Most checks are better with OriginalDefinition, but keep the ones passed in around.
ITypeSymbol castFromParam = castFrom;
ITypeSymbol castToParam = castTo;

castFrom = castFrom.OriginalDefinition;
castTo = castTo.OriginalDefinition;

Expand Down Expand Up @@ -269,8 +273,8 @@ static bool IsUnconstrainedTypeParameter(ITypeParameterSymbol typeParameterSymbo
return false;

case (TypeKind.Class, TypeKind.Class):
return !castFrom.DerivesFrom(castTo)
&& !castTo.DerivesFrom(castFrom);
return !castFromParam.DerivesFrom(castToParam)
&& !castToParam.DerivesFrom(castFromParam);

case (TypeKind.Interface, TypeKind.Class):
return castTo.IsSealed && !castTo.DerivesFrom(castFrom);
Expand Down

0 comments on commit f2eea04

Please sign in to comment.