Skip to content

Commit 8b92fd7

Browse files
committed
[Tests] Update Sema tests.
1 parent ee3f2f8 commit 8b92fd7

File tree

3 files changed

+39
-17
lines changed

3 files changed

+39
-17
lines changed

test/SILOptimizer/access_wmo_diagnose.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ public class C {
1010
}
1111

1212
public func testGlobalProp() {
13-
let a: AnyKeyPath = \C.globalProp // expected-error{{key path cannot refer to static member 'globalProp'}}
13+
let a: AnyKeyPath = \C.globalProp // expected-error{{static member 'globalProp' cannot be used on instance of type 'C'}}
1414
}

test/attr/attr_dynamic_member_lookup.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,7 @@ func invalid_refs_through_dynamic_lookup() {
682682
}
683683

684684
func test(_ lens: A<S>) {
685-
_ = lens.foo // expected-error {{dynamic key path member lookup cannot refer to static member 'foo'}}
685+
_ = lens.foo // expected-error {{static member 'foo' cannot be used on instance of type 'S'}}
686686
_ = lens.bar() // expected-error {{dynamic key path member lookup cannot refer to instance method 'bar()'}}
687687
_ = lens.bar().faz + 1 // expected-error {{dynamic key path member lookup cannot refer to instance method 'bar()'}}
688688
_ = lens.baz("hello") // expected-error {{dynamic key path member lookup cannot refer to static method 'baz'}}

test/expr/unary/keypath/keypath.swift

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -524,16 +524,39 @@ func testInvalidKeyPathComponents() {
524524
let _ = \.{return 0} // expected-error* {{}}
525525
}
526526

527+
struct W {
528+
static let h = 50
529+
}
530+
527531
class X {
528532
class var a: Int { return 1 }
529-
static var b = 2
533+
static var b = 20
534+
let c = true
535+
static subscript(d: Int) -> String { "\(d)" }
536+
var e: W.Type? { return W.self }
537+
}
538+
539+
class Y : X {
540+
subscript(f: Int) -> W.Type { W.self }
541+
static subscript(g: Int) -> W.Type { W.self }
530542
}
531543

532544
func testStaticKeyPathComponent() {
533-
_ = \X.a // expected-error{{cannot refer to static member}}
534-
_ = \X.Type.a // expected-error{{cannot refer to static member}}
535-
_ = \X.b // expected-error{{cannot refer to static member}}
536-
_ = \X.Type.b // expected-error{{cannot refer to static member}}
545+
_ = \X.a // expected-error{{static member 'a' cannot be used on instance of type 'X'}}
546+
_ = \X.Type.a
547+
_ = \X.b // expected-error{{static member 'b' cannot be used on instance of type 'X'}}
548+
_ = \X.Type.b
549+
_ = \X.c
550+
_ = \X.Type.c // expected-error{{instance member 'c' cannot be used on type 'X'}}
551+
_ = \X.[42] // expected-error{{static member 'subscript(_:)' cannot be used on instance of type 'X'}}
552+
_ = \X.Type.[42]
553+
554+
let _: KeyPath<X, Int?> = \.e?.h
555+
let _: PartialKeyPath<X> = \.e?.h
556+
let _: AnyKeyPath = \X.e?.h
557+
558+
let _ : KeyPath<Y, W.Type> = \Y.[40]
559+
let _ : KeyPath<Y.Type, W.Type> = \Y.Type.[70]
537560
}
538561

539562
class Bass: Hashable {
@@ -735,13 +758,13 @@ protocol P_With_Static_Members {
735758

736759
func test_keypath_with_static_members(_ p: P_With_Static_Members) {
737760
let _ = p[keyPath: \.x]
738-
// expected-error@-1 {{key path cannot refer to static member 'x'}}
761+
// expected-error@-1 {{static member 'x' cannot be used on instance of type 'any P_With_Static_Members'}}
739762
let _: KeyPath<P_With_Static_Members, Int> = \.x
740-
// expected-error@-1 {{key path cannot refer to static member 'x'}}
763+
// expected-error@-1 {{static member 'x' cannot be used on instance of type 'any P_With_Static_Members'}}
741764
let _ = \P_With_Static_Members.arr.count
742-
// expected-error@-1 {{key path cannot refer to static member 'arr'}}
765+
// expected-error@-1 {{static member 'arr' cannot be used on instance of type 'any P_With_Static_Members'}}
743766
let _ = p[keyPath: \.arr.count]
744-
// expected-error@-1 {{key path cannot refer to static member 'arr'}}
767+
// expected-error@-1 {{static member 'arr' cannot be used on instance of type 'any P_With_Static_Members'}}
745768

746769
struct S {
747770
static var foo: String = "Hello"
@@ -754,17 +777,16 @@ func test_keypath_with_static_members(_ p: P_With_Static_Members) {
754777

755778
func foo(_ s: S) {
756779
let _ = \S.Type.foo
757-
// expected-error@-1 {{key path cannot refer to static member 'foo'}}
758780
let _ = s[keyPath: \.foo]
759-
// expected-error@-1 {{key path cannot refer to static member 'foo'}}
781+
// expected-error@-1 {{static member 'foo' cannot be used on instance of type 'S'}}
760782
let _: KeyPath<S, String> = \.foo
761-
// expected-error@-1 {{key path cannot refer to static member 'foo'}}
783+
// expected-error@-1 {{static member 'foo' cannot be used on instance of type 'S'}}
762784
let _ = \S.foo
763-
// expected-error@-1 {{key path cannot refer to static member 'foo'}}
785+
// expected-error@-1 {{static member 'foo' cannot be used on instance of type 'S'}}
764786
let _ = \S.bar.baz
765-
// expected-error@-1 {{key path cannot refer to static member 'baz'}}
787+
// expected-error@-1 {{static member 'baz' cannot be used on instance of type 'Bar'}}
766788
let _ = s[keyPath: \.bar.baz]
767-
// expected-error@-1 {{key path cannot refer to static member 'baz'}}
789+
// expected-error@-1 {{static member 'baz' cannot be used on instance of type 'Bar'}}
768790
}
769791
}
770792

0 commit comments

Comments
 (0)