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-11395] bad diagnostic something goes wrong in an argument to an overloaded function #53796

Closed
weissi opened this issue Aug 29, 2019 · 6 comments
Assignees
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

Comments

@weissi
Copy link
Member

weissi commented Aug 29, 2019

Previous ID SR-11395
Radar rdar://problem/54851719
Original Reporter @weissi
Type Bug
Status Resolved
Resolution Done

Attachment: Download

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, DiagnosticsQoI
Assignee @weissi
Priority Medium

md5: e744518c73cc485f0758f112562c7cc5

Issue Description:

The below program has exactly one error: The argument how: String in Foo's constructor is missing. However the compiler tells us:

$ swift /tmp/test.swift
/tmp/test.swift:20:14: error: value of type 'Pair<L, R>' does not conform to 'P2' in assignment
Thing().doIt(f(Foo(), Foo(how: "random")))
             ^

whilst it's correct that Pair<L, R> does not conform to P2 it's extremely misleading.

protocol P {}
protocol P2 {}

struct Pair<L: P, R: P>: P {}

struct Thing {
    func doIt(_ handler: P2) {}
    func doIt<L, R>(_ handler: Pair<L, R>) {}
}


func f<L: P, R: P> (_ lhs: L, _ rhs: R) -> Pair<L, R> {
    return .init()
}

struct Foo: P {
    init(how: String) {}
}

Thing().doIt(f(Foo(/* MISSING how: "good" HERE */), Foo(how: "random")))

The most frustrating this is that if I rewrite the last line to

let t = f(Foo(), Foo(how: "random"))
Thing().doIt(t)

the compiler actually gets it:

/tmp/test.swift:20:15: error: missing argument for parameter 'how' in call
let t = f(Foo(), Foo(how: "random"))
              ^
              how: <#String#>
/tmp/test.swift:17:5: note: 'init(how:)' declared here
    init(how: String) {}
    ^
@weissi
Copy link
Member Author

weissi commented Aug 29, 2019

@swift-ci create

@belkadan
Copy link
Contributor

Straight-up crashes on my near-master:

Assertion failed: (isa<AssignExpr>(anchor)), function diagnoseAsError, file /Volumes/Data/swift-public/swift/lib/Sema/CSDiagnostics.cpp, line 3861.
Stack dump:
0.  Program arguments: /Volumes/Data/swift-public/build/ninja/swift-macosx-x86_64/bin/swift -frontend -c -primary-file - -target x86_64-apple-darwin18.7.0 -enable-objc-interop -sdk /Volumes/Data/Applications/Xcode11.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.Internal.sdk -color-diagnostics -module-name main -o /var/folders/_d/dmrgv26d3bs6lkrks9z825_w0000gn/T/--132163.o 
1.  Swift version 5.1-dev (LLVM af1f73e9e9, Swift aebf537aee)
2.  While type-checking statement at [<stdin>:20:1 - line:20:72] RangeText="Thing().doIt(f(Foo(/* MISSING how: "good" HERE */), Foo(how: "random"))"
3.  While type-checking expression at [<stdin>:20:1 - line:20:72] RangeText="Thing().doIt(f(Foo(/* MISSING how: "good" HERE */), Foo(how: "random"))"
4.  While type-checking expression at [<stdin>:20:13 - line:20:72] RangeText="(f(Foo(/* MISSING how: "good" HERE */), Foo(how: "random"))"
5.  While type-checking expression at [<stdin>:20:14 - line:20:71] RangeText="f(Foo(/* MISSING how: "good" HERE */), Foo(how: "random")"
6.  While type-checking expression at [<stdin>:20:14 - line:20:14] RangeText=""
0  swift                    0x0000000108b07725 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 37
1  swift                    0x0000000108b069c5 llvm::sys::RunSignalHandlers() + 85
2  swift                    0x0000000108b07d08 SignalHandler(int) + 264
3  libsystem_platform.dylib 0x00007fff750beb5d _sigtramp + 29
4  libsystem_platform.dylib 0x00007ffeea9fe6d0 _sigtramp + 1972632464
5  libsystem_c.dylib        0x00007fff74f786a6 abort + 127
6  libsystem_c.dylib        0x00007fff74f4120d basename_r + 0
7  swift                    0x0000000108e125e3 swift::constraints::MissingContextualConformanceFailure::diagnoseAsError() (.cold.4) + 35
8  swift                    0x0000000105b710f5 swift::constraints::MissingContextualConformanceFailure::diagnoseAsError() + 565
9  swift                    0x0000000105b5b9eb swift::constraints::MissingConformance::diagnose(swift::Expr*, bool) const + 123
10 swift                    0x0000000105ace174 swift::constraints::ConstraintSystem::applySolutionFixes(swift::Expr*, swift::constraints::Solution const&)::DiagnosticWalker::diagnose(swift::Expr*) + 276
11 swift                    0x0000000105acd917 swift::constraints::ConstraintSystem::applySolutionFixes(swift::Expr*, swift::constraints::Solution const&)::DiagnosticWalker::walkToExprPost(swift::Expr*) + 23
12 swift                    0x0000000105f19af3 swift::Expr::walk(swift::ASTWalker&) + 115
13 swift                    0x0000000105aca272 swift::constraints::ConstraintSystem::applySolutionFixes(swift::Expr*, swift::constraints::Solution const&) + 530
14 swift                    0x0000000105aca3cd swift::constraints::ConstraintSystem::applySolution(swift::constraints::Solution&, swift::Expr*, swift::Type, bool, bool) + 141

cc @hborla, @xedin

@belkadan
Copy link
Contributor

Oh, maybe the crash was SR-11394.

@xedin
Copy link
Member

xedin commented Sep 8, 2019

@hborla I think a fix for this problem could be pretty straightforward - use `fixMissingArguments` in `matchCallArguments`, currently it's only covers function conversions (in `matchFunctionTypes`).

@LucianoPAlmeida
Copy link
Collaborator

Seems like this is fixed on master the diagnostic produced are

note: 'init(how:)' declared here
    init(how: String) {}
    ^
 error:  missing argument for parameter 'how' in call
Thing().doIt(f(Foo(/* MISSING how: "good" HERE */), Foo(how: "random")))
                                                 ^

cc @xedin

@xedin
Copy link
Member

xedin commented Feb 6, 2020

@LucianoPAlmeida reports this this has been fixed on master, but it looks like 11.4 has a fix as well. Could you please verify and resolve?

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 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
Projects
None yet
Development

No branches or pull requests

4 participants