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-9726] Coercion using invalid conformance crashes REPL #4344

Closed
karwa opened this issue Jan 22, 2019 · 3 comments
Closed

[SR-9726] Coercion using invalid conformance crashes REPL #4344

karwa opened this issue Jan 22, 2019 · 3 comments

Comments

@karwa
Copy link

karwa commented Jan 22, 2019

Previous ID SR-9726
Radar None
Original Reporter @karwa
Type Bug
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s Compiler, LLDB for Swift
Labels Bug, CompilerCrash
Assignee None
Priority Medium

md5: 554842305cf65cdd81ba04504e0ae869

Issue Description:

Write this in the REPL line-by-line:

protocol P: AnyObject {}
extension Int: P {} // you'll get an error here.
42 is P

The REPL will first say that the line '42 is P' is always true, then crash:

Could not cast value of type 'Swift.Int' (0x11be12708) to 'REPL_3.P' (0x11be49fa8).

...

0  swift                    0x0000000112d8f978 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 40
1  swift                    0x0000000112d8ebf5 llvm::sys::RunSignalHandlers() + 85
2  swift                    0x0000000112d8ff82 SignalHandler(int) + 258
3  libsystem_platform.dylib 0x00007fff5f56cb3d _sigtramp + 29
4  libsystem_platform.dylib 0x00007fe0d0e44760 _sigtramp + 1905097792
5  libsystem_c.dylib        0x00007fff5f42a1c9 abort + 127
6  libswiftCore.dylib       0x000000011bd4a075 swift::fatalError(unsigned int, char const*, ...) + 149
7  libswiftCore.dylib       0x000000011bd40d12 swift::swift_dynamicCastFailure(void const*, char const*, void const*, char const*, char const*) + 82
8  libswiftCore.dylib       0x000000011bd40d8a swift::swift_dynamicCastFailure(swift::TargetMetadata<swift::InProcess> const*, swift::TargetMetadata<swift::InProcess> const*, char const*) + 106
9  libswiftCore.dylib       0x000000011bd451b0 _dynamicCastToExistential(swift::OpaqueValue*, swift::OpaqueValue*, swift::TargetMetadata<swift::InProcess> const*, swift::TargetExistentialTypeMetadata<swift::InProcess> const*, swift::DynamicCastFlags) + 2528
10 libswiftCore.dylib       0x000000011a92d046 _dynamicCastToExistential(swift::OpaqueValue*, swift::OpaqueValue*, swift::TargetMetadata<swift::InProcess> const*, swift::TargetExistentialTypeMetadata<swift::InProcess> const*, swift::DynamicCastFlags) + 4273899638
11 swift                    0x000000010e544c8d llvm::MCJIT::runFunction(llvm::Function*, llvm::ArrayRef<llvm::GenericValue>) + 461

Even though the "Int: P" conformance is invalid, it appears to still be available for type-checking.

@belkadan
Copy link

Lousy, but not a priority. The integrated REPL is just for compiler engineers testing things.

@karwa
Copy link
Author

karwa commented Jan 24, 2019

Also happens in LLDB REPL.

Tested on Apple Swift version 4.2 (swiftlang-1000.11.37.1 clang-1000.11.45.1) and master.

@dcci
Copy link
Mannequin

dcci mannequin commented Jul 25, 2019

Doesn't reproduce on top-of-tree for the integrated REPL and the LLDB REPL.

local@locals-iMac-Pro-3 ~ % ./swift/build/Ninja-ReleaseAssert+stdlib-Release/swift-macosx-x86_64/bin/swift     
***  You are running Swift's integrated REPL,  ***
***  intended for compiler and stdlib          ***
***  development and testing purposes only.    ***
***  The full REPL is built as part of LLDB.   ***
***  Type ':help' for assistance.              ***
(swift) protocol P: AnyObject {}
(swift) extension Int: P {} 
<REPL Input>:1:1: error: non-class type 'Int' cannot conform to class protocol 'P'
extension Int: P {} 
^
local@locals-iMac-Pro-3 ~ % ./swift/build/Ninja-ReleaseAssert+stdlib-Release/lldb-macosx-x86_64/bin/lldb --repl
Welcome to Swift version 5.1-dev (LLVM 200186e28b, Swift a8dc4be076).
Type :help for assistance.
  1> protocol P: AnyObject {}
  2> extension Int: P {}
error: repl.swift:2:1: error: non-class type 'Int' cannot conform to class protocol 'P'
extension Int: P {}
^

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 5, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants