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-11818] Bad downcast to Self not caught at runtime #54229

Closed
swift-ci opened this issue Nov 20, 2019 · 3 comments
Closed

[SR-11818] Bad downcast to Self not caught at runtime #54229

swift-ci opened this issue Nov 20, 2019 · 3 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior.

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-11818
Radar rdar://problem/57369535
Original Reporter Alvae (JIRA User)
Type Bug
Status Resolved
Resolution Done
Environment

macOS 10.14.6
Apple Swift version 5.1.2 (swiftlang-1100.0.278 clang-1100.0.33.9)
Target: x86_64-apple-darwin18.7.0

Additional Detail from JIRA
Votes 0
Component/s
Labels Bug
Assignee None
Priority Medium

md5: fbb65ac0c98f2c39a39b37ff1ba9c5f0

Issue Description:

The following code has undefined behavior:

protocol Boxable {
  func boxed() -> Self
}

class List: Boxable {
  let next: List?
  init(next: List?) { self.next = next }
  func boxed() -> Self { List(next: self) as! Self }
}

class DerivedList: List {
  let foo: String
  init(foo: String, next: List?) { self.foo = foo; super.init(next: next) }
}

let derived = DerivedList(foo: "bar", next: nil).boxed()
print(derived.foo)

I would have expected the downcast to Self in List.boxed() to crash the program when I called boxed on DerivedList's instance. As it didn't, the property derived.foo is actually uninitialized.

@typesanitizer
Copy link

cc @slavapestov

@swift-ci create

@CodaFi
Copy link
Member

CodaFi commented Nov 21, 2019

I love this bug. If I run it in -Onone it uses the JIT to start exploring the contents of my RAM and dumping garbage.

@slavapestov
Copy link
Member

#28401

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 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.
Projects
None yet
Development

No branches or pull requests

4 participants