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-12108] Array.init in flatMap crash: Unrecognized selector #54544
Comments
Hmm, reproduces on 5.2 too. This doesn't crash though: let array: [SomeClass] = SomeClass?.none.flatMap(Array.init) ?? []
print(array.count) |
@swift-ci create |
-dump-ast shows that (declref_expr type='(Array<SomeClass>.Type) -> (AnyObject) -> Array<SomeClass>' location=<stdin>:4:46 range=[<stdin>:4:46 - line:4:46] decl=Swift.(file).Array extension.init(_immutableCocoaArray:) [with (substitution_map generic_signature=<Element> (substitution Element -> SomeClass))] function_ref=unapplied) This is a result of our lax rules for matching unlabeled parameters. Banannzza (JIRA User), I'm not sure which initializer you were hoping |
Comment by Aleksey Ostapenko (JIRA) brentdax (JIRA User), so is everything ok that the compiler allows me to compile it? |
I wouldn't quite say it's "okay"—it's an undesirable behavior—but it's expected given our language rules. The language allows It's something we could perhaps fix in Swift 6 (or whatever the next version is that allows breaking changes to the language), but it will require an evolution proposal. Such a proposal has previously been discussed in this thread: https://forums.swift.org/t/require-parameter-names-when-referencing-to-functions/27048 |
(Sorry for the chain-reply…) Thinking about it a little more, we could at least warn when this construct matches an initializer whose first argument label starts with an |
Comment by Aleksey Ostapenko (JIRA) brentdax (JIRA User) Thanks! |
Would there be a fix-it attached to it? If so, what would it do? |
Comment by aaron crespo (JIRA) Thankfully we caught this bug today in Dev before it went out to Prod. Xcode 11.5, Swift 5.2.4. |
Attachment: Download
Environment
XCode 11.3 11.5
Additional Detail from JIRA
md5: c3a241e803036ffde4a8401eae0b9c38
Issue Description:
The runtime error Unrecognized selector -[__lldb_expr_1.SomeClass count] when trying to call Sequence protocol methods
Reproduce only with Class (otherwise compiler time error)
The text was updated successfully, but these errors were encountered: