Files
swift-mirror/test/expr/primary/unqualified_name.swift
Slava Pestov fbdecebf77 AST: Restore unqualified lookup quirk for Swift 3 mode
In Swift 3, unqualified lookup would skip static methods
when performing a lookup from instance context.

In Swift 4 mode, if a module method is shadowed by a static
method, you will need to qualify the module method with the
module name.

It would have been nice to isolate the quirk in Sema and
not AST, but unfortunately UnqualifiedLookup only proceeds
to lookup in the module if scope-based lookup failed to find
anything, and I don't want to change that since it risks
introducing performance regressions.

Fixes <rdar://problem/29961715>.
2017-01-12 22:43:23 -08:00

87 lines
2.9 KiB
Swift

// RUN: %target-typecheck-verify-swift -swift-version 4
func f0(_ x: Int, y: Int, z: Int) { }
func f1(_ x: Int, while: Int) { }
func f2(_ x: Int, `let` _: Int) { }
func f3(_ x: Int, _ y: Int, z: Int) { }
func test01() {
_ = f0(_:y:z:)
_ = f0(:y:z:) // expected-error{{an empty argument label is spelled with '_'}}{{10-10=_}}
_ = f1(_:`while`:) // expected-warning{{keyword 'while' does not need to be escaped in argument list}}{{12-13=}}{{18-19=}}
_ = f2(_:`let`:)
_ = f3(_::z:) // expected-error{{an empty argument label is spelled with '_'}}{{12-12=_}}
}
struct S0 {
func f0(_ x: Int, y: Int, z: Int) { }
func f1(_ x: Int, while: Int) { }
func f2(_ x: Int, `let` _: Int) { }
func testS0() {
_ = f0(_:y:z:)
_ = f0(:y:z:) // expected-error{{an empty argument label is spelled with '_'}}{{12-12=_}}
_ = f1(_:`while`:) // expected-warning{{keyword 'while' does not need to be escaped in argument list}}{{14-15=}}{{20-21=}}
_ = f2(_:`let`:)
_ = self.f0(_:y:z:)
_ = self.f0(:y:z:) // expected-error{{an empty argument label is spelled with '_'}}{{17-17=_}}
_ = self.f1(_:`while`:) // expected-warning{{keyword 'while' does not need to be escaped in argument list}}{{19-20=}}{{25-26=}}
_ = self.f2(_:`let`:)
_ = f3(_:y:z:) // expected-error{{static member 'f3(_:y:z:)' cannot be used on instance of type 'S0'}}{{9-9=S0.}}
}
static func testStaticS0() {
_ = f0(_:y:z:)
_ = f3(_:y:z:)
}
static func f3(_ x: Int, y: Int, z: Int) -> S0 { return S0() }
}
// Determine context from type.
let s0_static: S0 = .f3(_:y:z:)(0, y: 0, z: 0)
class C0 {
init(x: Int, y: Int, z: Int) { }
convenience init(all: Int) {
self.init(x:y:z:)(all, all, all)
}
func f0(_ x: Int, y: Int, z: Int) { }
func f1(_ x: Int, while: Int) { }
func f2(_ x: Int, `let` _: Int) { }
}
class C1 : C0 {
init(all: Int) {
super.init(x:y:z:)(all, all, all)
}
func testC0() {
_ = f0(_:y:z:)
_ = f0(:y:z:) // expected-error{{an empty argument label is spelled with '_'}}{{12-12=_}}
_ = f1(_:`while`:) // expected-warning{{keyword 'while' does not need to be escaped in argument list}}{{14-15=}}{{20-21=}}
_ = f2(_:`let`:)
_ = super.f0(_:y:z:)
_ = super.f0(:y:z:) // expected-error{{an empty argument label is spelled with '_'}}{{18-18=_}}
_ = super.f1(_:`while`:) // expected-warning{{keyword 'while' does not need to be escaped in argument list}}{{20-21=}}{{26-27=}}
_ = self.f2(_:`let`:)
}
}
struct S1 {
init(x: Int) {} // expected-note {{'init(x:)' declared here}}
func testS1() {
_ = S1.init(x:)(1)
_ = S1.init(`x`: 1) // expected-warning {{keyword 'x' does not need to be escaped in argument list}} {{17-18=}} {{19-20=}}
// Test for unknown token.
_ = S1.init(x: 0xG) // expected-error {{expected a digit after integer literal prefix}} expected-error {{missing argument for parameter 'x' in call}}
}
}