'_' can only appear in a pattern or on the left side of an assignment
| Originator: | neocool2 | ||
| Number: | rdar://20874094 | Date Originated: | 08-May-2015 06:50 PM |
| Status: | Open | Resolved: | |
| Product: | Developer Tools | Product Version: | Apple Swift version 1.2 (swiftlang-602.0.49.6 clang-602.0.49) |
| Classification: | Other Bug | Reproducible: | Always |
Summary:
This piece of code doesn’t compile:
```
#!/usr/bin/xcrun swift
let _ = 2
let x = _ / 2
println(x)
```
Steps to Reproduce:
Compile the given example.
Expected Results:
It compiles.
Actual Results:
$ ./underscore.swift
./underscore.swift:4:9: error: '_' can only appear in a pattern or on the left side of an assignment
let x = _ / 2
^
This seems kinda arbitrary — why allow declaring a variable that only be used in a narrow context?
Regression: -
Notes: -
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!