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-12329] Swift compiler seg faults when a Self property is used as a default value #54760

Closed
swift-ci opened this issue Mar 6, 2020 · 4 comments
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 type checker Area → compiler: Semantic analysis

Comments

@swift-ci
Copy link
Collaborator

swift-ci commented Mar 6, 2020

Previous ID SR-12329
Radar rdar://problem/60230430
Original Reporter erikstrottmann (JIRA User)
Type Bug
Status Resolved
Resolution Done
Environment

Swift 5.1, Xcode 11.3.1

Additional Detail from JIRA
Votes 1
Component/s Compiler
Labels Bug, CompilerCrash, TypeChecker
Assignee erikstrottmann (JIRA)
Priority Medium

md5: 187daa7f378004eb444485a4bcc20711

Issue Description:

Swift compiler seg faults when a method in a class uses a Self property or method as a default value.

class SomeType {
    static var someProperty: Int { 123 }
    func someMethod(int: Int = Self.anotherFunc) { print(int) }
}

This crash occurs for a class, whether or not it is final. It does not occur for a struct.

It occurs whether someProperty is a static var, class var, static func, or class func.

It does not occur when someProperty is referenced as SomeType.someProperty or simply as someProperty.

Also submitted to Feedback Assistant as FB7616689.

@theblixguy
Copy link
Collaborator

On master, the above code leads to:

/Users/suyashsrijan/Desktop/test.swift:3:37: error: type 'Self' has no member 'anotherFunc'
    func someMethod(int: Int = Self.anotherFunc) { print(int) }

But I suppose you meant Self.someProperty and not Self.anotherFunc. In that case, I get:

/Users/suyashsrijan/Desktop/test.swift:3:32: error: covariant 'Self' type cannot be referenced from a default argument expression
    func someMethod(int: Int = Self.someProperty) { print(int) }

So I think it's fixed, but I don't know if it made into 5.2. You can verify using the latest 5.2 snapshot from swift.org, or try the latest Xcode 11.4 beta.

@swift-ci
Copy link
Collaborator Author

swift-ci commented Mar 6, 2020

Comment by Erik Strottmann (JIRA)

Oops, you’re right that I meant Self.someProperty.

Good to see that it’s fixed, even though it would have been nice to use Self as a default argument!

@beccadax
Copy link
Contributor

beccadax commented Mar 9, 2020

@swift-ci create

@hborla
Copy link
Member

hborla commented Mar 11, 2020

It seems that this did make it into Swift 5.2. erikstrottmann (JIRA User) could you please verify in Xcode 11.4 beta or by downloading a 5.2 toolchain? Thank you!

@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 type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

5 participants