-
Notifications
You must be signed in to change notification settings - Fork 76
jextract: extract Foundation.Date as Instant
#506
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
base: main
Are you sure you want to change the base?
Conversation
ktoso
left a comment
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.
Neat :-) Please add info about it to the feature list docs
| | Existential parameters `f(x: any (A & B)) ` | ❌ | ✅ | | ||
| | Existential return types `f() -> any Collection ` | ❌ | ❌ | | ||
| | Foundation Data and DataProtocol: `f(x: any DataProtocol) -> Data` | ✅ | ❌ | | ||
| | Foundation Date: `f(date: Date) -> Date` | ❌ | ✅ | |
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.
because it's an unusual conversion I think we have to add actual docs about it
|
I keep thinking about this from an overall project perspective, it is a bit random to bless a few types, but yes this one would work kinda well... |
|
@ktoso Hm, imo this project exists to provide a seamless Swift/Java interop story. Since we are generating Java code meant to be used on Java platforms, perhaps also by Java developers, I think it makes sense to bridge any matching types, such as The alternative is that the developer has to use a generated type |
Primarily it must be: correct, safe, and then seamless. We must not sacrifice correctness just because it's convenient. The conversion is lossy, and could result in bugs in practice, e.g. if you're trying to key anything off the date. Such echo function showcases how this is a lossy conversion: import Foundation
public func echoDate(_ date: Date) -> Date {
return date
}and in Java + jextracted Date-as-Instant: Instant now = Instant.now();
Instant back = MySwiftLibrary.echoDate(now);
if (!now.equals(back)) {
System.out.println("NOT EQUAL! " + now + " != " + back);
} else {
System.out.println("EQUAL");
}gives: NOT EQUAL! 2026-01-14T05:45:55.764682Z != 2026-01-14T05:45:55.764682054Z
DONE.That's not something we should be just doing by default. Instead I propose:
Sounds good? |
ktoso
left a comment
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.
Yeah after all let's not do the automatic conversion because it could be a source of equality bugs
Adds support to JNI mode for extracting
Foundation.Dateasjava.time.Instant.