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