Commit Graph

956 Commits

Author SHA1 Message Date
John Schmidt
e41bc640c6 astgen: do not discard result location in for/while loops
If we use the discard result location any break with a value will be
ignored and not checked for usage.

Closes https://github.com/ziglang/zig/issues/14684.
2023-03-01 02:51:59 -05:00
Isaac Freund
05da5b32a8 Sema: implement @fieldParentPtr for unions 2023-02-21 15:57:13 +02:00
Andrew Kelley
53104b9165 add test coverage for fixed bug. closes #5410 2023-02-19 21:18:27 -07:00
Veikka Tuominen
f10950526e implement writeToMemory/readFromMemory for pointers 2023-02-19 13:54:52 -05:00
Andrew Kelley
15d767c621 add safety test cases for multi-object for loops 2023-02-18 19:20:19 -07:00
Andrew Kelley
8b05205bb7 implement error for unbounded for loops 2023-02-18 19:20:19 -07:00
Andrew Kelley
4dd958d585 improve error message for byref capture of byval array 2023-02-18 19:20:19 -07:00
Andrew Kelley
601db3981c fix source location for not-indexable for loop errors 2023-02-18 19:20:19 -07:00
Andrew Kelley
bcb72401d3 AstGen: add error for discard of unbounded counter 2023-02-18 19:17:21 -07:00
Andrew Kelley
22965e6fcb Sema: improve error message for mismatched for loop lengths 2023-02-18 19:17:21 -07:00
Andrew Kelley
b13745ac03 disable failing x86_64 backend tests 2023-02-18 19:17:21 -07:00
Andrew Kelley
8c96d0dddd update test-cases for new for loop syntax 2023-02-18 19:17:21 -07:00
Veikka Tuominen
7199d7c777 split @qualCast into @constCast and @volatileCast 2023-02-15 01:43:57 +02:00
Veikka Tuominen
b9c2837c1c Sema: validate inferred error set payload type
This was missed in b0a55e1b3b
2023-02-11 14:36:54 +02:00
Andrew Kelley
6b7ad22981
Merge pull request #14477 from Vexu/fixes
Improve `@ptrCast` errors, fix some bugs
2023-02-01 23:31:52 -05:00
Veikka Tuominen
490addde27 Sema: fix error location on comptime arg to typed generic param
Closes #14505
2023-02-01 20:50:43 +02:00
Andrew Kelley
34b3145099 update test case for new std.builtin.OptimizeMode API 2023-01-31 15:09:35 -07:00
r00ster91
17404f8e6e Sema: emit compile error for comptime or inline call of function pointer 2023-01-31 17:15:34 +02:00
Veikka Tuominen
f16c10a86b implement @qualCast 2023-01-30 18:55:57 +02:00
Veikka Tuominen
fe4ea31f7e Sema: replace backticks with single quotes
Most error messages already use single quotes for everything
so this makes the remaining ones consistent.
2023-01-30 15:20:16 +02:00
Veikka Tuominen
a9785fe8ee Sema: add helpful notes to invalid @ptrCast operations
Closes #14474
2023-01-30 15:20:16 +02:00
Veikka Tuominen
b129350cb5 AstGen: fix crash on invalid decltest
Closes  #14476
2023-01-30 15:20:16 +02:00
Veikka Tuominen
720d82721f Sema: ensure args to inline comptime args are comptime-known
Closes #14413
2023-01-30 15:20:16 +02:00
Veikka Tuominen
1f475de852 Sema: fix unwrapping null when reporting error on member access
Closes #14399
2023-01-22 01:04:20 +02:00
Veikka Tuominen
e04547642a Sema: promote smaller float types passed to variadic functions
Closes #6854
2023-01-17 20:28:43 +02:00
Veikka Tuominen
94be9dcc7f enable passing compile error test 2023-01-17 20:28:43 +02:00
Veikka Tuominen
1658e4893d AstGen: add note pointing to tuple field
Closes #14188
2023-01-11 21:11:21 +02:00
Veikka Tuominen
8b1780d939 Sema: fix condition for omitting comptime arg from function type
Closes #14164
2023-01-11 21:11:21 +02:00
Veikka Tuominen
f2faa303a5 Sema: handle enum expressions referencing local variables
Closes #12272
2023-01-05 22:03:32 +02:00
Veikka Tuominen
8c4727f9ab Sema: remove generic function from monomorphed_funcs on any error 2023-01-05 14:26:53 +02:00
Veikka Tuominen
3e084d8de3 Sema: only untyped undefined should coerce to all types
Closes #13958
2023-01-05 14:26:53 +02:00
Veikka Tuominen
352c71873b Sema: improve struct/union field error locations
Closes #14206
2023-01-05 13:11:36 +02:00
Veikka Tuominen
abd005f302 Sema: do not immediately destroy failed generic instantiation
Closes #12535
Closes #12765
Closes #12927
2023-01-03 18:38:15 +02:00
Veikka Tuominen
332a43858a Sema: @intToEnum on non-exhaustive enum at comptime should check int is in range
Closes #14155
2023-01-02 17:06:06 +02:00
Veikka Tuominen
58c1d98c14 add tests for fixed stage1 bugs
Closes #4144
Closes #4255
Closes #4372
Closes #4375
Closes #4380
Closes #4417
Closes #4423
Closes #4476
Closes #4528
Closes #4562
Closes #4572
Closes #4597
Closes #4639
Closes #4672
Closes #4782
Closes #4955
Closes #4984
Closes #4997
Closes #5010
Closes #5114
Closes #5166
Closes #5173
Closes #5276
2022-12-31 20:49:02 -05:00
Veikka Tuominen
e0b6140009 Type: fix printing of default alignment on non-byte aligned pointers 2022-12-29 12:47:11 +02:00
Veikka Tuominen
9a0c593a54 add tests for fixed stage1 bugs
Closes #1957
Closes #1994
Closes #2140
Closes #2746
Closes #2802
Closes #2855
Closes #2895
Closes #2981
Closes #3054
Closes #3158
Closes #3234
Closes #3259
Closes #3371
Closes #3376
Closes #3387
Closes #3529
Closes #3653
Closes #3750
Closes #3778
Closes #3882
Closes #3915
Closes #3929
Closes #3961
Closes #3988
Closes #4123
Closes #7448
2022-12-29 12:42:44 +02:00
Jacob Young
74b14edea8 link: fix memory leaks
* Fix linker memory leaks found while running `zig build test-cases`.
 * Add missing target to test manifest.
