File: operator_decl.swift

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (117 lines) | stat: -rw-r--r-- 5,205 bytes parent folder | download
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
114
115
116
117
// RUN: %target-typecheck-verify-swift

prefix operator +++ {} // expected-error {{operator should no longer be declared with body}} {{20-23=}}
postfix operator +++ {} // expected-error {{operator should no longer be declared with body}} {{21-24=}}
infix operator +++ {} // expected-error {{operator should no longer be declared with body}} {{19-22=}}
infix operator +++* { // expected-error {{operator should no longer be declared with body; use a precedence group instead}} {{none}}
  associativity right
}
infix operator +++*+ : A { } // expected-error {{operator should no longer be declared with body}} {{25-29=}}


prefix operator +++** : A { }
// expected-error@-1 {{only infix operators may declare a precedence}} {{23-27=}}
// expected-error@-2 {{operator should no longer be declared with body}} {{26-30=}}

prefix operator ++*++ : A
// expected-error@-1 {{only infix operators may declare a precedence}} {{23-26=}}

postfix operator ++*+* : A { }
// expected-error@-1 {{only infix operators may declare a precedence}} {{24-28=}}
// expected-error@-2 {{operator should no longer be declared with body}} {{27-31=}}

postfix operator ++**+ : A
// expected-error@-1 {{only infix operators may declare a precedence}} {{24-27=}}

operator ++*** : A
// expected-error@-1 {{operator must be declared as 'prefix', 'postfix', or 'infix'}}

operator +*+++ { }
// expected-error@-1 {{operator must be declared as 'prefix', 'postfix', or 'infix'}}
// expected-error@-2 {{operator should no longer be declared with body}} {{15-19=}}

operator +*++* : A { }
// expected-error@-1 {{operator must be declared as 'prefix', 'postfix', or 'infix'}}
// expected-error@-2 {{operator should no longer be declared with body}} {{19-23=}}

prefix operator // expected-error {{expected operator name in operator declaration}}

;
prefix operator %%+

prefix operator ??
postfix operator ?? // expected-error {{postfix operator names starting with '?' or '!' are disallowed to avoid collisions with built-in unwrapping operators}}
prefix operator !!
postfix operator !! // expected-error {{postfix operator names starting with '?' or '!' are disallowed to avoid collisions with built-in unwrapping operators}}
postfix operator ?$$
// expected-error@-1 {{postfix operator names starting with '?' or '!' are disallowed}}
// expected-error@-2 {{'$$' is considered an identifier}}

infix operator --aa // expected-error {{'aa' is considered an identifier and must not appear within an operator name}}
infix operator aa--: A // expected-error {{'aa' is considered an identifier and must not appear within an operator name}}
infix operator <<$$@< // expected-error {{'$$' is considered an identifier and must not appear within an operator name}}
infix operator !!@aa // expected-error {{'@' is not allowed in operator names}}
infix operator #++= // expected-error {{'#' is not allowed in operator names}}
infix operator ++=# // expected-error {{'#' is not allowed in operator names}}
infix operator -># // expected-error {{'#' is not allowed in operator names}}

// FIXME: Ideally, we shouldn't emit the «consistent whitespace» diagnostic
// where = cannot possibly mean an assignment.
infix operator =#=
// expected-error@-1 {{'#' is not allowed in operator names}}
// expected-error@-2 {{'=' must have consistent whitespace on both sides}}

infix operator +++=
infix operator *** : A
infix operator --- : ; // expected-error {{expected precedence group name after ':' in operator declaration}}

precedencegroup { // expected-error {{expected identifier after 'precedencegroup'}}
  associativity: right
}
precedencegroup A {
  associativity right // expected-error {{expected colon after attribute name in precedence group}}
}
precedencegroup B {
  precedence 123 // expected-error {{'precedence' is not a valid precedence group attribute}}
}
precedencegroup C {
  associativity: sinister // expected-error {{expected 'none', 'left', or 'right' after 'associativity'}}
}
precedencegroup D {
  assignment: no // expected-error {{expected 'true' or 'false' after 'assignment'}}
}
precedencegroup E {
  higherThan:
} // expected-error {{expected name of related precedence group after 'higherThan'}}

precedencegroup F {
  higherThan: A, B, C
}


precedencegroup BangBangBang {
  associativity: none
  associativity: left // expected-error{{'associativity' attribute for precedence group declared multiple times}}
}

precedencegroup CaretCaretCaret {
  assignment: true 
  assignment: false // expected-error{{'assignment' attribute for precedence group declared multiple times}}
}

class Foo {
  infix operator ||| // expected-error{{'operator' may only be declared at file scope}}
}

infix operator **<< : UndeclaredPrecedenceGroup
// expected-error@-1 {{unknown precedence group 'UndeclaredPrecedenceGroup'}}

protocol Proto {}
infix operator *<*< : F, Proto
// expected-error@-1 {{consecutive statements on a line must be separated by ';'}}
// expected-error@-2 {{expected expression}}

// https://github.com/apple/swift/issues/60932

// expected-error@+2 {{expected precedence group name after ':' in operator declaration}}
postfix operator ++: // expected-error {{only infix operators may declare a precedence}} {{20-21=}}