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-15591] Compiler crash (illegal instruction 4) related to implicit CGFloat/Double conversion #57894

Closed
jhammer opened this issue Dec 13, 2021 · 3 comments
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself crash Bug: A crash, i.e., an abnormal termination of software expressions Feature: expressions implicit conversions Feature: implicit conversions swift 5.5 type checker Area → compiler: Semantic analysis

Comments

@jhammer
Copy link

jhammer commented Dec 13, 2021

Previous ID SR-15591
Radar None
Original Reporter @jhammer
Type Bug
Status Resolved
Resolution Duplicate

Attachment: Download

Environment

$ swift --version

swift-driver version: 1.26.21 Apple Swift version 5.5.2 (swiftlang-1300.0.47.5 clang-1300.0.29.30)``Target: arm64-apple-macosx12.0

Additional Detail from JIRA
Votes 0
Component/s
Labels Bug, CompilerCrash, TypeChecker
Assignee @jhammer
Priority Medium

md5: 0d2d301054dc6e345997c1a022ef52f1

Issue Description:

The attached Xcode project crashes the compiler with error:

error: Illegal instruction: 4 (in target 'formcolor' from project 'formcolor')

Minimized example:

import Cocoa
struct SR15591 {
    let r: Double
    
    init(platformColor: NSColor) {
        let srgb = platformColor.usingColorSpace(.sRGB)
        r = srgb?.redComponent ?? 0
    }
}

Changing the struct properties from "Double" to "CGFloat" fixes the issue.

@LucianoPAlmeida
Copy link
Collaborator

LucianoPAlmeida commented Jan 15, 2022

This no longer crashes in main branch, I think crash was fixed by #40047

struct FormColor {
    let red: Double
    let green: Double
    let blue: Double
    let alpha: Double
    
    init(platformColor: NSColor) {
        let srgb = platformColor.usingColorSpace(.sRGB)
        red = srgb?.redComponent ?? 0 // error: Cannot implicitly convert value of type 'CGFloat?' to expected type 'Double?'
        green = srgb?.greenComponent ?? 0 // error: Cannot implicitly convert value of type 'CGFloat?' to expected type 'Double?'
        blue = srgb?.blueComponent ?? 0 // error: Cannot implicitly convert value of type 'CGFloat?' to expected type 'Double?'
        alpha = Double(srgb?.alphaComponent ?? 1.0)
    }
}

But I think this is still a bug because this should type check correctly because result of expression srgb?.blueComponent ?? 0 is non-optional CGFloat.
This workaround make it work

let lred = srgb?.redComponent ?? 0
red = lred // works

cc @xedin

@LucianoPAlmeida
Copy link
Collaborator

Ah I found that this implicit conversion through optional chaining is indeed not supported at the moment

// An attempt at Double/CGFloat conversion through

@xedin
Copy link
Member

xedin commented Jan 18, 2022

I'm going to dupe this one to #57540 since that's exactly the limitation here...

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis AnthonyLatsis added crash Bug: A crash, i.e., an abnormal termination of software compiler The Swift compiler in itself labels Dec 12, 2022
@AnthonyLatsis AnthonyLatsis added duplicate Resolution: Duplicates another issue implicit conversions Feature: implicit conversions swift 5.5 expressions Feature: expressions and removed duplicate Resolution: Duplicates another issue labels May 2, 2023
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 crash Bug: A crash, i.e., an abnormal termination of software expressions Feature: expressions implicit conversions Feature: implicit conversions swift 5.5 type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

4 participants