fix rdar://15735537: __conversion function not found in protocol if marked @mutating

- shouldTryUserConversion was not looking through @lvalue to determine if 
  the underlying type had a __conversion member, so we were only trying user
  conversions on lvalues through an lvalue-to-rvalue conversion.
- Similarly, fix the similar-but-different filter in tryUserConversion to look through
  lvalues as well.

This causes the QoI of some conversion diagnostics to get worse (the dreaded "does 
not type check error") because there are now two possible conversions instead of one 
in some cases and the diagnostics of the type checker doesn't handle this case well.


Swift SVN r11789
This commit is contained in:
Chris Lattner
2014-01-01 06:40:48 +00:00
parent 34e6e24eac
commit f30dd51763

View File

@@ -449,7 +449,10 @@ static ConstraintKind getConstraintKind(TypeMatchKind kind) {
/// Determine whether we should attempt a user-defined conversion.
static bool shouldTryUserConversion(ConstraintSystem &cs, Type type) {
// Strip the l-value qualifier if present.
if (!type->is<InOutType>())
type = type->getRValueType();
// If this isn't a type that can have user-defined conversions, there's
// nothing to do.
if (!type->getNominalOrBoundGenericNominal() && !type->is<ArchetypeType>())
@@ -472,10 +475,12 @@ tryUserConversion(ConstraintSystem &cs, Type type, ConstraintKind kind,
kind != ConstraintKind::Conversion &&
kind != ConstraintKind::OperatorConversion &&
"Construction/conversion constraints create potential cycles");
// If this isn't a type that can have user-defined conversions, there's
// nothing to do.
if (!type->getNominalOrBoundGenericNominal() && !type->is<ArchetypeType>())
Type rvType = type->getRValueType();
if (!rvType->getNominalOrBoundGenericNominal() &&
!rvType->is<ArchetypeType>())
return ConstraintSystem::SolutionKind::Unsolved;
// If there are no user-defined conversions, there's nothing to do.