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-14160] Runtime crash on passing functions with incompatible representations #56539

Open
LucianoPAlmeida opened this issue Feb 6, 2021 · 7 comments
Labels
compiler The Swift compiler in itself

Comments

@LucianoPAlmeida
Copy link
Collaborator

Previous ID SR-14160
Radar rdar://problem/74110413
Original Reporter @LucianoPAlmeida
Type Sub-task

Attachment: Download

Environment

Xcode 12.3 (12C33)

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Sub-task
Assignee None
Priority Medium

md5: d343b7970380688af4185c9df548b637

Parent-Task:

  • SR-14169 ☂️ Compiler/runtime issues while converting functions with incompatible representations

relates to:

Issue Description:

Both compiles fine, but crashes at runtime because of thick-to-thin conversion
Note: Removing @convention(thin) this executes fine

I think the compiler should emit a conversion mismatch diagnostic.

func a<K: Hashable, V>(d: [K: V], p: @convention(thin) (K, V) -> Void) {
  //_ = d.lazy.map(p) // Runtime crash
  p(d.first!.key, d.first!.value) // Also runtime crash.
}

let v = [1: "1"]

a(d: v, p: { _,_  in })

![](Screen Shot 2021-02-05 at 22.13.59.png)
![](Screen Shot 2021-02-05 at 22.09.57.png)

@LucianoPAlmeida
Copy link
Collaborator Author

cc theindigamer (JIRA User)

@LucianoPAlmeida
Copy link
Collaborator Author

I don't understand why, but if we constraint the generic arguments to objc convertible it runs fine, so maybe is just a runtime issue?

import Foundation

func a<K: NSObject, V: NSObject>(d: [K: V], p: @convention(thin) (K, V) -> Void) {
  _ = d.lazy.map(p) // NO crash
  p(d.first!.key, d.first!.value) // No crash.
}

let v = [1 as NSNumber: "1" as NSString]

a(d: v, p: { _,_  in })

print("finished")

@typesanitizer
Copy link

I think this might be the same problem as https://bugs.swift.org/browse/SR-14058 , we should be emitting a compile-time error.

@typesanitizer
Copy link

Maybe we should create an umbrella task for conversions between function conventions. Then this JIRA, SR-14058 and SR-14060 would all be sub-tasks of that.

@LucianoPAlmeida
Copy link
Collaborator Author

I like the idea of creating an umbrella task =]

@LucianoPAlmeida
Copy link
Collaborator Author

theindigamer (JIRA User) Here it is https://bugs.swift.org/browse/SR-14169

@typesanitizer
Copy link

@swift-ci create

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler The Swift compiler in itself
Projects
None yet
Development

No branches or pull requests

2 participants