Austin Eng | cc2516a | 2023-10-17 20:57:54 +0000 | [diff] [blame] | 1 | // Copyright 2021 The Dawn & Tint Authors |
Ben Clayton | b85e692 | 2022-02-02 23:07:11 +0000 | [diff] [blame] | 2 | // |
Austin Eng | cc2516a | 2023-10-17 20:57:54 +0000 | [diff] [blame] | 3 | // Redistribution and use in source and binary forms, with or without |
| 4 | // modification, are permitted provided that the following conditions are met: |
Ben Clayton | b85e692 | 2022-02-02 23:07:11 +0000 | [diff] [blame] | 5 | // |
Austin Eng | cc2516a | 2023-10-17 20:57:54 +0000 | [diff] [blame] | 6 | // 1. Redistributions of source code must retain the above copyright notice, this |
| 7 | // list of conditions and the following disclaimer. |
Ben Clayton | b85e692 | 2022-02-02 23:07:11 +0000 | [diff] [blame] | 8 | // |
Austin Eng | cc2516a | 2023-10-17 20:57:54 +0000 | [diff] [blame] | 9 | // 2. Redistributions in binary form must reproduce the above copyright notice, |
| 10 | // this list of conditions and the following disclaimer in the documentation |
| 11 | // and/or other materials provided with the distribution. |
| 12 | // |
| 13 | // 3. Neither the name of the copyright holder nor the names of its |
| 14 | // contributors may be used to endorse or promote products derived from |
| 15 | // this software without specific prior written permission. |
| 16 | // |
| 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 18 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 19 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 20 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
| 21 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 22 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 23 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| 24 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 25 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
Ben Clayton | b85e692 | 2022-02-02 23:07:11 +0000 | [diff] [blame] | 27 | |
| 28 | package resolver_test |
| 29 | |
| 30 | import ( |
| 31 | "fmt" |
| 32 | "strings" |
| 33 | "testing" |
| 34 | |
Ben Clayton | cde5009 | 2022-07-26 15:46:44 +0000 | [diff] [blame] | 35 | "dawn.googlesource.com/dawn/tools/src/tint/intrinsic/parser" |
| 36 | "dawn.googlesource.com/dawn/tools/src/tint/intrinsic/resolver" |
Ben Clayton | b85e692 | 2022-02-02 23:07:11 +0000 | [diff] [blame] | 37 | ) |
| 38 | |
| 39 | func TestResolver(t *testing.T) { |
| 40 | type test struct { |
| 41 | src string |
| 42 | err string |
| 43 | } |
| 44 | |
| 45 | success := "" |
| 46 | for _, test := range []test{ |
| 47 | { |
| 48 | `type X`, |
| 49 | success, |
| 50 | }, { |
| 51 | `enum E {}`, |
| 52 | success, |
| 53 | }, { |
| 54 | `enum E {A B C}`, |
| 55 | success, |
| 56 | }, { |
| 57 | `type X`, |
| 58 | success, |
| 59 | }, { |
Ben Clayton | e3e91c0 | 2022-06-01 20:44:50 +0000 | [diff] [blame] | 60 | `@display("Y") type X`, |
Ben Clayton | b85e692 | 2022-02-02 23:07:11 +0000 | [diff] [blame] | 61 | success, |
| 62 | }, { |
| 63 | ` |
| 64 | type x |
| 65 | match y: x`, |
| 66 | success, |
| 67 | }, { |
| 68 | ` |
| 69 | enum e {a b c} |
Ben Clayton | c768e64 | 2022-07-26 17:49:54 +0000 | [diff] [blame] | 70 | match y: e.c | e.a | e.b`, |
Ben Clayton | b85e692 | 2022-02-02 23:07:11 +0000 | [diff] [blame] | 71 | success, |
| 72 | }, { |
| 73 | `fn f()`, |
| 74 | success, |
| 75 | }, { |
dan sinclair | 4ac9ba9 | 2024-08-19 19:21:19 +0000 | [diff] [blame] | 76 | `implicit(T) fn f()`, |
Ben Clayton | b85e692 | 2022-02-02 23:07:11 +0000 | [diff] [blame] | 77 | success, |
| 78 | }, { |
| 79 | ` |
| 80 | type f32 |
Ben Clayton | 17770f5 | 2024-02-20 17:34:27 +0000 | [diff] [blame] | 81 | fn f<T>(T) -> f32`, |
| 82 | success, |
| 83 | }, { |
| 84 | ` |
| 85 | type f32 |
dan sinclair | 4ac9ba9 | 2024-08-19 19:21:19 +0000 | [diff] [blame] | 86 | implicit(N: num) fn f()`, |
Ben Clayton | b85e692 | 2022-02-02 23:07:11 +0000 | [diff] [blame] | 87 | success, |
| 88 | }, { |
| 89 | ` |
| 90 | enum e { a b c } |
dan sinclair | 4ac9ba9 | 2024-08-19 19:21:19 +0000 | [diff] [blame] | 91 | implicit(N: e) fn f()`, |
Ben Clayton | b85e692 | 2022-02-02 23:07:11 +0000 | [diff] [blame] | 92 | success, |
| 93 | }, { |
| 94 | ` |
| 95 | type f32 |
dan sinclair | 4ac9ba9 | 2024-08-19 19:21:19 +0000 | [diff] [blame] | 96 | implicit(T) fn f(T) -> f32`, |
Ben Clayton | b85e692 | 2022-02-02 23:07:11 +0000 | [diff] [blame] | 97 | success, |
| 98 | }, { |
| 99 | ` |
| 100 | type f32 |
dan sinclair | 4ac9ba9 | 2024-08-19 19:21:19 +0000 | [diff] [blame] | 101 | implicit(N: num) fn f<T: f32>()`, |
Ben Clayton | 17770f5 | 2024-02-20 17:34:27 +0000 | [diff] [blame] | 102 | success, |
| 103 | }, { |
| 104 | ` |
| 105 | type f32 |
dan sinclair | 4ac9ba9 | 2024-08-19 19:21:19 +0000 | [diff] [blame] | 106 | implicit(T: f32) fn f(T: f32) -> f32`, |
Ben Clayton | 17770f5 | 2024-02-20 17:34:27 +0000 | [diff] [blame] | 107 | success, |
| 108 | }, { |
| 109 | ` |
| 110 | type f32 |
Ben Clayton | b85e692 | 2022-02-02 23:07:11 +0000 | [diff] [blame] | 111 | type P<T> |
| 112 | match m: f32 |
dan sinclair | 4ac9ba9 | 2024-08-19 19:21:19 +0000 | [diff] [blame] | 113 | implicit(T: m) fn f(P<T>) -> T`, |
Ben Clayton | b85e692 | 2022-02-02 23:07:11 +0000 | [diff] [blame] | 114 | success, |
| 115 | }, { |
| 116 | ` |
Ben Clayton | b85e692 | 2022-02-02 23:07:11 +0000 | [diff] [blame] | 117 | enum e { a } |
Ben Clayton | c768e64 | 2022-07-26 17:49:54 +0000 | [diff] [blame] | 118 | match m: e.a |
| 119 | fn f(m)`, |
Ben Clayton | b85e692 | 2022-02-02 23:07:11 +0000 | [diff] [blame] | 120 | success, |
| 121 | }, { |
| 122 | ` |
| 123 | enum e { a b } |
| 124 | type T<E: e> |
Ben Clayton | c768e64 | 2022-07-26 17:49:54 +0000 | [diff] [blame] | 125 | match m: e.a |
Ben Clayton | b85e692 | 2022-02-02 23:07:11 +0000 | [diff] [blame] | 126 | fn f(T<m>)`, |
| 127 | success, |
| 128 | }, { |
| 129 | ` |
| 130 | enum e { a } |
| 131 | type T<E: e> |
Ben Clayton | c768e64 | 2022-07-26 17:49:54 +0000 | [diff] [blame] | 132 | match m : e.a |
| 133 | fn f(T<m>)`, |
| 134 | success, |
| 135 | }, { |
| 136 | ` |
| 137 | enum e { a } |
| 138 | type T<E: e> |
| 139 | match a : e.a |
Ben Clayton | b85e692 | 2022-02-02 23:07:11 +0000 | [diff] [blame] | 140 | fn f(T<a>)`, |
| 141 | success, |
| 142 | }, { |
| 143 | ` |
| 144 | type T<E: num> |
dan sinclair | 4ac9ba9 | 2024-08-19 19:21:19 +0000 | [diff] [blame] | 145 | implicit(E: num) fn f(T<E>)`, |
Ben Clayton | b85e692 | 2022-02-02 23:07:11 +0000 | [diff] [blame] | 146 | success, |
| 147 | }, { |
dan sinclair | 4ac9ba9 | 2024-08-19 19:21:19 +0000 | [diff] [blame] | 148 | `implicit(T) fn f(T)`, |
Ben Clayton | b85e692 | 2022-02-02 23:07:11 +0000 | [diff] [blame] | 149 | success, |
| 150 | }, { |
| 151 | ` |
| 152 | enum e { a b } |
dan sinclair | 4ac9ba9 | 2024-08-19 19:21:19 +0000 | [diff] [blame] | 153 | implicit(E: e) fn f()`, |
Ben Clayton | b85e692 | 2022-02-02 23:07:11 +0000 | [diff] [blame] | 154 | success, |
| 155 | }, { |
| 156 | ` |
| 157 | enum e { a b } |
Ben Clayton | c768e64 | 2022-07-26 17:49:54 +0000 | [diff] [blame] | 158 | match m: e.a | e.b |
dan sinclair | 4ac9ba9 | 2024-08-19 19:21:19 +0000 | [diff] [blame] | 159 | implicit(E: m) fn f()`, |
Ben Clayton | b85e692 | 2022-02-02 23:07:11 +0000 | [diff] [blame] | 160 | success, |
| 161 | }, { |
| 162 | ` |
| 163 | type f32 |
| 164 | type T<x> |
Ben Clayton | e6e96de | 2022-05-09 18:08:23 +0000 | [diff] [blame] | 165 | fn f(T< T<f32> >)`, |
Ben Clayton | b85e692 | 2022-02-02 23:07:11 +0000 | [diff] [blame] | 166 | success, |
| 167 | }, { |
Ben Clayton | 5a69597 | 2022-05-16 09:48:41 +0000 | [diff] [blame] | 168 | ` |
Ben Clayton | 17770f5 | 2024-02-20 17:34:27 +0000 | [diff] [blame] | 169 | type a |
| 170 | type b |
| 171 | type c |
| 172 | match S: a | b | c |
| 173 | type V<N: num, T> |
dan sinclair | 4ac9ba9 | 2024-08-19 19:21:19 +0000 | [diff] [blame] | 174 | implicit(N: num, T: S, U: S) fn f<I: V<N, T> >(V<N, U>) -> I`, |
Ben Clayton | 17770f5 | 2024-02-20 17:34:27 +0000 | [diff] [blame] | 175 | success, |
| 176 | }, { |
| 177 | ` |
Ben Clayton | 5a69597 | 2022-05-16 09:48:41 +0000 | [diff] [blame] | 178 | type f32 |
| 179 | op -(f32)`, |
| 180 | success, |
| 181 | }, { |
| 182 | ` |
| 183 | type f32 |
| 184 | type T<x> |
| 185 | op +(T<f32>, T<f32>)`, |
| 186 | success, |
| 187 | }, { |
| 188 | ` |
| 189 | type f32 |
Ben Clayton | 54a104e | 2023-02-22 20:04:40 +0000 | [diff] [blame] | 190 | ctor f32(f32)`, |
Ben Clayton | 5a69597 | 2022-05-16 09:48:41 +0000 | [diff] [blame] | 191 | success, |
| 192 | }, { |
| 193 | ` |
| 194 | type f32 |
| 195 | type T<x> |
Ben Clayton | 54a104e | 2023-02-22 20:04:40 +0000 | [diff] [blame] | 196 | ctor f32(T<f32>)`, |
Ben Clayton | 5a69597 | 2022-05-16 09:48:41 +0000 | [diff] [blame] | 197 | success, |
| 198 | }, { |
| 199 | ` |
| 200 | type f32 |
| 201 | type i32 |
| 202 | conv f32(i32)`, |
| 203 | success, |
| 204 | }, { |
| 205 | ` |
| 206 | type f32 |
| 207 | type T<x> |
| 208 | conv f32(T<f32>)`, |
| 209 | success, |
| 210 | }, { |
Ben Clayton | d849032 | 2023-02-22 13:52:21 +0000 | [diff] [blame] | 211 | ` |
| 212 | type f32 |
| 213 | @must_use fn f() -> f32`, |
| 214 | success, |
| 215 | }, { |
Ben Clayton | f6c20f1 | 2024-02-20 14:45:27 +0000 | [diff] [blame] | 216 | ` |
| 217 | type f32 |
James Price | 53f9392 | 2024-06-11 18:24:06 +0000 | [diff] [blame] | 218 | @member_function fn f(f32)`, |
| 219 | success, |
| 220 | }, { |
| 221 | ` |
| 222 | type f32 |
Ben Clayton | f6c20f1 | 2024-02-20 14:45:27 +0000 | [diff] [blame] | 223 | type P<T> |
| 224 | match m: f32 |
| 225 | fn f(m)`, |
| 226 | success, |
| 227 | }, { |
| 228 | ` |
| 229 | type f32 |
| 230 | type P<T> |
| 231 | match m: f32 |
| 232 | fn f(P<m>)`, |
| 233 | success, |
| 234 | }, { |
Ben Clayton | b85e692 | 2022-02-02 23:07:11 +0000 | [diff] [blame] | 235 | `enum E {A A}`, |
| 236 | ` |
Ben Clayton | c768e64 | 2022-07-26 17:49:54 +0000 | [diff] [blame] | 237 | file.txt:1:11 duplicate enum entry 'A' |
Ben Clayton | b85e692 | 2022-02-02 23:07:11 +0000 | [diff] [blame] | 238 | `, |
| 239 | }, |
| 240 | { |
| 241 | `type X type X`, |
| 242 | ` |
| 243 | file.txt:1:13 'X' already declared |
| 244 | First declared here: file.txt:1:6`, |
| 245 | }, { |
Ben Clayton | e3e91c0 | 2022-06-01 20:44:50 +0000 | [diff] [blame] | 246 | `@meow type X`, |
Ben Clayton | b85e692 | 2022-02-02 23:07:11 +0000 | [diff] [blame] | 247 | ` |
Ben Clayton | e3e91c0 | 2022-06-01 20:44:50 +0000 | [diff] [blame] | 248 | file.txt:1:2 unknown attribute |
Ben Clayton | b85e692 | 2022-02-02 23:07:11 +0000 | [diff] [blame] | 249 | `, |
| 250 | }, { |
Ben Clayton | e3e91c0 | 2022-06-01 20:44:50 +0000 | [diff] [blame] | 251 | `@display("Y", "Z") type X`, |
Ben Clayton | b85e692 | 2022-02-02 23:07:11 +0000 | [diff] [blame] | 252 | ` |
Ben Clayton | e3e91c0 | 2022-06-01 20:44:50 +0000 | [diff] [blame] | 253 | file.txt:1:2 expected a single value for 'display' attribute`, |
Ben Clayton | b85e692 | 2022-02-02 23:07:11 +0000 | [diff] [blame] | 254 | }, { |
| 255 | ` |
| 256 | enum e { a } |
| 257 | enum e { b }`, |
| 258 | ` |
| 259 | file.txt:2:6 'e' already declared |
| 260 | First declared here: file.txt:1:6`, |
| 261 | }, { |
| 262 | ` |
| 263 | type X |
| 264 | match X : X`, |
| 265 | ` |
| 266 | file.txt:2:7 'X' already declared |
| 267 | First declared here: file.txt:1:6`, |
| 268 | }, { |
| 269 | `type T<X> |
| 270 | match M : T`, |
| 271 | `file.txt:2:11 'T' requires 1 template arguments, but 0 were provided`, |
| 272 | }, { |
| 273 | ` |
| 274 | match x: y`, |
| 275 | ` |
| 276 | file.txt:1:10 cannot resolve 'y' |
| 277 | `, |
| 278 | }, { |
| 279 | ` |
| 280 | type a |
| 281 | match x: a | b`, |
| 282 | ` |
| 283 | file.txt:2:14 cannot resolve 'b' |
| 284 | `, |
| 285 | }, { |
| 286 | ` |
| 287 | type a |
Ben Clayton | b85e692 | 2022-02-02 23:07:11 +0000 | [diff] [blame] | 288 | type b |
| 289 | match x: a | b | a`, |
| 290 | ` |
| 291 | file.txt:3:18 duplicate option 'a' in matcher |
| 292 | First declared here: file.txt:3:10 |
| 293 | `, |
| 294 | }, { |
| 295 | ` |
| 296 | enum e { a c } |
Ben Clayton | c768e64 | 2022-07-26 17:49:54 +0000 | [diff] [blame] | 297 | match x: e.a | e.b | e.c`, |
Ben Clayton | b85e692 | 2022-02-02 23:07:11 +0000 | [diff] [blame] | 298 | ` |
Ben Clayton | c768e64 | 2022-07-26 17:49:54 +0000 | [diff] [blame] | 299 | file.txt:2:18 enum 'e' does not contain 'b' |
Ben Clayton | b85e692 | 2022-02-02 23:07:11 +0000 | [diff] [blame] | 300 | `, |
| 301 | }, { |
| 302 | ` |
| 303 | enum e { a } |
Ben Clayton | c768e64 | 2022-07-26 17:49:54 +0000 | [diff] [blame] | 304 | match x: e.a |
| 305 | match x: e.a`, |
Ben Clayton | b85e692 | 2022-02-02 23:07:11 +0000 | [diff] [blame] | 306 | ` |
| 307 | file.txt:3:7 'x' already declared |
| 308 | First declared here: file.txt:2:7 |
| 309 | `, |
| 310 | }, { |
| 311 | ` |
| 312 | type t |
| 313 | match x: t |
| 314 | match y: x`, |
| 315 | ` |
Ben Clayton | c768e64 | 2022-07-26 17:49:54 +0000 | [diff] [blame] | 316 | file.txt:3:10 'x' resolves to type matcher 'x' but type is expected |
Ben Clayton | b85e692 | 2022-02-02 23:07:11 +0000 | [diff] [blame] | 317 | `, |
| 318 | }, { |
| 319 | `fn f(u)`, |
| 320 | `file.txt:1:6 cannot resolve 'u'`, |
| 321 | }, { |
| 322 | `fn f() -> u`, |
| 323 | `file.txt:1:11 cannot resolve 'u'`, |
| 324 | }, { |
dan sinclair | 4ac9ba9 | 2024-08-19 19:21:19 +0000 | [diff] [blame] | 325 | `implicit(T: u) fn f()`, |
| 326 | `file.txt:1:13 cannot resolve 'u'`, |
Ben Clayton | b85e692 | 2022-02-02 23:07:11 +0000 | [diff] [blame] | 327 | }, { |
| 328 | ` |
| 329 | enum e { a } |
| 330 | fn f() -> e`, |
| 331 | `file.txt:2:11 cannot use 'e' as return type. Must be a type or template type`, |
| 332 | }, { |
| 333 | ` |
| 334 | type T<x> |
| 335 | fn f(T<u>)`, |
| 336 | `file.txt:2:8 cannot resolve 'u'`, |
| 337 | }, { |
| 338 | ` |
| 339 | type x |
dan sinclair | 4ac9ba9 | 2024-08-19 19:21:19 +0000 | [diff] [blame] | 340 | implicit(T) fn f(T<x>)`, |
| 341 | `file.txt:2:18 'T' template parameters do not accept template arguments`, |
Ben Clayton | b85e692 | 2022-02-02 23:07:11 +0000 | [diff] [blame] | 342 | }, { |
| 343 | ` |
| 344 | type A<N: num> |
| 345 | type B |
| 346 | fn f(A<B>)`, |
| 347 | `file.txt:3:8 cannot use type 'B' as template number`, |
| 348 | }, { |
| 349 | ` |
Ben Clayton | b85e692 | 2022-02-02 23:07:11 +0000 | [diff] [blame] | 350 | type T |
| 351 | type P<N: num> |
| 352 | match m: T |
| 353 | fn f(P<m>)`, |
| 354 | `file.txt:4:8 cannot use type matcher 'm' as template number`, |
| 355 | }, { |
| 356 | ` |
| 357 | type P<N: num> |
| 358 | enum E { b } |
| 359 | fn f(P<E>)`, |
| 360 | `file.txt:3:8 cannot use enum 'E' as template number`, |
| 361 | }, { |
| 362 | ` |
| 363 | type P<N: num> |
| 364 | enum E { a b } |
Ben Clayton | c768e64 | 2022-07-26 17:49:54 +0000 | [diff] [blame] | 365 | match m: E.a | E.b |
Ben Clayton | b85e692 | 2022-02-02 23:07:11 +0000 | [diff] [blame] | 366 | fn f(P<m>)`, |
| 367 | `file.txt:4:8 cannot use enum matcher 'm' as template number`, |
| 368 | }, { |
| 369 | ` |
| 370 | type P<N: num> |
| 371 | enum E { a b } |
Ben Clayton | c768e64 | 2022-07-26 17:49:54 +0000 | [diff] [blame] | 372 | match m: E.a | E.b |
dan sinclair | 4ac9ba9 | 2024-08-19 19:21:19 +0000 | [diff] [blame] | 373 | implicit(M: m) fn f(P<M>)`, |
| 374 | `file.txt:4:23 cannot use template enum 'E' as template number`, |
Ben Clayton | b85e692 | 2022-02-02 23:07:11 +0000 | [diff] [blame] | 375 | }, { |
| 376 | ` |
Ben Clayton | e6e96de | 2022-05-09 18:08:23 +0000 | [diff] [blame] | 377 | type i |
| 378 | enum e { a } |
| 379 | op << (i) -> e`, |
| 380 | `file.txt:3:14 cannot use 'e' as return type. Must be a type or template type`, |
| 381 | }, { |
| 382 | ` |
| 383 | type T<x> |
| 384 | op << (T<u>)`, |
| 385 | `file.txt:2:10 cannot resolve 'u'`, |
| 386 | }, { |
| 387 | ` |
| 388 | op << ()`, |
| 389 | `file.txt:1:4 operators must have either 1 or 2 parameters`, |
| 390 | }, { |
| 391 | ` |
| 392 | type i |
| 393 | op << (i, i, i)`, |
| 394 | `file.txt:2:4 operators must have either 1 or 2 parameters`, |
| 395 | }, { |
| 396 | ` |
| 397 | type x |
dan sinclair | 4ac9ba9 | 2024-08-19 19:21:19 +0000 | [diff] [blame] | 398 | implicit(T) op << (T<x>)`, |
| 399 | `file.txt:2:20 'T' template parameters do not accept template arguments`, |
Ben Clayton | e6e96de | 2022-05-09 18:08:23 +0000 | [diff] [blame] | 400 | }, { |
| 401 | ` |
| 402 | type A<N: num> |
| 403 | type B |
| 404 | op << (A<B>)`, |
| 405 | `file.txt:3:10 cannot use type 'B' as template number`, |
| 406 | }, { |
| 407 | ` |
| 408 | type A<N> |
| 409 | enum E { b } |
Ben Clayton | c768e64 | 2022-07-26 17:49:54 +0000 | [diff] [blame] | 410 | match M: E.b |
| 411 | op << (A<M>)`, |
| 412 | `file.txt:4:10 cannot use enum matcher 'M' as template type`, |
Ben Clayton | e6e96de | 2022-05-09 18:08:23 +0000 | [diff] [blame] | 413 | }, { |
| 414 | ` |
| 415 | type T |
| 416 | type P<N: num> |
| 417 | match m: T |
| 418 | op << (P<m>)`, |
| 419 | `file.txt:4:10 cannot use type matcher 'm' as template number`, |
| 420 | }, { |
| 421 | ` |
| 422 | type P<N: num> |
| 423 | enum E { b } |
| 424 | op << (P<E>)`, |
| 425 | `file.txt:3:10 cannot use enum 'E' as template number`, |
| 426 | }, { |
| 427 | ` |
| 428 | type P<N: num> |
| 429 | enum E { a b } |
Ben Clayton | c768e64 | 2022-07-26 17:49:54 +0000 | [diff] [blame] | 430 | match m: E.a | E.b |
Ben Clayton | e6e96de | 2022-05-09 18:08:23 +0000 | [diff] [blame] | 431 | op << (P<m>)`, |
| 432 | `file.txt:4:10 cannot use enum matcher 'm' as template number`, |
| 433 | }, { |
| 434 | ` |
| 435 | type P<N: num> |
| 436 | enum E { a b } |
Ben Clayton | c768e64 | 2022-07-26 17:49:54 +0000 | [diff] [blame] | 437 | match m: E.a | E.b |
dan sinclair | 4ac9ba9 | 2024-08-19 19:21:19 +0000 | [diff] [blame] | 438 | implicit(M: m) op << (P<M>)`, |
| 439 | `file.txt:4:25 cannot use template enum 'E' as template number`, |
Ben Clayton | e6e96de | 2022-05-09 18:08:23 +0000 | [diff] [blame] | 440 | }, { |
| 441 | ` |
Ben Clayton | 5a69597 | 2022-05-16 09:48:41 +0000 | [diff] [blame] | 442 | type i |
| 443 | enum e { a } |
Ben Clayton | 54a104e | 2023-02-22 20:04:40 +0000 | [diff] [blame] | 444 | ctor F(i) -> e`, |
Ben Clayton | 5a69597 | 2022-05-16 09:48:41 +0000 | [diff] [blame] | 445 | `file.txt:3:14 cannot use 'e' as return type. Must be a type or template type`, |
| 446 | }, { |
| 447 | ` |
| 448 | type T<x> |
Ben Clayton | 54a104e | 2023-02-22 20:04:40 +0000 | [diff] [blame] | 449 | ctor F(T<u>)`, |
Ben Clayton | 5a69597 | 2022-05-16 09:48:41 +0000 | [diff] [blame] | 450 | `file.txt:2:10 cannot resolve 'u'`, |
| 451 | }, { |
| 452 | ` |
| 453 | type x |
dan sinclair | 4ac9ba9 | 2024-08-19 19:21:19 +0000 | [diff] [blame] | 454 | implicit(T) ctor F(T<x>)`, |
| 455 | `file.txt:2:20 'T' template parameters do not accept template arguments`, |
Ben Clayton | 5a69597 | 2022-05-16 09:48:41 +0000 | [diff] [blame] | 456 | }, { |
| 457 | ` |
| 458 | type A<N: num> |
| 459 | type B |
Ben Clayton | 54a104e | 2023-02-22 20:04:40 +0000 | [diff] [blame] | 460 | ctor F(A<B>)`, |
Ben Clayton | 5a69597 | 2022-05-16 09:48:41 +0000 | [diff] [blame] | 461 | `file.txt:3:10 cannot use type 'B' as template number`, |
| 462 | }, { |
| 463 | ` |
| 464 | type A<N> |
| 465 | enum E { b } |
Ben Clayton | c768e64 | 2022-07-26 17:49:54 +0000 | [diff] [blame] | 466 | match M: E.b |
Ben Clayton | 54a104e | 2023-02-22 20:04:40 +0000 | [diff] [blame] | 467 | ctor F(A<M>)`, |
Ben Clayton | c768e64 | 2022-07-26 17:49:54 +0000 | [diff] [blame] | 468 | `file.txt:4:10 cannot use enum matcher 'M' as template type`, |
Ben Clayton | 5a69597 | 2022-05-16 09:48:41 +0000 | [diff] [blame] | 469 | }, { |
| 470 | ` |
| 471 | type T |
| 472 | type P<N: num> |
| 473 | match m: T |
Ben Clayton | 54a104e | 2023-02-22 20:04:40 +0000 | [diff] [blame] | 474 | ctor F(P<m>)`, |
Ben Clayton | 5a69597 | 2022-05-16 09:48:41 +0000 | [diff] [blame] | 475 | `file.txt:4:10 cannot use type matcher 'm' as template number`, |
| 476 | }, { |
| 477 | ` |
| 478 | type P<N: num> |
| 479 | enum E { b } |
Ben Clayton | 54a104e | 2023-02-22 20:04:40 +0000 | [diff] [blame] | 480 | ctor F(P<E>)`, |
Ben Clayton | 5a69597 | 2022-05-16 09:48:41 +0000 | [diff] [blame] | 481 | `file.txt:3:10 cannot use enum 'E' as template number`, |
| 482 | }, { |
| 483 | ` |
| 484 | type P<N: num> |
| 485 | enum E { a b } |
Ben Clayton | c768e64 | 2022-07-26 17:49:54 +0000 | [diff] [blame] | 486 | match m: E.a | E.b |
Ben Clayton | 54a104e | 2023-02-22 20:04:40 +0000 | [diff] [blame] | 487 | ctor F(P<m>)`, |
Ben Clayton | 5a69597 | 2022-05-16 09:48:41 +0000 | [diff] [blame] | 488 | `file.txt:4:10 cannot use enum matcher 'm' as template number`, |
| 489 | }, { |
| 490 | ` |
| 491 | type P<N: num> |
| 492 | enum E { a b } |
Ben Clayton | c768e64 | 2022-07-26 17:49:54 +0000 | [diff] [blame] | 493 | match m: E.a | E.b |
dan sinclair | 4ac9ba9 | 2024-08-19 19:21:19 +0000 | [diff] [blame] | 494 | implicit(M: m) ctor F(P<M>)`, |
| 495 | `file.txt:4:25 cannot use template enum 'E' as template number`, |
Ben Clayton | 5a69597 | 2022-05-16 09:48:41 +0000 | [diff] [blame] | 496 | }, { |
| 497 | ` |
| 498 | conv F()`, |
| 499 | `file.txt:1:6 conversions must have a single parameter`, |
| 500 | }, { |
| 501 | ` |
| 502 | type i |
| 503 | conv F(i, i, i)`, |
| 504 | `file.txt:2:6 conversions must have a single parameter`, |
| 505 | }, { |
| 506 | ` |
| 507 | type i |
| 508 | enum e { a } |
| 509 | conv F(i) -> e`, |
| 510 | `file.txt:3:14 cannot use 'e' as return type. Must be a type or template type`, |
| 511 | }, { |
| 512 | ` |
| 513 | type T<x> |
| 514 | conv F(T<u>)`, |
| 515 | `file.txt:2:10 cannot resolve 'u'`, |
| 516 | }, { |
| 517 | ` |
| 518 | type x |
dan sinclair | 4ac9ba9 | 2024-08-19 19:21:19 +0000 | [diff] [blame] | 519 | implicit(T) conv F(T<x>)`, |
| 520 | `file.txt:2:20 'T' template parameters do not accept template arguments`, |
Ben Clayton | 5a69597 | 2022-05-16 09:48:41 +0000 | [diff] [blame] | 521 | }, { |
| 522 | ` |
| 523 | type A<N: num> |
| 524 | type B |
| 525 | conv F(A<B>)`, |
| 526 | `file.txt:3:10 cannot use type 'B' as template number`, |
| 527 | }, { |
| 528 | ` |
| 529 | type A<N> |
| 530 | enum E { b } |
Ben Clayton | c768e64 | 2022-07-26 17:49:54 +0000 | [diff] [blame] | 531 | match M: E.b |
| 532 | conv F(A<M>)`, |
| 533 | `file.txt:4:10 cannot use enum matcher 'M' as template type`, |
Ben Clayton | 5a69597 | 2022-05-16 09:48:41 +0000 | [diff] [blame] | 534 | }, { |
| 535 | ` |
| 536 | type T |
| 537 | type P<N: num> |
| 538 | match m: T |
| 539 | conv F(P<m>)`, |
| 540 | `file.txt:4:10 cannot use type matcher 'm' as template number`, |
| 541 | }, { |
| 542 | ` |
| 543 | type P<N: num> |
| 544 | enum E { b } |
| 545 | conv F(P<E>)`, |
| 546 | `file.txt:3:10 cannot use enum 'E' as template number`, |
| 547 | }, { |
| 548 | ` |
| 549 | type P<N: num> |
| 550 | enum E { a b } |
Ben Clayton | c768e64 | 2022-07-26 17:49:54 +0000 | [diff] [blame] | 551 | match m: E.a | E.b |
Ben Clayton | 5a69597 | 2022-05-16 09:48:41 +0000 | [diff] [blame] | 552 | conv F(P<m>)`, |
| 553 | `file.txt:4:10 cannot use enum matcher 'm' as template number`, |
| 554 | }, { |
| 555 | ` |
| 556 | type P<N: num> |
| 557 | enum E { a b } |
Ben Clayton | c768e64 | 2022-07-26 17:49:54 +0000 | [diff] [blame] | 558 | match m: E.a | E.b |
dan sinclair | 4ac9ba9 | 2024-08-19 19:21:19 +0000 | [diff] [blame] | 559 | implicit(M: m) conv F(P<M>)`, |
| 560 | `file.txt:4:25 cannot use template enum 'E' as template number`, |
Ben Clayton | 55ceebe | 2022-12-14 21:18:23 +0000 | [diff] [blame] | 561 | }, { |
| 562 | ` |
Ben Clayton | d849032 | 2023-02-22 13:52:21 +0000 | [diff] [blame] | 563 | @must_use fn f()`, |
| 564 | `file.txt:1:2 @must_use can only be used on a function with a return type`, |
Ben Clayton | 17770f5 | 2024-02-20 17:34:27 +0000 | [diff] [blame] | 565 | }, { |
| 566 | ` |
| 567 | type f32 |
James Price | 53f9392 | 2024-06-11 18:24:06 +0000 | [diff] [blame] | 568 | @member_function(0) fn f(f32)`, |
| 569 | `file.txt:2:2 unexpected value for member_function attribute`, |
| 570 | }, { |
| 571 | ` |
| 572 | @member_function fn f()`, |
| 573 | `file.txt:1:2 @member_function can only be used on a function with at least one parameter`, |
| 574 | }, { |
| 575 | ` |
dan sinclair | 4ac9ba9 | 2024-08-19 19:21:19 +0000 | [diff] [blame] | 576 | implicit(T) fn f<T>()`, |
| 577 | `file.txt:1:18 'T' already declared |
| 578 | First declared here: file.txt:1:10`, |
Ben Clayton | b85e692 | 2022-02-02 23:07:11 +0000 | [diff] [blame] | 579 | }, |
| 580 | } { |
| 581 | |
| 582 | ast, err := parser.Parse(strings.TrimSpace(string(test.src)), "file.txt") |
| 583 | if err != nil { |
Ben Clayton | c768e64 | 2022-07-26 17:49:54 +0000 | [diff] [blame] | 584 | t.Errorf("While parsing:\n%s\nUnexpected parser error: %v", test.src, err) |
Ben Clayton | b85e692 | 2022-02-02 23:07:11 +0000 | [diff] [blame] | 585 | continue |
| 586 | } |
| 587 | |
| 588 | expectErr := strings.TrimSpace(test.err) |
| 589 | _, err = resolver.Resolve(ast) |
| 590 | if err != nil { |
| 591 | gotErr := strings.TrimSpace(fmt.Sprint(err)) |
| 592 | if gotErr != expectErr { |
| 593 | t.Errorf("While parsing:\n%s\nGot error:\n%s\nExpected:\n%s", test.src, gotErr, expectErr) |
| 594 | } |
| 595 | } else if expectErr != success { |
| 596 | t.Errorf("While parsing:\n%s\nGot no error, expected error:\n%s", test.src, expectErr) |
| 597 | } |
| 598 | } |
| 599 | } |