|
| 1 | +//===--- ConstraintSimplificationTests.cpp --------------------------------===// |
| 2 | +// |
| 3 | +// This source file is part of the Swift.org open source project |
| 4 | +// |
| 5 | +// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors |
| 6 | +// Licensed under Apache License v2.0 with Runtime Library Exception |
| 7 | +// |
| 8 | +// See https://swift.org/LICENSE.txt for license information |
| 9 | +// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors |
| 10 | +// |
| 11 | +//===----------------------------------------------------------------------===// |
| 12 | + |
| 13 | +#include "SemaFixture.h" |
| 14 | +#include "swift/Sema/ConstraintSystem.h" |
| 15 | + |
| 16 | +using namespace swift; |
| 17 | +using namespace swift::unittest; |
| 18 | +using namespace swift::constraints; |
| 19 | + |
| 20 | +TEST_F(SemaTest, TestTrailingClosureMatchRecordingForIdenticalFunctions) { |
| 21 | + ConstraintSystem cs(DC, ConstraintSystemOptions()); |
| 22 | + |
| 23 | + auto intType = getStdlibType("Int"); |
| 24 | + auto floatType = getStdlibType("Float"); |
| 25 | + |
| 26 | + auto func = FunctionType::get({FunctionType::Param(intType)}, floatType); |
| 27 | + |
| 28 | + cs.addConstraint( |
| 29 | + ConstraintKind::ApplicableFunction, func, func, |
| 30 | + cs.getConstraintLocator({}, ConstraintLocator::ApplyFunction)); |
| 31 | + |
| 32 | + SmallVector<Solution, 2> solutions; |
| 33 | + cs.solve(solutions); |
| 34 | + |
| 35 | + ASSERT_EQ(solutions.size(), (unsigned)1); |
| 36 | + |
| 37 | + const auto &solution = solutions.front(); |
| 38 | + |
| 39 | + auto *locator = cs.getConstraintLocator({}, ConstraintLocator::ApplyArgument); |
| 40 | + auto choice = solution.trailingClosureMatchingChoices.find(locator); |
| 41 | + ASSERT_TRUE(choice != solution.trailingClosureMatchingChoices.end()); |
| 42 | + ASSERT_EQ(choice->second, TrailingClosureMatching::Forward); |
| 43 | +} |
0 commit comments