Skip to content
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

[SR-14091] Improve "ambiguous without more context" error on misusing SwiftUI's Axis #56477

Closed
typesanitizer opened this issue Jan 23, 2021 · 7 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself diagnostics QoI Bug: Diagnostics Quality of Implementation failed to produce diagnostic Bug → internal error: Failed to produce diagnostic for expression SwiftUI Flag: Related to (but not an issue with) SwiftUI type checker Area → compiler: Semantic analysis

Comments

@typesanitizer
Copy link

Previous ID SR-14091
Radar rdar://problem/73526027
Original Reporter @typesanitizer
Type Bug
Status Resolved
Resolution Duplicate
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, DiagnosticsQoI, TypeChecker
Assignee None
Priority Medium

md5: 13235f51f4aa56e9507c4193beacbb86

duplicates:

  • SR-14083 Failed to produce diagnostic on misusing PinnedScrollableViews

Issue Description:

import SwiftUI

let x: Axis.Set = Axis.Set(Axis.allCases)
               // ^error: type of expression is ambiguous without more context 

Tested with main @ 21e99917142c11f.

We should try to improve the diagnostic, it's not at all clear what context is missing here.

@typesanitizer
Copy link
Author

@swift-ci create

@LucianoPAlmeida
Copy link
Collaborator

Just by a quick -debug-constraints I can see that this is a problem related to generic argument mismatch when solver is producing two solutions, one recording a generic requirement fix and the other a generic mismatch. We saw something similar to this in SR-13776 and we did a bit of investigation there #34451 just couldn't find the right solution for the problem =]
This case is slightly different, because it could be fix just increase the impact for requirement fix ... note that it may not be the ideal solution. But I suspect the core of the problem is the same (generic mismatch ambiguities involving requirement failures).

cc @xedin

@LucianoPAlmeida
Copy link
Collaborator

Oe way we could fix that is maybe teach `diagnoseConflictingGenericArguments` to accept attempt diagnose if all solutions fixes are a FixKind::GenericArgumentsMismatch or FixKind::SkipSameTypeRequirement as well?

@xedin
Copy link
Member

xedin commented Jan 23, 2021

Looks like this is yet another consequence of an attempt to maintain subtyping relationship between collections when passed as an argument (https://github.com/apple/swift/blob/main/lib/Sema/CSBindings.cpp#L1461-L1476). Solver fails to diagnose ambiguity because collection is first attempted as `[Axis]` and then opened and re-attempted as `[$T]` where `$T` would get bound to `Axis` again. First step might be to try and restrict this behavior to only happen if there is a possible conversion/subtype relationship between the types and teach diagnostics to ignore second (duplicate) attempt.

theindigamer (JIRA User) This is a dupe of SR-14083.

@LucianoPAlmeida
Copy link
Collaborator

Humm, so it would be try narrow the behavior to not always do this, but when it does tell diagnostics do not record any fix?

@xedin
Copy link
Member

xedin commented Jan 24, 2021

Yes, exactly. Diagnostics should recognize that this is just a duplicate type attempt (since we still have to do that for anything which might have a supertype or conversion).

@LucianoPAlmeida
Copy link
Collaborator

Ah got it thanks Pavel!
I think I can put this on queue to work on if is not urgent, but not assigning in case someone else wants to tackle meanwhile feel free =]

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis AnthonyLatsis added SwiftUI Flag: Related to (but not an issue with) SwiftUI failed to produce diagnostic Bug → internal error: Failed to produce diagnostic for expression labels Dec 22, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself diagnostics QoI Bug: Diagnostics Quality of Implementation failed to produce diagnostic Bug → internal error: Failed to produce diagnostic for expression SwiftUI Flag: Related to (but not an issue with) SwiftUI type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

4 participants