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-8221] Crash using inout operator with Optional argument on non-optional value #50753

Closed
swift-ci opened this issue Jul 10, 2018 · 4 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

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-8221
Radar rdar://problem/42075018
Original Reporter mrh.is (JIRA User)
Type Bug
Status Closed
Resolution Done
Environment

macOS 10.13.4

Xcode 9.4.1 (9F2000) with built-in Swift

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

md5: 533e53fc2a529490ce7fb5754e8bc9c1

Issue Description:

infix operator ??=
func ??= <T>(lhs: inout T?, rhs: T?) {
    print(lhs as Any)
}

prefix operator ~~
prefix func ~~ <T>(foo: inout T?) {
    print(foo as Any)
}

var a: Int?
a ??= 5 // OK
~~a // OK

var b: Int!
b ??= 5 // Binary operator '??=' cannot be applied to operands of type 'Int!' and 'Int'
~~b // Cannot convert value of type 'Int!' to expected argument type 'inout _?'

var c: Int = 0
c ??= 5 // Binary operator '??=' cannot be applied to two 'Int' operands
~~c // Cannot convert value of type 'Int' to expected argument type 'inout _?'

In general, IUOs & non-Optionals are magically transformed into Optionals, so it feels odd that it doesn't happen here. Inout Optional parameters on regular (i.e., non-operator) functions seem to work.

Apologies if this has already been filed elsewhere; I couldn't really figure out how to search for this problem.

@belkadan
Copy link
Contributor

The first part seems to be fixed in Swift 4.2 (not surprising, given the changes in the IUO implementation). The second part is correct behavior, since the implementation of, say, ??= could be to just assign nil to the inout parameter.

…except that with an asserts build I'm seeing a crash on the second example, and we should definitely fix that!

Assertion failed: (toIO->getObjectType()->isEqual(fromLValue->getObjectType())), function coerceToType, file /Volumes/Data/swift-public/swift/lib/Sema/CSApply.cpp, line 6776.

@swift-ci create

@gregomni
Copy link
Collaborator

Second part fixed in #18135

@AnnaZaks
Copy link
Mannequin

AnnaZaks mannequin commented Jul 23, 2019

mrh.is (JIRA User), Could you verify if the problem is fixed and if so move the JIRA to "Closed"?

Thanks!
Anna

@swift-ci
Copy link
Collaborator Author

Comment by Michael Helmbrecht (JIRA)

I can confirm that it works in line with @belkadan's comment above! The `a` & `b` sections both work now, and the `c` section is not supposed to work.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis AnthonyLatsis added the crash Bug: A crash, i.e., an abnormal termination of software label Dec 12, 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 crash Bug: A crash, i.e., an abnormal termination of software
Projects
None yet
Development

No branches or pull requests

4 participants