| ... | ... | @@ -1,328 +1,253 @@ |
| 1 | 1 | const tests = @import("tests.zig"); |
| 2 | 2 | |
| 3 | 3 | pub fn addCases(cases: &tests.CompileErrorContext) { |
| 4 | | cases.add("wrong return type for main", |
| 5 | | \\pub fn main() { } |
| 6 | | , ".tmp_source.zig:1:15: error: expected return type of main to be '%void', instead is 'void'"); |
| 7 | | |
| 8 | | cases.add("double ?? on main return value", |
| 9 | | \\pub fn main() -> ??void { |
| 10 | | \\} |
| 11 | | , ".tmp_source.zig:1:18: error: expected return type of main to be '%void', instead is '??void'"); |
| 12 | | |
| 13 | | cases.add("setting a section on an extern variable", |
| 14 | | \\extern var foo: i32 section(".text2"); |
| 15 | | \\extern fn entry() -> i32 { |
| 16 | | \\ return foo; |
| 17 | | \\} |
| 18 | | \\comptime { @export("entry", entry); } |
| 19 | | , |
| 20 | | ".tmp_source.zig:1:29: error: cannot set section of external variable 'foo'"); |
| 21 | | |
| 22 | | cases.add("setting a section on a local variable", |
| 23 | | \\extern fn entry() -> i32 { |
| 24 | | \\ var foo: i32 section(".text2") = 1234; |
| 25 | | \\ return foo; |
| 26 | | \\} |
| 27 | | \\comptime { @export("entry", entry); } |
| 28 | | , |
| 29 | | ".tmp_source.zig:2:26: error: cannot set section of local variable 'foo'"); |
| 30 | | |
| 31 | | cases.add("setting a section on an extern fn", |
| 32 | | \\extern fn foo() section(".text2"); |
| 33 | | \\extern fn entry() { |
| 34 | | \\ foo(); |
| 35 | | \\} |
| 36 | | \\comptime { @export("entry", entry); } |
| 37 | | , |
| 38 | | ".tmp_source.zig:1:25: error: cannot set section of external function 'foo'"); |
| 39 | | |
| 40 | | cases.add("wrong types given to exportWithLinkage", |
| 41 | | \\extern fn entry() { } |
| 42 | | \\comptime { |
| 43 | | \\ @exportWithLinkage("entry", entry, u32(1234)); |
| 44 | | \\} |
| 45 | | , |
| 46 | | ".tmp_source.zig:3:43: error: expected type 'GlobalLinkage', found 'u32'"); |
| 47 | | |
| 48 | 4 | cases.add("implicit semicolon - block statement", |
| 49 | | \\extern fn entry() { |
| 5 | \\export fn entry() { |
| 50 | 6 | \\ {} |
| 51 | 7 | \\ var good = {}; |
| 52 | 8 | \\ ({}) |
| 53 | 9 | \\ var bad = {}; |
| 54 | 10 | \\} |
| 55 | | \\comptime {@export("entry", entry);} |
| 56 | 11 | , ".tmp_source.zig:5:5: error: invalid token: 'var'"); |
| 57 | 12 | |
| 58 | 13 | cases.add("implicit semicolon - block expr", |
| 59 | | \\extern fn entry() { |
| 14 | \\export fn entry() { |
| 60 | 15 | \\ _ = {}; |
| 61 | 16 | \\ var good = {}; |
| 62 | 17 | \\ _ = {} |
| 63 | 18 | \\ var bad = {}; |
| 64 | 19 | \\} |
| 65 | | \\comptime {@export("entry", entry);} |
| 66 | 20 | , ".tmp_source.zig:5:5: error: invalid token: 'var'"); |
| 67 | 21 | |
| 68 | 22 | cases.add("implicit semicolon - comptime statement", |
| 69 | | \\extern fn entry() { |
| 23 | \\export fn entry() { |
| 70 | 24 | \\ comptime {} |
| 71 | 25 | \\ var good = {}; |
| 72 | 26 | \\ comptime ({}) |
| 73 | 27 | \\ var bad = {}; |
| 74 | 28 | \\} |
| 75 | | \\comptime {@export("entry", entry);} |
| 76 | 29 | , ".tmp_source.zig:5:5: error: invalid token: 'var'"); |
| 77 | 30 | |
| 78 | 31 | cases.add("implicit semicolon - comptime expression", |
| 79 | | \\extern fn entry() { |
| 32 | \\export fn entry() { |
| 80 | 33 | \\ _ = comptime {}; |
| 81 | 34 | \\ var good = {}; |
| 82 | 35 | \\ _ = comptime {} |
| 83 | 36 | \\ var bad = {}; |
| 84 | 37 | \\} |
| 85 | | \\comptime {@export("entry", entry);} |
| 86 | 38 | , ".tmp_source.zig:5:5: error: invalid token: 'var'"); |
| 87 | 39 | |
| 88 | 40 | cases.add("implicit semicolon - defer", |
| 89 | | \\extern fn entry() { |
| 41 | \\export fn entry() { |
| 90 | 42 | \\ defer {} |
| 91 | 43 | \\ var good = {}; |
| 92 | 44 | \\ defer ({}) |
| 93 | 45 | \\ var bad = {}; |
| 94 | 46 | \\} |
| 95 | | \\comptime {@export("entry", entry);} |
| 96 | 47 | , ".tmp_source.zig:5:5: error: expected token ';', found 'var'"); |
| 97 | 48 | |
| 98 | 49 | cases.add("implicit semicolon - if statement", |
| 99 | | \\extern fn entry() { |
| 50 | \\export fn entry() { |
| 100 | 51 | \\ if(true) {} |
| 101 | 52 | \\ var good = {}; |
| 102 | 53 | \\ if(true) ({}) |
| 103 | 54 | \\ var bad = {}; |
| 104 | 55 | \\} |
| 105 | | \\comptime {@export("entry", entry);} |
| 106 | 56 | , ".tmp_source.zig:5:5: error: invalid token: 'var'"); |
| 107 | 57 | |
| 108 | 58 | cases.add("implicit semicolon - if expression", |
| 109 | | \\extern fn entry() { |
| 59 | \\export fn entry() { |
| 110 | 60 | \\ _ = if(true) {}; |
| 111 | 61 | \\ var good = {}; |
| 112 | 62 | \\ _ = if(true) {} |
| 113 | 63 | \\ var bad = {}; |
| 114 | 64 | \\} |
| 115 | | \\comptime {@export("entry", entry);} |
| 116 | 65 | , ".tmp_source.zig:5:5: error: invalid token: 'var'"); |
| 117 | 66 | |
| 118 | 67 | cases.add("implicit semicolon - if-else statement", |
| 119 | | \\extern fn entry() { |
| 68 | \\export fn entry() { |
| 120 | 69 | \\ if(true) {} else {} |
| 121 | 70 | \\ var good = {}; |
| 122 | 71 | \\ if(true) ({}) else ({}) |
| 123 | 72 | \\ var bad = {}; |
| 124 | 73 | \\} |
| 125 | | \\comptime {@export("entry", entry);} |
| 126 | 74 | , ".tmp_source.zig:5:5: error: invalid token: 'var'"); |
| 127 | 75 | |
| 128 | 76 | cases.add("implicit semicolon - if-else expression", |
| 129 | | \\extern fn entry() { |
| 77 | \\export fn entry() { |
| 130 | 78 | \\ _ = if(true) {} else {}; |
| 131 | 79 | \\ var good = {}; |
| 132 | 80 | \\ _ = if(true) {} else {} |
| 133 | 81 | \\ var bad = {}; |
| 134 | 82 | \\} |
| 135 | | \\comptime {@export("entry", entry);} |
| 136 | 83 | , ".tmp_source.zig:5:5: error: invalid token: 'var'"); |
| 137 | 84 | |
| 138 | 85 | cases.add("implicit semicolon - if-else-if statement", |
| 139 | | \\extern fn entry() { |
| 86 | \\export fn entry() { |
| 140 | 87 | \\ if(true) {} else if(true) {} |
| 141 | 88 | \\ var good = {}; |
| 142 | 89 | \\ if(true) ({}) else if(true) ({}) |
| 143 | 90 | \\ var bad = {}; |
| 144 | 91 | \\} |
| 145 | | \\comptime {@export("entry", entry);} |
| 146 | 92 | , ".tmp_source.zig:5:5: error: invalid token: 'var'"); |
| 147 | 93 | |
| 148 | 94 | cases.add("implicit semicolon - if-else-if expression", |
| 149 | | \\extern fn entry() { |
| 95 | \\export fn entry() { |
| 150 | 96 | \\ _ = if(true) {} else if(true) {}; |
| 151 | 97 | \\ var good = {}; |
| 152 | 98 | \\ _ = if(true) {} else if(true) {} |
| 153 | 99 | \\ var bad = {}; |
| 154 | 100 | \\} |
| 155 | | \\comptime {@export("entry", entry);} |
| 156 | 101 | , ".tmp_source.zig:5:5: error: invalid token: 'var'"); |
| 157 | 102 | |
| 158 | 103 | cases.add("implicit semicolon - if-else-if-else statement", |
| 159 | | \\extern fn entry() { |
| 104 | \\export fn entry() { |
| 160 | 105 | \\ if(true) {} else if(true) {} else {} |
| 161 | 106 | \\ var good = {}; |
| 162 | 107 | \\ if(true) ({}) else if(true) ({}) else ({}) |
| 163 | 108 | \\ var bad = {}; |
| 164 | 109 | \\} |
| 165 | | \\comptime {@export("entry", entry);} |
| 166 | 110 | , ".tmp_source.zig:5:5: error: invalid token: 'var'"); |
| 167 | 111 | |
| 168 | 112 | cases.add("implicit semicolon - if-else-if-else expression", |
| 169 | | \\extern fn entry() { |
| 113 | \\export fn entry() { |
| 170 | 114 | \\ _ = if(true) {} else if(true) {} else {}; |
| 171 | 115 | \\ var good = {}; |
| 172 | 116 | \\ _ = if(true) {} else if(true) {} else {} |
| 173 | 117 | \\ var bad = {}; |
| 174 | 118 | \\} |
| 175 | | \\comptime {@export("entry", entry);} |
| 176 | 119 | , ".tmp_source.zig:5:5: error: invalid token: 'var'"); |
| 177 | 120 | |
| 178 | 121 | cases.add("implicit semicolon - test statement", |
| 179 | | \\extern fn entry() { |
| 122 | \\export fn entry() { |
| 180 | 123 | \\ if (foo()) |_| {} |
| 181 | 124 | \\ var good = {}; |
| 182 | 125 | \\ if (foo()) |_| ({}) |
| 183 | 126 | \\ var bad = {}; |
| 184 | 127 | \\} |
| 185 | | \\comptime {@export("entry", entry);} |
| 186 | 128 | , ".tmp_source.zig:5:5: error: invalid token: 'var'"); |
| 187 | 129 | |
| 188 | 130 | cases.add("implicit semicolon - test expression", |
| 189 | | \\extern fn entry() { |
| 131 | \\export fn entry() { |
| 190 | 132 | \\ _ = if (foo()) |_| {}; |
| 191 | 133 | \\ var good = {}; |
| 192 | 134 | \\ _ = if (foo()) |_| {} |
| 193 | 135 | \\ var bad = {}; |
| 194 | 136 | \\} |
| 195 | | \\comptime {@export("entry", entry);} |
| 196 | 137 | , ".tmp_source.zig:5:5: error: invalid token: 'var'"); |
| 197 | 138 | |
| 198 | 139 | cases.add("implicit semicolon - while statement", |
| 199 | | \\extern fn entry() { |
| 140 | \\export fn entry() { |
| 200 | 141 | \\ while(true) {} |
| 201 | 142 | \\ var good = {}; |
| 202 | 143 | \\ while(true) ({}) |
| 203 | 144 | \\ var bad = {}; |
| 204 | 145 | \\} |
| 205 | | \\comptime {@export("entry", entry);} |
| 206 | 146 | , ".tmp_source.zig:5:5: error: invalid token: 'var'"); |
| 207 | 147 | |
| 208 | 148 | cases.add("implicit semicolon - while expression", |
| 209 | | \\extern fn entry() { |
| 149 | \\export fn entry() { |
| 210 | 150 | \\ _ = while(true) {}; |
| 211 | 151 | \\ var good = {}; |
| 212 | 152 | \\ _ = while(true) {} |
| 213 | 153 | \\ var bad = {}; |
| 214 | 154 | \\} |
| 215 | | \\comptime {@export("entry", entry);} |
| 216 | 155 | , ".tmp_source.zig:5:5: error: invalid token: 'var'"); |
| 217 | 156 | |
| 218 | 157 | cases.add("implicit semicolon - while-continue statement", |
| 219 | | \\extern fn entry() { |
| 158 | \\export fn entry() { |
| 220 | 159 | \\ while(true):({}) {} |
| 221 | 160 | \\ var good = {}; |
| 222 | 161 | \\ while(true):({}) ({}) |
| 223 | 162 | \\ var bad = {}; |
| 224 | 163 | \\} |
| 225 | | \\comptime {@export("entry", entry);} |
| 226 | 164 | , ".tmp_source.zig:5:5: error: invalid token: 'var'"); |
| 227 | 165 | |
| 228 | 166 | cases.add("implicit semicolon - while-continue expression", |
| 229 | | \\extern fn entry() { |
| 167 | \\export fn entry() { |
| 230 | 168 | \\ _ = while(true):({}) {}; |
| 231 | 169 | \\ var good = {}; |
| 232 | 170 | \\ _ = while(true):({}) {} |
| 233 | 171 | \\ var bad = {}; |
| 234 | 172 | \\} |
| 235 | | \\comptime {@export("entry", entry);} |
| 236 | 173 | , ".tmp_source.zig:5:5: error: invalid token: 'var'"); |
| 237 | 174 | |
| 238 | 175 | cases.add("implicit semicolon - for statement", |
| 239 | | \\extern fn entry() { |
| 176 | \\export fn entry() { |
| 240 | 177 | \\ for(foo()) {} |
| 241 | 178 | \\ var good = {}; |
| 242 | 179 | \\ for(foo()) ({}) |
| 243 | 180 | \\ var bad = {}; |
| 244 | 181 | \\} |
| 245 | | \\comptime {@export("entry", entry);} |
| 246 | 182 | , ".tmp_source.zig:5:5: error: invalid token: 'var'"); |
| 247 | 183 | |
| 248 | 184 | cases.add("implicit semicolon - for expression", |
| 249 | | \\extern fn entry() { |
| 185 | \\export fn entry() { |
| 250 | 186 | \\ _ = for(foo()) {}; |
| 251 | 187 | \\ var good = {}; |
| 252 | 188 | \\ _ = for(foo()) {} |
| 253 | 189 | \\ var bad = {}; |
| 254 | 190 | \\} |
| 255 | | \\comptime {@export("entry", entry);} |
| 256 | 191 | , ".tmp_source.zig:5:5: error: invalid token: 'var'"); |
| 257 | 192 | |
| 258 | 193 | cases.add("multiple function definitions", |
| 259 | 194 | \\fn a() {} |
| 260 | 195 | \\fn a() {} |
| 261 | | \\comptime {@export("entry", entry);} |
| 262 | | \\extern fn entry() { a(); } |
| 196 | \\export fn entry() { a(); } |
| 263 | 197 | , ".tmp_source.zig:2:1: error: redefinition of 'a'"); |
| 264 | 198 | |
| 265 | 199 | cases.add("unreachable with return", |
| 266 | 200 | \\fn a() -> noreturn {return;} |
| 267 | | \\comptime {@export("entry", entry);} |
| 268 | | \\extern fn entry() { a(); } |
| 201 | \\export fn entry() { a(); } |
| 269 | 202 | , ".tmp_source.zig:1:21: error: expected type 'noreturn', found 'void'"); |
| 270 | 203 | |
| 271 | 204 | cases.add("control reaches end of non-void function", |
| 272 | 205 | \\fn a() -> i32 {} |
| 273 | | \\comptime {@export("entry", entry);} |
| 274 | | \\extern fn entry() { _ = a(); } |
| 206 | \\export fn entry() { _ = a(); } |
| 275 | 207 | , ".tmp_source.zig:1:15: error: expected type 'i32', found 'void'"); |
| 276 | 208 | |
| 277 | 209 | cases.add("undefined function call", |
| 278 | | \\extern fn a() { |
| 210 | \\export fn a() { |
| 279 | 211 | \\ b(); |
| 280 | 212 | \\} |
| 281 | | \\comptime {@export("a", a);} |
| 282 | 213 | , ".tmp_source.zig:2:5: error: use of undeclared identifier 'b'"); |
| 283 | 214 | |
| 284 | 215 | cases.add("wrong number of arguments", |
| 285 | | \\extern fn a() { |
| 216 | \\export fn a() { |
| 286 | 217 | \\ b(1); |
| 287 | 218 | \\} |
| 288 | 219 | \\fn b(a: i32, b: i32, c: i32) { } |
| 289 | | \\comptime {@export("a", a);} |
| 290 | 220 | , ".tmp_source.zig:2:6: error: expected 3 arguments, found 1"); |
| 291 | 221 | |
| 292 | 222 | cases.add("invalid type", |
| 293 | 223 | \\fn a() -> bogus {} |
| 294 | | \\comptime {@export("entry", entry);} |
| 295 | | \\extern fn entry() { _ = a(); } |
| 224 | \\export fn entry() { _ = a(); } |
| 296 | 225 | , ".tmp_source.zig:1:11: error: use of undeclared identifier 'bogus'"); |
| 297 | 226 | |
| 298 | 227 | cases.add("pointer to unreachable", |
| 299 | 228 | \\fn a() -> &noreturn {} |
| 300 | | \\comptime {@export("entry", entry);} |
| 301 | | \\extern fn entry() { _ = a(); } |
| 229 | \\export fn entry() { _ = a(); } |
| 302 | 230 | , ".tmp_source.zig:1:12: error: pointer to unreachable not allowed"); |
| 303 | 231 | |
| 304 | 232 | cases.add("unreachable code", |
| 305 | | \\extern fn a() { |
| 233 | \\export fn a() { |
| 306 | 234 | \\ return; |
| 307 | 235 | \\ b(); |
| 308 | 236 | \\} |
| 309 | 237 | \\ |
| 310 | 238 | \\fn b() {} |
| 311 | | \\comptime {@export("a", a);} |
| 312 | 239 | , ".tmp_source.zig:3:5: error: unreachable code"); |
| 313 | 240 | |
| 314 | 241 | cases.add("bad import", |
| 315 | 242 | \\const bogus = @import("bogus-does-not-exist.zig"); |
| 316 | | \\comptime {@export("entry", entry);} |
| 317 | | \\extern fn entry() { bogus.bogo(); } |
| 243 | \\export fn entry() { bogus.bogo(); } |
| 318 | 244 | , ".tmp_source.zig:1:15: error: unable to find 'bogus-does-not-exist.zig'"); |
| 319 | 245 | |
| 320 | 246 | cases.add("undeclared identifier", |
| 321 | | \\extern fn a() { |
| 247 | \\export fn a() { |
| 322 | 248 | \\ b + |
| 323 | 249 | \\ c |
| 324 | 250 | \\} |
| 325 | | \\comptime {@export("a", a);} |
| 326 | 251 | , |
| 327 | 252 | ".tmp_source.zig:2:5: error: use of undeclared identifier 'b'", |
| 328 | 253 | ".tmp_source.zig:3:5: error: use of undeclared identifier 'c'"); |
| ... | ... | @@ -330,114 +255,99 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 330 | 255 | cases.add("parameter redeclaration", |
| 331 | 256 | \\fn f(a : i32, a : i32) { |
| 332 | 257 | \\} |
| 333 | | \\comptime {@export("entry", entry);} |
| 334 | | \\extern fn entry() { f(1, 2); } |
| 258 | \\export fn entry() { f(1, 2); } |
| 335 | 259 | , ".tmp_source.zig:1:15: error: redeclaration of variable 'a'"); |
| 336 | 260 | |
| 337 | 261 | cases.add("local variable redeclaration", |
| 338 | | \\extern fn f() { |
| 262 | \\export fn f() { |
| 339 | 263 | \\ const a : i32 = 0; |
| 340 | 264 | \\ const a = 0; |
| 341 | 265 | \\} |
| 342 | | \\comptime {@export("f", f);} |
| 343 | 266 | , ".tmp_source.zig:3:5: error: redeclaration of variable 'a'"); |
| 344 | 267 | |
| 345 | 268 | cases.add("local variable redeclares parameter", |
| 346 | 269 | \\fn f(a : i32) { |
| 347 | 270 | \\ const a = 0; |
| 348 | 271 | \\} |
| 349 | | \\comptime {@export("entry", entry);} |
| 350 | | \\extern fn entry() { f(1); } |
| 272 | \\export fn entry() { f(1); } |
| 351 | 273 | , ".tmp_source.zig:2:5: error: redeclaration of variable 'a'"); |
| 352 | 274 | |
| 353 | 275 | cases.add("variable has wrong type", |
| 354 | | \\extern fn f() -> i32 { |
| 276 | \\export fn f() -> i32 { |
| 355 | 277 | \\ const a = c"a"; |
| 356 | 278 | \\ a |
| 357 | 279 | \\} |
| 358 | | \\comptime {@export("f", f);} |
| 359 | 280 | , ".tmp_source.zig:3:5: error: expected type 'i32', found '&const u8'"); |
| 360 | 281 | |
| 361 | 282 | cases.add("if condition is bool, not int", |
| 362 | | \\extern fn f() { |
| 283 | \\export fn f() { |
| 363 | 284 | \\ if (0) {} |
| 364 | 285 | \\} |
| 365 | | \\comptime {@export("f", f);} |
| 366 | 286 | , ".tmp_source.zig:2:9: error: integer value 0 cannot be implicitly casted to type 'bool'"); |
| 367 | 287 | |
| 368 | 288 | cases.add("assign unreachable", |
| 369 | | \\extern fn f() { |
| 289 | \\export fn f() { |
| 370 | 290 | \\ const a = return; |
| 371 | 291 | \\} |
| 372 | | \\comptime {@export("f", f);} |
| 373 | 292 | , ".tmp_source.zig:2:5: error: unreachable code"); |
| 374 | 293 | |
| 375 | 294 | cases.add("unreachable variable", |
| 376 | | \\extern fn f() { |
| 295 | \\export fn f() { |
| 377 | 296 | \\ const a: noreturn = {}; |
| 378 | 297 | \\} |
| 379 | | \\comptime {@export("f", f);} |
| 380 | 298 | , ".tmp_source.zig:2:14: error: variable of type 'noreturn' not allowed"); |
| 381 | 299 | |
| 382 | 300 | cases.add("unreachable parameter", |
| 383 | 301 | \\fn f(a: noreturn) {} |
| 384 | | \\comptime {@export("entry", entry);} |
| 385 | | \\extern fn entry() { f(); } |
| 302 | \\export fn entry() { f(); } |
| 386 | 303 | , ".tmp_source.zig:1:9: error: parameter of type 'noreturn' not allowed"); |
| 387 | 304 | |
| 388 | 305 | cases.add("bad assignment target", |
| 389 | | \\extern fn f() { |
| 306 | \\export fn f() { |
| 390 | 307 | \\ 3 = 3; |
| 391 | 308 | \\} |
| 392 | | \\comptime {@export("f", f);} |
| 393 | 309 | , ".tmp_source.zig:2:7: error: cannot assign to constant"); |
| 394 | 310 | |
| 395 | 311 | cases.add("assign to constant variable", |
| 396 | | \\extern fn f() { |
| 312 | \\export fn f() { |
| 397 | 313 | \\ const a = 3; |
| 398 | 314 | \\ a = 4; |
| 399 | 315 | \\} |
| 400 | | \\comptime {@export("f", f);} |
| 401 | 316 | , ".tmp_source.zig:3:7: error: cannot assign to constant"); |
| 402 | 317 | |
| 403 | 318 | cases.add("use of undeclared identifier", |
| 404 | | \\extern fn f() { |
| 319 | \\export fn f() { |
| 405 | 320 | \\ b = 3; |
| 406 | 321 | \\} |
| 407 | | \\comptime {@export("f", f);} |
| 408 | 322 | , ".tmp_source.zig:2:5: error: use of undeclared identifier 'b'"); |
| 409 | 323 | |
| 410 | 324 | cases.add("const is a statement, not an expression", |
| 411 | | \\extern fn f() { |
| 325 | \\export fn f() { |
| 412 | 326 | \\ (const a = 0); |
| 413 | 327 | \\} |
| 414 | | \\comptime {@export("f", f);} |
| 415 | 328 | , ".tmp_source.zig:2:6: error: invalid token: 'const'"); |
| 416 | 329 | |
| 417 | 330 | cases.add("array access of undeclared identifier", |
| 418 | | \\extern fn f() { |
| 331 | \\export fn f() { |
| 419 | 332 | \\ i[i] = i[i]; |
| 420 | 333 | \\} |
| 421 | | \\comptime {@export("f", f);} |
| 422 | 334 | , ".tmp_source.zig:2:5: error: use of undeclared identifier 'i'", |
| 423 | 335 | ".tmp_source.zig:2:12: error: use of undeclared identifier 'i'"); |
| 424 | 336 | |
| 425 | 337 | cases.add("array access of non array", |
| 426 | | \\extern fn f() { |
| 338 | \\export fn f() { |
| 427 | 339 | \\ var bad : bool = undefined; |
| 428 | 340 | \\ bad[bad] = bad[bad]; |
| 429 | 341 | \\} |
| 430 | | \\comptime {@export("f", f);} |
| 431 | 342 | , ".tmp_source.zig:3:8: error: array access of non-array type 'bool'", |
| 432 | 343 | ".tmp_source.zig:3:19: error: array access of non-array type 'bool'"); |
| 433 | 344 | |
| 434 | 345 | cases.add("array access with non integer index", |
| 435 | | \\extern fn f() { |
| 346 | \\export fn f() { |
| 436 | 347 | \\ var array = "aoeu"; |
| 437 | 348 | \\ var bad = false; |
| 438 | 349 | \\ array[bad] = array[bad]; |
| 439 | 350 | \\} |
| 440 | | \\comptime {@export("f", f);} |
| 441 | 351 | , ".tmp_source.zig:4:11: error: expected type 'usize', found 'bool'", |
| 442 | 352 | ".tmp_source.zig:4:24: error: expected type 'usize', found 'bool'"); |
| 443 | 353 | |
| ... | ... | @@ -446,8 +356,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 446 | 356 | \\fn f() { |
| 447 | 357 | \\ x = 1; |
| 448 | 358 | \\} |
| 449 | | \\extern fn entry() { f(); } |
| 450 | | \\comptime {@export("entry", entry);} |
| 359 | \\export fn entry() { f(); } |
| 451 | 360 | , ".tmp_source.zig:3:7: error: cannot assign to constant"); |
| 452 | 361 | |
| 453 | 362 | |
| ... | ... | @@ -456,33 +365,29 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 456 | 365 | \\ const x : i32 = if (b) { 1 }; |
| 457 | 366 | \\ const y = if (b) { i32(1) }; |
| 458 | 367 | \\} |
| 459 | | \\extern fn entry() { f(true); } |
| 460 | | \\comptime {@export("entry", entry);} |
| 368 | \\export fn entry() { f(true); } |
| 461 | 369 | , ".tmp_source.zig:2:30: error: integer value 1 cannot be implicitly casted to type 'void'", |
| 462 | 370 | ".tmp_source.zig:3:15: error: incompatible types: 'i32' and 'void'"); |
| 463 | 371 | |
| 464 | 372 | cases.add("direct struct loop", |
| 465 | 373 | \\const A = struct { a : A, }; |
| 466 | | \\extern fn entry() -> usize { @sizeOf(A) } |
| 467 | | \\comptime {@export("entry", entry);} |
| 374 | \\export fn entry() -> usize { @sizeOf(A) } |
| 468 | 375 | , ".tmp_source.zig:1:11: error: struct 'A' contains itself"); |
| 469 | 376 | |
| 470 | 377 | cases.add("indirect struct loop", |
| 471 | 378 | \\const A = struct { b : B, }; |
| 472 | 379 | \\const B = struct { c : C, }; |
| 473 | 380 | \\const C = struct { a : A, }; |
| 474 | | \\extern fn entry() -> usize { @sizeOf(A) } |
| 475 | | \\comptime {@export("entry", entry);} |
| 381 | \\export fn entry() -> usize { @sizeOf(A) } |
| 476 | 382 | , ".tmp_source.zig:1:11: error: struct 'A' contains itself"); |
| 477 | 383 | |
| 478 | 384 | cases.add("invalid struct field", |
| 479 | 385 | \\const A = struct { x : i32, }; |
| 480 | | \\extern fn f() { |
| 386 | \\export fn f() { |
| 481 | 387 | \\ var a : A = undefined; |
| 482 | 388 | \\ a.foo = 1; |
| 483 | 389 | \\ const y = a.bar; |
| 484 | 390 | \\} |
| 485 | | \\comptime {@export("f", f);} |
| 486 | 391 | , |
| 487 | 392 | ".tmp_source.zig:4:6: error: no member named 'foo' in struct 'A'", |
| 488 | 393 | ".tmp_source.zig:5:16: error: no member named 'bar' in struct 'A'"); |
| ... | ... | @@ -510,7 +415,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 510 | 415 | \\ y : i32, |
| 511 | 416 | \\ z : i32, |
| 512 | 417 | \\}; |
| 513 | | \\extern fn f() { |
| 418 | \\export fn f() { |
| 514 | 419 | \\ const a = A { |
| 515 | 420 | \\ .z = 1, |
| 516 | 421 | \\ .y = 2, |
| ... | ... | @@ -518,7 +423,6 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 518 | 423 | \\ .z = 4, |
| 519 | 424 | \\ }; |
| 520 | 425 | \\} |
| 521 | | \\comptime {@export("f", f);} |
| 522 | 426 | , ".tmp_source.zig:11:9: error: duplicate field"); |
| 523 | 427 | |
| 524 | 428 | cases.add("missing field in struct value expression", |
| ... | ... | @@ -527,7 +431,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 527 | 431 | \\ y : i32, |
| 528 | 432 | \\ z : i32, |
| 529 | 433 | \\}; |
| 530 | | \\extern fn f() { |
| 434 | \\export fn f() { |
| 531 | 435 | \\ // we want the error on the '{' not the 'A' because |
| 532 | 436 | \\ // the A could be a complicated expression |
| 533 | 437 | \\ const a = A { |
| ... | ... | @@ -535,7 +439,6 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 535 | 439 | \\ .y = 2, |
| 536 | 440 | \\ }; |
| 537 | 441 | \\} |
| 538 | | \\comptime {@export("f", f);} |
| 539 | 442 | , ".tmp_source.zig:9:17: error: missing field: 'x'"); |
| 540 | 443 | |
| 541 | 444 | cases.add("invalid field in struct value expression", |
| ... | ... | @@ -544,79 +447,69 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 544 | 447 | \\ y : i32, |
| 545 | 448 | \\ z : i32, |
| 546 | 449 | \\}; |
| 547 | | \\extern fn f() { |
| 450 | \\export fn f() { |
| 548 | 451 | \\ const a = A { |
| 549 | 452 | \\ .z = 4, |
| 550 | 453 | \\ .y = 2, |
| 551 | 454 | \\ .foo = 42, |
| 552 | 455 | \\ }; |
| 553 | 456 | \\} |
| 554 | | \\comptime {@export("f", f);} |
| 555 | 457 | , ".tmp_source.zig:10:9: error: no member named 'foo' in struct 'A'"); |
| 556 | 458 | |
| 557 | 459 | cases.add("invalid break expression", |
| 558 | | \\extern fn f() { |
| 460 | \\export fn f() { |
| 559 | 461 | \\ break; |
| 560 | 462 | \\} |
| 561 | | \\comptime {@export("f", f);} |
| 562 | 463 | , ".tmp_source.zig:2:5: error: break expression outside loop"); |
| 563 | 464 | |
| 564 | 465 | cases.add("invalid continue expression", |
| 565 | | \\extern fn f() { |
| 466 | \\export fn f() { |
| 566 | 467 | \\ continue; |
| 567 | 468 | \\} |
| 568 | | \\comptime {@export("f", f);} |
| 569 | 469 | , ".tmp_source.zig:2:5: error: continue expression outside loop"); |
| 570 | 470 | |
| 571 | 471 | cases.add("invalid maybe type", |
| 572 | | \\extern fn f() { |
| 472 | \\export fn f() { |
| 573 | 473 | \\ if (true) |x| { } |
| 574 | 474 | \\} |
| 575 | | \\comptime {@export("f", f);} |
| 576 | 475 | , ".tmp_source.zig:2:9: error: expected nullable type, found 'bool'"); |
| 577 | 476 | |
| 578 | 477 | cases.add("cast unreachable", |
| 579 | 478 | \\fn f() -> i32 { |
| 580 | 479 | \\ i32(return 1) |
| 581 | 480 | \\} |
| 582 | | \\extern fn entry() { _ = f(); } |
| 583 | | \\comptime {@export("entry", entry);} |
| 481 | \\export fn entry() { _ = f(); } |
| 584 | 482 | , ".tmp_source.zig:2:8: error: unreachable code"); |
| 585 | 483 | |
| 586 | 484 | cases.add("invalid builtin fn", |
| 587 | 485 | \\fn f() -> @bogus(foo) { |
| 588 | 486 | \\} |
| 589 | | \\extern fn entry() { _ = f(); } |
| 590 | | \\comptime {@export("entry", entry);} |
| 487 | \\export fn entry() { _ = f(); } |
| 591 | 488 | , ".tmp_source.zig:1:11: error: invalid builtin function: 'bogus'"); |
| 592 | 489 | |
| 593 | 490 | cases.add("top level decl dependency loop", |
| 594 | 491 | \\const a : @typeOf(b) = 0; |
| 595 | 492 | \\const b : @typeOf(a) = 0; |
| 596 | | \\extern fn entry() { |
| 493 | \\export fn entry() { |
| 597 | 494 | \\ const c = a + b; |
| 598 | 495 | \\} |
| 599 | | \\comptime {@export("entry", entry);} |
| 600 | 496 | , ".tmp_source.zig:1:1: error: 'a' depends on itself"); |
| 601 | 497 | |
| 602 | 498 | cases.add("noalias on non pointer param", |
| 603 | 499 | \\fn f(noalias x: i32) {} |
| 604 | | \\extern fn entry() { f(1234); } |
| 605 | | \\comptime {@export("entry", entry);} |
| 500 | \\export fn entry() { f(1234); } |
| 606 | 501 | , ".tmp_source.zig:1:6: error: noalias on non-pointer parameter"); |
| 607 | 502 | |
| 608 | 503 | cases.add("struct init syntax for array", |
| 609 | 504 | \\const foo = []u16{.x = 1024,}; |
| 610 | | \\extern fn entry() -> usize { @sizeOf(@typeOf(foo)) } |
| 611 | | \\comptime {@export("entry", entry);} |
| 505 | \\export fn entry() -> usize { @sizeOf(@typeOf(foo)) } |
| 612 | 506 | , ".tmp_source.zig:1:18: error: type '[]u16' does not support struct initialization syntax"); |
| 613 | 507 | |
| 614 | 508 | cases.add("type variables must be constant", |
| 615 | 509 | \\var foo = u8; |
| 616 | | \\extern fn entry() -> foo { |
| 510 | \\export fn entry() -> foo { |
| 617 | 511 | \\ return 1; |
| 618 | 512 | \\} |
| 619 | | \\comptime {@export("entry", entry);} |
| 620 | 513 | , ".tmp_source.zig:1:1: error: variable of type 'type' must be constant"); |
| 621 | 514 | |
| 622 | 515 | |
| ... | ... | @@ -628,10 +521,9 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 628 | 521 | \\ var Bar : i32 = undefined; |
| 629 | 522 | \\} |
| 630 | 523 | \\ |
| 631 | | \\extern fn entry() { |
| 524 | \\export fn entry() { |
| 632 | 525 | \\ f(1234); |
| 633 | 526 | \\} |
| 634 | | \\comptime {@export("entry", entry);} |
| 635 | 527 | , |
| 636 | 528 | ".tmp_source.zig:4:6: error: redefinition of 'Foo'", |
| 637 | 529 | ".tmp_source.zig:1:1: note: previous definition is here", |
| ... | ... | @@ -653,8 +545,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 653 | 545 | \\ } |
| 654 | 546 | \\} |
| 655 | 547 | \\ |
| 656 | | \\extern fn entry() -> usize { @sizeOf(@typeOf(f)) } |
| 657 | | \\comptime {@export("entry", entry);} |
| 548 | \\export fn entry() -> usize { @sizeOf(@typeOf(f)) } |
| 658 | 549 | , ".tmp_source.zig:8:5: error: enumeration value 'Number.Four' not handled in switch"); |
| 659 | 550 | |
| 660 | 551 | cases.add("switch expression - duplicate enumeration prong", |
| ... | ... | @@ -674,8 +565,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 674 | 565 | \\ } |
| 675 | 566 | \\} |
| 676 | 567 | \\ |
| 677 | | \\extern fn entry() -> usize { @sizeOf(@typeOf(f)) } |
| 678 | | \\comptime {@export("entry", entry);} |
| 568 | \\export fn entry() -> usize { @sizeOf(@typeOf(f)) } |
| 679 | 569 | , ".tmp_source.zig:13:15: error: duplicate switch value", |
| 680 | 570 | ".tmp_source.zig:10:15: note: other value is here"); |
| 681 | 571 | |
| ... | ... | @@ -697,8 +587,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 697 | 587 | \\ } |
| 698 | 588 | \\} |
| 699 | 589 | \\ |
| 700 | | \\extern fn entry() -> usize { @sizeOf(@typeOf(f)) } |
| 701 | | \\comptime {@export("entry", entry);} |
| 590 | \\export fn entry() -> usize { @sizeOf(@typeOf(f)) } |
| 702 | 591 | , ".tmp_source.zig:13:15: error: duplicate switch value", |
| 703 | 592 | ".tmp_source.zig:10:15: note: other value is here"); |
| 704 | 593 | |
| ... | ... | @@ -710,10 +599,9 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 710 | 599 | \\ else => true, |
| 711 | 600 | \\ }; |
| 712 | 601 | \\} |
| 713 | | \\extern fn entry() { |
| 602 | \\export fn entry() { |
| 714 | 603 | \\ f(1234); |
| 715 | 604 | \\} |
| 716 | | \\comptime {@export("entry", entry);} |
| 717 | 605 | , ".tmp_source.zig:5:9: error: multiple else prongs in switch expression"); |
| 718 | 606 | |
| 719 | 607 | cases.add("switch expression - non exhaustive integer prongs", |
| ... | ... | @@ -722,8 +610,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 722 | 610 | \\ 0 => {}, |
| 723 | 611 | \\ } |
| 724 | 612 | \\} |
| 725 | | \\extern fn entry() -> usize { @sizeOf(@typeOf(foo)) } |
| 726 | | \\comptime {@export("entry", entry);} |
| 613 | \\export fn entry() -> usize { @sizeOf(@typeOf(foo)) } |
| 727 | 614 | , |
| 728 | 615 | ".tmp_source.zig:2:5: error: switch must handle all possibilities"); |
| 729 | 616 | |
| ... | ... | @@ -736,8 +623,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 736 | 623 | \\ 206 ... 255 => 3, |
| 737 | 624 | \\ } |
| 738 | 625 | \\} |
| 739 | | \\extern fn entry() -> usize { @sizeOf(@typeOf(foo)) } |
| 740 | | \\comptime {@export("entry", entry);} |
| 626 | \\export fn entry() -> usize { @sizeOf(@typeOf(foo)) } |
| 741 | 627 | , |
| 742 | 628 | ".tmp_source.zig:6:9: error: duplicate switch value", |
| 743 | 629 | ".tmp_source.zig:5:14: note: previous value is here"); |
| ... | ... | @@ -749,16 +635,14 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 749 | 635 | \\ } |
| 750 | 636 | \\} |
| 751 | 637 | \\const y: u8 = 100; |
| 752 | | \\extern fn entry() -> usize { @sizeOf(@typeOf(foo)) } |
| 753 | | \\comptime {@export("entry", entry);} |
| 638 | \\export fn entry() -> usize { @sizeOf(@typeOf(foo)) } |
| 754 | 639 | , |
| 755 | 640 | ".tmp_source.zig:2:5: error: else prong required when switching on type '&u8'"); |
| 756 | 641 | |
| 757 | 642 | cases.add("global variable initializer must be constant expression", |
| 758 | 643 | \\extern fn foo() -> i32; |
| 759 | 644 | \\const x = foo(); |
| 760 | | \\extern fn entry() -> i32 { x } |
| 761 | | \\comptime {@export("entry", entry);} |
| 645 | \\export fn entry() -> i32 { x } |
| 762 | 646 | , ".tmp_source.zig:2:11: error: unable to evaluate constant expression"); |
| 763 | 647 | |
| 764 | 648 | cases.add("array concatenation with wrong type", |
| ... | ... | @@ -766,8 +650,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 766 | 650 | \\const derp = usize(1234); |
| 767 | 651 | \\const a = derp ++ "foo"; |
| 768 | 652 | \\ |
| 769 | | \\extern fn entry() -> usize { @sizeOf(@typeOf(a)) } |
| 770 | | \\comptime {@export("entry", entry);} |
| 653 | \\export fn entry() -> usize { @sizeOf(@typeOf(a)) } |
| 771 | 654 | , ".tmp_source.zig:3:11: error: expected array or C string literal, found 'usize'"); |
| 772 | 655 | |
| 773 | 656 | cases.add("non compile time array concatenation", |
| ... | ... | @@ -775,14 +658,12 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 775 | 658 | \\ s ++ "foo" |
| 776 | 659 | \\} |
| 777 | 660 | \\var s: [10]u8 = undefined; |
| 778 | | \\extern fn entry() -> usize { @sizeOf(@typeOf(f)) } |
| 779 | | \\comptime {@export("entry", entry);} |
| 661 | \\export fn entry() -> usize { @sizeOf(@typeOf(f)) } |
| 780 | 662 | , ".tmp_source.zig:2:5: error: unable to evaluate constant expression"); |
| 781 | 663 | |
| 782 | 664 | cases.add("@cImport with bogus include", |
| 783 | 665 | \\const c = @cImport(@cInclude("bogus.h")); |
| 784 | | \\extern fn entry() -> usize { @sizeOf(@typeOf(c.bogo)) } |
| 785 | | \\comptime {@export("entry", entry);} |
| 666 | \\export fn entry() -> usize { @sizeOf(@typeOf(c.bogo)) } |
| 786 | 667 | , ".tmp_source.zig:1:11: error: C import failed", |
| 787 | 668 | ".h:1:10: note: 'bogus.h' file not found"); |
| 788 | 669 | |
| ... | ... | @@ -790,20 +671,17 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 790 | 671 | \\const x = 3; |
| 791 | 672 | \\const y = &x; |
| 792 | 673 | \\fn foo() -> &const i32 { y } |
| 793 | | \\extern fn entry() -> usize { @sizeOf(@typeOf(foo)) } |
| 794 | | \\comptime {@export("entry", entry);} |
| 674 | \\export fn entry() -> usize { @sizeOf(@typeOf(foo)) } |
| 795 | 675 | , ".tmp_source.zig:3:26: error: expected type '&const i32', found '&const (integer literal)'"); |
| 796 | 676 | |
| 797 | 677 | cases.add("integer overflow error", |
| 798 | 678 | \\const x : u8 = 300; |
| 799 | | \\extern fn entry() -> usize { @sizeOf(@typeOf(x)) } |
| 800 | | \\comptime {@export("entry", entry);} |
| 679 | \\export fn entry() -> usize { @sizeOf(@typeOf(x)) } |
| 801 | 680 | , ".tmp_source.zig:1:16: error: integer value 300 cannot be implicitly casted to type 'u8'"); |
| 802 | 681 | |
| 803 | 682 | cases.add("incompatible number literals", |
| 804 | 683 | \\const x = 2 == 2.0; |
| 805 | | \\extern fn entry() -> usize { @sizeOf(@typeOf(x)) } |
| 806 | | \\comptime {@export("entry", entry);} |
| 684 | \\export fn entry() -> usize { @sizeOf(@typeOf(x)) } |
| 807 | 685 | , ".tmp_source.zig:1:11: error: integer value 2 cannot be implicitly casted to type '(float literal)'"); |
| 808 | 686 | |
| 809 | 687 | cases.add("missing function call param", |
| ... | ... | @@ -829,15 +707,13 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 829 | 707 | \\ const result = members[index](); |
| 830 | 708 | \\} |
| 831 | 709 | \\ |
| 832 | | \\extern fn entry() -> usize { @sizeOf(@typeOf(f)) } |
| 833 | | \\comptime {@export("entry", entry);} |
| 710 | \\export fn entry() -> usize { @sizeOf(@typeOf(f)) } |
| 834 | 711 | , ".tmp_source.zig:20:34: error: expected 1 arguments, found 0"); |
| 835 | 712 | |
| 836 | 713 | cases.add("missing function name and param name", |
| 837 | 714 | \\fn () {} |
| 838 | 715 | \\fn f(i32) {} |
| 839 | | \\extern fn entry() -> usize { @sizeOf(@typeOf(f)) } |
| 840 | | \\comptime {@export("entry", entry);} |
| 716 | \\export fn entry() -> usize { @sizeOf(@typeOf(f)) } |
| 841 | 717 | , |
| 842 | 718 | ".tmp_source.zig:1:1: error: missing function name", |
| 843 | 719 | ".tmp_source.zig:2:6: error: missing parameter name"); |
| ... | ... | @@ -847,20 +723,16 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 847 | 723 | \\fn a() -> i32 {0} |
| 848 | 724 | \\fn b() -> i32 {1} |
| 849 | 725 | \\fn c() -> i32 {2} |
| 850 | | \\extern fn entry() -> usize { @sizeOf(@typeOf(fns)) } |
| 851 | | \\comptime {@export("entry", entry);} |
| 726 | \\export fn entry() -> usize { @sizeOf(@typeOf(fns)) } |
| 852 | 727 | , ".tmp_source.zig:1:21: error: expected type 'fn()', found 'fn() -> i32'"); |
| 853 | 728 | |
| 854 | 729 | cases.add("extern function pointer mismatch", |
| 855 | 730 | \\const fns = [](fn(i32)->i32){ a, b, c }; |
| 856 | 731 | \\pub fn a(x: i32) -> i32 {x + 0} |
| 857 | 732 | \\pub fn b(x: i32) -> i32 {x + 1} |
| 858 | | \\extern fn c(x: i32) -> i32 {x + 2} |
| 859 | | \\ |
| 860 | | \\extern fn entry() -> usize { @sizeOf(@typeOf(fns)) } |
| 733 | \\export fn c(x: i32) -> i32 {x + 2} |
| 861 | 734 | \\ |
| 862 | | \\comptime {@export("entry", entry);} |
| 863 | | \\comptime {@export("c", c);} |
| 735 | \\export fn entry() -> usize { @sizeOf(@typeOf(fns)) } |
| 864 | 736 | , ".tmp_source.zig:1:37: error: expected type 'fn(i32) -> i32', found 'extern fn(i32) -> i32'"); |
| 865 | 737 | |
| 866 | 738 | |
| ... | ... | @@ -868,16 +740,14 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 868 | 740 | \\const x : f64 = 1.0; |
| 869 | 741 | \\const y : f32 = x; |
| 870 | 742 | \\ |
| 871 | | \\extern fn entry() -> usize { @sizeOf(@typeOf(y)) } |
| 872 | | \\comptime {@export("entry", entry);} |
| 743 | \\export fn entry() -> usize { @sizeOf(@typeOf(y)) } |
| 873 | 744 | , ".tmp_source.zig:2:17: error: expected type 'f32', found 'f64'"); |
| 874 | 745 | |
| 875 | 746 | |
| 876 | 747 | cases.add("colliding invalid top level functions", |
| 877 | 748 | \\fn func() -> bogus {} |
| 878 | 749 | \\fn func() -> bogus {} |
| 879 | | \\extern fn entry() -> usize { @sizeOf(@typeOf(func)) } |
| 880 | | \\comptime {@export("entry", entry);} |
| 750 | \\export fn entry() -> usize { @sizeOf(@typeOf(func)) } |
| 881 | 751 | , |
| 882 | 752 | ".tmp_source.zig:2:1: error: redefinition of 'func'", |
| 883 | 753 | ".tmp_source.zig:1:14: error: use of undeclared identifier 'bogus'"); |
| ... | ... | @@ -885,8 +755,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 885 | 755 | |
| 886 | 756 | cases.add("bogus compile var", |
| 887 | 757 | \\const x = @import("builtin").bogus; |
| 888 | | \\extern fn entry() -> usize { @sizeOf(@typeOf(x)) } |
| 889 | | \\comptime {@export("entry", entry);} |
| 758 | \\export fn entry() -> usize { @sizeOf(@typeOf(x)) } |
| 890 | 759 | , ".tmp_source.zig:1:29: error: no member named 'bogus' in '"); |
| 891 | 760 | |
| 892 | 761 | |
| ... | ... | @@ -897,8 +766,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 897 | 766 | \\var global_var: usize = 1; |
| 898 | 767 | \\fn get() -> usize { global_var } |
| 899 | 768 | \\ |
| 900 | | \\extern fn entry() -> usize { @sizeOf(@typeOf(Foo)) } |
| 901 | | \\comptime {@export("entry", entry);} |
| 769 | \\export fn entry() -> usize { @sizeOf(@typeOf(Foo)) } |
| 902 | 770 | , |
| 903 | 771 | ".tmp_source.zig:5:21: error: unable to evaluate constant expression", |
| 904 | 772 | ".tmp_source.zig:2:12: note: called from here", |
| ... | ... | @@ -911,8 +779,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 911 | 779 | \\}; |
| 912 | 780 | \\const x = Foo {.field = 1} + Foo {.field = 2}; |
| 913 | 781 | \\ |
| 914 | | \\extern fn entry() -> usize { @sizeOf(@typeOf(x)) } |
| 915 | | \\comptime {@export("entry", entry);} |
| 782 | \\export fn entry() -> usize { @sizeOf(@typeOf(x)) } |
| 916 | 783 | , ".tmp_source.zig:4:28: error: invalid operands to binary expression: 'Foo' and 'Foo'"); |
| 917 | 784 | |
| 918 | 785 | |
| ... | ... | @@ -922,14 +789,10 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 922 | 789 | \\const int_x = u32(1) / u32(0); |
| 923 | 790 | \\const float_x = f32(1.0) / f32(0.0); |
| 924 | 791 | \\ |
| 925 | | \\extern fn entry1() -> usize { @sizeOf(@typeOf(lit_int_x)) } |
| 926 | | \\extern fn entry2() -> usize { @sizeOf(@typeOf(lit_float_x)) } |
| 927 | | \\extern fn entry3() -> usize { @sizeOf(@typeOf(int_x)) } |
| 928 | | \\extern fn entry4() -> usize { @sizeOf(@typeOf(float_x)) } |
| 929 | | \\comptime {@export("entry1", entry1);} |
| 930 | | \\comptime {@export("entry2", entry2);} |
| 931 | | \\comptime {@export("entry3", entry3);} |
| 932 | | \\comptime {@export("entry4", entry4);} |
| 792 | \\export fn entry1() -> usize { @sizeOf(@typeOf(lit_int_x)) } |
| 793 | \\export fn entry2() -> usize { @sizeOf(@typeOf(lit_float_x)) } |
| 794 | \\export fn entry3() -> usize { @sizeOf(@typeOf(int_x)) } |
| 795 | \\export fn entry4() -> usize { @sizeOf(@typeOf(float_x)) } |
| 933 | 796 | , |
| 934 | 797 | ".tmp_source.zig:1:21: error: division by zero is undefined", |
| 935 | 798 | ".tmp_source.zig:2:25: error: division by zero is undefined", |
| ... | ... | @@ -941,16 +804,14 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 941 | 804 | \\const foo = "a |
| 942 | 805 | \\b"; |
| 943 | 806 | \\ |
| 944 | | \\extern fn entry() -> usize { @sizeOf(@typeOf(foo)) } |
| 945 | | \\comptime {@export("entry", entry);} |
| 807 | \\export fn entry() -> usize { @sizeOf(@typeOf(foo)) } |
| 946 | 808 | , ".tmp_source.zig:1:13: error: newline not allowed in string literal"); |
| 947 | 809 | |
| 948 | 810 | cases.add("invalid comparison for function pointers", |
| 949 | 811 | \\fn foo() {} |
| 950 | 812 | \\const invalid = foo > foo; |
| 951 | 813 | \\ |
| 952 | | \\extern fn entry() -> usize { @sizeOf(@typeOf(invalid)) } |
| 953 | | \\comptime {@export("entry", entry);} |
| 814 | \\export fn entry() -> usize { @sizeOf(@typeOf(invalid)) } |
| 954 | 815 | , ".tmp_source.zig:2:21: error: operator not allowed for type 'fn()'"); |
| 955 | 816 | |
| 956 | 817 | cases.add("generic function instance with non-constant expression", |
| ... | ... | @@ -959,18 +820,16 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 959 | 820 | \\ return foo(a, b); |
| 960 | 821 | \\} |
| 961 | 822 | \\ |
| 962 | | \\extern fn entry() -> usize { @sizeOf(@typeOf(test1)) } |
| 963 | | \\comptime {@export("entry", entry);} |
| 823 | \\export fn entry() -> usize { @sizeOf(@typeOf(test1)) } |
| 964 | 824 | , ".tmp_source.zig:3:16: error: unable to evaluate constant expression"); |
| 965 | 825 | |
| 966 | 826 | cases.add("goto jumping into block", |
| 967 | | \\extern fn f() { |
| 827 | \\export fn f() { |
| 968 | 828 | \\ { |
| 969 | 829 | \\a_label: |
| 970 | 830 | \\ } |
| 971 | 831 | \\ goto a_label; |
| 972 | 832 | \\} |
| 973 | | \\comptime {@export("f", f);} |
| 974 | 833 | , ".tmp_source.zig:5:5: error: no label in scope named 'a_label'"); |
| 975 | 834 | |
| 976 | 835 | cases.add("goto jumping past a defer", |
| ... | ... | @@ -981,23 +840,20 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 981 | 840 | \\} |
| 982 | 841 | \\fn derp(){} |
| 983 | 842 | \\ |
| 984 | | \\extern fn entry() -> usize { @sizeOf(@typeOf(f)) } |
| 985 | | \\comptime {@export("entry", entry);} |
| 843 | \\export fn entry() -> usize { @sizeOf(@typeOf(f)) } |
| 986 | 844 | , ".tmp_source.zig:2:12: error: no label in scope named 'label'"); |
| 987 | 845 | |
| 988 | 846 | cases.add("assign null to non-nullable pointer", |
| 989 | 847 | \\const a: &u8 = null; |
| 990 | 848 | \\ |
| 991 | | \\extern fn entry() -> usize { @sizeOf(@typeOf(a)) } |
| 992 | | \\comptime {@export("entry", entry);} |
| 849 | \\export fn entry() -> usize { @sizeOf(@typeOf(a)) } |
| 993 | 850 | , ".tmp_source.zig:1:16: error: expected type '&u8', found '(null)'"); |
| 994 | 851 | |
| 995 | 852 | cases.add("indexing an array of size zero", |
| 996 | 853 | \\const array = []u8{}; |
| 997 | | \\extern fn foo() { |
| 854 | \\export fn foo() { |
| 998 | 855 | \\ const pointer = &array[0]; |
| 999 | 856 | \\} |
| 1000 | | \\comptime {@export("foo", foo);} |
| 1001 | 857 | , ".tmp_source.zig:3:27: error: index 0 outside array of size 0"); |
| 1002 | 858 | |
| 1003 | 859 | cases.add("compile time division by zero", |
| ... | ... | @@ -1006,8 +862,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 1006 | 862 | \\ 1 / x |
| 1007 | 863 | \\} |
| 1008 | 864 | \\ |
| 1009 | | \\extern fn entry() -> usize { @sizeOf(@typeOf(y)) } |
| 1010 | | \\comptime {@export("entry", entry);} |
| 865 | \\export fn entry() -> usize { @sizeOf(@typeOf(y)) } |
| 1011 | 866 | , |
| 1012 | 867 | ".tmp_source.zig:3:7: error: division by zero is undefined", |
| 1013 | 868 | ".tmp_source.zig:1:14: note: called from here"); |
| ... | ... | @@ -1015,8 +870,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 1015 | 870 | cases.add("branch on undefined value", |
| 1016 | 871 | \\const x = if (undefined) true else false; |
| 1017 | 872 | \\ |
| 1018 | | \\extern fn entry() -> usize { @sizeOf(@typeOf(x)) } |
| 1019 | | \\comptime {@export("entry", entry);} |
| 873 | \\export fn entry() -> usize { @sizeOf(@typeOf(x)) } |
| 1020 | 874 | , ".tmp_source.zig:1:15: error: use of undefined value"); |
| 1021 | 875 | |
| 1022 | 876 | |
| ... | ... | @@ -1026,8 +880,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 1026 | 880 | \\ return fibbonaci(x - 1) + fibbonaci(x - 2); |
| 1027 | 881 | \\} |
| 1028 | 882 | \\ |
| 1029 | | \\comptime {@export("entry", entry);} |
| 1030 | | \\extern fn entry() -> usize { @sizeOf(@typeOf(seventh_fib_number)) } |
| 883 | \\export fn entry() -> usize { @sizeOf(@typeOf(seventh_fib_number)) } |
| 1031 | 884 | , |
| 1032 | 885 | ".tmp_source.zig:3:21: error: evaluation exceeded 1000 backwards branches", |
| 1033 | 886 | ".tmp_source.zig:3:21: note: called from here"); |
| ... | ... | @@ -1035,8 +888,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 1035 | 888 | cases.add("@embedFile with bogus file", |
| 1036 | 889 | \\const resource = @embedFile("bogus.txt"); |
| 1037 | 890 | \\ |
| 1038 | | \\comptime {@export("entry", entry);} |
| 1039 | | \\extern fn entry() -> usize { @sizeOf(@typeOf(resource)) } |
| 891 | \\export fn entry() -> usize { @sizeOf(@typeOf(resource)) } |
| 1040 | 892 | , ".tmp_source.zig:1:29: error: unable to find '", "bogus.txt'"); |
| 1041 | 893 | |
| 1042 | 894 | cases.add("non-const expression in struct literal outside function", |
| ... | ... | @@ -1046,8 +898,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 1046 | 898 | \\const a = Foo {.x = get_it()}; |
| 1047 | 899 | \\extern fn get_it() -> i32; |
| 1048 | 900 | \\ |
| 1049 | | \\comptime {@export("entry", entry);} |
| 1050 | | \\extern fn entry() -> usize { @sizeOf(@typeOf(a)) } |
| 901 | \\export fn entry() -> usize { @sizeOf(@typeOf(a)) } |
| 1051 | 902 | , ".tmp_source.zig:4:21: error: unable to evaluate constant expression"); |
| 1052 | 903 | |
| 1053 | 904 | cases.add("non-const expression function call with struct return value outside function", |
| ... | ... | @@ -1061,20 +912,18 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 1061 | 912 | \\} |
| 1062 | 913 | \\var global_side_effect = false; |
| 1063 | 914 | \\ |
| 1064 | | \\comptime {@export("entry", entry);} |
| 1065 | | \\extern fn entry() -> usize { @sizeOf(@typeOf(a)) } |
| 915 | \\export fn entry() -> usize { @sizeOf(@typeOf(a)) } |
| 1066 | 916 | , |
| 1067 | 917 | ".tmp_source.zig:6:24: error: unable to evaluate constant expression", |
| 1068 | 918 | ".tmp_source.zig:4:17: note: called from here"); |
| 1069 | 919 | |
| 1070 | 920 | cases.add("undeclared identifier error should mark fn as impure", |
| 1071 | | \\extern fn foo() { |
| 921 | \\export fn foo() { |
| 1072 | 922 | \\ test_a_thing(); |
| 1073 | 923 | \\} |
| 1074 | 924 | \\fn test_a_thing() { |
| 1075 | 925 | \\ bad_fn_call(); |
| 1076 | 926 | \\} |
| 1077 | | \\comptime {@export("foo", foo);} |
| 1078 | 927 | , ".tmp_source.zig:5:5: error: use of undeclared identifier 'bad_fn_call'"); |
| 1079 | 928 | |
| 1080 | 929 | cases.add("illegal comparison of types", |
| ... | ... | @@ -1089,16 +938,14 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 1089 | 938 | \\ *a == *b |
| 1090 | 939 | \\} |
| 1091 | 940 | \\ |
| 1092 | | \\extern fn entry1() -> usize { @sizeOf(@typeOf(bad_eql_1)) } |
| 1093 | | \\extern fn entry2() -> usize { @sizeOf(@typeOf(bad_eql_2)) } |
| 1094 | | \\comptime {@export("entry1", entry1);} |
| 1095 | | \\comptime {@export("entry2", entry2);} |
| 941 | \\export fn entry1() -> usize { @sizeOf(@typeOf(bad_eql_1)) } |
| 942 | \\export fn entry2() -> usize { @sizeOf(@typeOf(bad_eql_2)) } |
| 1096 | 943 | , |
| 1097 | 944 | ".tmp_source.zig:2:7: error: operator not allowed for type '[]u8'", |
| 1098 | 945 | ".tmp_source.zig:9:8: error: operator not allowed for type 'EnumWithData'"); |
| 1099 | 946 | |
| 1100 | 947 | cases.add("non-const switch number literal", |
| 1101 | | \\extern fn foo() { |
| 948 | \\export fn foo() { |
| 1102 | 949 | \\ const x = switch (bar()) { |
| 1103 | 950 | \\ 1, 2 => 1, |
| 1104 | 951 | \\ 3, 4 => 2, |
| ... | ... | @@ -1108,25 +955,22 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 1108 | 955 | \\fn bar() -> i32 { |
| 1109 | 956 | \\ 2 |
| 1110 | 957 | \\} |
| 1111 | | \\comptime {@export("foo", foo);} |
| 1112 | 958 | , ".tmp_source.zig:2:15: error: unable to infer expression type"); |
| 1113 | 959 | |
| 1114 | 960 | cases.add("atomic orderings of cmpxchg - failure stricter than success", |
| 1115 | 961 | \\const AtomicOrder = @import("builtin").AtomicOrder; |
| 1116 | | \\extern fn f() { |
| 962 | \\export fn f() { |
| 1117 | 963 | \\ var x: i32 = 1234; |
| 1118 | 964 | \\ while (!@cmpxchg(&x, 1234, 5678, AtomicOrder.Monotonic, AtomicOrder.SeqCst)) {} |
| 1119 | 965 | \\} |
| 1120 | | \\comptime {@export("f", f);} |
| 1121 | 966 | , ".tmp_source.zig:4:72: error: failure atomic ordering must be no stricter than success"); |
| 1122 | 967 | |
| 1123 | 968 | cases.add("atomic orderings of cmpxchg - success Monotonic or stricter", |
| 1124 | 969 | \\const AtomicOrder = @import("builtin").AtomicOrder; |
| 1125 | | \\extern fn f() { |
| 970 | \\export fn f() { |
| 1126 | 971 | \\ var x: i32 = 1234; |
| 1127 | 972 | \\ while (!@cmpxchg(&x, 1234, 5678, AtomicOrder.Unordered, AtomicOrder.Unordered)) {} |
| 1128 | 973 | \\} |
| 1129 | | \\comptime {@export("f", f);} |
| 1130 | 974 | , ".tmp_source.zig:4:49: error: success atomic ordering must be Monotonic or stricter"); |
| 1131 | 975 | |
| 1132 | 976 | cases.add("negation overflow in function evaluation", |
| ... | ... | @@ -1135,8 +979,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 1135 | 979 | \\ -x |
| 1136 | 980 | \\} |
| 1137 | 981 | \\ |
| 1138 | | \\extern fn entry() -> usize { @sizeOf(@typeOf(y)) } |
| 1139 | | \\comptime {@export("entry", entry);} |
| 982 | \\export fn entry() -> usize { @sizeOf(@typeOf(y)) } |
| 1140 | 983 | , |
| 1141 | 984 | ".tmp_source.zig:3:5: error: negation caused overflow", |
| 1142 | 985 | ".tmp_source.zig:1:14: note: called from here"); |
| ... | ... | @@ -1147,8 +990,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 1147 | 990 | \\ a + b |
| 1148 | 991 | \\} |
| 1149 | 992 | \\ |
| 1150 | | \\extern fn entry() -> usize { @sizeOf(@typeOf(y)) } |
| 1151 | | \\comptime {@export("entry", entry);} |
| 993 | \\export fn entry() -> usize { @sizeOf(@typeOf(y)) } |
| 1152 | 994 | , |
| 1153 | 995 | ".tmp_source.zig:3:7: error: operation caused overflow", |
| 1154 | 996 | ".tmp_source.zig:1:14: note: called from here"); |
| ... | ... | @@ -1160,8 +1002,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 1160 | 1002 | \\ a - b |
| 1161 | 1003 | \\} |
| 1162 | 1004 | \\ |
| 1163 | | \\extern fn entry() -> usize { @sizeOf(@typeOf(y)) } |
| 1164 | | \\comptime {@export("entry", entry);} |
| 1005 | \\export fn entry() -> usize { @sizeOf(@typeOf(y)) } |
| 1165 | 1006 | , |
| 1166 | 1007 | ".tmp_source.zig:3:7: error: operation caused overflow", |
| 1167 | 1008 | ".tmp_source.zig:1:14: note: called from here"); |
| ... | ... | @@ -1172,8 +1013,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 1172 | 1013 | \\ a * b |
| 1173 | 1014 | \\} |
| 1174 | 1015 | \\ |
| 1175 | | \\extern fn entry() -> usize { @sizeOf(@typeOf(y)) } |
| 1176 | | \\comptime {@export("entry", entry);} |
| 1016 | \\export fn entry() -> usize { @sizeOf(@typeOf(y)) } |
| 1177 | 1017 | , |
| 1178 | 1018 | ".tmp_source.zig:3:7: error: operation caused overflow", |
| 1179 | 1019 | ".tmp_source.zig:1:14: note: called from here"); |
| ... | ... | @@ -1184,35 +1024,40 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 1184 | 1024 | \\ @truncate(i8, x) |
| 1185 | 1025 | \\} |
| 1186 | 1026 | \\ |
| 1187 | | \\extern fn entry() -> usize { @sizeOf(@typeOf(f)) } |
| 1188 | | \\comptime {@export("entry", entry);} |
| 1027 | \\export fn entry() -> usize { @sizeOf(@typeOf(f)) } |
| 1189 | 1028 | , ".tmp_source.zig:3:19: error: expected signed integer type, found 'u32'"); |
| 1190 | 1029 | |
| 1191 | 1030 | cases.add("%return in function with non error return type", |
| 1192 | | \\extern fn f() { |
| 1031 | \\export fn f() { |
| 1193 | 1032 | \\ %return something(); |
| 1194 | 1033 | \\} |
| 1195 | 1034 | \\fn something() -> %void { } |
| 1196 | | \\comptime {@export("f", f);} |
| 1197 | 1035 | , |
| 1198 | 1036 | ".tmp_source.zig:2:5: error: expected type 'void', found 'error'"); |
| 1199 | 1037 | |
| 1038 | cases.add("wrong return type for main", |
| 1039 | \\pub fn main() { } |
| 1040 | , ".tmp_source.zig:1:15: error: expected return type of main to be '%void', instead is 'void'"); |
| 1041 | |
| 1042 | cases.add("double ?? on main return value", |
| 1043 | \\pub fn main() -> ??void { |
| 1044 | \\} |
| 1045 | , ".tmp_source.zig:1:18: error: expected return type of main to be '%void', instead is '??void'"); |
| 1046 | |
| 1200 | 1047 | cases.add("invalid pointer for var type", |
| 1201 | 1048 | \\extern fn ext() -> usize; |
| 1202 | 1049 | \\var bytes: [ext()]u8 = undefined; |
| 1203 | | \\extern fn f() { |
| 1050 | \\export fn f() { |
| 1204 | 1051 | \\ for (bytes) |*b, i| { |
| 1205 | 1052 | \\ *b = u8(i); |
| 1206 | 1053 | \\ } |
| 1207 | 1054 | \\} |
| 1208 | | \\comptime {@export("f", f);} |
| 1209 | 1055 | , ".tmp_source.zig:2:13: error: unable to evaluate constant expression"); |
| 1210 | 1056 | |
| 1211 | 1057 | cases.add("export function with comptime parameter", |
| 1212 | | \\extern fn foo(comptime x: i32, y: i32) -> i32{ |
| 1058 | \\export fn foo(comptime x: i32, y: i32) -> i32{ |
| 1213 | 1059 | \\ x + y |
| 1214 | 1060 | \\} |
| 1215 | | \\comptime {@export("foo", foo);} |
| 1216 | 1061 | , ".tmp_source.zig:1:15: error: comptime parameter not allowed in function with calling convention 'ccc'"); |
| 1217 | 1062 | |
| 1218 | 1063 | cases.add("extern function with comptime parameter", |
| ... | ... | @@ -1220,16 +1065,14 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 1220 | 1065 | \\fn f() -> i32 { |
| 1221 | 1066 | \\ foo(1, 2) |
| 1222 | 1067 | \\} |
| 1223 | | \\extern fn entry() -> usize { @sizeOf(@typeOf(f)) } |
| 1224 | | \\comptime {@export("entry", entry);} |
| 1068 | \\export fn entry() -> usize { @sizeOf(@typeOf(f)) } |
| 1225 | 1069 | , ".tmp_source.zig:1:15: error: comptime parameter not allowed in function with calling convention 'ccc'"); |
| 1226 | 1070 | |
| 1227 | 1071 | cases.add("convert fixed size array to slice with invalid size", |
| 1228 | | \\extern fn f() { |
| 1072 | \\export fn f() { |
| 1229 | 1073 | \\ var array: [5]u8 = undefined; |
| 1230 | 1074 | \\ var foo = ([]const u32)(array)[0]; |
| 1231 | 1075 | \\} |
| 1232 | | \\comptime {@export("f", f);} |
| 1233 | 1076 | , ".tmp_source.zig:3:28: error: unable to convert [5]u8 to []const u32: size mismatch"); |
| 1234 | 1077 | |
| 1235 | 1078 | cases.add("non-pure function returns type", |
| ... | ... | @@ -1247,11 +1090,10 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 1247 | 1090 | \\ } |
| 1248 | 1091 | \\} |
| 1249 | 1092 | \\ |
| 1250 | | \\extern fn function_with_return_type_type() { |
| 1093 | \\export fn function_with_return_type_type() { |
| 1251 | 1094 | \\ var list: List(i32) = undefined; |
| 1252 | 1095 | \\ list.length = 10; |
| 1253 | 1096 | \\} |
| 1254 | | \\comptime {@export("function_with_return_type_type", function_with_return_type_type);} |
| 1255 | 1097 | , ".tmp_source.zig:3:7: error: unable to evaluate constant expression", |
| 1256 | 1098 | ".tmp_source.zig:16:19: note: called from here"); |
| 1257 | 1099 | |
| ... | ... | @@ -1260,8 +1102,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 1260 | 1102 | \\fn f(m: []const u8) { |
| 1261 | 1103 | \\ m.copy(u8, self[0..], m); |
| 1262 | 1104 | \\} |
| 1263 | | \\extern fn entry() -> usize { @sizeOf(@typeOf(f)) } |
| 1264 | | \\comptime {@export("entry", entry);} |
| 1105 | \\export fn entry() -> usize { @sizeOf(@typeOf(f)) } |
| 1265 | 1106 | , ".tmp_source.zig:3:6: error: no member named 'copy' in '[]const u8'"); |
| 1266 | 1107 | |
| 1267 | 1108 | cases.add("wrong number of arguments for method fn call", |
| ... | ... | @@ -1272,24 +1113,21 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 1272 | 1113 | \\ |
| 1273 | 1114 | \\ foo.method(1, 2); |
| 1274 | 1115 | \\} |
| 1275 | | \\extern fn entry() -> usize { @sizeOf(@typeOf(f)) } |
| 1276 | | \\comptime {@export("entry", entry);} |
| 1116 | \\export fn entry() -> usize { @sizeOf(@typeOf(f)) } |
| 1277 | 1117 | , ".tmp_source.zig:6:15: error: expected 2 arguments, found 3"); |
| 1278 | 1118 | |
| 1279 | 1119 | cases.add("assign through constant pointer", |
| 1280 | | \\extern fn f() { |
| 1120 | \\export fn f() { |
| 1281 | 1121 | \\ var cstr = c"Hat"; |
| 1282 | 1122 | \\ cstr[0] = 'W'; |
| 1283 | 1123 | \\} |
| 1284 | | \\comptime {@export("f", f);} |
| 1285 | 1124 | , ".tmp_source.zig:3:11: error: cannot assign to constant"); |
| 1286 | 1125 | |
| 1287 | 1126 | cases.add("assign through constant slice", |
| 1288 | | \\extern fn f() { |
| 1127 | \\export fn f() { |
| 1289 | 1128 | \\ var cstr: []const u8 = "Hat"; |
| 1290 | 1129 | \\ cstr[0] = 'W'; |
| 1291 | 1130 | \\} |
| 1292 | | \\comptime {@export("f", f);} |
| 1293 | 1131 | , ".tmp_source.zig:3:11: error: cannot assign to constant"); |
| 1294 | 1132 | |
| 1295 | 1133 | cases.add("main function with bogus args type", |
| ... | ... | @@ -1300,8 +1138,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 1300 | 1138 | \\fn foo(blah: []u8) { |
| 1301 | 1139 | \\ for (blah) { } |
| 1302 | 1140 | \\} |
| 1303 | | \\extern fn entry() -> usize { @sizeOf(@typeOf(foo)) } |
| 1304 | | \\comptime {@export("entry", entry);} |
| 1141 | \\export fn entry() -> usize { @sizeOf(@typeOf(foo)) } |
| 1305 | 1142 | , ".tmp_source.zig:2:5: error: for loop expression missing element parameter"); |
| 1306 | 1143 | |
| 1307 | 1144 | cases.add("misspelled type with pointer only reference", |
| ... | ... | @@ -1334,8 +1171,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 1334 | 1171 | \\ var jd = JsonNode {.kind = JsonType.JSONArray , .jobject = JsonOA.JSONArray {jll} }; |
| 1335 | 1172 | \\} |
| 1336 | 1173 | \\ |
| 1337 | | \\extern fn entry() -> usize { @sizeOf(@typeOf(foo)) } |
| 1338 | | \\comptime {@export("entry", entry);} |
| 1174 | \\export fn entry() -> usize { @sizeOf(@typeOf(foo)) } |
| 1339 | 1175 | , ".tmp_source.zig:5:16: error: use of undeclared identifier 'JsonList'"); |
| 1340 | 1176 | |
| 1341 | 1177 | cases.add("method call with first arg type primitive", |
| ... | ... | @@ -1349,12 +1185,11 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 1349 | 1185 | \\ } |
| 1350 | 1186 | \\}; |
| 1351 | 1187 | \\ |
| 1352 | | \\extern fn f() { |
| 1188 | \\export fn f() { |
| 1353 | 1189 | \\ const derp = Foo.init(3); |
| 1354 | 1190 | \\ |
| 1355 | 1191 | \\ derp.init(); |
| 1356 | 1192 | \\} |
| 1357 | | \\comptime {@export("f", f);} |
| 1358 | 1193 | , ".tmp_source.zig:14:5: error: expected type 'i32', found '&const Foo'"); |
| 1359 | 1194 | |
| 1360 | 1195 | cases.add("method call with first arg type wrong container", |
| ... | ... | @@ -1378,11 +1213,10 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 1378 | 1213 | \\ field: i32, |
| 1379 | 1214 | \\}; |
| 1380 | 1215 | \\ |
| 1381 | | \\extern fn foo() { |
| 1216 | \\export fn foo() { |
| 1382 | 1217 | \\ var x = List.init(&global_allocator); |
| 1383 | 1218 | \\ x.init(); |
| 1384 | 1219 | \\} |
| 1385 | | \\comptime {@export("foo", foo);} |
| 1386 | 1220 | , ".tmp_source.zig:23:5: error: expected type '&Allocator', found '&List'"); |
| 1387 | 1221 | |
| 1388 | 1222 | cases.add("binary not on number literal", |
| ... | ... | @@ -1390,18 +1224,16 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 1390 | 1224 | \\const TINY_QUANTUM_SIZE = 1 << TINY_QUANTUM_SHIFT; |
| 1391 | 1225 | \\var block_aligned_stuff: usize = (4 + TINY_QUANTUM_SIZE) & ~(TINY_QUANTUM_SIZE - 1); |
| 1392 | 1226 | \\ |
| 1393 | | \\extern fn entry() -> usize { @sizeOf(@typeOf(block_aligned_stuff)) } |
| 1394 | | \\comptime {@export("entry", entry);} |
| 1227 | \\export fn entry() -> usize { @sizeOf(@typeOf(block_aligned_stuff)) } |
| 1395 | 1228 | , ".tmp_source.zig:3:60: error: unable to perform binary not operation on type '(integer literal)'"); |
| 1396 | 1229 | |
| 1397 | 1230 | cases.addCase({ |
| 1398 | 1231 | const tc = cases.create("multiple files with private function error", |
| 1399 | 1232 | \\const foo = @import("foo.zig"); |
| 1400 | 1233 | \\ |
| 1401 | | \\extern fn callPrivFunction() { |
| 1234 | \\export fn callPrivFunction() { |
| 1402 | 1235 | \\ foo.privateFunction(); |
| 1403 | 1236 | \\} |
| 1404 | | \\comptime {@export("callPrivFunction", callPrivFunction);} |
| 1405 | 1237 | , |
| 1406 | 1238 | ".tmp_source.zig:4:8: error: 'privateFunction' is private", |
| 1407 | 1239 | "foo.zig:1:1: note: declared here"); |
| ... | ... | @@ -1417,19 +1249,17 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 1417 | 1249 | \\const zero: i32 = 0; |
| 1418 | 1250 | \\const a = zero{1}; |
| 1419 | 1251 | \\ |
| 1420 | | \\extern fn entry() -> usize { @sizeOf(@typeOf(a)) } |
| 1421 | | \\comptime {@export("entry", entry);} |
| 1252 | \\export fn entry() -> usize { @sizeOf(@typeOf(a)) } |
| 1422 | 1253 | , ".tmp_source.zig:2:11: error: expected type, found 'i32'"); |
| 1423 | 1254 | |
| 1424 | 1255 | cases.add("assign to constant field", |
| 1425 | 1256 | \\const Foo = struct { |
| 1426 | 1257 | \\ field: i32, |
| 1427 | 1258 | \\}; |
| 1428 | | \\extern fn derp() { |
| 1259 | \\export fn derp() { |
| 1429 | 1260 | \\ const f = Foo {.field = 1234,}; |
| 1430 | 1261 | \\ f.field = 0; |
| 1431 | 1262 | \\} |
| 1432 | | \\comptime {@export("derp", derp);} |
| 1433 | 1263 | , ".tmp_source.zig:6:13: error: cannot assign to constant"); |
| 1434 | 1264 | |
| 1435 | 1265 | cases.add("return from defer expression", |
| ... | ... | @@ -1447,8 +1277,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 1447 | 1277 | \\ return 0; |
| 1448 | 1278 | \\} |
| 1449 | 1279 | \\ |
| 1450 | | \\extern fn entry() -> usize { @sizeOf(@typeOf(testTrickyDefer)) } |
| 1451 | | \\comptime {@export("entry", entry);} |
| 1280 | \\export fn entry() -> usize { @sizeOf(@typeOf(testTrickyDefer)) } |
| 1452 | 1281 | , ".tmp_source.zig:4:11: error: cannot return from defer expression"); |
| 1453 | 1282 | |
| 1454 | 1283 | cases.add("attempt to access var args out of bounds", |
| ... | ... | @@ -1460,8 +1289,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 1460 | 1289 | \\ add(i32(1234)) |
| 1461 | 1290 | \\} |
| 1462 | 1291 | \\ |
| 1463 | | \\comptime {@export("entry", entry);} |
| 1464 | | \\extern fn entry() -> usize { @sizeOf(@typeOf(foo)) } |
| 1292 | \\export fn entry() -> usize { @sizeOf(@typeOf(foo)) } |
| 1465 | 1293 | , |
| 1466 | 1294 | ".tmp_source.zig:2:19: error: index 1 outside argument list of size 1", |
| 1467 | 1295 | ".tmp_source.zig:6:8: note: called from here"); |
| ... | ... | @@ -1479,31 +1307,27 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 1479 | 1307 | \\ add(1, 2, 3, 4) |
| 1480 | 1308 | \\} |
| 1481 | 1309 | \\ |
| 1482 | | \\comptime {@export("entry", entry);} |
| 1483 | | \\extern fn entry() -> usize { @sizeOf(@typeOf(bar)) } |
| 1310 | \\export fn entry() -> usize { @sizeOf(@typeOf(bar)) } |
| 1484 | 1311 | , ".tmp_source.zig:10:9: error: parameter of type '(integer literal)' requires comptime"); |
| 1485 | 1312 | |
| 1486 | 1313 | cases.add("assign too big number to u16", |
| 1487 | | \\extern fn foo() { |
| 1314 | \\export fn foo() { |
| 1488 | 1315 | \\ var vga_mem: u16 = 0xB8000; |
| 1489 | 1316 | \\} |
| 1490 | | \\comptime {@export("foo", foo);} |
| 1491 | 1317 | , ".tmp_source.zig:2:24: error: integer value 753664 cannot be implicitly casted to type 'u16'"); |
| 1492 | 1318 | |
| 1493 | 1319 | cases.add("global variable alignment non power of 2", |
| 1494 | 1320 | \\const some_data: [100]u8 align(3) = undefined; |
| 1495 | | \\extern fn entry() -> usize { @sizeOf(@typeOf(some_data)) } |
| 1496 | | \\comptime {@export("entry", entry);} |
| 1321 | \\export fn entry() -> usize { @sizeOf(@typeOf(some_data)) } |
| 1497 | 1322 | , ".tmp_source.zig:1:32: error: alignment value 3 is not a power of 2"); |
| 1498 | 1323 | |
| 1499 | 1324 | cases.add("function alignment non power of 2", |
| 1500 | 1325 | \\extern fn foo() align(3); |
| 1501 | | \\extern fn entry() { foo() } |
| 1502 | | \\comptime {@export("entry", entry);} |
| 1326 | \\export fn entry() { foo() } |
| 1503 | 1327 | , ".tmp_source.zig:1:23: error: alignment value 3 is not a power of 2"); |
| 1504 | 1328 | |
| 1505 | 1329 | cases.add("compile log", |
| 1506 | | \\extern fn foo() { |
| 1330 | \\export fn foo() { |
| 1507 | 1331 | \\ comptime bar(12, "hi"); |
| 1508 | 1332 | \\} |
| 1509 | 1333 | \\fn bar(a: i32, b: []const u8) { |
| ... | ... | @@ -1511,7 +1335,6 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 1511 | 1335 | \\ @compileLog("a", a, "b", b); |
| 1512 | 1336 | \\ @compileLog("end"); |
| 1513 | 1337 | \\} |
| 1514 | | \\comptime {@export("foo", foo);} |
| 1515 | 1338 | , |
| 1516 | 1339 | ".tmp_source.zig:5:5: error: found compile log statement", |
| 1517 | 1340 | ".tmp_source.zig:2:17: note: called from here", |
| ... | ... | @@ -1535,8 +1358,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 1535 | 1358 | \\ return *x; |
| 1536 | 1359 | \\} |
| 1537 | 1360 | \\ |
| 1538 | | \\extern fn entry() -> usize { @sizeOf(@typeOf(foo)) } |
| 1539 | | \\comptime {@export("entry", entry);} |
| 1361 | \\export fn entry() -> usize { @sizeOf(@typeOf(foo)) } |
| 1540 | 1362 | , ".tmp_source.zig:8:26: error: expected type '&const u3', found '&align(1:3:6) const u3'"); |
| 1541 | 1363 | |
| 1542 | 1364 | cases.add("referring to a struct that is invalid", |
| ... | ... | @@ -1544,20 +1366,19 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 1544 | 1366 | \\ Type: u8, |
| 1545 | 1367 | \\}; |
| 1546 | 1368 | \\ |
| 1547 | | \\extern fn foo() { |
| 1369 | \\export fn foo() { |
| 1548 | 1370 | \\ comptime assert(@sizeOf(UsbDeviceRequest) == 0x8); |
| 1549 | 1371 | \\} |
| 1550 | 1372 | \\ |
| 1551 | 1373 | \\fn assert(ok: bool) { |
| 1552 | 1374 | \\ if (!ok) unreachable; |
| 1553 | 1375 | \\} |
| 1554 | | \\comptime {@export("foo", foo);} |
| 1555 | 1376 | , |
| 1556 | 1377 | ".tmp_source.zig:10:14: error: unable to evaluate constant expression", |
| 1557 | 1378 | ".tmp_source.zig:6:20: note: called from here"); |
| 1558 | 1379 | |
| 1559 | 1380 | cases.add("control flow uses comptime var at runtime", |
| 1560 | | \\extern fn foo() { |
| 1381 | \\export fn foo() { |
| 1561 | 1382 | \\ comptime var i = 0; |
| 1562 | 1383 | \\ while (i < 5) : (i += 1) { |
| 1563 | 1384 | \\ bar(); |
| ... | ... | @@ -1565,61 +1386,53 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 1565 | 1386 | \\} |
| 1566 | 1387 | \\ |
| 1567 | 1388 | \\fn bar() { } |
| 1568 | | \\comptime {@export("foo", foo);} |
| 1569 | 1389 | , |
| 1570 | 1390 | ".tmp_source.zig:3:5: error: control flow attempts to use compile-time variable at runtime", |
| 1571 | 1391 | ".tmp_source.zig:3:24: note: compile-time variable assigned here"); |
| 1572 | 1392 | |
| 1573 | 1393 | cases.add("ignored return value", |
| 1574 | | \\extern fn foo() { |
| 1394 | \\export fn foo() { |
| 1575 | 1395 | \\ bar(); |
| 1576 | 1396 | \\} |
| 1577 | 1397 | \\fn bar() -> i32 { 0 } |
| 1578 | | \\comptime {@export("foo", foo);} |
| 1579 | 1398 | , ".tmp_source.zig:2:8: error: expression value is ignored"); |
| 1580 | 1399 | |
| 1581 | 1400 | cases.add("ignored assert-err-ok return value", |
| 1582 | | \\extern fn foo() { |
| 1401 | \\export fn foo() { |
| 1583 | 1402 | \\ %%bar(); |
| 1584 | 1403 | \\} |
| 1585 | 1404 | \\fn bar() -> %i32 { 0 } |
| 1586 | | \\comptime {@export("foo", foo);} |
| 1587 | 1405 | , ".tmp_source.zig:2:5: error: expression value is ignored"); |
| 1588 | 1406 | |
| 1589 | 1407 | cases.add("ignored statement value", |
| 1590 | | \\extern fn foo() { |
| 1408 | \\export fn foo() { |
| 1591 | 1409 | \\ 1; |
| 1592 | 1410 | \\} |
| 1593 | | \\comptime {@export("foo", foo);} |
| 1594 | 1411 | , ".tmp_source.zig:2:5: error: expression value is ignored"); |
| 1595 | 1412 | |
| 1596 | 1413 | cases.add("ignored comptime statement value", |
| 1597 | | \\extern fn foo() { |
| 1414 | \\export fn foo() { |
| 1598 | 1415 | \\ comptime {1;} |
| 1599 | 1416 | \\} |
| 1600 | | \\comptime {@export("foo", foo);} |
| 1601 | 1417 | , ".tmp_source.zig:2:15: error: expression value is ignored"); |
| 1602 | 1418 | |
| 1603 | 1419 | cases.add("ignored comptime value", |
| 1604 | | \\extern fn foo() { |
| 1420 | \\export fn foo() { |
| 1605 | 1421 | \\ comptime 1; |
| 1606 | 1422 | \\} |
| 1607 | | \\comptime {@export("foo", foo);} |
| 1608 | 1423 | , ".tmp_source.zig:2:5: error: expression value is ignored"); |
| 1609 | 1424 | |
| 1610 | 1425 | cases.add("ignored defered statement value", |
| 1611 | | \\extern fn foo() { |
| 1426 | \\export fn foo() { |
| 1612 | 1427 | \\ defer {1;} |
| 1613 | 1428 | \\} |
| 1614 | | \\comptime {@export("foo", foo);} |
| 1615 | 1429 | , ".tmp_source.zig:2:12: error: expression value is ignored"); |
| 1616 | 1430 | |
| 1617 | 1431 | cases.add("ignored defered statement value", |
| 1618 | | \\extern fn foo() { |
| 1432 | \\export fn foo() { |
| 1619 | 1433 | \\ defer bar(); |
| 1620 | 1434 | \\} |
| 1621 | 1435 | \\fn bar() -> %i32 { 0 } |
| 1622 | | \\comptime {@export("foo", foo);} |
| 1623 | 1436 | , ".tmp_source.zig:2:14: error: expression value is ignored"); |
| 1624 | 1437 | |
| 1625 | 1438 | cases.add("dereference an array", |
| ... | ... | @@ -1630,8 +1443,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 1630 | 1443 | \\ return (*out)[0..1]; |
| 1631 | 1444 | \\} |
| 1632 | 1445 | \\ |
| 1633 | | \\extern fn entry() -> usize { @sizeOf(@typeOf(pass)) } |
| 1634 | | \\comptime {@export("entry", entry);} |
| 1446 | \\export fn entry() -> usize { @sizeOf(@typeOf(pass)) } |
| 1635 | 1447 | , ".tmp_source.zig:4:5: error: attempt to dereference non pointer type '[10]u8'"); |
| 1636 | 1448 | |
| 1637 | 1449 | cases.add("pass const ptr to mutable ptr fn", |
| ... | ... | @@ -1644,31 +1456,46 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 1644 | 1456 | \\ return true; |
| 1645 | 1457 | \\} |
| 1646 | 1458 | \\ |
| 1647 | | \\extern fn entry() -> usize { @sizeOf(@typeOf(foo)) } |
| 1648 | | \\comptime {@export("entry", entry);} |
| 1459 | \\export fn entry() -> usize { @sizeOf(@typeOf(foo)) } |
| 1649 | 1460 | , ".tmp_source.zig:4:19: error: expected type '&[]const u8', found '&const []const u8'"); |
| 1650 | 1461 | |
| 1462 | cases.addCase({ |
| 1463 | const tc = cases.create("export collision", |
| 1464 | \\const foo = @import("foo.zig"); |
| 1465 | \\ |
| 1466 | \\export fn bar() -> usize { |
| 1467 | \\ return foo.baz; |
| 1468 | \\} |
| 1469 | , |
| 1470 | "foo.zig:1:8: error: exported symbol collision: 'bar'", |
| 1471 | ".tmp_source.zig:3:8: note: other symbol here"); |
| 1472 | |
| 1473 | tc.addSourceFile("foo.zig", |
| 1474 | \\export fn bar() {} |
| 1475 | \\pub const baz = 1234; |
| 1476 | ); |
| 1477 | |
| 1478 | tc |
| 1479 | }); |
| 1480 | |
| 1651 | 1481 | cases.add("pass non-copyable type by value to function", |
| 1652 | 1482 | \\const Point = struct { x: i32, y: i32, }; |
| 1653 | 1483 | \\fn foo(p: Point) { } |
| 1654 | | \\extern fn entry() -> usize { @sizeOf(@typeOf(foo)) } |
| 1655 | | \\comptime {@export("entry", entry);} |
| 1484 | \\export fn entry() -> usize { @sizeOf(@typeOf(foo)) } |
| 1656 | 1485 | , ".tmp_source.zig:2:11: error: type 'Point' is not copyable; cannot pass by value"); |
| 1657 | 1486 | |
| 1658 | 1487 | cases.add("implicit cast from array to mutable slice", |
| 1659 | 1488 | \\var global_array: [10]i32 = undefined; |
| 1660 | 1489 | \\fn foo(param: []i32) {} |
| 1661 | | \\extern fn entry() { |
| 1490 | \\export fn entry() { |
| 1662 | 1491 | \\ foo(global_array); |
| 1663 | 1492 | \\} |
| 1664 | | \\comptime {@export("entry", entry);} |
| 1665 | 1493 | , ".tmp_source.zig:4:9: error: expected type '[]i32', found '[10]i32'"); |
| 1666 | 1494 | |
| 1667 | 1495 | cases.add("ptrcast to non-pointer", |
| 1668 | | \\extern fn entry(a: &i32) -> usize { |
| 1496 | \\export fn entry(a: &i32) -> usize { |
| 1669 | 1497 | \\ return @ptrCast(usize, a); |
| 1670 | 1498 | \\} |
| 1671 | | \\comptime {@export("entry", entry);} |
| 1672 | 1499 | , ".tmp_source.zig:2:21: error: expected pointer, found 'usize'"); |
| 1673 | 1500 | |
| 1674 | 1501 | cases.add("too many error values to cast to small integer", |
| ... | ... | @@ -1677,8 +1504,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 1677 | 1504 | \\fn foo(e: error) -> u2 { |
| 1678 | 1505 | \\ return u2(e); |
| 1679 | 1506 | \\} |
| 1680 | | \\extern fn entry() -> usize { @sizeOf(@typeOf(foo)) } |
| 1681 | | \\comptime {@export("entry", entry);} |
| 1507 | \\export fn entry() -> usize { @sizeOf(@typeOf(foo)) } |
| 1682 | 1508 | , ".tmp_source.zig:4:14: error: too many error values to fit in 'u2'"); |
| 1683 | 1509 | |
| 1684 | 1510 | cases.add("asm at compile time", |
| ... | ... | @@ -1697,46 +1523,41 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 1697 | 1523 | |
| 1698 | 1524 | cases.add("invalid member of builtin enum", |
| 1699 | 1525 | \\const builtin = @import("builtin"); |
| 1700 | | \\extern fn entry() { |
| 1526 | \\export fn entry() { |
| 1701 | 1527 | \\ const foo = builtin.Arch.x86; |
| 1702 | 1528 | \\} |
| 1703 | | \\comptime {@export("entry", entry);} |
| 1704 | 1529 | , ".tmp_source.zig:3:29: error: container 'Arch' has no member called 'x86'"); |
| 1705 | 1530 | |
| 1706 | 1531 | cases.add("int to ptr of 0 bits", |
| 1707 | | \\extern fn foo() { |
| 1532 | \\export fn foo() { |
| 1708 | 1533 | \\ var x: usize = 0x1000; |
| 1709 | 1534 | \\ var y: &void = @intToPtr(&void, x); |
| 1710 | 1535 | \\} |
| 1711 | | \\comptime {@export("foo", foo);} |
| 1712 | 1536 | , ".tmp_source.zig:3:31: error: type '&void' has 0 bits and cannot store information"); |
| 1713 | 1537 | |
| 1714 | 1538 | cases.add("@fieldParentPtr - non struct", |
| 1715 | 1539 | \\const Foo = i32; |
| 1716 | | \\extern fn foo(a: &i32) -> &Foo { |
| 1540 | \\export fn foo(a: &i32) -> &Foo { |
| 1717 | 1541 | \\ return @fieldParentPtr(Foo, "a", a); |
| 1718 | 1542 | \\} |
| 1719 | | \\comptime {@export("foo", foo);} |
| 1720 | 1543 | , ".tmp_source.zig:3:28: error: expected struct type, found 'i32'"); |
| 1721 | 1544 | |
| 1722 | 1545 | cases.add("@fieldParentPtr - bad field name", |
| 1723 | 1546 | \\const Foo = struct { |
| 1724 | 1547 | \\ derp: i32, |
| 1725 | 1548 | \\}; |
| 1726 | | \\extern fn foo(a: &i32) -> &Foo { |
| 1549 | \\export fn foo(a: &i32) -> &Foo { |
| 1727 | 1550 | \\ return @fieldParentPtr(Foo, "a", a); |
| 1728 | 1551 | \\} |
| 1729 | | \\comptime {@export("foo", foo);} |
| 1730 | 1552 | , ".tmp_source.zig:5:33: error: struct 'Foo' has no field 'a'"); |
| 1731 | 1553 | |
| 1732 | 1554 | cases.add("@fieldParentPtr - field pointer is not pointer", |
| 1733 | 1555 | \\const Foo = struct { |
| 1734 | 1556 | \\ a: i32, |
| 1735 | 1557 | \\}; |
| 1736 | | \\extern fn foo(a: i32) -> &Foo { |
| 1558 | \\export fn foo(a: i32) -> &Foo { |
| 1737 | 1559 | \\ return @fieldParentPtr(Foo, "a", a); |
| 1738 | 1560 | \\} |
| 1739 | | \\comptime {@export("foo", foo);} |
| 1740 | 1561 | , ".tmp_source.zig:5:38: error: expected pointer, found 'i32'"); |
| 1741 | 1562 | |
| 1742 | 1563 | cases.add("@fieldParentPtr - comptime field ptr not based on struct", |
| ... | ... | @@ -1766,20 +1587,18 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 1766 | 1587 | |
| 1767 | 1588 | cases.add("@offsetOf - non struct", |
| 1768 | 1589 | \\const Foo = i32; |
| 1769 | | \\extern fn foo() -> usize { |
| 1590 | \\export fn foo() -> usize { |
| 1770 | 1591 | \\ return @offsetOf(Foo, "a"); |
| 1771 | 1592 | \\} |
| 1772 | | \\comptime {@export("foo", foo);} |
| 1773 | 1593 | , ".tmp_source.zig:3:22: error: expected struct type, found 'i32'"); |
| 1774 | 1594 | |
| 1775 | 1595 | cases.add("@offsetOf - bad field name", |
| 1776 | 1596 | \\const Foo = struct { |
| 1777 | 1597 | \\ derp: i32, |
| 1778 | 1598 | \\}; |
| 1779 | | \\extern fn foo() -> usize { |
| 1599 | \\export fn foo() -> usize { |
| 1780 | 1600 | \\ return @offsetOf(Foo, "a"); |
| 1781 | 1601 | \\} |
| 1782 | | \\comptime {@export("foo", foo);} |
| 1783 | 1602 | , ".tmp_source.zig:5:27: error: struct 'Foo' has no field 'a'"); |
| 1784 | 1603 | |
| 1785 | 1604 | cases.addExe("missing main fn in executable", |
| ... | ... | @@ -1792,22 +1611,44 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 1792 | 1611 | "error: 'main' is private", |
| 1793 | 1612 | ".tmp_source.zig:1:1: note: declared here"); |
| 1794 | 1613 | |
| 1614 | cases.add("setting a section on an extern variable", |
| 1615 | \\extern var foo: i32 section(".text2"); |
| 1616 | \\export fn entry() -> i32 { |
| 1617 | \\ return foo; |
| 1618 | \\} |
| 1619 | , |
| 1620 | ".tmp_source.zig:1:29: error: cannot set section of external variable 'foo'"); |
| 1621 | |
| 1622 | cases.add("setting a section on a local variable", |
| 1623 | \\export fn entry() -> i32 { |
| 1624 | \\ var foo: i32 section(".text2") = 1234; |
| 1625 | \\ return foo; |
| 1626 | \\} |
| 1627 | , |
| 1628 | ".tmp_source.zig:2:26: error: cannot set section of local variable 'foo'"); |
| 1629 | |
| 1630 | cases.add("setting a section on an extern fn", |
| 1631 | \\extern fn foo() section(".text2"); |
| 1632 | \\export fn entry() { |
| 1633 | \\ foo(); |
| 1634 | \\} |
| 1635 | , |
| 1636 | ".tmp_source.zig:1:25: error: cannot set section of external function 'foo'"); |
| 1637 | |
| 1795 | 1638 | cases.add("returning address of local variable - simple", |
| 1796 | | \\extern fn foo() -> &i32 { |
| 1639 | \\export fn foo() -> &i32 { |
| 1797 | 1640 | \\ var a: i32 = undefined; |
| 1798 | 1641 | \\ return &a; |
| 1799 | 1642 | \\} |
| 1800 | | \\comptime {@export("foo", foo);} |
| 1801 | 1643 | , |
| 1802 | 1644 | ".tmp_source.zig:3:13: error: function returns address of local variable"); |
| 1803 | 1645 | |
| 1804 | 1646 | cases.add("returning address of local variable - phi", |
| 1805 | | \\extern fn foo(c: bool) -> &i32 { |
| 1647 | \\export fn foo(c: bool) -> &i32 { |
| 1806 | 1648 | \\ var a: i32 = undefined; |
| 1807 | 1649 | \\ var b: i32 = undefined; |
| 1808 | 1650 | \\ return if (c) &a else &b; |
| 1809 | 1651 | \\} |
| 1810 | | \\comptime {@export("foo", foo);} |
| 1811 | 1652 | , |
| 1812 | 1653 | ".tmp_source.zig:4:12: error: function returns address of local variable"); |
| 1813 | 1654 | |
| ... | ... | @@ -1836,61 +1677,55 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 1836 | 1677 | ".tmp_source.zig:5:9: note: previous definition is here"); |
| 1837 | 1678 | |
| 1838 | 1679 | cases.add("while expected bool, got nullable", |
| 1839 | | \\extern fn foo() { |
| 1680 | \\export fn foo() { |
| 1840 | 1681 | \\ while (bar()) {} |
| 1841 | 1682 | \\} |
| 1842 | 1683 | \\fn bar() -> ?i32 { 1 } |
| 1843 | | \\comptime {@export("foo", foo);} |
| 1844 | 1684 | , |
| 1845 | 1685 | ".tmp_source.zig:2:15: error: expected type 'bool', found '?i32'"); |
| 1846 | 1686 | |
| 1847 | 1687 | cases.add("while expected bool, got error union", |
| 1848 | | \\extern fn foo() { |
| 1688 | \\export fn foo() { |
| 1849 | 1689 | \\ while (bar()) {} |
| 1850 | 1690 | \\} |
| 1851 | 1691 | \\fn bar() -> %i32 { 1 } |
| 1852 | | \\comptime {@export("foo", foo);} |
| 1853 | 1692 | , |
| 1854 | 1693 | ".tmp_source.zig:2:15: error: expected type 'bool', found '%i32'"); |
| 1855 | 1694 | |
| 1856 | 1695 | cases.add("while expected nullable, got bool", |
| 1857 | | \\extern fn foo() { |
| 1696 | \\export fn foo() { |
| 1858 | 1697 | \\ while (bar()) |x| {} |
| 1859 | 1698 | \\} |
| 1860 | 1699 | \\fn bar() -> bool { true } |
| 1861 | | \\comptime {@export("foo", foo);} |
| 1862 | 1700 | , |
| 1863 | 1701 | ".tmp_source.zig:2:15: error: expected nullable type, found 'bool'"); |
| 1864 | 1702 | |
| 1865 | 1703 | cases.add("while expected nullable, got error union", |
| 1866 | | \\extern fn foo() { |
| 1704 | \\export fn foo() { |
| 1867 | 1705 | \\ while (bar()) |x| {} |
| 1868 | 1706 | \\} |
| 1869 | 1707 | \\fn bar() -> %i32 { 1 } |
| 1870 | | \\comptime {@export("foo", foo);} |
| 1871 | 1708 | , |
| 1872 | 1709 | ".tmp_source.zig:2:15: error: expected nullable type, found '%i32'"); |
| 1873 | 1710 | |
| 1874 | 1711 | cases.add("while expected error union, got bool", |
| 1875 | | \\extern fn foo() { |
| 1712 | \\export fn foo() { |
| 1876 | 1713 | \\ while (bar()) |x| {} else |err| {} |
| 1877 | 1714 | \\} |
| 1878 | 1715 | \\fn bar() -> bool { true } |
| 1879 | | \\comptime {@export("foo", foo);} |
| 1880 | 1716 | , |
| 1881 | 1717 | ".tmp_source.zig:2:15: error: expected error union type, found 'bool'"); |
| 1882 | 1718 | |
| 1883 | 1719 | cases.add("while expected error union, got nullable", |
| 1884 | | \\extern fn foo() { |
| 1720 | \\export fn foo() { |
| 1885 | 1721 | \\ while (bar()) |x| {} else |err| {} |
| 1886 | 1722 | \\} |
| 1887 | 1723 | \\fn bar() -> ?i32 { 1 } |
| 1888 | | \\comptime {@export("foo", foo);} |
| 1889 | 1724 | , |
| 1890 | 1725 | ".tmp_source.zig:2:15: error: expected error union type, found '?i32'"); |
| 1891 | 1726 | |
| 1892 | 1727 | cases.add("inline fn calls itself indirectly", |
| 1893 | | \\extern fn foo() { |
| 1728 | \\export fn foo() { |
| 1894 | 1729 | \\ bar(); |
| 1895 | 1730 | \\} |
| 1896 | 1731 | \\inline fn bar() { |
| ... | ... | @@ -1902,33 +1737,29 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 1902 | 1737 | \\ quux(); |
| 1903 | 1738 | \\} |
| 1904 | 1739 | \\extern fn quux(); |
| 1905 | | \\comptime {@export("foo", foo);} |
| 1906 | 1740 | , |
| 1907 | 1741 | ".tmp_source.zig:4:8: error: unable to inline function"); |
| 1908 | 1742 | |
| 1909 | 1743 | cases.add("save reference to inline function", |
| 1910 | | \\extern fn foo() { |
| 1744 | \\export fn foo() { |
| 1911 | 1745 | \\ quux(@ptrToInt(bar)); |
| 1912 | 1746 | \\} |
| 1913 | 1747 | \\inline fn bar() { } |
| 1914 | 1748 | \\extern fn quux(usize); |
| 1915 | | \\comptime {@export("foo", foo);} |
| 1916 | 1749 | , |
| 1917 | 1750 | ".tmp_source.zig:4:8: error: unable to inline function"); |
| 1918 | 1751 | |
| 1919 | 1752 | cases.add("signed integer division", |
| 1920 | | \\extern fn foo(a: i32, b: i32) -> i32 { |
| 1753 | \\export fn foo(a: i32, b: i32) -> i32 { |
| 1921 | 1754 | \\ a / b |
| 1922 | 1755 | \\} |
| 1923 | | \\comptime {@export("foo", foo);} |
| 1924 | 1756 | , |
| 1925 | 1757 | ".tmp_source.zig:2:7: error: division with 'i32' and 'i32': signed integers must use @divTrunc, @divFloor, or @divExact"); |
| 1926 | 1758 | |
| 1927 | 1759 | cases.add("signed integer remainder division", |
| 1928 | | \\extern fn foo(a: i32, b: i32) -> i32 { |
| 1760 | \\export fn foo(a: i32, b: i32) -> i32 { |
| 1929 | 1761 | \\ a % b |
| 1930 | 1762 | \\} |
| 1931 | | \\comptime {@export("foo", foo);} |
| 1932 | 1763 | , |
| 1933 | 1764 | ".tmp_source.zig:2:7: error: remainder division with 'i32' and 'i32': signed integers and floats must use @rem or @mod"); |
| 1934 | 1765 | |
| ... | ... | @@ -1967,65 +1798,59 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 1967 | 1798 | ".tmp_source.zig:3:20: error: cast from 'u16' to 'u8' truncates bits"); |
| 1968 | 1799 | |
| 1969 | 1800 | cases.add("@setDebugSafety twice for same scope", |
| 1970 | | \\extern fn foo() { |
| 1801 | \\export fn foo() { |
| 1971 | 1802 | \\ @setDebugSafety(this, false); |
| 1972 | 1803 | \\ @setDebugSafety(this, false); |
| 1973 | 1804 | \\} |
| 1974 | | \\comptime {@export("foo", foo);} |
| 1975 | 1805 | , |
| 1976 | 1806 | ".tmp_source.zig:3:5: error: debug safety set twice for same scope", |
| 1977 | 1807 | ".tmp_source.zig:2:5: note: first set here"); |
| 1978 | 1808 | |
| 1979 | 1809 | cases.add("@setFloatMode twice for same scope", |
| 1980 | | \\extern fn foo() { |
| 1810 | \\export fn foo() { |
| 1981 | 1811 | \\ @setFloatMode(this, @import("builtin").FloatMode.Optimized); |
| 1982 | 1812 | \\ @setFloatMode(this, @import("builtin").FloatMode.Optimized); |
| 1983 | 1813 | \\} |
| 1984 | | \\comptime {@export("foo", foo);} |
| 1985 | 1814 | , |
| 1986 | 1815 | ".tmp_source.zig:3:5: error: float mode set twice for same scope", |
| 1987 | 1816 | ".tmp_source.zig:2:5: note: first set here"); |
| 1988 | 1817 | |
| 1989 | 1818 | cases.add("array access of type", |
| 1990 | | \\extern fn foo() { |
| 1819 | \\export fn foo() { |
| 1991 | 1820 | \\ var b: u8[40] = undefined; |
| 1992 | 1821 | \\} |
| 1993 | | \\comptime {@export("foo", foo);} |
| 1994 | 1822 | , |
| 1995 | 1823 | ".tmp_source.zig:2:14: error: array access of non-array type 'type'"); |
| 1996 | 1824 | |
| 1997 | 1825 | cases.add("cannot break out of defer expression", |
| 1998 | | \\extern fn foo() { |
| 1826 | \\export fn foo() { |
| 1999 | 1827 | \\ while (true) { |
| 2000 | 1828 | \\ defer { |
| 2001 | 1829 | \\ break; |
| 2002 | 1830 | \\ } |
| 2003 | 1831 | \\ } |
| 2004 | 1832 | \\} |
| 2005 | | \\comptime {@export("foo", foo);} |
| 2006 | 1833 | , |
| 2007 | 1834 | ".tmp_source.zig:4:13: error: cannot break out of defer expression"); |
| 2008 | 1835 | |
| 2009 | 1836 | cases.add("cannot continue out of defer expression", |
| 2010 | | \\extern fn foo() { |
| 1837 | \\export fn foo() { |
| 2011 | 1838 | \\ while (true) { |
| 2012 | 1839 | \\ defer { |
| 2013 | 1840 | \\ continue; |
| 2014 | 1841 | \\ } |
| 2015 | 1842 | \\ } |
| 2016 | 1843 | \\} |
| 2017 | | \\comptime {@export("foo", foo);} |
| 2018 | 1844 | , |
| 2019 | 1845 | ".tmp_source.zig:4:13: error: cannot continue out of defer expression"); |
| 2020 | 1846 | |
| 2021 | 1847 | cases.add("cannot goto out of defer expression", |
| 2022 | | \\extern fn foo() { |
| 1848 | \\export fn foo() { |
| 2023 | 1849 | \\ defer { |
| 2024 | 1850 | \\ goto label; |
| 2025 | 1851 | \\ }; |
| 2026 | 1852 | \\label: |
| 2027 | 1853 | \\} |
| 2028 | | \\comptime {@export("foo", foo);} |
| 2029 | 1854 | , |
| 2030 | 1855 | ".tmp_source.zig:3:9: error: cannot goto out of defer expression"); |
| 2031 | 1856 | |
| ... | ... | @@ -2059,10 +1884,9 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 2059 | 1884 | \\const bar = baz + foo; |
| 2060 | 1885 | \\const baz = 1; |
| 2061 | 1886 | \\ |
| 2062 | | \\extern fn entry() -> i32 { |
| 1887 | \\export fn entry() -> i32 { |
| 2063 | 1888 | \\ return bar; |
| 2064 | 1889 | \\} |
| 2065 | | \\comptime {@export("entry", entry);} |
| 2066 | 1890 | , |
| 2067 | 1891 | ".tmp_source.zig:1:13: error: aoeu", |
| 2068 | 1892 | ".tmp_source.zig:3:19: note: referenced here", |
| ... | ... | @@ -2075,10 +1899,9 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 2075 | 1899 | \\ |
| 2076 | 1900 | \\var foo: Foo = undefined; |
| 2077 | 1901 | \\ |
| 2078 | | \\extern fn entry() -> usize { |
| 1902 | \\export fn entry() -> usize { |
| 2079 | 1903 | \\ return @sizeOf(@typeOf(foo.x)); |
| 2080 | 1904 | \\} |
| 2081 | | \\comptime {@export("entry", entry);} |
| 2082 | 1905 | , |
| 2083 | 1906 | ".tmp_source.zig:1:13: error: struct 'Foo' contains itself"); |
| 2084 | 1907 | |
| ... | ... | @@ -2097,18 +1920,16 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 2097 | 1920 | ".tmp_source.zig:2:15: error: float literal out of range of any type"); |
| 2098 | 1921 | |
| 2099 | 1922 | cases.add("explicit cast float literal to integer when there is a fraction component", |
| 2100 | | \\extern fn entry() -> i32 { |
| 1923 | \\export fn entry() -> i32 { |
| 2101 | 1924 | \\ i32(12.34) |
| 2102 | 1925 | \\} |
| 2103 | | \\comptime {@export("entry", entry);} |
| 2104 | 1926 | , |
| 2105 | 1927 | ".tmp_source.zig:2:9: error: fractional component prevents float value 12.340000 from being casted to type 'i32'"); |
| 2106 | 1928 | |
| 2107 | 1929 | cases.add("non pointer given to @ptrToInt", |
| 2108 | | \\extern fn entry(x: i32) -> usize { |
| 1930 | \\export fn entry(x: i32) -> usize { |
| 2109 | 1931 | \\ @ptrToInt(x) |
| 2110 | 1932 | \\} |
| 2111 | | \\comptime {@export("entry", entry);} |
| 2112 | 1933 | , |
| 2113 | 1934 | ".tmp_source.zig:2:15: error: expected pointer, found 'i32'"); |
| 2114 | 1935 | |
| ... | ... | @@ -2127,27 +1948,24 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 2127 | 1948 | ".tmp_source.zig:2:15: error: exact shift shifted out 1 bits"); |
| 2128 | 1949 | |
| 2129 | 1950 | cases.add("shifting without int type or comptime known", |
| 2130 | | \\extern fn entry(x: u8) -> u8 { |
| 1951 | \\export fn entry(x: u8) -> u8 { |
| 2131 | 1952 | \\ return 0x11 << x; |
| 2132 | 1953 | \\} |
| 2133 | | \\comptime {@export("entry", entry);} |
| 2134 | 1954 | , |
| 2135 | 1955 | ".tmp_source.zig:2:17: error: LHS of shift must be an integer type, or RHS must be compile-time known"); |
| 2136 | 1956 | |
| 2137 | 1957 | cases.add("shifting RHS is log2 of LHS int bit width", |
| 2138 | | \\extern fn entry(x: u8, y: u8) -> u8 { |
| 1958 | \\export fn entry(x: u8, y: u8) -> u8 { |
| 2139 | 1959 | \\ return x << y; |
| 2140 | 1960 | \\} |
| 2141 | | \\comptime {@export("entry", entry);} |
| 2142 | 1961 | , |
| 2143 | 1962 | ".tmp_source.zig:2:17: error: expected type 'u3', found 'u8'"); |
| 2144 | 1963 | |
| 2145 | 1964 | cases.add("globally shadowing a primitive type", |
| 2146 | 1965 | \\const u16 = @intType(false, 8); |
| 2147 | | \\extern fn entry() { |
| 1966 | \\export fn entry() { |
| 2148 | 1967 | \\ const a: u16 = 300; |
| 2149 | 1968 | \\} |
| 2150 | | \\comptime {@export("entry", entry);} |
| 2151 | 1969 | , |
| 2152 | 1970 | ".tmp_source.zig:1:1: error: declaration shadows type 'u16'"); |
| 2153 | 1971 | |
| ... | ... | @@ -2157,7 +1975,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 2157 | 1975 | \\ b: u32, |
| 2158 | 1976 | \\}; |
| 2159 | 1977 | \\ |
| 2160 | | \\extern fn entry() { |
| 1978 | \\export fn entry() { |
| 2161 | 1979 | \\ var foo = Foo { .a = 1, .b = 10 }; |
| 2162 | 1980 | \\ bar(&foo.b); |
| 2163 | 1981 | \\} |
| ... | ... | @@ -2165,7 +1983,6 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 2165 | 1983 | \\fn bar(x: &u32) { |
| 2166 | 1984 | \\ *x += 1; |
| 2167 | 1985 | \\} |
| 2168 | | \\comptime {@export("entry", entry);} |
| 2169 | 1986 | , |
| 2170 | 1987 | ".tmp_source.zig:8:13: error: expected type '&u32', found '&align(1) u32'"); |
| 2171 | 1988 | |
| ... | ... | @@ -2175,7 +1992,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 2175 | 1992 | \\ b: u32, |
| 2176 | 1993 | \\}; |
| 2177 | 1994 | \\ |
| 2178 | | \\extern fn entry() { |
| 1995 | \\export fn entry() { |
| 2179 | 1996 | \\ var foo = Foo { .a = 1, .b = 10 }; |
| 2180 | 1997 | \\ foo.b += 1; |
| 2181 | 1998 | \\ bar((&foo.b)[0..1]); |
| ... | ... | @@ -2184,61 +2001,55 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 2184 | 2001 | \\fn bar(x: []u32) { |
| 2185 | 2002 | \\ x[0] += 1; |
| 2186 | 2003 | \\} |
| 2187 | | \\comptime {@export("entry", entry);} |
| 2188 | 2004 | , |
| 2189 | 2005 | ".tmp_source.zig:9:17: error: expected type '[]u32', found '[]align(1) u32'"); |
| 2190 | 2006 | |
| 2191 | 2007 | cases.add("increase pointer alignment in @ptrCast", |
| 2192 | | \\extern fn entry() -> u32 { |
| 2008 | \\export fn entry() -> u32 { |
| 2193 | 2009 | \\ var bytes: [4]u8 = []u8{0x01, 0x02, 0x03, 0x04}; |
| 2194 | 2010 | \\ const ptr = @ptrCast(&u32, &bytes[0]); |
| 2195 | 2011 | \\ return *ptr; |
| 2196 | 2012 | \\} |
| 2197 | | \\comptime {@export("entry", entry);} |
| 2198 | 2013 | , |
| 2199 | 2014 | ".tmp_source.zig:3:17: error: cast increases pointer alignment", |
| 2200 | 2015 | ".tmp_source.zig:3:38: note: '&u8' has alignment 1", |
| 2201 | 2016 | ".tmp_source.zig:3:27: note: '&u32' has alignment 4"); |
| 2202 | 2017 | |
| 2203 | 2018 | cases.add("increase pointer alignment in slice resize", |
| 2204 | | \\extern fn entry() -> u32 { |
| 2019 | \\export fn entry() -> u32 { |
| 2205 | 2020 | \\ var bytes = []u8{0x01, 0x02, 0x03, 0x04}; |
| 2206 | 2021 | \\ return ([]u32)(bytes[0..])[0]; |
| 2207 | 2022 | \\} |
| 2208 | | \\comptime {@export("entry", entry);} |
| 2209 | 2023 | , |
| 2210 | 2024 | ".tmp_source.zig:3:19: error: cast increases pointer alignment", |
| 2211 | 2025 | ".tmp_source.zig:3:19: note: '[]u8' has alignment 1", |
| 2212 | 2026 | ".tmp_source.zig:3:19: note: '[]u32' has alignment 4"); |
| 2213 | 2027 | |
| 2214 | 2028 | cases.add("@alignCast expects pointer or slice", |
| 2215 | | \\extern fn entry() { |
| 2029 | \\export fn entry() { |
| 2216 | 2030 | \\ @alignCast(4, u32(3)) |
| 2217 | 2031 | \\} |
| 2218 | | \\comptime {@export("entry", entry);} |
| 2219 | 2032 | , |
| 2220 | 2033 | ".tmp_source.zig:2:22: error: expected pointer or slice, found 'u32'"); |
| 2221 | 2034 | |
| 2222 | 2035 | cases.add("passing an under-aligned function pointer", |
| 2223 | | \\extern fn entry() { |
| 2036 | \\export fn entry() { |
| 2224 | 2037 | \\ testImplicitlyDecreaseFnAlign(alignedSmall, 1234); |
| 2225 | 2038 | \\} |
| 2226 | 2039 | \\fn testImplicitlyDecreaseFnAlign(ptr: fn () align(8) -> i32, answer: i32) { |
| 2227 | 2040 | \\ if (ptr() != answer) unreachable; |
| 2228 | 2041 | \\} |
| 2229 | 2042 | \\fn alignedSmall() align(4) -> i32 { 1234 } |
| 2230 | | \\comptime {@export("entry", entry);} |
| 2231 | 2043 | , |
| 2232 | 2044 | ".tmp_source.zig:2:35: error: expected type 'fn() align(8) -> i32', found 'fn() align(4) -> i32'"); |
| 2233 | 2045 | |
| 2234 | 2046 | cases.add("passing a not-aligned-enough pointer to cmpxchg", |
| 2235 | 2047 | \\const AtomicOrder = @import("builtin").AtomicOrder; |
| 2236 | | \\extern fn entry() -> bool { |
| 2048 | \\export fn entry() -> bool { |
| 2237 | 2049 | \\ var x: i32 align(1) = 1234; |
| 2238 | 2050 | \\ while (!@cmpxchg(&x, 1234, 5678, AtomicOrder.SeqCst, AtomicOrder.SeqCst)) {} |
| 2239 | 2051 | \\ return x == 5678; |
| 2240 | 2052 | \\} |
| 2241 | | \\comptime {@export("entry", entry);} |
| 2242 | 2053 | , |
| 2243 | 2054 | ".tmp_source.zig:4:23: error: expected pointer alignment of at least 4, found 1"); |
| 2244 | 2055 | |
| ... | ... | @@ -2264,18 +2075,17 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 2264 | 2075 | cases.add("wrong pointer implicitly casted to pointer to @OpaqueType()", |
| 2265 | 2076 | \\const Derp = @OpaqueType(); |
| 2266 | 2077 | \\extern fn bar(d: &Derp); |
| 2267 | | \\extern fn foo() { |
| 2078 | \\export fn foo() { |
| 2268 | 2079 | \\ const x = u8(1); |
| 2269 | 2080 | \\ bar(@ptrCast(&c_void, &x)); |
| 2270 | 2081 | \\} |
| 2271 | | \\comptime {@export("foo", foo);} |
| 2272 | 2082 | , |
| 2273 | 2083 | ".tmp_source.zig:5:9: error: expected type '&Derp', found '&c_void'"); |
| 2274 | 2084 | |
| 2275 | 2085 | cases.add("non-const variables of things that require const variables", |
| 2276 | 2086 | \\const Opaque = @OpaqueType(); |
| 2277 | 2087 | \\ |
| 2278 | | \\extern fn entry(opaque: &Opaque) { |
| 2088 | \\export fn entry(opaque: &Opaque) { |
| 2279 | 2089 | \\ var m2 = &2; |
| 2280 | 2090 | \\ const y: u32 = *m2; |
| 2281 | 2091 | \\ |
| ... | ... | @@ -2295,7 +2105,6 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 2295 | 2105 | \\const Foo = struct { |
| 2296 | 2106 | \\ fn bar(self: &const Foo) {} |
| 2297 | 2107 | \\}; |
| 2298 | | \\comptime {@export("entry", entry);} |
| 2299 | 2108 | , |
| 2300 | 2109 | ".tmp_source.zig:4:4: error: variable of type '&const (integer literal)' must be const or comptime", |
| 2301 | 2110 | ".tmp_source.zig:7:4: error: variable of type '(undefined)' must be const or comptime", |
| ... | ... | @@ -2310,14 +2119,21 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 2310 | 2119 | ".tmp_source.zig:17:4: error: unreachable code"); |
| 2311 | 2120 | |
| 2312 | 2121 | cases.add("wrong types given to atomic order args in cmpxchg", |
| 2313 | | \\extern fn entry() { |
| 2122 | \\export fn entry() { |
| 2314 | 2123 | \\ var x: i32 = 1234; |
| 2315 | 2124 | \\ while (!@cmpxchg(&x, 1234, 5678, u32(1234), u32(1234))) {} |
| 2316 | 2125 | \\} |
| 2317 | | \\comptime {@export("entry", entry);} |
| 2318 | 2126 | , |
| 2319 | 2127 | ".tmp_source.zig:3:41: error: expected type 'AtomicOrder', found 'u32'"); |
| 2320 | 2128 | |
| 2129 | cases.add("wrong types given to @export", |
| 2130 | \\extern fn entry() { } |
| 2131 | \\comptime { |
| 2132 | \\ @export("entry", entry, u32(1234)); |
| 2133 | \\} |
| 2134 | , |
| 2135 | ".tmp_source.zig:3:32: error: expected type 'GlobalLinkage', found 'u32'"); |
| 2136 | |
| 2321 | 2137 | cases.add("struct with invalid field", |
| 2322 | 2138 | \\const std = @import("std"); |
| 2323 | 2139 | \\const Allocator = std.mem.Allocator; |
| ... | ... | @@ -2336,13 +2152,12 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 2336 | 2152 | \\ }, |
| 2337 | 2153 | \\}; |
| 2338 | 2154 | \\ |
| 2339 | | \\extern fn entry() { |
| 2155 | \\export fn entry() { |
| 2340 | 2156 | \\ const a = MdNode.Header { |
| 2341 | 2157 | \\ .text = MdText.init(&std.debug.global_allocator), |
| 2342 | 2158 | \\ .weight = HeaderWeight.H1, |
| 2343 | 2159 | \\ }; |
| 2344 | 2160 | \\} |
| 2345 | | \\comptime {@export("entry", entry);} |
| 2346 | 2161 | , |
| 2347 | 2162 | ".tmp_source.zig:14:17: error: use of undeclared identifier 'HeaderValue'"); |
| 2348 | 2163 | |
| ... | ... | @@ -2354,39 +2169,35 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 2354 | 2169 | ".tmp_source.zig:2:5: error: @setAlignStack outside function"); |
| 2355 | 2170 | |
| 2356 | 2171 | cases.add("@setAlignStack in naked function", |
| 2357 | | \\nakedcc fn entry() { |
| 2172 | \\export nakedcc fn entry() { |
| 2358 | 2173 | \\ @setAlignStack(16); |
| 2359 | 2174 | \\} |
| 2360 | | \\comptime {@export("entry", entry);} |
| 2361 | 2175 | , |
| 2362 | 2176 | ".tmp_source.zig:2:5: error: @setAlignStack in naked function"); |
| 2363 | 2177 | |
| 2364 | 2178 | cases.add("@setAlignStack in inline function", |
| 2365 | | \\extern fn entry() { |
| 2179 | \\export fn entry() { |
| 2366 | 2180 | \\ foo(); |
| 2367 | 2181 | \\} |
| 2368 | 2182 | \\inline fn foo() { |
| 2369 | 2183 | \\ @setAlignStack(16); |
| 2370 | 2184 | \\} |
| 2371 | | \\comptime {@export("entry", entry);} |
| 2372 | 2185 | , |
| 2373 | 2186 | ".tmp_source.zig:5:5: error: @setAlignStack in inline function"); |
| 2374 | 2187 | |
| 2375 | 2188 | cases.add("@setAlignStack set twice", |
| 2376 | | \\extern fn entry() { |
| 2189 | \\export fn entry() { |
| 2377 | 2190 | \\ @setAlignStack(16); |
| 2378 | 2191 | \\ @setAlignStack(16); |
| 2379 | 2192 | \\} |
| 2380 | | \\comptime {@export("entry", entry);} |
| 2381 | 2193 | , |
| 2382 | 2194 | ".tmp_source.zig:3:5: error: alignstack set twice", |
| 2383 | 2195 | ".tmp_source.zig:2:5: note: first set here"); |
| 2384 | 2196 | |
| 2385 | 2197 | cases.add("@setAlignStack too big", |
| 2386 | | \\extern fn entry() { |
| 2198 | \\export fn entry() { |
| 2387 | 2199 | \\ @setAlignStack(511 + 1); |
| 2388 | 2200 | \\} |
| 2389 | | \\comptime {@export("entry", entry);} |
| 2390 | 2201 | , |
| 2391 | 2202 | ".tmp_source.zig:2:5: error: attempt to @setAlignStack(512); maximum is 256"); |
| 2392 | 2203 | |
| ... | ... | @@ -2417,7 +2228,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 2417 | 2228 | \\ LinkLibC, |
| 2418 | 2229 | \\}; |
| 2419 | 2230 | \\ |
| 2420 | | \\extern fn entry() { |
| 2231 | \\export fn entry() { |
| 2421 | 2232 | \\ const tests = []TestCase { |
| 2422 | 2233 | \\ Free("001"), |
| 2423 | 2234 | \\ Free("002"), |
| ... | ... | @@ -2432,14 +2243,13 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 2432 | 2243 | \\ } |
| 2433 | 2244 | \\ } |
| 2434 | 2245 | \\} |
| 2435 | | \\comptime {@export("entry", entry);} |
| 2436 | 2246 | , |
| 2437 | 2247 | ".tmp_source.zig:37:16: error: cannot store runtime value in compile time variable"); |
| 2438 | 2248 | |
| 2439 | 2249 | cases.add("field access of opaque type", |
| 2440 | 2250 | \\const MyType = @OpaqueType(); |
| 2441 | 2251 | \\ |
| 2442 | | \\extern fn entry() -> bool { |
| 2252 | \\export fn entry() -> bool { |
| 2443 | 2253 | \\ var x: i32 = 1; |
| 2444 | 2254 | \\ return bar(@ptrCast(&MyType, &x)); |
| 2445 | 2255 | \\} |
| ... | ... | @@ -2447,7 +2257,6 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 2447 | 2257 | \\fn bar(x: &MyType) -> bool { |
| 2448 | 2258 | \\ return x.blah; |
| 2449 | 2259 | \\} |
| 2450 | | \\comptime {@export("entry", entry);} |
| 2451 | 2260 | , |
| 2452 | 2261 | ".tmp_source.zig:9:13: error: type '&MyType' does not support field access"); |
| 2453 | 2262 | |
| ... | ... | @@ -2551,11 +2360,10 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 2551 | 2360 | ".tmp_source.zig:2:26: error: member index 1 out of bounds; 'Foo' has 1 members"); |
| 2552 | 2361 | |
| 2553 | 2362 | cases.add("calling var args extern function, passing array instead of pointer", |
| 2554 | | \\extern fn entry() { |
| 2363 | \\export fn entry() { |
| 2555 | 2364 | \\ foo("hello"); |
| 2556 | 2365 | \\} |
| 2557 | 2366 | \\pub extern fn foo(format: &const u8, ...); |
| 2558 | | \\comptime {@export("entry", entry);} |
| 2559 | 2367 | , |
| 2560 | 2368 | ".tmp_source.zig:2:9: error: expected type '&const u8', found '[5]u8'"); |
| 2561 | 2369 | |
| ... | ... | @@ -2570,10 +2378,9 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 2570 | 2378 | \\ } |
| 2571 | 2379 | \\} |
| 2572 | 2380 | \\ |
| 2573 | | \\extern fn entry() { |
| 2381 | \\export fn entry() { |
| 2574 | 2382 | \\ var allocator: ContextAllocator = undefined; |
| 2575 | 2383 | \\} |
| 2576 | | \\comptime {@export("entry", entry);} |
| 2577 | 2384 | , |
| 2578 | 2385 | ".tmp_source.zig:4:25: error: aoeu", |
| 2579 | 2386 | ".tmp_source.zig:1:36: note: called from here", |
| ... | ... | @@ -2588,10 +2395,9 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 2588 | 2395 | \\ Five, |
| 2589 | 2396 | \\}; |
| 2590 | 2397 | \\ |
| 2591 | | \\extern fn entry() { |
| 2398 | \\export fn entry() { |
| 2592 | 2399 | \\ var x = Small.One; |
| 2593 | 2400 | \\} |
| 2594 | | \\comptime {@export("entry", entry);} |
| 2595 | 2401 | , |
| 2596 | 2402 | ".tmp_source.zig:1:20: error: 'u2' too small to hold all bits; must be at least 'u3'"); |
| 2597 | 2403 | |
| ... | ... | @@ -2602,10 +2408,9 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 2602 | 2408 | \\ Three, |
| 2603 | 2409 | \\}; |
| 2604 | 2410 | \\ |
| 2605 | | \\extern fn entry() { |
| 2411 | \\export fn entry() { |
| 2606 | 2412 | \\ var x = Small.One; |
| 2607 | 2413 | \\} |
| 2608 | | \\comptime {@export("entry", entry);} |
| 2609 | 2414 | , |
| 2610 | 2415 | ".tmp_source.zig:1:20: error: expected integer, found 'f32'"); |
| 2611 | 2416 | |
| ... | ... | @@ -2617,10 +2422,9 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 2617 | 2422 | \\ Four, |
| 2618 | 2423 | \\}; |
| 2619 | 2424 | \\ |
| 2620 | | \\extern fn entry() { |
| 2425 | \\export fn entry() { |
| 2621 | 2426 | \\ var x: u2 = Small.Two; |
| 2622 | 2427 | \\} |
| 2623 | | \\comptime {@export("entry", entry);} |
| 2624 | 2428 | , |
| 2625 | 2429 | ".tmp_source.zig:9:22: error: expected type 'u2', found 'Small'"); |
| 2626 | 2430 | |
| ... | ... | @@ -2632,10 +2436,9 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 2632 | 2436 | \\ Four, |
| 2633 | 2437 | \\}; |
| 2634 | 2438 | \\ |
| 2635 | | \\extern fn entry() { |
| 2439 | \\export fn entry() { |
| 2636 | 2440 | \\ var x = u3(Small.Two); |
| 2637 | 2441 | \\} |
| 2638 | | \\comptime {@export("entry", entry);} |
| 2639 | 2442 | , |
| 2640 | 2443 | ".tmp_source.zig:9:15: error: enum to integer cast to 'u3' instead of its tag type, 'u2'"); |
| 2641 | 2444 | |
| ... | ... | @@ -2647,11 +2450,10 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 2647 | 2450 | \\ Four, |
| 2648 | 2451 | \\}; |
| 2649 | 2452 | \\ |
| 2650 | | \\extern fn entry() { |
| 2453 | \\export fn entry() { |
| 2651 | 2454 | \\ var y = u3(3); |
| 2652 | 2455 | \\ var x = Small(y); |
| 2653 | 2456 | \\} |
| 2654 | | \\comptime {@export("entry", entry);} |
| 2655 | 2457 | , |
| 2656 | 2458 | ".tmp_source.zig:10:18: error: integer to enum cast from 'u3' instead of its tag type, 'u2'"); |
| 2657 | 2459 | |
| ... | ... | @@ -2663,10 +2465,9 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 2663 | 2465 | \\ Four, |
| 2664 | 2466 | \\}; |
| 2665 | 2467 | \\ |
| 2666 | | \\extern fn entry() { |
| 2468 | \\export fn entry() { |
| 2667 | 2469 | \\ var y = Small.Two; |
| 2668 | 2470 | \\} |
| 2669 | | \\comptime {@export("entry", entry);} |
| 2670 | 2471 | , |
| 2671 | 2472 | ".tmp_source.zig:1:19: error: expected unsigned integer, found 'i2'"); |
| 2672 | 2473 | |
| ... | ... | @@ -2674,10 +2475,9 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 2674 | 2475 | \\const MultipleChoice = struct { |
| 2675 | 2476 | \\ A: i32 = 20, |
| 2676 | 2477 | \\}; |
| 2677 | | \\extern fn entry() { |
| 2478 | \\export fn entry() { |
| 2678 | 2479 | \\ var x: MultipleChoice = undefined; |
| 2679 | 2480 | \\} |
| 2680 | | \\comptime {@export("entry", entry);} |
| 2681 | 2481 | , |
| 2682 | 2482 | ".tmp_source.zig:2:14: error: enums, not structs, support field assignment"); |
| 2683 | 2483 | |
| ... | ... | @@ -2685,29 +2485,26 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 2685 | 2485 | \\const MultipleChoice = union { |
| 2686 | 2486 | \\ A: i32 = 20, |
| 2687 | 2487 | \\}; |
| 2688 | | \\extern fn entry() { |
| 2488 | \\export fn entry() { |
| 2689 | 2489 | \\ var x: MultipleChoice = undefined; |
| 2690 | 2490 | \\} |
| 2691 | | \\comptime {@export("entry", entry);} |
| 2692 | 2491 | , |
| 2693 | 2492 | ".tmp_source.zig:2:14: error: non-enum union field assignment", |
| 2694 | 2493 | ".tmp_source.zig:1:24: note: consider 'union(enum)' here"); |
| 2695 | 2494 | |
| 2696 | 2495 | cases.add("enum with 0 fields", |
| 2697 | 2496 | \\const Foo = enum {}; |
| 2698 | | \\extern fn entry() -> usize { |
| 2497 | \\export fn entry() -> usize { |
| 2699 | 2498 | \\ return @sizeOf(Foo); |
| 2700 | 2499 | \\} |
| 2701 | | \\comptime {@export("entry", entry);} |
| 2702 | 2500 | , |
| 2703 | 2501 | ".tmp_source.zig:1:13: error: enums must have 1 or more fields"); |
| 2704 | 2502 | |
| 2705 | 2503 | cases.add("union with 0 fields", |
| 2706 | 2504 | \\const Foo = union {}; |
| 2707 | | \\extern fn entry() -> usize { |
| 2505 | \\export fn entry() -> usize { |
| 2708 | 2506 | \\ return @sizeOf(Foo); |
| 2709 | 2507 | \\} |
| 2710 | | \\comptime {@export("entry", entry);} |
| 2711 | 2508 | , |
| 2712 | 2509 | ".tmp_source.zig:1:13: error: unions must have 1 or more fields"); |
| 2713 | 2510 | |
| ... | ... | @@ -2719,10 +2516,9 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 2719 | 2516 | \\ D = 1000, |
| 2720 | 2517 | \\ E = 60, |
| 2721 | 2518 | \\}; |
| 2722 | | \\extern fn entry() { |
| 2519 | \\export fn entry() { |
| 2723 | 2520 | \\ var x = MultipleChoice.C; |
| 2724 | 2521 | \\} |
| 2725 | | \\comptime {@export("entry", entry);} |
| 2726 | 2522 | , |
| 2727 | 2523 | ".tmp_source.zig:6:9: error: enum tag value 60 already taken", |
| 2728 | 2524 | ".tmp_source.zig:4:9: note: other occurrence here"); |
| ... | ... | @@ -2737,10 +2533,9 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 2737 | 2533 | \\ A: i32, |
| 2738 | 2534 | \\ B: f64, |
| 2739 | 2535 | \\}; |
| 2740 | | \\extern fn entry() -> usize { |
| 2536 | \\export fn entry() -> usize { |
| 2741 | 2537 | \\ return @sizeOf(Payload); |
| 2742 | 2538 | \\} |
| 2743 | | \\comptime {@export("entry", entry);} |
| 2744 | 2539 | , |
| 2745 | 2540 | ".tmp_source.zig:6:17: error: enum field missing: 'C'", |
| 2746 | 2541 | ".tmp_source.zig:4:5: note: declared here"); |
| ... | ... | @@ -2749,10 +2544,9 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 2749 | 2544 | \\const Foo = union { |
| 2750 | 2545 | \\ A: i32, |
| 2751 | 2546 | \\}; |
| 2752 | | \\extern fn entry() { |
| 2547 | \\export fn entry() { |
| 2753 | 2548 | \\ const x = @TagType(Foo); |
| 2754 | 2549 | \\} |
| 2755 | | \\comptime {@export("entry", entry);} |
| 2756 | 2550 | , |
| 2757 | 2551 | ".tmp_source.zig:5:24: error: union 'Foo' has no tag", |
| 2758 | 2552 | ".tmp_source.zig:1:13: note: consider 'union(enum)' here"); |
| ... | ... | @@ -2761,10 +2555,9 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 2761 | 2555 | \\const Foo = union(enum(f32)) { |
| 2762 | 2556 | \\ A: i32, |
| 2763 | 2557 | \\}; |
| 2764 | | \\extern fn entry() { |
| 2558 | \\export fn entry() { |
| 2765 | 2559 | \\ const x = @TagType(Foo); |
| 2766 | 2560 | \\} |
| 2767 | | \\comptime {@export("entry", entry);} |
| 2768 | 2561 | , |
| 2769 | 2562 | ".tmp_source.zig:1:23: error: expected integer tag type, found 'f32'"); |
| 2770 | 2563 | |
| ... | ... | @@ -2772,10 +2565,9 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 2772 | 2565 | \\const Foo = union(u32) { |
| 2773 | 2566 | \\ A: i32, |
| 2774 | 2567 | \\}; |
| 2775 | | \\extern fn entry() { |
| 2568 | \\export fn entry() { |
| 2776 | 2569 | \\ const x = @TagType(Foo); |
| 2777 | 2570 | \\} |
| 2778 | | \\comptime {@export("entry", entry);} |
| 2779 | 2571 | , |
| 2780 | 2572 | ".tmp_source.zig:1:18: error: expected enum tag type, found 'u32'"); |
| 2781 | 2573 | |
| ... | ... | @@ -2787,10 +2579,9 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 2787 | 2579 | \\ D = 1000, |
| 2788 | 2580 | \\ E = 60, |
| 2789 | 2581 | \\}; |
| 2790 | | \\extern fn entry() { |
| 2582 | \\export fn entry() { |
| 2791 | 2583 | \\ var x = MultipleChoice { .C = {} }; |
| 2792 | 2584 | \\} |
| 2793 | | \\comptime {@export("entry", entry);} |
| 2794 | 2585 | , |
| 2795 | 2586 | ".tmp_source.zig:6:9: error: enum tag value 60 already taken", |
| 2796 | 2587 | ".tmp_source.zig:4:9: note: other occurrence here"); |
| ... | ... | @@ -2807,10 +2598,9 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 2807 | 2598 | \\ C: bool, |
| 2808 | 2599 | \\ D: bool, |
| 2809 | 2600 | \\}; |
| 2810 | | \\extern fn entry() { |
| 2601 | \\export fn entry() { |
| 2811 | 2602 | \\ var a = Payload {.A = 1234}; |
| 2812 | 2603 | \\} |
| 2813 | | \\comptime {@export("entry", entry);} |
| 2814 | 2604 | , |
| 2815 | 2605 | ".tmp_source.zig:10:5: error: enum field not found: 'D'", |
| 2816 | 2606 | ".tmp_source.zig:1:16: note: enum declared here"); |
| ... | ... | @@ -2821,10 +2611,9 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 2821 | 2611 | \\ B, |
| 2822 | 2612 | \\ C, |
| 2823 | 2613 | \\}; |
| 2824 | | \\extern fn entry() { |
| 2614 | \\export fn entry() { |
| 2825 | 2615 | \\ var b = Letter.B; |
| 2826 | 2616 | \\} |
| 2827 | | \\comptime {@export("entry", entry);} |
| 2828 | 2617 | , |
| 2829 | 2618 | ".tmp_source.zig:2:8: error: structs and unions, not enums, support field types", |
| 2830 | 2619 | ".tmp_source.zig:1:16: note: consider 'union(enum)' here"); |
| ... | ... | @@ -2833,10 +2622,9 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 2833 | 2622 | \\const Letter = struct { |
| 2834 | 2623 | \\ A, |
| 2835 | 2624 | \\}; |
| 2836 | | \\extern fn entry() { |
| 2625 | \\export fn entry() { |
| 2837 | 2626 | \\ var a = Letter { .A = {} }; |
| 2838 | 2627 | \\} |
| 2839 | | \\comptime {@export("entry", entry);} |
| 2840 | 2628 | , |
| 2841 | 2629 | ".tmp_source.zig:2:5: error: struct field missing type"); |
| 2842 | 2630 | |
| ... | ... | @@ -2844,10 +2632,9 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 2844 | 2632 | \\const Letter = extern union { |
| 2845 | 2633 | \\ A, |
| 2846 | 2634 | \\}; |
| 2847 | | \\extern fn entry() { |
| 2635 | \\export fn entry() { |
| 2848 | 2636 | \\ var a = Letter { .A = {} }; |
| 2849 | 2637 | \\} |
| 2850 | | \\comptime {@export("entry", entry);} |
| 2851 | 2638 | , |
| 2852 | 2639 | ".tmp_source.zig:2:5: error: union field missing type"); |
| 2853 | 2640 | |
| ... | ... | @@ -2862,10 +2649,9 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 2862 | 2649 | \\ B: f64, |
| 2863 | 2650 | \\ C: bool, |
| 2864 | 2651 | \\}; |
| 2865 | | \\extern fn entry() { |
| 2652 | \\export fn entry() { |
| 2866 | 2653 | \\ var a = Payload { .A = { 1234 } }; |
| 2867 | 2654 | \\} |
| 2868 | | \\comptime {@export("entry", entry);} |
| 2869 | 2655 | , |
| 2870 | 2656 | ".tmp_source.zig:6:29: error: extern union does not support enum tag type"); |
| 2871 | 2657 | |
| ... | ... | @@ -2880,10 +2666,9 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 2880 | 2666 | \\ B: f64, |
| 2881 | 2667 | \\ C: bool, |
| 2882 | 2668 | \\}; |
| 2883 | | \\extern fn entry() { |
| 2669 | \\export fn entry() { |
| 2884 | 2670 | \\ var a = Payload { .A = { 1234 } }; |
| 2885 | 2671 | \\} |
| 2886 | | \\comptime {@export("entry", entry);} |
| 2887 | 2672 | , |
| 2888 | 2673 | ".tmp_source.zig:6:29: error: packed union does not support enum tag type"); |
| 2889 | 2674 | |
| ... | ... | @@ -2893,7 +2678,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 2893 | 2678 | \\ B: f64, |
| 2894 | 2679 | \\ C: bool, |
| 2895 | 2680 | \\}; |
| 2896 | | \\extern fn entry() { |
| 2681 | \\export fn entry() { |
| 2897 | 2682 | \\ const a = Payload { .A = { 1234 } }; |
| 2898 | 2683 | \\ foo(a); |
| 2899 | 2684 | \\} |
| ... | ... | @@ -2903,7 +2688,6 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 2903 | 2688 | \\ else => unreachable, |
| 2904 | 2689 | \\ } |
| 2905 | 2690 | \\} |
| 2906 | | \\comptime {@export("entry", entry);} |
| 2907 | 2691 | , |
| 2908 | 2692 | ".tmp_source.zig:11:13: error: switch on union which has no attached enum", |
| 2909 | 2693 | ".tmp_source.zig:1:17: note: consider 'union(enum)' here"); |
| ... | ... | @@ -2913,10 +2697,9 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 2913 | 2697 | \\ A = 10, |
| 2914 | 2698 | \\ B = 11, |
| 2915 | 2699 | \\}; |
| 2916 | | \\extern fn entry() { |
| 2700 | \\export fn entry() { |
| 2917 | 2701 | \\ var x = Foo(0); |
| 2918 | 2702 | \\} |
| 2919 | | \\comptime {@export("entry", entry);} |
| 2920 | 2703 | , |
| 2921 | 2704 | ".tmp_source.zig:6:16: error: enum 'Foo' has no tag matching integer value 0", |
| 2922 | 2705 | ".tmp_source.zig:1:13: note: 'Foo' declared here"); |
| ... | ... | @@ -2928,10 +2711,9 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 2928 | 2711 | \\ B, |
| 2929 | 2712 | \\ C, |
| 2930 | 2713 | \\}; |
| 2931 | | \\extern fn entry() { |
| 2714 | \\export fn entry() { |
| 2932 | 2715 | \\ var x: Value = Letter.A; |
| 2933 | 2716 | \\} |
| 2934 | | \\comptime {@export("entry", entry);} |
| 2935 | 2717 | , |
| 2936 | 2718 | ".tmp_source.zig:8:26: error: cast to union 'Value' must initialize 'i32' field 'A'", |
| 2937 | 2719 | ".tmp_source.zig:3:5: note: field 'A' declared here"); |
| ... | ... | @@ -2943,36 +2725,13 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 2943 | 2725 | \\ B, |
| 2944 | 2726 | \\ C, |
| 2945 | 2727 | \\}; |
| 2946 | | \\extern fn entry() { |
| 2728 | \\export fn entry() { |
| 2947 | 2729 | \\ foo(Letter.A); |
| 2948 | 2730 | \\} |
| 2949 | 2731 | \\fn foo(l: Letter) { |
| 2950 | 2732 | \\ var x: Value = l; |
| 2951 | 2733 | \\} |
| 2952 | | \\comptime {@export("entry", entry);} |
| 2953 | 2734 | , |
| 2954 | 2735 | ".tmp_source.zig:11:20: error: runtime cast to union 'Value' which has non-void fields", |
| 2955 | 2736 | ".tmp_source.zig:3:5: note: field 'A' has type 'i32'"); |
| 2956 | | |
| 2957 | | cases.addCase({ |
| 2958 | | const tc = cases.create("export collision", |
| 2959 | | \\const foo = @import("foo.zig"); |
| 2960 | | \\ |
| 2961 | | \\comptime {@export("bar", bar);} |
| 2962 | | \\extern fn bar() -> usize { |
| 2963 | | \\ return foo.baz; |
| 2964 | | \\} |
| 2965 | | , |
| 2966 | | "foo.zig:2:11: error: exported symbol collision: 'bar'", |
| 2967 | | ".tmp_source.zig:3:11: note: other symbol is here"); |
| 2968 | | |
| 2969 | | tc.addSourceFile("foo.zig", |
| 2970 | | \\extern fn bar() {} |
| 2971 | | \\comptime {@export("bar", bar);} |
| 2972 | | \\pub const baz = 1234; |
| 2973 | | ); |
| 2974 | | |
| 2975 | | tc |
| 2976 | | }); |
| 2977 | | |
| 2978 | 2737 | } |