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-11134] Missing comma not diagnosed resulting a runtime crash rather than compile time error #53530

Closed
DevAndArtist mannequin opened this issue Jul 15, 2019 · 4 comments
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@DevAndArtist
Copy link
Mannequin

DevAndArtist mannequin commented Jul 15, 2019

Previous ID SR-11134
Radar None
Original Reporter @DevAndArtist
Type Bug
Status Resolved
Resolution Done
Environment

Apple Swift version 5.1 (swiftlang-1100.0.212.5 clang-1100.0.28.2)
Target: x86_64-apple-darwin19.0.0

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

md5: 800226d4c9df36713bd9fbf8b113f1ac

Issue Description:

let array = [[1, 1, 1], [], [4, 5, 6, 7], [0], [], [] [42]]

This line of code is missing a comma before `[42]` and was a hard to spot typo. This results in a runtime crash rather than a compile time error.

error: Execution was interrupted, reason: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0).
The process has been left at the point where it was interrupted, use "thread return -x" to return to the state before expression evaluation.

* thread #​1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)
  * frame #&#8203;0: 0x0000000102a8e3ef libswiftCore.dylib`function signature specialization <Arg[0] = Exploded, Arg[1] = Exploded, Arg[2] = Dead, Arg[3] = Dead> of Swift._fatalErrorMessage(_: Swift.StaticString, _: Swift.StaticString, file: Swift.StaticString, line: Swift.UInt, flags: Swift.UInt32) -> Swift.Never + 463
    frame #&#8203;1: 0x000000010286238f libswiftCore.dylib`Swift._ArrayBuffer._checkInoutAndNativeTypeCheckedBounds(_: Swift.Int, wasNativeTypeChecked: Swift.Bool) -> () + 239
    frame #&#8203;2: 0x0000000102865221 libswiftCore.dylib`Swift.Array.subscript.getter : (Swift.Int) -> A + 81
    frame #&#8203;3: 0x0000000104eaa34e $__lldb_expr100`main at Untitled Page 2.xcplaygroundpage:7:55
    frame #&#8203;4: 0x000000010279b580 DeinitTest`linkResources + 304
    frame #&#8203;5: 0x00007fff23a5ce4c CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
    frame #&#8203;6: 0x00007fff23a5c5b8 CoreFoundation`__CFRunLoopDoBlocks + 312
    frame #&#8203;7: 0x00007fff23a57444 CoreFoundation`__CFRunLoopRun + 1284
    frame #&#8203;8: 0x00007fff23a56c16 CoreFoundation`CFRunLoopRunSpecific + 438
    frame #&#8203;9: 0x00007fff37a98bb0 GraphicsServices`GSEventRunModal + 65
    frame #&#8203;10: 0x00007fff46c97bef UIKitCore`UIApplicationMain + 1621
    frame #&#8203;11: 0x000000010279b64d DeinitTest`main + 205
    frame #&#8203;12: 0x00007fff50fb24ad libdyld.dylib`start + 1

Related discussion: https://forums.swift.org/t/is-this-a-bug-of-xcode-or-is-this-intended/26978

@theblixguy
Copy link
Collaborator

Reduced case:

let array = [[] [42]]

The problem is that we're parsing subscript expression inside a collection expression, so the parser doesn't throw an error for a missing comma. We can emit a warning diagnostic if we parse a subscript along with a fix-it to insert the comma.

cc @rintaro

@belkadan
Copy link
Contributor

I mean, the code is valid as written. It's just doing something silly. (For a simpler example, consider [[1, 2] [3]].) But maybe the compiler should warn on it and suggest parens if you really want to subscript a literal?

@theblixguy
Copy link
Collaborator

Here's a fix: #26149

@theblixguy
Copy link
Collaborator

Fixed on master

@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. compiler The Swift compiler in itself
Projects
None yet
Development

No branches or pull requests

2 participants