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

A unicode scalar initialization now errors about overflow since the Dec. 19 trunk snapshot #78371

Open
finagolfin opened this issue Dec 27, 2024 · 3 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler itself init Feature → declarations: Initializers overload resolution Area → compiler → type checker: Overload resolution (ranking) potentially source breaking type checker Area → compiler: Semantic analysis unexpected error Bug: Unexpected error

Comments

@finagolfin
Copy link
Member

finagolfin commented Dec 27, 2024

Description

I can no longer build the swift-experimental-string-processing package on linux x86_64 or Android AArch64:

> ../swift-DEVELOPMENT-SNAPSHOT-2024-12-19-a-fedora39/usr/bin/swift build
--- snip other output ---
swift-experimental-string-processing/Sources/Exercises/Participants/HandWrittenParticipant.swift:63:44: error: integer literal '2045' overflows when stored into 'UInt8'
 61 | 
 62 |   // For testing our framework
 63 |   if forceFailure, lower == Unicode.Scalar(0x07FD) {
    |                                            `- error: integer literal '2045' overflows when stored into 'UInt8'
 64 |     return nil
 65 |   }

Patching that call to force unwrap like so, Unicode.Scalar(0x07FD)!, now gets the compiler to choose the right overload that returns an optional and takes larger values to avoid this issue.

Whether this build issue should be fixed in the compiler or the regex package depends on whether this was a conscious decision to break such code, which I'm guessing is a consequence of @xedin's #63585 that was finally merged last week.

Expected behavior

Builds fine with the prior trunk Dec. 16 snapshot and the latest 6.0 and 6.1 releases

Environment

Swift 6.2 on Linux x86_64 and Android AArch64

@finagolfin finagolfin added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. potentially source breaking compiler The Swift compiler itself overload resolution Area → compiler → type checker: Overload resolution (ranking) init Feature → declarations: Initializers labels Dec 27, 2024
@AnthonyLatsis AnthonyLatsis added type checker Area → compiler: Semantic analysis unexpected error Bug: Unexpected error labels Dec 27, 2024
@natecook1000
Copy link
Member

Standalone reproducer — builds with the 12/16 snapshot, but gives the error above for the 12/19 and later toolchains:

let lower: Unicode.Scalar = "a"
if lower == Unicode.Scalar(0x07FD) {
    print("Y")
} else {
    print("N")
}

@finagolfin
Copy link
Member Author

finagolfin commented Jan 6, 2025

@xedin, I had built the last Dec. 22 snapshot tag before winter break natively on Android and it was exhibiting this issue, so I reverted your #63585 and rebuilt that compiler and this issue went away. It appears this issue is clearly a consequence of your pull, please advise on how we should approach this problem.

natecook1000 added a commit to swiftlang/swift-experimental-string-processing that referenced this issue Jan 7, 2025
Related to swiftlang/swift#78371,
but doesn't need to be reverted after that issue is fixed.
natecook1000 added a commit to swiftlang/swift-experimental-string-processing that referenced this issue Jan 7, 2025
Related to swiftlang/swift#78371,
but doesn't need to be reverted after that issue is fixed.
@xedin
Copy link
Contributor

xedin commented Jan 7, 2025

Hello! Sorry I just got back from vacation. I think we should treat this as a regression and fix it in the solver. I took a quick look and it looks like we started preferring a concrete overload of == that takes non-optional Unicode.Scalar as arguments and that force the solver to select a non-failing overload of Unicode.Scalar initializer that takes UInt8. I have a few ideas how to address this and will try to open a PR in the next few days.

natecook1000 added a commit to swiftlang/swift-experimental-string-processing that referenced this issue Jan 7, 2025
* Work around change in integer literal inference

Related to swiftlang/swift#78371,
but doesn't need to be reverted after that issue is fixed.

* Fix availability for capture tests
natecook1000 added a commit to milseman/swift-experimental-string-processing that referenced this issue Jan 8, 2025
* Work around change in integer literal inference

Related to swiftlang/swift#78371,
but doesn't need to be reverted after that issue is fixed.

* Fix availability for capture tests
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 itself init Feature → declarations: Initializers overload resolution Area → compiler → type checker: Overload resolution (ranking) potentially source breaking type checker Area → compiler: Semantic analysis unexpected error Bug: Unexpected error
Projects
None yet
Development

No branches or pull requests

4 participants