Diagnose free type variables that correspond to generic parameters.

t2.swift:3:1: error: argument for generic parameter 'U' could not be
inferred
f(i)
^
t2.swift:2:6: note: in call to function 'f'
func f<T, U>(t: T) -> U? { return nil }
     ^

Our lack of decent locator information means that we don't get notes
in all of the cases we want them. I'll look at that separately.

Swift SVN r21921
This commit is contained in:
Doug Gregor
2014-09-12 20:27:21 +00:00
parent dd6c32cf3e
commit e002261865
8 changed files with 58 additions and 7 deletions

View File

@@ -1071,8 +1071,41 @@ bool ConstraintSystem::solve(SmallVectorImpl<Solution> &solutions,
// If any free type variables remain and we're not allowed to have them,
// fail.
if (allowFreeTypeVariables == FreeTypeVariableBinding::Disallow &&
hasFreeTypeVariables())
hasFreeTypeVariables()) {
if (shouldRecordFailures()) {
// Find a free type variable that refers to an archetype.
for (auto tv : TypeVariables) {
if (tv->getImpl().hasRepresentativeOrFixed())
continue;
auto locator = tv->getImpl().getLocator();
if (!locator || locator->getPath().empty() ||
locator->getPath().back().getKind()
!= ConstraintLocator::Archetype)
continue;
// We found one; diagnose it.
SmallVector<LocatorPathElt, 2> path;
auto anchor = ConstraintLocatorBuilder(locator).getLocatorParts(path);
// Only diagnose archetypes that don't have a parent, i.e., ones
// that correspond to generic parameters.
auto archetype = path.back().getArchetype();
if (archetype->getParent())
continue;
auto shortPath = llvm::makeArrayRef(path.data(), path.size()-1);
recordFailure(getConstraintLocator(
anchor,
shortPath,
ConstraintLocator::getSummaryFlagsForPath(shortPath)),
Failure::UnboundGenericParameter,
archetype);
break;
}
}
return true;
}
auto solution = finalize(allowFreeTypeVariables);
if (TC.getLangOpts().DebugConstraintSolver) {