-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[Diagnostics] Add a detailed diagnostic for generic argument mismatches #25060
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
sl
merged 12 commits into
swiftlang:master
from
sl:generic-arguments-mismatch-diagnostic
Jun 14, 2019
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
7719b0f
Sema: Add a more descriptive diagnostic for generic argument mismatches
sl dc5ccd1
Test: Add tests for the new generic arguments mismatch diagnostic
sl 81dc546
Sema / Test: Fix tests broken by introduction of GenericArgumentsMism…
sl 1701ea1
Sema: Changed GenericArgumentsMismatch to use trailing objects
sl de7851b
Test: Update tests to reflect change to generic mismatch note locations
sl 0a7cdb8
Sema: Handle CTP_SubscripAssignSource in GenericArgumentsMismatch::ge…
sl cc8c2b1
Sema: Fix how matchDeepEqualityType failures are handled
sl 122a68c
Sema: Change generic argument mismatch diags to reuse existing ones
sl cd0cc3c
Test: Add a todo about a regression introduced by generic mismatch di…
sl 64b1186
Sema: Change closure passed to matchDeepTypeArguments to return if it…
sl 2cefbe0
Test: Update additional tests with improved generic mismatch diagnostic
sl ff950a4
Sema: Refactor logic for excluding arrays / optionals out of closure
sl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -69,6 +69,8 @@ class FailureDiagnostic { | |
bool diagnose(bool asNote = false); | ||
|
||
/// Try to produce an error diagnostic for the problem at hand. | ||
/// | ||
/// \returns true If anything was diagnosed, false otherwise. | ||
virtual bool diagnoseAsError() = 0; | ||
|
||
/// Instead of producing an error diagnostic, attempt to | ||
|
@@ -359,6 +361,45 @@ class MissingConformanceFailure final : public RequirementFailure { | |
} | ||
}; | ||
|
||
/// Diagnostics for mismatched generic arguments e.g | ||
/// ```swift | ||
/// struct F<G> {} | ||
/// let _:F<Int> = F<Bool>() | ||
/// ``` | ||
class GenericArgumentsMismatchFailure final : public FailureDiagnostic { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this should be based off of |
||
BoundGenericType *Actual; | ||
BoundGenericType *Required; | ||
ArrayRef<unsigned> Mismatches; | ||
|
||
public: | ||
GenericArgumentsMismatchFailure(Expr *expr, ConstraintSystem &cs, | ||
BoundGenericType *actual, | ||
BoundGenericType *required, | ||
ArrayRef<unsigned> mismatches, | ||
ConstraintLocator *locator) | ||
: FailureDiagnostic(expr, cs, locator), Actual(actual), | ||
Required(required), Mismatches(mismatches) {} | ||
|
||
bool diagnoseAsError() override; | ||
|
||
private: | ||
void emitNotesForMismatches() { | ||
for (unsigned position : Mismatches) { | ||
emitNoteForMismatch(position); | ||
} | ||
} | ||
|
||
void emitNoteForMismatch(int mismatchPosition); | ||
|
||
Optional<Diag<Type, Type>> getDiagnosticFor(ContextualTypePurpose context); | ||
|
||
/// The actual type being used. | ||
BoundGenericType *getActual() const { return Actual; } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the base type is |
||
|
||
/// The type needed by the generic requirement. | ||
BoundGenericType *getRequired() const { return Required; } | ||
}; | ||
|
||
/// Diagnose failures related to same-type generic requirements, e.g. | ||
/// ```swift | ||
/// protocol P { | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can replace all of
resolveType
calls here with a single one for actual/expected and retrieve arguments from there sinceresolveType
is going to recursively resolve all type variables.