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