2022-12-28 14:24:27 -05:00
Andrew Kelley
0be6157a23 disable failing compile errors test
tracking issue #14105
2022-12-28 12:08:03 -07:00
Veikka Tuominen
81443fcde8 Sema: add error for recursive inline call
Closes #12973
2022-12-26 16:36:30 +02:00
Andrew Kelley
f211c1559a
Merge pull request #13960 from r00ster91/stage1cruft
Close more old stage1 issues
2022-12-22 16:36:55 -05:00
r00ster91
a429f72ae8 cases: more test coverage
Closes #11986
Closes #11850
Closes #12159
2022-12-21 23:34:29 +01:00
Veikka Tuominen
0eddf0cbc0 Sema: fix condition for non-pointer noalias error
Closes #13987
2022-12-19 12:19:25 +02:00
Andrew Kelley
aca9c74e80
Merge pull request #13914 from Vexu/variadic
implement defining C variadic functions
2022-12-18 16:24:13 -05:00
Veikka Tuominen
40ed6ae846
Merge pull request #13930 from r00ster91/renamings
std.builtin: renamings
2022-12-18 19:33:15 +02:00
shwqf
11a81e1b29 Call ensureResultUsed before comptime .call is evaluated.
Fixes #12580
2022-12-18 16:04:33 +02:00
r00ster91
ceff03f3e9 std.builtin: remove layout field from Type.Enum 2022-12-18 13:31:38 +01:00
r00ster91
aac2d6b56f std.builtin: rename Type.UnionField and Type.StructField's field_type to type 2022-12-17 14:11:33 +01:00
r00ster91
7350ea3e2d std.builtin: rename Type.Fn's args to params
This was a poor naming choice; these are parameters, not arguments.
Parameters specify what kind of arguments are expected, whereas the arguments are the actual values passed.
2022-12-17 14:11:33 +01:00
r00ster91
20d3fd901e std.builtin: rename Type.Fn.Param's arg_type to type
It's the type of a parameter, not an argument, but the prefix is redundant either way.
2022-12-17 14:11:33 +01:00
Veikka Tuominen
9bb1104e37 implement defining C variadic functions 2022-12-17 13:22:09 +02:00
Veikka Tuominen
58caed1c71 Sema: make is_non_{null,err} stricter about types
Closes #13023
2022-12-17 13:22:09 +02:00
Veikka Tuominen
8a0a6b7387 port packed vector elem ptr logic from stage1
Closes #12812
Closes #13925
2022-12-15 21:06:35 -05:00
Veikka Tuominen
bc97a5662d Sema: display cimport errors from clang 2022-12-14 14:08:22 +02:00
Veikka Tuominen
886fa455fa Sema: avoid analyzing functions which failed when inlining 2022-12-14 14:08:21 +02:00
Veikka Tuominen
41913ddb1a remove no longer relevant stage1 compile errors 2022-12-14 14:08:21 +02:00
Veikka Tuominen
927d20b46b Sema: implement missing stage1 errors 2022-12-14 14:08:21 +02:00
Veikka Tuominen
423d7a74a4 move async compile errors into their own folder 2022-12-14 14:05:57 +02:00
Veikka Tuominen
327fb798c3 move stage2 compile errors out of special folder 2022-12-14 14:05:57 +02:00
Veikka Tuominen
08b2d491bc update usages of @call 2022-12-13 13:14:20 +02:00
IntegratedQuantum
15a6336bb4
Add a helpful note when using ** on number types. (#13871) 2022-12-11 14:41:42 -05:00
r00ster91
654e30069d behavior and cases: more test coverage for old issues
Closes #2622
Closes #2727
Closes #6047
Closes #6947
Closes #6656
2022-12-10 12:34:42 +01:00
Veikka Tuominen
5831b68341 AstGen: add check for missing builtin argument
Closes #13817
2022-12-09 20:37:18 -07:00
Veikka Tuominen
653c0bae0c remove stage1 specific compile error tests 2022-12-07 20:32:27 +02:00
r00ster91
f094c4bce5 Sema: detect duplicate enum tag values 2022-12-04 14:12:24 +02:00
Veikka Tuominen
b500e0eb17 Sema: add "parameter type declared here" note to type coercion 2022-12-03 00:48:04 +02:00
Veikka Tuominen
74285a4ed7 add test for error message improved by self-hosted
Closes #5099
2022-12-03 00:48:04 +02:00
Veikka Tuominen
f20e449fd6 Sema: improve error for mismatched type in implicit return
Closes #2653
2022-12-03 00:48:03 +02:00
Veikka Tuominen
e2509ddbe6 AstGen: add error for invalid string comparisons
These operations are allowed because the string literals are just
pointers but they produce unexpected results. These errors prevent
beginners from shooting themselves in the foot while still allowing
advanced users to circumvent them if they desire to do so.

Closes #8290
2022-12-03 00:09:23 +02:00
Veikka Tuominen
59dad43de2 Sema: add error for failed assumption about struct having runtime bits 2022-12-02 18:46:59 +02:00
Veikka Tuominen
86e6acb37b AstGen: improve error message for missing parameter name
Closes #13393
2022-12-02 15:39:40 +02:00
Andrew Kelley
ceb0a632cf std.mem.Allocator: allow shrink to fail
closes #13535
2022-11-29 23:30:38 -07:00
Veikka Tuominen
b2b1d421c3 Sema: add missing failWithBadMemberAccess to zirExport
The assumption that AstGen would error only holds when exporting
a identifier not a namespace member.
2022-11-29 21:44:08 +02:00
Veikka Tuominen
4b0ef6a409 Sema: make non-existent field error point to field name
Closes #13698
2022-11-29 21:44:08 +02:00
Veikka Tuominen
ed73429926 Sema: explain why parameter must be declared comptime
Closes #13692
2022-11-29 21:44:08 +02:00
Veikka Tuominen
17ff002bc0 Sema: improve safety panic for access of inactive union field 2022-11-29 21:44:08 +02:00
Veikka Tuominen
6337c04244 Sema: improve panic for slice start index being greater than end index
Closes #13689
2022-11-29 15:47:02 +02:00
Veikka Tuominen
304e828088
Merge pull request #13637 from Vexu/stage2-fixes
Stage2 bug fixes
2022-11-26 22:03:49 +02:00
Veikka Tuominen
fe38898246 Sema: pass c_import_buf to child block in more places
Closes  #13651
2022-11-26 18:05:27 +02:00
Veikka Tuominen
587ef60a28 Sema: resolve union fields before using getTagType
Closes #13649
2022-11-26 18:05:27 +02:00
Veikka Tuominen
bf62cb453b Sema: handle anytype parameter requiring comptime
Closes #13645
2022-11-26 18:05:27 +02:00
Veikka Tuominen
9f055e2eb0 Sema: improve compile error for tuple coercion mismatch 2022-11-23 22:16:31 +02:00
Veikka Tuominen
8eea73fb92 add tests for tuple declarations 2022-11-23 22:16:31 +02:00
Veikka Tuominen
9e276d32f3 Sema: fix memory management of missing field error
Closes #13590
2022-11-20 20:25:12 +02:00
Veikka Tuominen
835a1f7f0c Sema: fix missing error on mismatched array init count
Closes #13582
2022-11-20 20:25:12 +02:00
Veikka Tuominen
034507ef7c Module: fix compile error for non-comptime-known global initializer 2022-11-20 20:25:12 +02:00
Veikka Tuominen
bc76873827 Sema: fix type check in zirIntToPtr
Simple fix: don't assume a ptr type before it has been checked.

Closes #13567
2022-11-20 20:25:11 +02:00
mparadinha
c4f7663c92
Fix error reporting the wrong line for struct field inits (#13502)
* point to init part of field delc when that's where the error occurs

* update test to reflect fixed error message

* only lookup source location in case of error
2022-11-15 15:17:23 +02:00
Veikka Tuominen
0a188190b3 AstGen: make pointless discard error more strict
The error should only happen as a result of `_ = <expr>` not
for an operand of a break expression that is discarded.

Closes #13212
2022-11-11 17:59:53 +02:00
Veikka Tuominen
89e8bb409a AstGen: use condbr_inline if force_comptime is set
The `finishThenElseBlock` would correctly use `break_inline`
which would cause Sema to use `addRuntimeBreak` instead of
doing the branch at comptime.
2022-11-11 17:59:53 +02:00
Veikka Tuominen
dc128f403b
Merge pull request #13446 from Vexu/stage2-fixes
Stage2 bug fixes
2022-11-07 14:17:26 +02:00
Veikka Tuominen
ea48f06fc2 stage2: address of threadlocal variable is not comptime known
Closes #13215
2022-11-05 13:22:21 +02:00
Veikka Tuominen
f92e7bed7b stage2: bitsize of packed struct should trigger backing int ty check
Closes #13398
2022-11-05 12:54:38 +02:00
Andrew Kelley
1d68045919
Merge pull request #13101 from alichraghi/o4 2022-11-05 02:34:24 -04:00
Veikka Tuominen
e6b3cb5043 Sema: detect division overflow
Closes #13434
2022-11-04 23:13:29 +02:00
Veikka Tuominen
8c4faa5f3f
Merge pull request #13338 from Vexu/stage2-compile-errors
Improve some error messages
2022-11-04 16:04:31 +02:00
Ali Chraghi
f5f1f8c666 all: rename i386 to x86 2022-11-04 00:09:27 +03:30
Andrew Kelley
5f5a20ebaf
Merge pull request #13093 from jacobly0/backend-fixes
C backend fixes
2022-10-29 23:06:59 -04:00
Andrew Kelley
28dc208f65
Merge pull request #13082 from g-w1/unnamed-decls-and-relocs-p9
Plan9: Fix The Backend
2022-10-29 17:45:00 -04:00
Veikka Tuominen
d7314555f2 Sema: improve compile error for casting double pointer to anyopaque pointer
Closes #12042
2022-10-29 14:55:43 +03:00
Veikka Tuominen
61f5ea4c9a Sema: add error note for wrong pointer dereference syntax
Closes #1897
2022-10-29 14:55:43 +03:00
Jacob Young
48a2783969 cbe: implement optional slice representation change 2022-10-29 05:58:41 -04:00
Veikka Tuominen
c3b85e4e2f Sema: further enhance explanation of why expr is evaluated at comptime 2022-10-28 13:31:16 +03:00
Andrew Kelley
c389f8800b
Merge pull request #13290 from Vexu/generic-deletion-mitigation
Mitigate generic deletion bug
2022-10-28 01:04:00 -04:00
Andrew Kelley
2991e4a454
Merge pull request #13288 from Vexu/opt-slice
Optimize size of optional slices (+ some fixes)
2022-10-27 22:09:17 -04:00
InKryption
bc72ae5e4e Sema: Prevent coercion from tuple pointer to mutable slice.
Also fix some stdlib code affected by this.

Co-authored by: topolarity <topolarity@tapscott.me>
2022-10-27 22:00:47 -04:00
Veikka Tuominen
648d34d8ea Sema: coerce zero-bit generic args are coerced properly
Closes #13307
2022-10-27 13:40:20 +03:00
Veikka Tuominen
d9fe5ba7f8 Sema: add error for too big packed struct 2022-10-27 01:31:18 +03:00
Veikka Tuominen
b12a5cea75 remove test case triggering generic deletion bug
This test should be restored once the underlying issue is resolved (with the typo fixed).
2022-10-27 01:31:05 +03:00
Jacob Young
15df64ade8 std: add cbe hacks to more targets
These are needed because clang doesn't support anything in naked
functions, not even assembly register inputs.
2022-10-25 05:11:29 -04:00
Jacob G-W
5aef54cbc8 additional fixes for Plan9
with this, the tests should pass
2022-10-24 17:01:26 -04:00
Jacob G-W
c6fb798740 Revert "remove plan9 test coverage": Plan9 now works :^)
This reverts commit 67db2b85b7.
2022-10-24 16:53:12 -04:00
Veikka Tuominen
07b6173cb8 delete failing recursive test
Don't forget to add these back when solving #12973
2022-10-20 20:11:12 +03:00
Veikka Tuominen
c95a34b68f stage2: improve source location of assignment 2022-10-20 20:11:00 +03:00
Veikka Tuominen
34e4b07d0c Sema: allow runtime only instructions to be emitted in outside functions
It is possible to get comptime-known values from runtime-known values
for example the length of array. Allowing runtime only instructions to
be emitted outside function bodies allows these operations to happen.
In places where comptime-known values are required we have other methods
to ensure that and they usually result in more specific compile errors too.

Closes #12240
2022-10-20 20:11:00 +03:00
Veikka Tuominen
4e134f6dcb Sema: respect inline call semantics
If an argument is comptime-known but shouldn't be create an alloc
to store it in to get a runtime-known value.
2022-10-19 01:38:18 +03:00
Veikka Tuominen
3a8777a8bb fix hyphenation in test case
Follow up to 51d9db8569
2022-10-12 16:10:57 +03:00
Andrew Kelley
7ce1ee1bce
Merge pull request #13081 from r00ster91/docs
fix(text): hyphenation and other fixes
2022-10-12 05:26:11 -04:00
Veikka Tuominen
b316c25cc6
Merge pull request #13075 from Vexu/stage2-fixes
Stage2 misc fixes
2022-10-10 23:27:17 +02:00
Veikka Tuominen
3ccd4907fb Sema: add error for capturing a runtime value outside of function scope
Closes #13104
2022-10-08 16:58:54 +03:00
Veikka Tuominen
1500b9ddc3 Sema: restore sema.src after inline call
Closes #13099
2022-10-08 16:58:26 +03:00
Veikka Tuominen
4a6cc1c602 Sema: allow equality comparisons between error unions and error sets
Closes #1302
2022-10-07 11:04:02 +03:00
Veikka Tuominen
2315e1b410 safety: add safety check for hitting else branch on a corrupt enum value
Closes #7053
2022-10-07 11:04:02 +03:00
Veikka Tuominen
29ae6515f3 AstGen: use 'shadows' instead of 'redeclaration' when names are in different scopes
Closes #8532
2022-10-07 11:04:02 +03:00
Ali Chraghi
6672921e32 Sema: fix error location when casting pointer to slice
Co-authored-by: Veikka Tuominen <git@vexu.eu>
2022-10-06 21:18:01 +03:00
Veikka Tuominen
dffce98045 Sema: disallow using stage1 fn ptrs in extern contexts
Closes #13022
2022-10-06 20:09:45 +03:00
Veikka Tuominen
775e055b59 Sema: generic function instantiation inherits parent's branch quota
Closes #12624
2022-10-06 20:09:45 +03:00
Veikka Tuominen
94039d66ed Sema: disallow fieldParentPtr and offsetOf on comptime fields
Comptime fields are tied to the type and behave more like declarations
so these operations cannot return anything useful for them.
2022-10-06 20:09:45 +03:00
Veikka Tuominen
0b1dd845d9 stage2: add error for non-void error union payload being ignored
See https://github.com/ziglang/zig/pull/6060#discussion_r471032912
2022-10-06 15:39:06 +03:00
r00ster91
8e2aaf6aed fix(text): hyphenate "runtime" adjectives 2022-10-05 21:33:42 +02:00
r00ster91
51d9db8569 fix(text): hyphenate "comptime" adjectives 2022-10-05 21:19:30 +02:00
r00ster91
654e0b6679 fix(text): hyphenation and other fixes 2022-10-05 21:19:10 +02:00
Veikka Tuominen
c0350cf87e Sema: avoid passing undefined as reason to failWithNeededComptime
Closes #13046
2022-10-05 17:26:29 +03:00
Andrew Kelley
ff534d2267
Merge pull request #12979 from Vexu/inline-switch
Implement inline switch cases
2022-10-03 23:43:09 -04:00
Jacob Young
9d8cdb855b Sema: fix function paramater count mismatch note
expected type 'fn() void', found 'fn(i32) void'
function with 0 parameters cannot cast into a function with 0 parameters
  =>
expected type 'fn() void', found 'fn(i32) void'
function with 1 parameters cannot cast into a function with 0 parameters
2022-10-03 13:06:49 +03:00
Julian
32d755beb8
Sema: require reified packed struct fields to have zero alignment 2022-10-03 13:05:12 +03:00
Veikka Tuominen
b3c6d774d2 stage2: improve error message for missing member in file root struct
* the root struct decl name is fully qualified
  this prevents error messages containing 'main.main'
* avoid declared here note when file struct is missing a member
  It always points at the start of the file which might contain another
  container misleading the user.
2022-09-30 00:09:24 +03:00
Igor Anić
9f6f460124 Sema: improve source location in errors
resolves #12793
2022-09-29 14:45:08 +03:00
Jacob G-W
0a064eae99 stage2: detect duplicate enum values
Closes #12805
2022-09-28 12:48:54 +03:00
InKryption
c75e8f3616 Sema: check that reified enum field values fits tag type. 2022-09-27 18:38:37 +03:00
Veikka Tuominen
950a0e2405 Sema: implement inline else for errors enums and bools 2022-09-27 18:33:23 +03:00
Veikka Tuominen
0e77259f44 add inline switch union tag captures 2022-09-27 18:33:23 +03:00
Veikka Tuominen
cccc4c3827 AstGen: analyze inline switch cases 2022-09-27 18:05:08 +03:00
kkHAIKE
ba5cbea0c3
Sema: fix segfault when union init with empty field 2022-09-27 13:23:51 +03:00
John Schmidt
6cc2b26163 sema: load the correct AST in addFieldErrNote
The enum we want to get the fields from might not be declared in the
same file as the block we are analyzing, so we should get the AST from
the decl's file instead.

Closes #12950.
2022-09-25 10:28:48 +02:00
Veikka Tuominen
581df942e1 Sema: correct sentinel check on implicit cast from array ptr
Closes #12938
2022-09-23 17:39:06 +03:00
Veikka Tuominen
3de5c3b503 Sema: check for slices in packed and extern type validation
Closes #12930
2022-09-23 17:39:06 +03:00
kkHAIKE
4961044ce8 AstGen: store void to ptr result loc when there is no else branch 2022-09-21 20:21:02 +03:00
kkHAIKE
183127733c AstGen: make loop body's ResultLoc .none
Fixes #12555
Fixes #12551
Fixes #12455
2022-09-21 20:20:05 +03:00
Jacob Young
14f4c73191 sema: fix typo 2022-09-21 11:29:20 +02:00