mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
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:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user