aboutsummaryrefslogtreecommitdiff
path: root/test/cases/compile_errors
AgeCommit message (Collapse)Author
2023-07-10AstGen: make sure for range start and end are usizesr00ster91
Fixes #16311 The actual cause of #16311 is the `start_is_zero` special case: ```zig const range_len = if (end_val == .none or start_is_zero) end_val else try parent_gz.addPlNode(.sub, input, Zir.Inst.Bin{ .lhs = end_val, .rhs = start_val, }); ``` It only happens if the range start is 0. In that case we would not perform any type checking. Only in the other cases coincidentally `.sub` performs type checking in Sema, but the errors are still rather poor: ``` $ zig test x.zig x.zig:9:15: error: invalid operands to binary expression: 'Pointer' and 'Pointer' for ("abc".."def") |val| { ~~~~~^~~~~~~ ``` Note how it's the same as if I use `-`: ``` x.zig:9:11: error: invalid operands to binary expression: 'Pointer' and 'Pointer' "abc" - "def"; ~~~~~~^~~~~~~ ``` Now after this PR, the errors are much clearer for both range start and end: ``` x.zig:9:10: error: expected type 'usize', found '*const [3:0]u8' for ("abc".."def") |val| { ^~~~~ ``` This is why I decided to use `.ty` instead of `.coerced_ty` for both range start and end rather than just perform type checking in that `end_val == .none or start_is_zero` case.
2023-07-10Merge pull request #16339 from r00ster91/ueficcAndrew Kelley
std.os.uefi: use std.os.uefi.cc instead of .C as calling convention
2023-07-09Change math.Order order (#16356)Niles Salter
This speeds up algorithms like binary search
2023-07-08Sema: infrastructure for supporting more than .C callconv for variadic functionsr00ster91
Now you can add new calling conventions that you confirmed to work with variadic functions simply in a single place and the rest will work automatically.
2023-06-27behavior: boolean vector with 2 or more elementsr00ster91
Closes #12169
2023-06-27test cases: expected optional type in for loopr00ster91
Closes #10674
2023-06-27test cases: never-inline call of inline function with comptime parameterr00ster91
Closes #5995
2023-06-27test cases: @intCast on vectorr00ster91
Closes #11770
2023-06-26AstGen: fix result locations for elements of typed array initmlugg
Resolves: #16226
2023-06-25Merge pull request #16192 from mlugg/builtins-infer-dest-ty-fixesAndrew Kelley
Follow-up to cast builtin result type inference
2023-06-25AstGen: add source location to certain const initializersJacob Young
Before: assign_local_bad_coercion.zig:5:1: error: expected type 'u32', found 'u64' export fn constEntry() u32 { ^~~~~~ assign_local_bad_coercion.zig:11:19: error: expected type 'u32', found 'u64' var x: u32 = g(); ~^~ After: assign_local_bad_coercion.zig:6:21: error: expected type 'u32', found 'u64' const x: u32 = g(); ~^~ assign_local_bad_coercion.zig:11:19: error: expected type 'u32', found 'u64' var x: u32 = g(); ~^~
2023-06-25cases: add tests for errors introduced by cast builtin result type inferencemlugg
2023-06-24all: migrate code to new cast builtin syntaxmlugg
Most of this migration was performed automatically with `zig fmt`. There were a few exceptions which I had to manually fix: * `@alignCast` and `@addrSpaceCast` cannot be automatically rewritten * `@truncate`'s fixup is incorrect for vectors * Test cases are not formatted, and their error locations change
2023-06-20Type: remove arbitrary restrictions on param and return typesJacob Young
Opaque and `noreturn` makes sense since they don't represent real values, but `null` and `undefined` are perfectly normal comptime-only values. Closes #16088
2023-06-19all: zig fmt and rename "@XToY" to "@YFromX"Eric Joldasov
Signed-off-by: Eric Joldasov <bratishkaerik@getgoogleoff.me>
2023-06-14Merge pull request #15726 from mlugg/feat/peer-type-resolution-but-betterAndrew Kelley
Sema: rewrite peer type resolution
2023-06-13Merge pull request #15957 from BratishkaErik/deprecated-Andrew Kelley
std.*: remove stuff that was deprecated in older versions
2023-06-13Sema: rewrite peer type resolutionmlugg
The existing logic for peer type resolution was quite convoluted and buggy. This rewrite makes it much more resilient, readable, and extensible. The algorithm works by first iterating over the types to select a "strategy", then applying that strategy, possibly applying peer resolution recursively. Several new tests have been added to cover cases which the old logic did not correctly handle. Resolves: #15138 Resolves: #15644 Resolves: #15693 Resolves: #15709 Resolves: #15752
2023-06-13Add a compiler error for @mulAdd with int vectors.IntegratedQuantum
2023-06-13std.meta: remove `Vector` (deprecated in 0.10)Eric Joldasov
Followup to d42d31f72f38165f70c2850e9cc63da44b3b470c. Signed-off-by: Eric Joldasov <bratishkaerik@getgoogleoff.me>
2023-06-13Fix bad source locations in switch capture errorsmlugg
To do this, I expanded SwitchProngSrc a bit. Several of the tags there aren't actually used by any current errors, but they're there for consistency and if we ever need them. Also delete a now-redundant test and fix another.
2023-06-13Sema: resolve union payload switch captures with peer type resolutionmlugg
This is a bit harder than it seems at first glance. Actually resolving the type is the easy part: the interesting thing is actually getting the capture value. We split this into three cases: * If all payload types are the same (as is required in status quo), we can just do what we already do: get the first field value. * If all payloads are in-memory coercible to the resolved type, we still fetch the first field, but we also emit a `bitcast` to convert to the resolved type. * Otherwise, we need to handle each case separately. We emit a nested `switch_br` which, for each possible case, gets the corresponding union field, and coerces it to the resolved type. As an optimization, the inner switch's 'else' prong is used for any peer which is in-memory coercible to the target type, and the bitcast approach described above is used. Pointer captures have the additional constraint that all payload types must be in-memory coercible to the resolved type. Resolves: #2812
2023-06-10stage2: pass most test cases under InternPoolmlugg
All but 2 test cases now pass (tested on x86_64 Linux, native only). The remaining two signify an issue requiring a larger refactor, which I will do in a separate commit. Notable changes: * Fix uninitialized memory when allocating objects from free lists * Implement TypedValue printing for pointers * Fix some TypedValue printing logic * Work around non-existence of InternPool.remove implementation
2023-06-10Sema: emit error on @intToPtr with slice dest typemlugg
Resolves: #15967
2023-05-31add missing note "operation is runtime due to this operand"Evin Yulo
2023-05-31don't crash when can't evaluate comptime expression with inferred typeyujiri8
Closes #15911.
2023-05-31sema: add compile error for incorrect extern typeBogdan Romanyuk
2023-05-29Prevent analysis of functions only referenced at comptimemlugg
The idea here is that there are two ways we can reference a function at runtime: * Through a direct call, i.e. where the function is comptime-known * Through a function pointer This means we can easily perform a form of rudimentary escape analysis on functions. If we ever see a `decl_ref` or `ref` of a function, we have a function pointer, which could "leak" into runtime code, so we emit the function; but for a plain `decl_val`, there's no need to. This change means that `comptime { _ = f; }` no longer forces a function to be emitted, which was used for some things (mainly tests). These use sites have been replaced with `_ = &f;`, which still triggers analysis of the function body, since you're taking a pointer to the function. Resolves: #6256 Resolves: #15353
2023-05-22Sema: improve error message when calling optional functionVeikka Tuominen
Co-authored-by: wrongnull <wrongnull@gmail.com>
2023-05-20Zir: eliminate `field_call_bind` and `field_call_bind_named`mlugg
This commit removes the `field_call_bind` and `field_call_bind_named` ZIR instructions, replacing them with a `field_call` instruction which does the bind and call in one. `field_call_bind` is an unfortunate instruction. It's tied into one very specific usage pattern - its result can only be used as a callee. This means that it creates a value of a "pseudo-type" of sorts, `bound_fn` - this type used to exist in Zig, but now we just hide it from the user and have AstGen ensure it's only used in one way. This is quite silly - `Type` and `Value` should, as much as possible, reflect real Zig types and values. It makes sense to instead encode the `a.b()` syntax as its own ZIR instruction, so that's what we do here. This commit introduces a new instruction, `field_call`. It's like `call`, but rather than a callee ref, it contains a ref to the object pointer (`&a` in `a.b()`) and the string field name (`b`). This eliminates `bound_fn` from the language, and slightly decreases the size of generated ZIR - stats below. This commit does remove a few usages which used to be allowed: - `@field(a, "b")()` - `@call(.auto, a.b, .{})` - `@call(.auto, @field(a, "b"), .{})` These forms used to work just like `a.b()`, but are no longer allowed. I believe this is the correct choice for a few reasons: - `a.b()` is a purely *syntactic* form; for instance, `(a.b)()` is not valid. This means it is *not* inconsistent to not allow it in these cases; the special case here isn't "a field access as a callee", but rather this exact syntactic form. - The second argument to `@call` looks much more visually distinct from the callee in standard call syntax. To me, this makes it seem strange for that argument to not work like a normal expression in this context. - A more practical argument: it's confusing! `@field` and `@call` are used in very different contexts to standard function calls: the former normally hints at some comptime machinery, and the latter that you want more precise control over parts of a function call. In these contexts, you don't want implicit arguments adding extra confusion: you want to be very explicit about what you're doing. Lastly, some stats. I mentioned before that this change slightly reduces the size of ZIR - this is due to two instructions (`field_call_bind` then `call`) being replaced with one (`field_call`). Here are some numbers: +--------------+----------+----------+--------+ | File | Before | After | Change | +--------------+----------+----------+--------+ | Sema.zig | 4.72M | 4.53M | -4% | | AstGen.zig | 1.52M | 1.48M | -3% | | hash_map.zig | 283.9K | 276.2K | -3% | | math.zig | 312.6K | 305.3K | -2% | +--------------+----------+----------+--------+
2023-05-18Sema: simplify "duplicate test name" error messageAndrew Kelley
* Avoid redundant words ("found") - All compile errors are found by the compiler * Avoid unnecessary prepositions ("with") - There is a grammatically correct alternate word order without the preposition.
2023-05-18make `@trap` return unreachable/noreturn (#15749)zooster
`@trap` is a special function that we know never returns so it should behave just like `@panic` and `@compileError` do currently and cause the "unreachable code" + "control flow is diverted here" compile error. Currently, `@trap(); @trap();` does not cause this error. Now it does.
2023-05-15Merge pull request #15704 from Vexu/fix-memcpysetAndrew Kelley
`@mem{cpy,set}` fixes
2023-05-15Sema: add more type checks to `@mem{cpy,set}`Veikka Tuominen
Closes #15634 Co-authored-by: Dima Afanasyev <dimaafanasev@example.com>
2023-05-15correct error note and check type of extern variableswrongnull
2023-05-11Sema: fix crash when generating anon name on invalid codeVeikka Tuominen
Closes #15615
2023-05-11Sema: add error for resolving inferred error set of generic functionVeikka Tuominen
Closes #14991
2023-05-11Sema: make `@call` compile errors match regular callsVeikka Tuominen
Closes #15642
2023-05-11module: return null if no candidate srcJohn Schmidt
Closes #15572.
2023-05-10Merge pull request #15508 from r00ster91/semathingsVeikka Tuominen
Sema: fixes to error messages
2023-05-08Disallow named test decls with duplicate namesDominic
2023-05-07Fix parsing of hexadecimal literalsDominic
2023-05-06Sema: fix and improve errors for `for` loop objects and non-indexablesr00ster91
Operands to @memcpy and @memset were being called "for loop operands" in the error.
2023-05-06Sema: add some missing apostrophes to error messagesr00ster91
2023-04-30sema: improve the error message when coercing to []anyopaquekcbanner
2023-04-29Merge pull request #15503 from r00ster91/noinlineAndrew Kelley
Sema: emit error for always_inline call of noinline function
2023-04-29Sema: disallow indexing non-tuple structr00ster91
Fixes #15497
2023-04-29Sema: emit error for always_inline call of noinline functionr00ster91
Fixes #15489 This also lays the groundwork for exposing the whether or not a function is noinline in std.builtin.Fn as an `is_noinline: bool` field if we ever want to do that.
2023-04-26Merge pull request #15278 from ziglang/memcpy-memsetAndrew Kelley
change semantics of `@memcpy` and `@memset`
2023-04-26sema: add error for coercing a slice to an anyopaque pointerkcbanner