mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Now that we have expressions that start with #, the [# introducer for
object literals is no longer guaranteed to indicate an object
literal. For example:
[#line, #column]
is an array literal and
[#line : #column]
is a dictionary literal. Use additional lookahead in the parser to
disambiguate these cases from object literals. Fixes
rdar://problem/24533081.
25 lines
533 B
Swift
25 lines
533 B
Swift
// RUN: %target-parse-verify-swift
|
|
|
|
// Test "context" literals, #file, #line, #column, etc.
|
|
|
|
func requireInt(x: Int) { }
|
|
func requireString(s: String) { }
|
|
|
|
func testContextLiterals() {
|
|
let file = #file
|
|
requireString(file)
|
|
let line = #line
|
|
requireInt(line)
|
|
let column = #column
|
|
requireInt(column)
|
|
let function = #function
|
|
requireString(function)
|
|
}
|
|
|
|
// Disambiguate between collection literals and object literals.
|
|
func collectionLiteralDisambiguation() {
|
|
_ = [#line]
|
|
_ = [#line, #column]
|
|
_ = [#line : #column]
|
|
}
|