File: lookup.swift

package info (click to toggle)
swiftlang 6.1.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,791,532 kB
  • sloc: cpp: 9,901,743; ansic: 2,201,431; asm: 1,091,827; python: 308,252; objc: 82,166; f90: 80,126; lisp: 38,358; pascal: 25,559; sh: 20,429; ml: 5,058; perl: 4,745; makefile: 4,484; awk: 3,535; javascript: 3,018; xml: 918; fortran: 664; cs: 573; ruby: 396
file content (113 lines) | stat: -rw-r--r-- 4,895 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
// RUN: %empty-directory(%t)

// RUN: %target-swift-frontend -emit-module %S/Inputs/lookup_moduleD.swift -module-name D -o %t -I %t
// RUN: %target-swift-frontend -emit-module %S/Inputs/lookup_moduleC.swift -module-name C -o %t -I %t
// RUN: %target-swift-frontend -emit-module %S/Inputs/lookup_moduleB.swift -module-name B -o %t -I %t
// RUN: %target-swift-frontend -emit-module %S/Inputs/lookup_moduleA.swift -module-name A -o %t -I %t
// RUN: %target-swift-frontend -emit-module %S/Inputs/lookup_module_exportsAC.swift -module-name ExportsAC -o %t -I %t
// RUN: %target-swift-frontend -typecheck -verify -primary-file %s %S/Inputs/lookup_other.swift %S/Inputs/lookup_other2.swift %S/Inputs/lookup_other_noncompat.swift -I %t -enable-new-operator-lookup

import ExportsAC
import B

infix operator ^^^ : DeclaredAcrossFiles
func ^^^ (lhs: Int, rhs: Int) -> Int { 0 }
func &&& (lhs: Int, rhs: Int) -> Int { 0 }

// The operator decl >>> is declared in module A, which we should be able to
// see through ExportsAC.
prefix func >>> (rhs: Double) {}

// Make sure we can also see precedencegroups in module A through ExportsAC.
infix operator ^^^^ : DeclaredInModuleA

// The operator decl for ??? is declared in both modules A and B, but has the
// same default precedence group in both, so there's no ambiguity.
func ??? (lhs: Int, rhs: Int) {}

// Same for ???!, declared in modules ExportsAC and B, but has the same
// precedence group in both.
func ???! (lhs: Int, rhs: Int) {}

// The operator decl for ???? is declared in both modules A and B, and has a
// different precedence group in each. Therefore ambiguous.
func ???? (lhs: Int, rhs: Int) {} // expected-error {{ambiguous operator declarations found for operator}}

// Same for ????!, declared in both modules ExportsAC and B, and has a different
// precedence group in each. Therefore ambiguous.
func ????! (lhs: Int, rhs: Int) {} // expected-error {{ambiguous operator declarations found for operator}}

// The precedencegroup is declared in both modules A and B, therefore ambiguous.
infix operator <?> : DeclaredInModulesAB // expected-error {{multiple precedence groups found}}

// The precedencegroup is declared in both modules ExportsAC and B, therefore
// ambiguous.
infix operator <!> : DeclaredInModulesBExportsAC // expected-error {{multiple precedence groups found}}

// While this precedencegroup is declared in both modules A and B, it's also
// declared in this module, which therefore shadows those decls.
infix operator <??> : DeclaredInModulesABShadowed

// The operator decl for <? is declared in both modules A and B, but there's no
// meaningful difference between the declarations, so legal.
postfix func <? (lhs: Int) {}

// Same thing, <! is declared in both modules ExportsAC and B, but there's no
// meaningful difference between the declarations, so legal.
postfix func <! (lhs: Int) {}

// This precedencegroup is declared in both modules A and ExportsAC, but the
// latter shadows the former.
infix operator <???> : ShadowsModuleA

// This precedencegroup is declared in modules A, C, and ExportsAC, but the
// latter shadows both of the former.
infix operator <????> : ShadowsModulesAC

// This operator decl is declared in modules A, C, and ExportsAC, but the
// latter shadows both of the former.
func ????? (lhs: Int, rhs: Int) {}

// This operator decl is declared in modules A, C, and ExportsAC, but the
// latter shadows both of the former, despite them having different
// precedencegroups.
func ?????? (lhs: Int, rhs: Int) {}

// Module D is imported through exports in both lookup_other and lookup_other2.
// Make sure we correctly handle visiting the same module twice.
infix operator <> : DeclaredInModuleD

// Also declared in lookup_other.
precedencegroup RedeclaredInModule {}
// expected-error@-1 {{precedence group redeclared}}
// expected-note@-2 {{found this matching precedence group}}

infix operator *** : RedeclaredInModule // expected-error {{multiple precedence groups found}}

func testOperatorLookup() {
  // In lookup_other, DeclaredAcrossFiles is left associative, whereas in
  // module B it is non-associative. Make sure we use lookup_other's.
  _ = 5 ^^^ 5 ^^^ 5 // Okay.

  // Same for &&&, in lookup_other it is declared as left associative.
  _ = 5 &&& 5 &&& 5

  // The operator >>> is declared in module A, which we should be able to see
  // through ExportsAC.
  >>>1

  // We've been evil and overridden TernaryPrecedence in both modules A and B.
  // Make sure we emit an ambiguity error without emitting a 'broken stdlib'
  // error.
  true ? () : () // expected-error {{multiple precedence groups found}}
}

precedencegroup CastingPrecedence {
  lowerThan: AssignmentPrecedence
}

func testBuiltinPrecedenceGroupOverriding() {
  // Evil, but allowed.
  var x = 0
  x = 0 as Int // expected-error {{cannot convert value of type '()' to type 'Int' in coercion}}
}